psemdel / py-trading-bot

Trading-bot in python using django, vertorbt lib and interactive-brokers
MIT License
141 stars 34 forks source link

cannot unpack non-iterable NoneType object #6

Closed ben1628 closed 1 year ago

ben1628 commented 1 year ago

I got this error when I try to run the 17h report, I guess I have to run something else first. I'm now using PostgreSQL so I can use ArrayField.

TypeError at /17h/ cannot unpack non-iterable NoneType object Request Method: GET Request URL: http://127.0.0.1:8000/17h/ Django Version: 4.1.4 Exception Type: TypeError Exception Value:
cannot unpack non-iterable NoneType object Exception Location: /home/usr/trading-bot/trading-bot/core/btP.py, line 55, in init Raised during: reporting.views.trigger_17h Python Executable: /home/usr/trading-bot/trading-bot/.vbt/bin/python Python Version: 3.8.10 Python Path:
['/home/usr/trading-bot/trading-bot', '/home/usr/trading-bot/trading-bot', '/home/usr/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/usr/trading-bot/trading-bot/.vbt/lib/python3.8/site-packages'] Server time: Thu, 15 Dec 2022 12:35:45 +0000 Traceback Switch to copy-and-paste view /home/usr/trading-bot/trading-bot/.vbt/lib/python3.8/site-packages/django/core/handlers/exception.py, line 55, in inner response = get_response(request) … Local vars /home/usr/trading-bot/trading-bot/.vbt/lib/python3.8/site-packages/django/core/handlers/base.py, line 197, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) … Local vars /home/usr/trading-bot/trading-bot/reporting/views.py, line 56, in trigger_17h report1.presel(st,"Paris") … Local vars /home/usr/trading-bot/trading-bot/reporting/models.py, line 250, in presel self.presel_sub(l,st,exchange,kwargs) … Local vars /home/usr/trading-bot/trading-bot/reporting/models.py, line 187, in presel_sub presel=btP.Presel(st=st,exchange=exchange) … Local vars /home/usr/trading-bot/trading-bot/core/btP.py, line 55, in init self.high, self.low, self.close, self.open,self.volume,\ …

psemdel commented 1 year ago

Hi, no normally it should run right away. Do you have something in your database? retrieve_data makes a for loop on the symbols, so if there is no symbol, it will send you this error (I should catch this error better obviously).

ben1628 commented 1 year ago

I did migrate and loaddata so there are data in the db.

The major problem I see is I'm not using VectorBT Pro, so the error may be due to that. For example, there are differences in the naming of the functions that I find so far.

1/ IndicatorFactory is now called IF 2/ from_apply_func is now called with_apply_func 3/ vbt.YFData.download_symbol is now called vbt.YFData.fetch??

the .download_symbol has similar syntax to .fetch, although that is when the code fails somewhere there. I don't have the documentation to confirm that. lol

psemdel commented 1 year ago

Your assumptions 1, 2 and 3 are correct. Are you sure that "st" is not None?

I am also testing on my side from 0. At row 355. normal_strat_act=StratCandidates.objects.get(strategy=Strategy.objects.get(name="normal"))

Can cause problem, if you don't have a strategy 'normal' and not StratCandidates 'normal'. (definitely one more thing to be improved)

ben1628 commented 1 year ago

Thanks for your quick reply.

I use download instead of download_symbol and it seems to work fine. Now I get into an error

at line 189 of orders/models.py

cours_action=cours.select(symbols) cours_open =cours_action.get('Open')

'YFData' object has no attribute 'select'

psemdel commented 1 year ago

Yes, select() is only in the pro version.

def select(self: DataT, symbols: tp.Union[tp.Symbol, tp.Symbols], **kwargs) -> DataT:
    """Create a new `Data` instance with one or more symbols from this instance."""
    if isinstance(symbols, list):
        single_symbol = False
    else:
        single_symbol = True
        symbols = [symbols]
    return self.replace(
        data=symbol_dict({k: v for k, v in self.data.items() if k in symbols}),
        single_symbol=single_symbol,
        symbol_classes=symbol_dict({k: v for k, v in self.symbol_classes.items() if k in symbols}),
        fetch_kwargs=symbol_dict({k: v for k, v in self.fetch_kwargs.items() if k in symbols}),
        returned_kwargs=symbol_dict(
            {k: v for k, v in self.returned_kwargs.items() if k in symbols},
        ),
        last_index=symbol_dict({k: v for k, v in self.last_index.items() if k in symbols}),
        **kwargs,
    )
ben1628 commented 1 year ago

it is missing DataT and symbol_dict, so there may be few more changes.

I end up creating my own select and that seems to work. Now working on the next issue, lol

psemdel commented 1 year ago

This select is quite useful. We could use download the data directly separately, but then there is a, huge, risk that the days are not aligned anymore between index and corresponding action prices. You need it only, if like me you make some calculation on the index and some other on the stock prices.

ben1628 commented 1 year ago

Okay, instead of trying to add functions that are not available in Vectorbt, the simple answer is just to get a copy of VectorBt Pro.

How often is the update in the Pro version?

It looks like it is not just a simple addon and enhancement in the pro version. I am hoping that you can spend some of your valuable time in getting trading-bot better. Lots to learn for me.

Please don't spend any time in getting this working for Vectorbt, it is just not worth your time.

psemdel commented 1 year ago

I also think that vbtpro is worth getting it. And yes, there are many improvements in it (and more to come!). But I also understand that it is an investment in the beginning in the unknown, as basically you cannot know if it will fullfil your needs. I am by the way also interested in alternative to IB, as to me it is very powerfull, but also quite constraining...

ben1628 commented 1 year ago

That is the main reason why I try to use the vectorbt community version and sqlite first. However, as soon as I see it working somewhat and see the potential of it, I get the pro version.