Inter-Commodity Futures

View as MarkdownOpen in Claude

For Inter-Commodity futures, the ‘Local Symbol’ field in TWS is used for the ‘Symbol’ field in the API contract definition, e.g. “CL.BZ”. They are always guaranteed combos, which is the default in the API.

In some instances, a generic symbol must be provided instead. For example, a inter-commodity future containing ZF and ZN will require that the symbol be set to “FYT”.

Please be mindful of the fact that inter-commodity spreads are offered by the exchange directly, and so they are direct-routed though the legs have different underlyings. Only real time, and not historical, data is offered for inter-commodity spread contracts through the API.

It is also possible in many cases to create a spread of the same future contracts in a inter-commodity spread which is smart-routed and non-guaranteed. Historical data for this spread would generally be available from the API. Also, historical data for expired spread contracts is not available in TWS or the API.

1contract = Contract()
2contract.symbol = "COL.WTI" #symbol is 'local symbol' of intercommodity spread.
3contract.secType = "BAG"
4contract.currency = "USD"
5contract.exchange = "IPE"
6
7leg1 = ComboLeg()
8leg1.conId = 183405603 #WTI�Dec'23�@IPE
9leg1.ratio = 1
10leg1.action = "BUY"
11leg1.exchange = "IPE"
12
13leg2 = ComboLeg()
14leg2.conId = 254011009 #COIL�Dec'23�@IPE
15leg2.ratio = 1
16leg2.action = "SELL"
17leg2.exchange = "IPE"
18
19contract.comboLegs = []
20contract.comboLegs.append(leg1)
21contract.comboLegs.append(leg2)