atreyuxtrading / atreyu-backtrader-api

Atreyu's integration of IB Native API with backtrader
BSD 2-Clause "Simplified" License
91 stars 58 forks source link

IndexError: list index out of range #10

Closed stefanppetkov closed 8 months ago

stefanppetkov commented 1 year ago

Trying to run TestStrategy in paper trading mode. I can get data if ibstore.getbroker() is not run, otherwise the following error appears. Would be grateful for any help!

File "/Users/stefan/strategies/come_on/at_api_test_live.py", line 134, in <module> cerebro.run() File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/backtrader/cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/backtrader/cerebro.py", line 1187, in runstrategies self._broker.start() File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibbroker.py", line 288, in start File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibstore.py", line 2050, in reqAccountUpdates IndexError: list index out of range

t3chap commented 1 year ago

I am also having this problem or a related one. If I don't pass an account number, I get the following error message: `--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Cell In[1], line 168 166 broker = ibstore.getbroker() 167 cerebro.setbroker(broker) --> 168 stats = cerebro.run()

File ~/miniconda3/lib/python3.9/site-packages/backtrader/cerebro.py:1127, in Cerebro.run(self, **kwargs) 1123 if not self._dooptimize or self.p.maxcpus == 1: 1124 # If no optimmization is wished ... or 1 core is to be used 1125 # let's skip process "spawning" 1126 for iterstrat in iterstrats: -> 1127 runstrat = self.runstrategies(iterstrat) 1128 self.runstrats.append(runstrat) 1129 if self._dooptimize:

File ~/miniconda3/lib/python3.9/site-packages/backtrader/cerebro.py:1187, in Cerebro.runstrategies(self, iterstrat, predata) 1184 for orders, onotify in self._ohistory: 1185 self._broker.add_order_history(orders, onotify) -> 1187 self._broker.start() 1189 for feed in self.feeds: 1190 feed.start()

File ~/miniconda3/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibbroker.py:288, in IBBroker.start(self) 286 self.ib.start(broker=self) 287 if self.ib.connected(): --> 288 self.ib.reqAccountUpdates() 289 self.startingcash = self.cash = self.ib.get_acc_cash() 290 self.startingvalue = self.value = self.ib.get_acc_value()

File ~/miniconda3/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibstore.py:2055, in IBStore.reqAccountUpdates(self, subscribe, account) 2048 '''Proxy to reqAccountUpdates 2049 2050 If account is None, wait for the managedAccounts message to 2051 set the account codes 2052 ''' 2053 if account is None: 2054 # self._event_managed_accounts.wait() -> 2055 account = self.managed_accounts[0] 2057 self.conn.reqAccountUpdates(subscribe, bytes(account))

IndexError: list index out of range`

I then pass the account via a kwarg when the ibstore is called, and I get the following error message:

`--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[2], line 168 166 broker = ibstore.getbroker() 167 cerebro.setbroker(broker) --> 168 stats = cerebro.run()

File ~/miniconda3/lib/python3.9/site-packages/backtrader/cerebro.py:1127, in Cerebro.run(self, **kwargs) 1123 if not self._dooptimize or self.p.maxcpus == 1: 1124 # If no optimmization is wished ... or 1 core is to be used 1125 # let's skip process "spawning" 1126 for iterstrat in iterstrats: -> 1127 runstrat = self.runstrategies(iterstrat) 1128 self.runstrats.append(runstrat) 1129 if self._dooptimize:

File ~/miniconda3/lib/python3.9/site-packages/backtrader/cerebro.py:1187, in Cerebro.runstrategies(self, iterstrat, predata) 1184 for orders, onotify in self._ohistory: 1185 self._broker.add_order_history(orders, onotify) -> 1187 self._broker.start() 1189 for feed in self.feeds: 1190 feed.start()

File ~/miniconda3/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibbroker.py:290, in IBBroker.start(self) 288 self.ib.reqAccountUpdates() 289 self.startingcash = self.cash = self.ib.get_acc_cash() --> 290 self.startingvalue = self.value = self.ib.get_acc_value() 291 else: 292 self.startingcash = self.cash = 0.0

File ~/miniconda3/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibstore.py:2178, in IBStore.get_acc_value(self, account) 2165 '''Returns the net liquidation value sent by TWS during regular updates 2166 Waits for at least 1 successful download 2167 (...) 2172 corresponding to that account is returned 2173 ''' 2174 # Wait for at least 1 account update download to have been finished 2175 # before the value can be returned to the calling client 2176 # Lock access to acc_cash to avoid an event intefering -> 2178 with self._updacclock: 2179 if account is None: 2180 if not self.managed_accounts:

AttributeError: 'IBStore' object has no attribute '_updacclock'`