Backtrader Community

    • 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/

    IB market data subscriptions & End Date/Time: The date, time, or time-zone entered is invalid.

    General Code/Help
    5
    5
    331
    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.
    • F
      floodfill last edited by

      I can't establish FX market data subscriptions against paper account TWS. I had this working previously, now it stopped working and I can't figure out what change on my side caused this.

      Can someone please let me know what I am doing wrong?

      Thanks.

      Code with dummy mean reverting strat:

      import backtrader as bt
      import meanrev as mr
      
      def run(args=None):
          cerebro = bt.Cerebro()
          store = bt.stores.IBStore(host='127.0.0.1', port=4002, clientId=None, reconnect=100, timeout=3.0, _debug=False)
      
          for sym,config in mr.syms.items():
              print('starting strategy for ' + sym)
              data = store.getdata(dataname=f"{sym}-CASH-IDEALPRO", tradename=f"{sym[:3]}-CFD-SMART-{sym[4:]}", timeframe=bt.TimeFrame.Ticks)
              cerebro.resampledata(data, timeframe=bt.TimeFrame.Seconds, compression=30)
          
              cerebro.addstrategy(mr.MeanRevStrat, md=data, sym=sym, config=config)
      
          cerebro.broker = store.getbroker()
          cerebro.run()
      
      if __name__ == '__main__':
          run()
      

      From IB logs API:

      10:21:34:256 <- 20-5-16777228-12087792-EUR-CASH--0.0---IDEALPRO--USD-EUR.USD-EUR.USD-0-20220914 09:21:33 GMT-30 secs-28800 S-0-BID-2-
      10:21:34:277 -> 4-2-16777228-10314-End Date/Time: The date, time, or time-zone entered is invalid. The correct format is yyyymmdd hh:mm:ss xxx where yyyymmdd and xxx are optional. E.g.: 20031126 15:59:00 US/Eastern  Note that there is a space between the date and time, and between the time and time-zone.  If no date is specified, current date is assumed. If no time-zone is specified, local time-zone is assumed(deprecated).  You can also provide yyyymmddd-hh:mm:ss time is in UTC. Note that there is a dash between the date and time in UTC notation.-
      

      venv depedencies:

      backtrader      1.9.76.123
      cycler          0.11.0
      fonttools       4.33.3
      ibapi           9.81.1.post1
      IbPy2           0.8.0
      kiwisolver      1.4.3
      matplotlib      3.5.3
      numpy           1.23.0
      packaging       21.3
      pandas          1.4.3
      Pillow          9.2.0
      pip             22.0.2
      pyparsing       3.0.9
      python-dateutil 2.8.2
      pytz            2022.1
      setuptools      59.6.0
      six             1.16.0
      

      TWS versions:

      Build 10.18.1d, Sep 13, 2022 3:41:49 PM 
      Jolt Build 1.18.9, Jul 5, 2022 05:27:19 PM 
      Nia Build 2.24.2, Jan 17, 2022 05:48:10 PM 
      ModelNav Build 1.13.2, Jan 24, 2022 04:59:21 PM 
      Riskfeed Build 2.45.3, Jul 25, 2022 06:42:42 PM
      
      1 Reply Last reply Reply Quote 0
      • C
        colin last edited by

        @emr what would the solution to this be for people who require backfilling/historical data? Here is the relevant piece of my script:

        ibstore = backtrader.stores.IBStore(host='127.0.0.1', port=7497 if args.paper else 7496)
        cerebro.setbroker(ibstore.getbroker())
        data_backfill = ibstore.getdata(
            dataname=f'ES-{contract_date}-GLOBEX-USD', timeframe=backtrader.TimeFrame.Seconds,
            historical=True, fromdate=now.date(), tz='Canada/Mountain'
        )
        live_data = ibstore.getdata(
            dataname=f'ES-{contract_date}-GLOBEX-USD',
            timeframe=backtrader.TimeFrame.Seconds,
            compression=1,
            tz='Canada/Mountain',
            backfill_from=data_backfill,
            qcheck=0.1,
            filters=[btfilters.SessionFiller]
        )
        

        ^ This used to work until the IB change roughly a week ago. Similar to what you said, my code works when I set historical=False and remove backfill_from from the live_data. I'd greatly prefer a fix that lets me keep the backfilling components though.

        1 Reply Last reply Reply Quote 0
        • sickboy_76au
          sickboy_76au last edited by

          Hi everyone, I am experiencing the same issue. was moving house and hadnt run my algo for a month or so just got setup and it stopped working. Traced it to IB requiring date data in YYYYMMDD format. My code checks the last date for data and begins pulling from that date, that format is used throughout the program so changing it is problematic as it is different to format backtrader uses, any other ideas would be really appreciated.

          1 Reply Last reply Reply Quote 0
          • sickboy_76au
            sickboy_76au last edited by

            @vuduclong0309, I rebuilt the part of the algo that calls to backfill the data into a separate module that runs on its own, it wasnt the ideal solution but has worked so my algo now only calls live data.

            vuduclong0309 1 Reply Last reply Reply Quote 0
            • vuduclong0309
              vuduclong0309 @sickboy_76au last edited by

              @sickboy_76au Nice. I just started using Backtrader, so your approach might be out of reach to me at the moment, but this might be a nice idea for me to experiment later on. Cheers.

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