metalcorebear / Pi-Trader

A cryptocurrency day-trading bot for Raspberry Pi.
MIT License
47 stars 17 forks source link

TypeError: 'NoneType' object is not subscriptable #1

Open dRing2000 opened 3 years ago

dRing2000 commented 3 years ago

Initializing optimal trading strategy... Traceback (most recent call last): File "./run_bot.py", line 12, in <module> mojo.main(parameters.API_KEY, pair=parameters.pair, granularity=parameters.granularity, duration=parameters.duration, cash_buffer=parameters.cash_buffer, reframe_threshold=parameters.reframe_threshold, continuous=parameters.continuous, chandelier=parameters.chandelier) File "/home/pi/Pi-Trader-master/helper_monkey.py", line 309, in main history_array, buy_point, sell_point = iterate_signal(history_array, best_strategy, pair=pair, granularity=granularity, chandelier=chandelier) File "/home/pi/Pi-Trader-master/helper_monkey.py", line 230, in iterate_signal history_pd = strategize(history_pd, strategy=strategy, chandelier=chandelier) File "/home/pi/Pi-Trader-master/helper_monkey.py", line 113, in strategize if (m[i,3] > (m[i-1,3] + strategy['buy']*m[i-1,5])) and (m[i-1,5]>0): TypeError: 'NoneType' object is not subscriptable

got this after filling API key details and issuing ./run_bot.py command. I'm using XLM/BTC trading pair. 0 XLM, small amount of test BTC on account.

dRing2000 commented 3 years ago

I get the same error using the default BTC-USD trading pair also.

metalcorebear commented 3 years ago

Thanks for pointing this out. What is the granularity set to? I’ve not tested it at granularity values other than 300 (5 min) and 900 (15 min). I’ve also not tested with pairs other than USD-BTC. I’ll look into this a bit. It’s a new script and could be a little buggy.

Mushguys commented 3 years ago

As far as I can tell, this is caused when no strategies have a profit greater than zero. When that happens, no strategies "beat" the default best_strategy of None in find_optimal_strategy. This None is returned up the stack to main, which passes it to iterate_signal, which can't subscript it, thus the error.

metalcorebear commented 3 years ago

Oh interesting. That makes sense. I didn’t consider that potential failure point. Will update the script to correct that. Thanks for pointing it out.

metalcorebear commented 3 years ago

OK, I fixed the NoneType issue in the helper_monkey.py script. It will now default to a {'buy':1.0, 'risk':1.0} strategy in the event that an optimal strategy can't be found.

metalcorebear commented 3 years ago

When I have a little bit more time, I think I am going to add a feature where the user can override the strategy optimization and set a default strategy of their choosing.