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/

    Interactive Brokers for orders only ,not for data feed

    General Code/Help
    4
    10
    1811
    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.
    • T
      Trade Prophet last edited by

      Hello,
      Is it possible to use IB for buy/sell orders (+portfolio status) but take the ticker data from a csv file ?
      Meaning,
      Can I replace the ibstore.getdata(...) line with 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)
      

      Thank you.

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • T
          Trade Prophet last edited by

          Hi and thank you for your reply,
          Can you elaborate what that means?

          Thank you

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              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.

              1 Reply Last reply Reply Quote 1
              • T
                Trade Prophet last edited by

                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.

                C 1 Reply Last reply Reply Quote 0
                • C
                  cwse @Trade Prophet last edited by

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

                  Thanks,
                  Charles

                  bb2 1 Reply Last reply Reply Quote 0
                  • C
                    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.

                    @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/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'
                    

                    Thanks!

                    1 Reply Last reply Reply Quote 0
                    • bb2
                      bb2 @cwse 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.

                      C 1 Reply Last reply Reply Quote 0
                      • C
                        cwse @bb2 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?

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