place order spread of futures interactive brokers python

74 views Asked by At

I'm attempting to send a spread order for futures with two different expiration dates using python API.

Future1 SR3Z7 Future2 SR3M8

I am following this link to create a contract. https://interactivebrokers.github.io/tws-api/spread_contracts.html

I am following this link to create a simple order. https://interactivebrokers.github.io/tws-api/basic_orders.html

My code ran without any errors, but when I checked in TWS, it didn't work.

When I use TWS, I can manually send the order with the same spread of futures.

Anyone who can help me understand what is wrong with my python code.


from ib_insync import *

ib = IB()
ib.connect('127.0.0.1', 7497, clientId=3)

### contract
contract = Contract()
contract.symbol = 'SR3'
contract.secType = "BAG"
contract.exchange = "CME"
contract.currency = "USD"

leg1 = ComboLeg()
leg1.conId = 385575897  # SR3Z7
leg1.ratio = 1
leg1.action = "BUY"
leg1.exchange = "CME"

leg2 = ComboLeg()
leg2.conId = 385575856  # SR3M8
leg2.ratio = 1
leg2.action = "SELL"
leg2.exchange = "CME"

contract.comboLegs = []
contract.comboLegs.append(leg1)
contract.comboLegs.append(leg2)

spread_order = Order()
spread_order.action = 'BUY'
spread_order.orderType = "MKT"
spread_order.totalQuantity = 1
spread_order.smartComboRoutingParams = []
spread_order.smartComboRoutingParams.append(TagValue('NonGuaranteed', '1'))

ib.placeOrder(contract, spread_order)

I already try change future to stock, it work.

0

There are 0 answers