For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Interactive Brokers for orders only ,not for data feed

  • Hello,
    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 ibstore.getdata(...) line with cerebro.adddata(...) line, in the following example?

        cerebro = bt.Cerebro()
        ibstore = bt.stores.IBStore(host='', port=1001, clientId=33,notifyall=True) = 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,

    Thank you.

  • administrators

    Data feeds and brokers are independent.

    But you still need a contract reference for the Broker connecting 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?

    Thank you

  • administrators

    The broker needs to know what is being bought and sold. Your csv based 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.

  • administrators

    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.

  • @trade-prophet @backtrader
    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?


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

    @RandyT or @ab_trader - I don't suppose you have any experience in implementing your own data into a live trading system on IB?

    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/", line 1084, in <module>
        timer = RunStrategy(timer,minholddays=v.minholddays,buyscore=v.buyscore,mode=mode)
      File "D:/Google Drive/Capriole Production/Python Production/Processor/", line 1008, in RunStrategy
        results =, writer=True, quicknotify=False)
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\", line 1127, in run
        runstrat = self.runstrategies(iterstrat)
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\", line 1298, in runstrategies
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\", line 1630, in _runnext
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\", line 347, in _next
        super(Strategy, self)._next()
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\", line 266, in _next
      File "D:/Google Drive/Capriole Production/Python Production/Processor/", line 277, in next
        for i, d in enumerate(d for d in self.datas if
      File "D:/Google Drive/Capriole Production/Python Production/Processor/", line 277, in <genexpr>
        for i, d in enumerate(d for d in self.datas if
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\brokers\", line 306, in getposition
        return self.ib.getposition(data.tradecontract, clone=clone)
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\", line 461, in __getattr__
        return getattr(self.lines, name)
    AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'tradecontract'


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

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