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/

    Sampling 1 hour data every 5 seconds on Live data feed

    General Code/Help
    3
    4
    279
    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.
    • Maor Kima
      Maor Kima last edited by

      Hi Backtraders,
      first of all i've got to say that the platform ROCKS! one thing i'm having trouble to understand is the below:
      I have a strategy with an IBData feed (live) that will query hourly candles every 5 seconds. however, i couldn't get it to work using the below code:

      from_date= datetime.datetime.today() - datetime.timedelta(days=1)
      IBDataFactory = store.getdata
      IBDataFactory(dataname='AAPL',timeframe=bt.TimeFrame.Minutes, useRTH=True,compression=60,sectype='STK', fromdate=from_date,exchange='SMART',currency='USD')
      cerebro.adddata(dt,name='AAPL')
      

      also tried the following with no luck:

      store = bt.stores.IBStore(host='127.0.0.1', port=4002,clientId=15)
          from_date= datetime.datetime.today() - datetime.timedelta(days=1)
          IBDataFactory = store.getdata
      dt = IBDataFactory(dataname='AAPL',timeframe=bt.TimeFrame.Seconds,
                               compression=5,fromdate=from_date,useRTH=False,
                               sectype='STK', exchange='SMART',currency='USD',adjusted=True) 
      cerebro.replaydata(dt, timeframe=bt.TimeFrame.Minutes, compression=60)
      
      
      

      tried to read the replaydata / resample data documenatation but couldn't understand which should i use for my purpose.

      thanks in advance!

      1 Reply Last reply Reply Quote 0
      • Z
        zkl last edited by

        Hello,
        I have just started to play around with backtrader.
        With this I have some more progress (tested in jupyter notbook):


        import backtrader as bt
        import datetime

        from_date= datetime.datetime.today() - datetime.timedelta(days=1)

        IBDataFactory = store.getdata

        dt = IBDataFactory(dataname='AAPL',timeframe=bt.TimeFrame.Seconds,
        compression=5,fromdate=from_date,useRTH=False,
        sectype='STK', exchange='SMART',currency='USD',adjusted=True)

        cerebro = bt.Cerebro(stdstats=False)
        store = bt.stores.IBStore(port=7497)

        cerebro.replaydata(dt, timeframe=bt.TimeFrame.Minutes, compression=60)

        #Out[11]: <backtrader.feeds.ibdata.IBData at 0x7fde502ec650>

        cerebro.broker = store.getbroker()
        cerebro.run()

        #Server Version: 76
        #TWS Time at connection:20200618 20:56:55 CET

        I don't get the answer shown. But I was asked from the IB Program if i accept the connection

        1 Reply Last reply Reply Quote 0
        • run-out
          run-out last edited by

          @zkl Please have a look at the top of the posting for information about formatting your code to make it more readable for the user. Thanks :)

          RunBacktest.com

          1 Reply Last reply Reply Quote 0
          • Maor Kima
            Maor Kima last edited by

            @zkl was that an answer to my question or another question on my post? :)

            Anyway, I've achieved this by creating one IBData object that receives 1 second data and resample it with 60 minutes compression.

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