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

Generating proper dataname for Crude Oil Futures with the certain expiration date

  • Hi.

    I am new in backtrader. I am trading with Interactive Brokers and I am stuck with generating proper dataname for Crude Oil Futures with the certain expiration date.

    The lines below works fine for different forex data:
    ibstore = bt.stores.IBStore(host='', port=7496, clientId=35)
    data = ibstore.getdata(dataname='EUR.USD-CASH-IDEALPRO')

    But when I try to generate dataname for futures, according any of the templates below. Does anybody was able to generate dataname for Crude oil futures that works? What is my mistake?


    #This line does not work.
    data = ibstore.getdata(dataname='CL-FUT-NYMEX-USD-202001')

    I got the same error, even if I try ibtest instead of my code.

    C:\Work\Advisors\BackTrader\backtrader-master\samples\ibtest>python --port 4002 --data0 CL-201912-NYMEX --timeframe Days Server Version: 76 TWS Time at connection:20191202 19:41:06 PST -------------------------------------------------- Strategy Created -------------------------------------------------- Datetime, Open, High, Low, Close, Volume, OpenInterest, SMA ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm> ***** STORE NOTIF: <error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:cashhmds> ***** STORE NOTIF: <error id=16777216, errorCode=200, errorMsg=No security definition has been found for the request>
    ***** STORE NOTIF: Ambiguous contract: none/multiple answers received ***** DATA NOTIF: DISCONNECTED

    Thank you.

  • administrators

    See this:

    For example the section which says:

    Occasionally, you can expect to have more than a single future contract for the same underlying with the same expiry. To rule out the ambiguity, the contract's multiplier can be given as shown below:

    I can only suggest that your are VERY specific on the definition and use the more verbose form (and the debugging option in either the store or ibtest)


Log in to reply