edeng23 / binance-trade-bot

Automated cryptocurrency trading bot
GNU General Public License v3.0
7.88k stars 2.19k forks source link

First API Call Failing Results in get_trade_fee() Error #284

Closed pes7 closed 3 years ago

pes7 commented 3 years ago

binance_trader | 2021-04-17 10:54:16,157 - crypto_trading_logger - ERROR - Error while scouting... binance_trader | Traceback (most recent call last): binance_trader | File "/app/binance_trade_bot/scheduler.py", line 25, in _run_job binance_trader | super()._run_job(job) binance_trader | File "/usr/local/lib/python3.8/site-packages/schedule/init.py", line 147, in _run_job binance_trader | ret = job.run() binance_trader | File "/usr/local/lib/python3.8/site-packages/schedule/init.py", line 491, in run binance_trader | ret = self.job_func() binance_trader | File "/app/binance_trade_bot/strategies/default_strategy.py", line 34, in scout binance_trader | self._jump_to_best_coin(current_coin, current_coin_price, all_tickers) binance_trader | File "/app/binance_trade_bot/auto_trader.py", line 140, in _jump_to_best_coin binance_trader | ratio_dict = self._get_ratios(coin, coin_price, all_tickers) binance_trader | File "/app/binance_trade_bot/auto_trader.py", line 127, in _get_ratios binance_trader | transaction_fee = self.manager.get_fee(pair.from_coin, self.config.BRIDGE, True) + self.manager.get_fee( binance_trader | File "/app/binance_trade_bot/binance_api_manager.py", line 44, in get_fee binance_trader | base_fee = self.get_trade_fees()[origin_coin + target_coin] binance_trader | File "/usr/local/lib/python3.8/site-packages/cachetools/decorators.py", line 22, in wrapper binance_trader | v = func(*args, **kwargs) binance_trader | File "/app/binance_trade_bot/binance_api_manager.py", line 37, in get_trade_fees binance_trader | return {ticker["symbol"]: ticker["taker"] for ticker in self.binance_client.get_trade_fee()["tradeFee"]} binance_trader | File "/usr/local/lib/python3.8/site-packages/binance/client.py", line 2169, in get_trade_fee binance_trader | if not res['success']: binance_trader | KeyError: 'success' binance_trader |

My time completely synked with docker container, second to second)

j-waters commented 3 years ago

I've noticed this issue being reported a few times, and usually it's a configuration or connection issue, so double check your config file.

To contributors: The reason it always happens here is that this is the first API request we make to Binance after starting the bot for the first time, so if there is such an issue this is where the crash happens, and it isn't very descriptive at all! The crash has nothing to with get_trade_fee. I think a good idea would be to make a request as soon as the bot starts just to make sure the config is okay, and if we get any errors print a message suggesting that the config is incorrect.

rel-s commented 3 years ago

Great catch @j-waters, we should probably add a call in the beginning to get the server time or something similar; that way we can fail gracefully.

rel-s commented 3 years ago

Ok, so getting the server time probably won't help here since it doesn't require valid API keys.