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



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



  • 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



  • @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 :)



  • @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.


Log in to reply
 

});