plnx
plnx copied to clipboard
automatically delay call if last call was too recent or maybe not finished?
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?
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?
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 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.
@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 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.... ?
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 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 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 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 !
@rferro any chance to merge branch issue-5 into master ?