pycryptobot
pycryptobot copied to clipboard
Pandas KeyError: 'currency'
Describe the bug Pandas failing with KeyError: 'currency'. Was running fine for few days and randomly failed
Error
Restarting application after exception: KeyError('currency')
JSONDecodeError: https://api.pro.coinbase.com/
KeyError('currency')
Traceback (most recent call last):
File "pandas\_libs\hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'currency'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\arman\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py", line 2897, in get_loc
raise KeyError(key) from err
KeyError: 'currency'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pandas\_libs\hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'currency'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\*\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py", line 2897, in get_loc
raise KeyError(key) from err
KeyError: 'currency'
Info
- Bot Version: 2.47.0
- Exchange: CoinbasePro
Config
"base_currency": "DOGE",
"quote_currency": "EUR",
"live": 1,
"verbose": 1,
"disablebuynearhigh": 1,
"disablebuyobv": 1,
"disablebuyelderray": 1,
"disablebullonly": 0,
"autorestart": 1,
"sellatresistance": 1,
"sellupperpcnt": 1,
"sellatloss": 0
Additional context Feeling like this is similar to "A KeyError means the key you gave pandas isn’t valid. In your case, there is no column named “*” in the Excel file you are reading."
And browsing the code seems it's due to:
https://github.com/whittlem/pycryptobot/blob/main/models/TradingAccount.py#L192
https://github.com/whittlem/pycryptobot/blob/main/models/exchange/coinbase_pro/api.py#L125
and then df_filtered = df[df['currency'] == currency]['available']
fails as there is no such key in an empty DataFrame
what is your python version ?
python3 -V
My python version is 3.9.5 but it doesn't matter really.
If I wrote something not understandably - everything works for me after restarting the bot and this was a one-off random failure that I posted so that a KeyError can be fixed - aka nothing critical. Everything that I could debug about it is in "Additional context"
sometime people missing the ".9" after "python3" command.
@hellresistor we have discussed this earlier, version 3.9 is not actually required, 3.6-3.7-3.8 will do as well. hence, using python3
does not change much.
Found that this happens when Coinbase throws 503 Got the same error again but now it started with these lines:
error: GET (503) https://api.pro.coinbase.com/accounts - ServiceUnavailable
Restarting application after exception: KeyError('currency')
error: GET (503) https://api.pro.coinbase.com/accounts - ServiceUnavailable
KeyError('currency')
Possible enhancement: wrap all requests in python try except blocks, to catch these errors early, and fail.
I think this could be a good first issue.