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/

    Help with Data Feed not recognized for IB Live Trading

    General Code/Help
    1
    2
    120
    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.
    • E
      esondrstd last edited by

      Hi ,

      I'm trying to add the following datafeed (TICK-NYSE) to the ibstore, but i keep getting a disconnected error (all other feeds working fine).

      Interestingly, I tested this ticker with a direct call to IB (using reqMktData() and reqHistoricalData() in a separate program (see below), and was able to get the data (TickTypes 1,2, and 4 had information, and TickType 4 ('LAST') was the data i needed.

      Wondering if this has to do with the fact that the sectype is an "IND" - saw you had some exception handling in files like 'ibstore.py' for other sectypes like "CASH", but couldn't quite follow the code (I'm still a Python novice).

      Any ideas on how to get this data working? Thanks in advance....

      Backtrader Data Feed code:

      store = bt.stores.IBStore(host='127.0.0.1',
      			port=7497,
      			clientId = 100)
      
      #ADD MARKET BREADTH DATA LIKE TICK
      indexdatalist = ['TICK-NYSE']  #MAKE SURE NO COMMAS AFTER LAST TICKER
      for i,j in enumerate(indexdatalist):
      	tickdata = store.getdata(dataname=j,
      				sectype='IND',
      				exchange='NYSE',
      				currency='USD',
      				timeframe=bt.TimeFrame.Minutes,
      				what = 'TRADES',
      				tz = pytz.timezone('US/Central'),
      				sessionstart = session_start,
      				sessionend = session_end,
      				)
      

      Here is the error message:

      Datas in Strategy TICK-NYSE0
      Start preloading data to meet minimum data requirements
      ***** DATA NOTIF: DISCONNECTED
      

      Here is the separate program (direct call to IB outside backtrader framework) where data feed works:

      from ibapi.client import EClient
      from ibapi.wrapper import EWrapper
      import threading
      import time
      from ibapi.ticktype import TickTypeEnum	
      from ibapi.contract import Contract
      #from ibapi.ticktype import TickTypeEnum
      							
      class IBapi(EWrapper, EClient):
          def __init__(self):
              EClient.__init__(self, self)
          def tickPrice(self, reqId, tickType, price, attrib):
      	print(tickType,price)
      									
          def historicalData(self, reqId, bar):
      	print(f'Time: {bar.date} Close: {bar.close}')
      	app.data.append([bar.date, bar.close])						
      
      def run_loop():
      	app.run()
      
      app = IBapi()
      app.connect('127.0.0.1', 7497, 100)
      
      #Start the socket in a thread
      api_thread = threading.Thread(target=run_loop, daemon=True)
      api_thread.start()
      
      time.sleep(1) #Sleep interval to allow time for connection to server
      
      #Create contract object
      contract = Contract()
      
      contract.symbol = 'TICK-NYSE'
      contract.secType = 'IND'
      contract.exchange = 'NYSE'
      contract.currency = 'USD'
      #Request Market Data
      app.reqMktData(1, contract, '' , False, False, [])
      
      app.data = [] #Initialize variable to store candle
      
      #Historical Candlestick data request
      app.reqHistoricalData(1, contract, '', '2 D', '1 hour', 'TRADES', 0, 2, True, [])
      
      time.sleep(10) #Sleep interval to allow time for incoming price data
      

      Here's the data loaded from the above program:

      ERROR:ibapi.wrapper:ERROR -1 2104 Market data farm connection is OK:usfarm
      ERROR:ibapi.wrapper:ERROR -1 2106 HMDS data farm connection is OK:ushmds.nj
      ERROR:ibapi.wrapper:ERROR -1 2106 HMDS data farm connection is OK:cashhmds
      ERROR:ibapi.wrapper:ERROR -1 2106 HMDS data farm connection is OK:ushmds
      ERROR:ibapi.wrapper:ERROR -1 2158 Sec-def data farm connection is OK:secdefnj
      Time: 1586352600 Close: -353.0
      Time: 1586354400 Close: 134.0
      Time: 1586358000 Close: 0.0
      Time: 1586361600 Close: -63.0
      Time: 1586365200 Close: -287.0
      Time: 1586368800 Close: 59.0
      Time: 1586372400 Close: 15.0
      Time: 1586439000 Close: 246.0
      Time: 1586440800 Close: 123.0
      Time: 1586444400 Close: 220.0
      Time: 1586448000 Close: -31.0
      Time: 1586451600 Close: -5.0
      Time: 1586455200 Close: 269.0
      Time: 1586458800 Close: -538.0
      ERROR:ibapi.wrapper:ERROR -1 2104 Market data farm connection is OK:usfarm.nj
      1 -1.0
      2 -1.0
      4 -402.0
      9 0.0
      4 -334.0
      4 -234.0
      4 -218.0
      4 -302.0
      
      1 Reply Last reply Reply Quote 0
      • E
        esondrstd last edited by

        Just following up on this. I figured out why the ticker was not recognized (Backtrader's parsing logic parses with a '-' which was effectively splitting the ticker name into 2 separate parts) - I tweaked the code to bypass the parser for this ticker.

        I can now see prices streaming for TICK-NYSE, but only when i print "price" from within the RTVolume Class of ibstore.py. When outputted by next() at my time interval, i only see prices of -1. Any ideas?

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }