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/

    Custom live data feed not calling _load

    General Code/Help
    2
    2
    939
    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.
    • J
      jpjamipark last edited by

      Hi. First off, thanks so much for writing this library.

      I've been working on implementing a live feed for use with Intrinio's IEX socket data. I'm trying to get just a hacky implementation up using Intrinio's python client before I start really integrating the 2 together.

      class MetaIntrinioData(DataBase.__class__):
          def __init__(cls, name, bases, dct):
              '''Class has already been created ... register'''
              # Initialize the class
              super(MetaIntrinioData, cls).__init__(name, bases, dct)
      
      class IntrinioData(with_metaclass(MetaIntrinioData, DataBase)):
              def __init__(self):
          options = {
              'username': 'afc02b9ad3eb215c40fe1d2b0117fda0',
              'password': '3fc9c2dc9db2288887a68c0a8d89965c',
              'provider': 'iex',
              'on_quote': self.on_quote
          }
          self.client = IntrinioRealtimeClient(options)
          self.queue = Queue(25000)
      
          super(IntrinioFeed, self).__init__()
      
          def on_quote(self, quote, backlog):
          # print("QUOTE: ", quote, "BACKLOG LENGTH: ", backlog)
          self.queue.put(quote)
      
          def islive(self):
          '''Returns ``True`` to notify ``Cerebro`` that preloading and runonce
          should be deactivated'''
          return True
      
          def start(self):
          #listen to stocks (eventually set by user)
          self.client.join(['AAPL', 'GE', 'MSFT'])
          self.client.connect()
          self.client.keep_alive()
      
          super(IntrinioFeed, self).start()
      
          def haslivedata(self):
              return bool(self.backlog)
      
          def stop(self):
              self.client.disconnect()
      
          def _load(self):
              print("yo")
              while True:
                  if self.islive() == True:
                      try:
                          print(self.client.quotes.get())
                          #get message, put in queuee
                      except queue.Empty:
                          if True:
                              return None
      
                      ret = self._load_tick(self.msg)
                      if ret:
                          return True
      
      
          def _load_tick(self, msg):
              dtobj = datetime.utcfromtimestamp(msg['timestamp'])
              dt = date2num(dtobj)
              if dt <= self.lines.datetime[-1]:
                  return False  # time already seen
      
              # Common fields
              self.lines.datetime[0] = dt
              self.lines.volume[0] = msg['volume']
      
              # Put the prices into the bar
              tick = msg['price']
              self.lines.open[0] = tick
              self.lines.high[0] = tick
              self.lines.low[0] = tick
              self.lines.close[0] = tick
      
              return True
      

      This code is still quite hacky, but when I try to test using a dummy strategy, nothing is called. The client connects to the server, and starts filling the queue, but _load and start is not called at all. What am I missing/doing incorrectly?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        As you also mention, the code seems too hacky to make any real assertion.

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