Interactive Brokers for orders only ,not for data feed
Is it possible to use IB for buy/sell orders (+portfolio status) but take the ticker data from a csv file ?
Can I replace the
cerebro.adddata(...)line, in the following example?
cerebro = bt.Cerebro() ibstore = bt.stores.IBStore(host='127.0.0.1', port=1001, clientId=33,notifyall=True) cerebro.broker = ibstore.getbroker() for ticker in ['AAPL', 'XOM']: ib_dataname = ticker+'-STK-SMART-USD' data = ibstore.getdata(dataname=ib_dataname,name=ticker,timeframe=bt.TimeFrame.Days, compression=1,rtbar=False) cerebro.adddata(data)
Data feeds and brokers are independent.
But you still need a contract reference for the
Brokerconnecting to Interactive Brokers, to let it know what it is being bought and sold.
Hi and thank you for your reply,
Can you elaborate what that means?
The broker needs to know what is being bought and sold. Your
csvbased data feed is not a reference for anything when talking to Interactive Brokers. You need a data feed from Interactive Brokers, even if only for it to be the target of your order.
Addtionally and taking into account that you are clearly developing software for a 3rd party and trying to get free information from the community, you could be the one actually elaborating your questions.
The software I develop is for my personal use only and I'm not trying to get anything for free,I have my own .csv files with up-to-date historical quotes which I would like to use as the data feed, while the bt-ib interface is not working smoothly,this is why I wanted to know if I may use the up-to-date csv file as datafeed while leaving the bt-ib interface for orders and portfolio status,I have done this before with C++ TWS interface and it worked fine.
cwse last edited by
I have a similar question as I have a paid data source from elsewhere and was hoping I didn't need to pay more and subscribe to IB data also... is there no way following connection to the IB broker and TWS, that I can place orders using my own data... and the correct IB ticker names?
cwse last edited by cwse
@backtrader another reason to use my own data instead of IB -- I have many custom columns in my data which I use to help make trading decisions.
Also: this error may be related. I connected to the IB broker and used my own data, at the begining of
Next()I get this error:
Traceback (most recent call last): File "D:/Google Drive/Capriole Production/Python Production/Processor/Backtrader.py", line 1084, in <module> timer = RunStrategy(timer,minholddays=v.minholddays,buyscore=v.buyscore,mode=mode) File "D:/Google Drive/Capriole Production/Python Production/Processor/Backtrader.py", line 1008, in RunStrategy results = cerebro.run(runonce=False, writer=True, quicknotify=False) File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies self._runnext(runstrats) File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1630, in _runnext strat._next() File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\strategy.py", line 347, in _next super(Strategy, self)._next() File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\lineiterator.py", line 266, in _next self.next() File "D:/Google Drive/Capriole Production/Python Production/Processor/Backtrader.py", line 277, in next for i, d in enumerate(d for d in self.datas if self.broker.getposition(d).size): File "D:/Google Drive/Capriole Production/Python Production/Processor/Backtrader.py", line 277, in <genexpr> for i, d in enumerate(d for d in self.datas if self.broker.getposition(d).size): File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\brokers\ibbroker.py", line 306, in getposition return self.ib.getposition(data.tradecontract, clone=clone) File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\lineseries.py", line 461, in __getattr__ return getattr(self.lines, name) AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'tradecontract'
bb2 last edited by bb2
@cwse in that case i would write my own data feed of the custom source for backtrader and use ib_insync to make orders. In my setup I am using ib_insync for paper/live trading and backtrader for backtesting only. I found backtrader not flexible enough for a live trading solution.
cwse last edited by
Thanks @bb2, ib_insync seems like an interesting tool.
Though I am a huge fan of backtrader, and have everything working like clockwork in bt, so would like to leverage the awesome backtrader platform if possible!
@backtrader any suggestions?