asavinov / intelligent-trading-bot

Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering
https://t.me/intelligent_trading_signals
MIT License
802 stars 179 forks source link

Problems trade status sync. 'NoneType' object has no attribute 'get' #47

Open posido opened 3 weeks ago

posido commented 3 weeks ago

Hi,

I am running: python -m service.server -c configs/config.jsonc

I get the error message shown in the screenshot.

image

asavinov commented 3 weeks ago

Hi, it seems to be a problem with trader. It is not tested in latest versions and might be removed in future. Do you have more output like log or stacktrace?

posido commented 3 weeks ago

Unfortunately, not. It seems to happen in Server.py:

image

Here you see the output "Balance: = 0.002...." misses the left side.

print(f"Balance: {App.config['base_asset']} = {str(App.base_quantity)}") print(f"Balance: {App.config['quote_asset']} = {str(App.quote_quantity)}")

base_asset and quote_asset is not set in App.py. might that be the reason?

base_asset": "", # BTC ETH quote_asset": "",

I did not set it as the readme says it is already configured for Bitcoin.

asavinov commented 3 weeks ago

If I use the sample config 'config-sample-v0.7.dev.jsonc' then I do not have any errors. This exception seems to be raised from 'trader.py' if I turn on the trade function by adding "actions": ["trade"] in the config. So if you want to run it without trade (and without this exceptions) then turn off trade mode by removing "trade" from "actions". It will not try to access your account where seem to be a problem.

posido commented 3 weeks ago

Yes, without trade it works. But of course at the end I want to try to trade with it.

asavinov commented 3 weeks ago

Could you check what is in your collector.log file. There should be an exception message like this one:

2024-06-08 18:05:49,982 DEBUG https://api.binance.com:443 "GET /api/v3/openOrders?symbol=BTCUSDT&timestamp=1717862749666&signature=xyz HTTP/1.1" 401 70
2024-06-08 18:06:35,664 ERROR Binance exception in 'get_open_orders' APIError(code=-2015): Invalid API-key, IP, or permissions for action.
posido commented 3 weeks ago

Right, didn't see that log before:

2024-06-08 18:16:01,347 INFO ===> Start trade task. Timestamp 1717870561347. Interval [1717870560000,1717870620000]. 2024-06-08 18:16:01,348 ERROR Wrong status value None. 2024-06-08 18:16:01,348 ERROR Task exception was never retrieved future: <Task finished name='Task-348' coro=<main_trader_task() done, defined at /home/posido/intelligent-trading-bot/service/trader.py:31> exception=AttributeError("'NoneType' object has no attribute 'get'")> Traceback (most recent call last): File "/home/posido/intelligent-trading-bot/service/trader.py", line 100, in main_trader_task signal_side = signal.get("side") ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get' 2024-06-08 18:17:01,007 INFO ===> Start collector task. Timestamp 1717870621007. Interval [1717870620000,1717870680000]. 2024-06-08 18:17:01,269 DEBUG https://api.binance.com:443 "GET /api/v3/klines?endTime=1717870621007&interval=1m&limit=4&symbol=BTCUSDT HTTP/1.1" 200 229 2024-06-08 18:17:01,271 DEBUG Stored klines. Total 2880 in db. Last kline end: 1717870620000. Current time: 1717870621270 2024-06-08 18:17:01,272 INFO <=== End collector task. 2024-06-08 18:17:01,272 INFO Analyze BTCUSDT. Last kline timestamp: 2024-06-08 18:16:00 2024-06-08 18:17:01,323 INFO Analyze finished. Close: 69,462 Signals: trade_score=-0.004, buy_signal_column=False, sell_signal_column=False 2024-06-08 18:17:01,346 INFO ===> Start trade task. Timestamp 1717870621346. Interval [1717870620000,1717870680000]. 2024-06-08 18:17:01,347 ERROR Wrong status value None. 2024-06-08 18:17:01,347 ERROR Task exception was never retrieved future: <Task finished name='Task-351' coro=<main_trader_task() done, defined at /home/posido/intelligent-trading-bot/service/trader.py:31> exception=AttributeError("'NoneType' object has no attribute 'get'")> Traceback (most recent call last): File "/home/posido/intelligent-trading-bot/service/trader.py", line 100, in main_trader_task signal_side = signal.get("side")

posido commented 3 weeks ago

Do you have an update on that issue? Many thanks!

asavinov commented 1 week ago

I tried to fix problems in binance trader but I cannot finally test it because I do not have a (working) API key. So let me know if you get any problems. Now actions attribute is not needed. To turn on Binance trading you need to set trade_model.trader_binance as well as all parameters after it. The logic is in the trader_binance.py in case you want to improve something.