psemdel / py-trading-bot

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

An unexpected keyword argument 'single_key' #48

Closed Fun1628 closed 2 months ago

Fun1628 commented 3 months ago

Setting

USED_API_DEFAULT to use "IB" and
"DAILY_REPORT_PERIOD":2, #in year

because yfinance doesn't allow 3 years. The IB is running well and then it is using fetch_symbol in ib.py to fetch historical data and after finished, it got this error

100%|█████████████████████████████████████████████████████████████████████████████████████████| 99/99 [00:28<00:00,  3.48it/s, symbol=COMP]
[2024-08-21 13:41:13] WARNING 109 /home//vectorbt.pro-develop/vectorbtpro/data/base.py:1905: UserWarning: Symbols have mismatching index. Dropping missing data points.
  data = cls_or_self.align_index(data, missing=missing_index, silence_warnings=silence_warnings)

[2024-08-21 13:41:13] ERROR 160 IBData.__init__() got an unexpected keyword argument 'single_key'
Traceback (most recent call last):
  File "/home//trading-bot/trading-bot/core/data_manager_online.py", line 138, in retrieve_data_ib
    data=IBData.fetch(

single_key is from vectorbt pro. So something is interesting there.

psemdel commented 3 months ago

I am reading the code, I don't understand where VBT could have initiated IBData to give it this argument... very curious indeed.

Fun1628 commented 3 months ago

Not much we can do here

Fun1628 commented 2 months ago

Thanks to Cursor AI, I am able to fix the problem, the revised codes are

 def __init__(self, *args, single_key=True, **kwargs):
        super().__init__(*args, single_key=single_key, **kwargs)
        self.resolve_client(None)

What happened here is single_key was added in vectorbtpro, and we need to update IBData to match. The cursor AI really helps a lot, it can pinpoint the problem in seconds

Fun1628 commented 2 months ago

However, it causes other problem in the rest of the codes because they were expecting IBData(), so instead

 def __init__(self, *args, single_key=True, **kwargs):
        if not args and not kwargs:
            # This is the case for the original no-argument __init__
            self.resolve_client(None)
        else:
            # This is the case for the __init__ with arguments
            super().__init__(*args, single_key=single_key, **kwargs)
            self.resolve_client(None)