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/

    cannot find right symbol for Interactive Brokers

    General Code/Help
    2
    5
    966
    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.
    • bb2
      bb2 last edited by

      Hello,

      I have been trying my code on the symbol EUR.USD-CASH-IDEALPRO successfully so far. The problem raises when I want to use another symbol with IBStore.

      Following is my code:

          cerebro = bt.Cerebro(stdstats=False)
          
          ibstore = bt.stores.IBStore(host='127.0.0.1', port=7496, clientId=35)
          # data = ibstore.getdata(dataname='EUR.USD-CASH-IDEALPRO', fromdate=datetime.datetime(
          data = ibstore.getdata(dataname='ES.USD-FUT-GLOBEX-201806', fromdate=datetime.datetime(
              2018, 4, 1), todate=datetime.datetime(2018, 5, 1), timeframe=bt.TimeFrame.Days, reverse=False)
      
          cerebro.broker.setcash(10000.0)
          cerebro.broker.setcommission(commission=0.0)
      
          cerebro.adddata(data)
          cerebro.addstrategy(TestStrategy)
      
          print('Starting portfolio: %f' % cerebro.broker.getvalue())
          strats = cerebro.run()
      
          ss = strats[0]
      
          for each in ss.analyzers:
              each.print()
      
      
          cerebro.plot(volume=False, style='candle')
          print('Final portfolio: %f' % cerebro.broker.getvalue())
      

      And I get the error:

      Starting portfolio: 10000.000000
      Server Version: 76
      TWS Time at connection:20180514 15:17:36 Eastern European Time
      ---------------------------------------------------------------------------
      IndexError                                Traceback (most recent call last)
      ~/Documents/Devel/trade/bt_basic.py in <module>()
          156 
          157     print('Starting portfolio: %f' % cerebro.broker.getvalue())
      --> 158     strats = cerebro.run()
          159 
          160     ss = strats[0]
      
      ~/.virtualenvs/trade-7uGUPCDQ/lib/python3.6/site-packages/backtrader/cerebro.py in run(self, **kwargs)
         1125             # let's skip process "spawning"
         1126             for iterstrat in iterstrats:
      -> 1127                 runstrat = self.runstrategies(iterstrat)
         1128                 self.runstrats.append(runstrat)
         1129                 if self._dooptimize:
      
      ~/.virtualenvs/trade-7uGUPCDQ/lib/python3.6/site-packages/backtrader/cerebro.py in runstrategies(self, iterstrat, predata)
         1299 
         1300             for strat in runstrats:
      -> 1301                 strat._stop()
         1302 
         1303         self._broker.stop()
      
      ~/.virtualenvs/trade-7uGUPCDQ/lib/python3.6/site-packages/backtrader/strategy.py in _stop(self)
          459 
          460     def _stop(self):
      --> 461         self.stop()
          462 
          463         for analyzer in itertools.chain(self.analyzers, self._slave_analyzers):
      
      ~/Documents/Devel/trade/bt_basic.py in stop(self)
           84 
           85     def stop(self):
      ---> 86         self.log('(MA Period %2d) Ending Value %.2f' % (self.params.maperiod, self.broker.getvalue()), doprint=True)
           87 
           88     def notify_order(self, order):
      
      ~/Documents/Devel/trade/bt_basic.py in log(self, txt, dt, doprint)
           21     def log(self, txt, dt=None, doprint=False):
           22         if self.params.printlog or doprint:
      ---> 23             dt = dt or self.datas[0].datetime.date(0)
           24             print('%s, %s' % (dt.isoformat(), txt))
           25 
      
      ~/.virtualenvs/trade-7uGUPCDQ/lib/python3.6/site-packages/backtrader/linebuffer.py in date(self, ago, tz, naive)
          389 
          390     def date(self, ago=0, tz=None, naive=True):
      --> 391         return num2date(self.array[self.idx + ago],
          392                         tz=tz or self._tz, naive=naive).date()
          393 
      
      IndexError: array index out of range
      

      How can I resolve this issue?

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

        @eduedix said in cannot find right symbol for Interactive Brokers:

        EUR.USD-CASH-IDEALPRO

        This is for FOREX where the pair is EUR.USD

        @eduedix said in cannot find right symbol for Interactive Brokers:

        ES.USD-FUT-GLOBEX-201806

        A future is not a forex pair and the currency is specified later, right after the exchange and before the expiration date.. See the reference here: Docs - Interactive Brokers

        1 Reply Last reply Reply Quote 0
        • bb2
          bb2 last edited by

          Thank you very much for the quick response!

          I fixed the symbol name now and the dataname looks like this:
          ES-FUT-GLOBEX-USD-201806. I do not receive any error anymore. However, the system stays in the DELAYED status forever. Do you have any idea what might be the problem here?

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

            That's usually due to lack of permissions to download real-time data.

            1 Reply Last reply Reply Quote 0
            • bb2
              bb2 last edited by bb2

              I am doing paper trading only. The delay occurs for EURUSD for only 1-2 seconds though. I also have this problem when I want to work on historical data only (limited with fromdate and todate as parameters to getdata. Do you think this is a permission related issue?

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