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/

    Can't trade commodity (XAUUSD) on IB paper account

    General Discussion
    2
    5
    1797
    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.
    • Y
      yangnw last edited by

      Some test codes:

      cerebro = bt.Cerebro()
      cerebro.addstrategy(A_Strategy)
      ibstore = bt.stores.IBStore(
          host = '192.168.0.120',
          port = 7497,
          _debug = True,
      )
      cerebro.broker = ibstore.getbroker()
      data = ibstore.getdata(
          dataname = 'XAUUSD',
          sectype = 'CMDTY',
      )
      cerebro.adddata(data)
      

      Which

      • doesn't invoke next()'s of A_Strategy at all, only its __init__().
      • doesn't print out the OHLC information.

      But for example 'EUR.USD-CASH-IDEALPRO' works well, invokes the strategy properly, and prints out OHLC information from IB.

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

        @yangnw said in Can't trade commodity (XAUUSD) on IB paper account:

        sectype = 'CMDTY',

        CMDTY is not a supported security type. The platform doesn't know what to do with it. The known types are listed in the documentation: Docs - Data Feeds Reference under IBData.

        1 Reply Last reply Reply Quote 0
        • Y
          yangnw last edited by

          Thanks. Is it possible to implement its support? Its request signature is exactly the same as STK, the only difference probably lies in how to parse the received messages, etc. in tickPrice() and tickSize(). It would be greatly appreciated.

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

            This will be looked into.

            1 Reply Last reply Reply Quote 0
            • Y
              yangnw last edited by

              Quick fix, though in no way tested:

              • in stores/ibstore.py, lines 725, 751 and 836, add 'CMDTY', etc. if contract.m_secType in ['CASH', 'CFD', 'CMDTY']: ..
              • when defining the data feed, use full kwargs, etc.
              data = ibstore.getdata(
                  dataname = 'XAUUSD',
                  sectype = 'CMDTY',
                  exchange = "SMART",
                  currency = "USD",
              )
              
              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors