Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hems opened this issue Apr 30, 2016 · 11 comments
Open

Comments

@hems
Copy link

hems commented Apr 30, 2016

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
Copy link
Author

hems commented May 5, 2016

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
Copy link
Author

hems commented May 6, 2016

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

@afanasy
Copy link

afanasy commented Jul 23, 2016

@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
Copy link

afanasy commented Jul 23, 2016

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

@rferro
Copy link
Owner

rferro commented Aug 27, 2016

@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

@hems
Copy link
Author

hems commented Aug 29, 2016

@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.... ?

@afanasy
Copy link

afanasy commented Aug 29, 2016

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

@hems
Copy link
Author

hems commented Sep 1, 2016

@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

@afanasy
Copy link

afanasy commented Sep 2, 2016

@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

@hems
Copy link
Author

hems commented Sep 5, 2016

@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 !

@rafaelcmrj
Copy link

rafaelcmrj commented Sep 9, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants