BenjiLee / PoloniexAnalyzer

Trade history and balance analyzer for Poloniex
MIT License
78 stars 22 forks source link

Error message? #24

Closed CasperNielsen closed 7 years ago

CasperNielsen commented 7 years ago

When i try to run the file with the API commands i get this error. It runs fine with the GetChangeOverTime arguments. Have checked my API key / Secret, but it seems fine.

Info: macOS Sierra 10.12.4
Python 2.7.10 (default, Feb  6 2017, 23:53:20)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

Can you spot the problem?

$ python poloniex.py -a CalculateFees
Traceback (most recent call last):
  File "poloniex.py", line 64, in <module>
    main()
  File "poloniex.py", line 56, in main
    actions[args.action]['function']()
  File "/Users/CasperVN/Downloads/PoloniexAnalyzer-master/analyzer.py", line 106, in calculate_fees
    trade_history = TradeHistory(trading_api.return_trade_history())
  File "/Users/CasperVN/Downloads/PoloniexAnalyzer-master/poloniex_apis/trading_api.py", line 60, in return_trade_history
    return _call_trading_api(body)
  File "/Users/CasperVN/Downloads/PoloniexAnalyzer-master/poloniex_apis/trading_api.py", line 84, in _call_trading_api
    response = urllib2.urlopen(request).read()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 422:
$
BenjiLee commented 7 years ago

Thanks for your bug report. I see this error occasionally but cannot reproduce this reliably.

Try again (maybe a different time of day) and see if you see that issue again.

https://github.com/Mikadily/poloniexlendingbot/issues/273

I'm going to leave this ticket open and see if I can add a better error message for the 422 error code.

d-fay commented 7 years ago

I just started getting this error today also. Keys still work with other apps.

BenjiLee commented 7 years ago

@d-fay @CasperNielsen Could you try creating a new api key/secret? Seemed to work for this person https://github.com/dutu/poloLender/issues/11 and also suggested in https://bitcointalk.org/index.php?topic=1715214.880

d-fay commented 7 years ago

@BenjiLee 422 error from my experience is too many API calls too fast. Considering that I am able to use this API key still with a different script, it does not seem to be the API key that is the issue. Instead their API appears to be unhappy with you app. I would venture a guess that your app might make too many sequential calls within a short period of time.

EDIT: I created a new API key and it is currently working again. I recommend spacing out your API calls a bit as well as catching this error and having the app retry again after a period of time.

BenjiLee commented 7 years ago

EDIT: I created a new API key and it is currently working again. I recommend spacing out your API calls a bit as well as catching this error and having the app retry again after a period of time.

The limit is 6 calls/second according to the Poloniex API doc and the max the scripts will call in a succession is 2. If I get closer to the limit of 6, I may consider added some throttling.

I've added an error message for now. https://github.com/BenjiLee/PoloniexAnalyzer/pull/26

d-fay commented 7 years ago

I must reiterate that at some point Polo decided it doesn't like your app as the API keys still work just not with this analyzer.

BenjiLee commented 7 years ago

@d-fay Thanks for mentioning that it works with other scripts. I think I know what the issue is. The Poloniex trading api uses a parameter called nonce which needs to be greater int than the last and this number persists on the account. If the script you ran is using a different nonce that what I am using (epoch time) than one of the scripts will get a 422. The script that gets the 422 is the one with the smaller nonce. The only solution here is to create a new API key for this script since each script uses their own system for the nonce parameter.

Is the other script you are using open source? I would like to confirm how they calculate the nonce parameter.