pycryptobot icon indicating copy to clipboard operation
pycryptobot copied to clipboard

Pandas KeyError: 'currency'

Open arma6655 opened this issue 3 years ago • 6 comments

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

arma6655 avatar Jul 15 '21 06:07 arma6655

what is your python version ? python3 -V

hellresistor avatar Jul 15 '21 17:07 hellresistor

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"

arma6655 avatar Jul 15 '21 20:07 arma6655

sometime people missing the ".9" after "python3" command.

hellresistor avatar Jul 15 '21 20:07 hellresistor

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

lazydroid avatar Jul 17 '21 08:07 lazydroid

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')

arma6655 avatar Jul 23 '21 08:07 arma6655

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.

loomsen avatar Aug 02 '21 14:08 loomsen