plnx icon indicating copy to clipboard operation
plnx copied to clipboard

automatically delay call if last call was too recent or maybe not finished?

Open hems opened this issue 8 years ago • 11 comments

I'm having an issue where i'm calling "returnCompleteBalances" and "getMarginPosition" together every minute and sometimes the "nonce" problem comes back again.

One work around that might be "ok" is to automatically delay a call let's say 50ms if the last call was done less than 50 ms ago, so hopefully they will arrive "in order" on the server?

Maybe this 50ms could be configurable? I'm not even sure if that would sort out the issue, but from my current experience it seems that adding a little delay kinda helps?

hems avatar Apr 30 '16 05:04 hems

From my tests i can see that happening sometimes when calling a method only 2 ms afterwards, for instance:

nounce -> 1462487495057001 nounce -> 1462487495059001 (STDERR) Nonce must be greater than 1462487495059001. You provided 1462487495057001

so perhaps scheduling private methods to happen at least 10 ms distance might be enough for this case?

my use case is: i have a few keys and i'm trying to pull the balance and positions for all of them in a timeout, i could implement the queueing on my side but perhaps would be safer to have it on the library?

hems avatar May 05 '16 22:05 hems

One temporary solution i found is to retry one time if it fails, it seems to eliminate 100% of the error calls on my console, not sure if this workaround is good enough, time will tell (( :

retry_once = ( method, data, callback ) ->

  retried = false

  method data, ( error, result ) ->

    if error and not retried
      retried = true

      return method data, callback

    callback error, result  

Maybe checking for retrying only for nonce errors would be better

hems avatar May 06 '16 01:05 hems

@hems I'm having the same issue too (nonce problems when calling methods too frequently). It probably happens because request are being processed in the reverse order on the server, so there I don't see how it can be fixed on the client side, except making calls sync and going one by one.

afanasy avatar Jul 23 '16 09:07 afanasy

what worked for me is using underscore's throttle/debounce funcs to wrap up the plnx calls

afanasy avatar Jul 23 '16 09:07 afanasy

@hems @afanasy I did several tests and the only way that I found was to use a requests queue, running one at a time. Use a delay only decreases, but the problem continues. Take a look at the branch issue-5. Ty

rferro avatar Aug 27 '16 06:08 rferro

@rferro yeah that would be a solution.

in the other hand, i have implemented "automatically retry once" on my application and that has sorted out 99.9999999% of the cases.

as in: if there is a NONCE problem, retry straight away. i believe this solution - retrying up to 2 or 3 times - before calling the callback would be enough.... ?

hems avatar Aug 29 '16 06:08 hems

I'm using a queue too. Another thought was to use separate API keys for separate calls, but I haven't tried this yet.

afanasy avatar Aug 29 '16 12:08 afanasy

@afanasy AFAIK you can specify API keys for each of the calls using the key/secret param?

i wasn't aware you can set a default API key

hems avatar Sep 01 '16 06:09 hems

@hems what I meant by separate API keys is that you can create several key/secret pairs on Poloniex, and each pair (probably) will have it's own nonce, so there should be no nonce clashing if you use one key/secret pair per API call

afanasy avatar Sep 02 '16 02:09 afanasy

@afanasy got it! interesting approach (( :

so you pass a list of API keys and it would rotate between 2 or 3 of them, sounds like it could work!

the rate limit would still be the same, but the nonce problem could potentially go away !

hems avatar Sep 05 '16 04:09 hems

@rferro any chance to merge branch issue-5 into master ?

rafaelcmrj avatar Sep 09 '16 15:09 rafaelcmrj