array index out of range linebuffer.py
-
I get an error saying
COde -
class BrokerFeed(DataBase):
params = (('dataname', None),
# ('fromdate', datetime.datetime.min),
# ('todate', datetime.datetime.max),
('name', ''),
('compression', 1),
('timeframe', TimeFrame.Minutes),
('sessionend', None),
)datafields = [ 'datetime', 'open', 'high', 'low', 'close', 'volume', 'openinterest' ] def __init__(self, user_data, access_data, scrip_code): self.ws = broker_ws(user_data, access_data) self.scrip_code = scrip_code self.price = None self.isOpen = True _thread.start_new_thread(self._timerstart, (1,)) def _timerstart(self, n): while True: if self.isOpen == False: self.isOpen = True time.sleep(n) def start(self): # super(BrokerFeed, self).start() self.ws.on_ticks = self.on_price self.ws.on_connect = self.on_join self.ws.connect() def on_join(self, ws, response): self.ws.subscribe([self.scrip_code]) self.ws.set_mode(ws.MODE_FULL, [self.scrip_code]) def on_price(self, ws, price): self.price = price self._load() def _load(self): if self.isOpen == True: price = self.price t = price[0]['timestamp'] o = price[0]['ohlc']['open'] h = price[0]['ohlc']['high'] l = price[0]['ohlc']['low'] c = price[0]['ohlc']['close'] v = price[0]['volume'] oi = price[0]['oi'] print(t, o, h, l, c, v, oi) dt = bt.date2num(t) # Set the standard datafields # for datafield in self.getlineal # convert to float via datetime and store it # dt = tstamp.to_pydatetime() # dtnum = date2num(dt) # self.lines.datetime[0] = dtnum # self.lines.datetime[0] = dt self.lines.open[0] = o self.lines.high[0] = h self.lines.low[0] = l self.lines.close[0] = c self.lines.volume[0] = v return True else: return None def notify_data(self, data, status, *args, **kwargs): if status == data.LIVE: print("live data") elif status == data.DELAYED: print("DELAYED data") def haslivedata(self): return True # must be overriden for those that can def islive(self): return True
Error : builtins.IndexError: array assignment index out of range at line self.lines.open[0] = o
Please help me !
-
@rajanprabu Could you please share your valuable insights on this issue ? It's related to how you integrated KiteTIcker with Backtrader . Any help would be greatly appreciiated !
-
FIrst suspect please check lenght of
self.lines.open
Usually the error states that the index that you are trying to address is not valid.
Lines are as far as I understood no normal python lists and needs to be treated differently.It seems here that you are trying to add the latest value.
If you want to do that check other implementations:
https://github.com/Dave-Vallance/bt-ccxt-store/blob/master/ccxtbt/ccxtfeed.py