Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    array index out of range linebuffer.py

    General Code/Help
    2
    3
    124
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      shubhamj7888 last edited by

      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 !

      Kjiessar 1 Reply Last reply Reply Quote 0
      • S
        shubhamj7888 last edited by

        @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 !

        1 Reply Last reply Reply Quote 0
        • Kjiessar
          Kjiessar @shubhamj7888 last edited by

          @shubhamj7888

          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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors