Interactive Broker on daily data and paper account
-
I'm trying to connect to IB with paper account to receive daily bars
cerebro = bt.Cerebro() ibstore = bt.stores.IBStore(host='127.0.0.1', port=8002, clientId=3,notifyall=True) cerebro.broker = ibstore.getbroker() ib_dataname = 'TWTR-STK-SMART-USD' data = ibstore.getdata(dataname=ib_dataname,name='TWTR',timeframe=bt.TimeFrame.Days,compression=1,rtbar=False) cerebro.resampledata(data, timeframe=bt.TimeFrame.Days, compression=1) cerebro.adddata(data) cerebro.addstrategy(strategy) cerebro.run()
After strategy init I get the message "Requested market data is not subscribed"
Since I did not configure ib store to receive rt data,can anyone explain the error mesage ?
Whan receiving daily bars, when exactly during the trading day is the bar accepted? end of day?
Thank you. -
@Trade-Prophet just wild guess - maybe you need subscription for real time data thru IB. By default all prices are delayed.
-
@Trade-Prophet said in Interactive Broker on daily data and paper account:
Since I did not configure ib store to receive rt data,can anyone explain the error mesage ?
Can you elaborate on what do you actually mean with it?
Unless my understanding of the
IBStore
is completely wrong you are requesting real-time data.Additionally and as pointed by @ab_trader
@ab_trader said in Interactive Broker on daily data and paper account:
@Trade-Prophet just wild guess - maybe you need subscription for real time data thru IB
You need a subscription even if request historical data. Getting delayed data quotes in TWS is not the same as being able to download them in your own client through the API.
-
Problem Solved!
Issues I had in the process:
- Paper account may receive RT bars(like 1 or 5 minutes bars), to enable that you need to enable "Share real-time market data subscriptions with paper trading account" option in your real live account, ask IB support for help to find it
- You MUST run the trading strategy on the same computer where the real live account runs, it's not possible to have the live account run TWS on one computer and the paper TWS run on another
once you take care of the above, the Backtrader running IB trading should start to trade with the paper account
-
Bit late here but would like to know how it got solved for you.
I qualify both the above conditions but still I am not getting historical data.
My code is as below :
from _datetime import datetime import backtrader as bt # Create a Stratey class TestStrategy(bt.Strategy): def log(self, txt, dt=None): ''' Logging function for this strategy''' dt = dt or self.datas[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataclose = self.datas[0].close def next(self): # Simply log the closing price of the series from the reference self.log('Close, %.2f' % self.dataclose[0]) if __name__ == '__main__': # Create a cerebro entity cerebro = bt.Cerebro() ibstore = bt.stores.IBStore(host='127.0.0.1', port=7497, clientId=777) #ibstore = bt.stores.IBStore(host='127.0.0.1', port=4002, clientId=6666666) data = ibstore.getdata(dataname="ITC-STK-SMART-IND", historical=True, fromdate=datetime(2019, 1, 1), todate=datetime(2019, 8, 1), timeframe=bt.TimeFrame.Minutes, compression=5) cerebro.adddata(data) cerebro.addstrategy(TestStrategy) cerebro.broker.setcash(100000.0) # Print out the starting conditions print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) # Run over everything cerebro.run() # Print out the final result print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
Getting below output without data :
Starting Portfolio Value: 100000.00 Final Portfolio Value: 100000.00
Please advise