swigibpy
swigibpy copied to clipboard
Combo Leg Order: Rejected - Invalid value in field # 6079
Hi,
I am experiencing problems sending comboLeg orders. Specifically, I get the following error message: "Rejected - Invalid value in field # 6079"
This message is displayed in the TWS as a pop-up window (not in Python).
I tried to send the comboLeg order using the following code:
1. Get contract IDs
m_contract_object1 = IBcontract() m_contract_object1.secType = 'STK' m_contract_object1.symbol = 'EWA' m_contract_object1.currency = 'USD' m_contract_object1.exchange = 'SMART'
m_contract_object2 = IBcontract() m_contract_object2.secType = 'STK' m_contract_object2.symbol = 'EWC' m_contract_object2.currency = 'USD' m_contract_object2.exchange = 'SMART'
cdetails1 = client.get_contract_details(m_contract_object1) cdetails2 = client.get_contract_details(m_contract_object2)
print cdetails1['conId'] # returns 2586606 print cdetails2['conId'] # returns 2586548
2. Create ComboLegs
leg1 = ComboLeg() leg2 = ComboLeg()
leg1.conId = cdetails1['conId'] leg1.ratio = 1 leg1.action = 'BUY' leg1.exchange = 'SMART' leg1.openClose = 0 leg1.shortSaleSlot = 0 leg1.designatedLocation = ""
leg2.conId = cdetails2['conId'] leg2.ratio = 1 leg2.action = 'SELL' leg2.exchange = 'SMART' leg2.openClose = 0 leg2.shortSaleSlot = 0 leg2.designatedLocation = ""
3. Create new contract and order
contract = IBcontract() contract.secType = 'BAG' contract.symbol = 'EWA' contract.currency = 'USD' contract.exchange = 'SMART' contract.comboLegs = ComboLegList([leg1, leg2])
order = IBOrder() order.action = 'BUY' order.totalQuantity = 1 order.orderType = 'MKT' order.lmtPrice = 1
client.place_order(contract,order)
I solved this issue and the instructions to send the comboleg order are described below. The key to this problem was to actually look at the native Python IB api. The native Python IB API order example is given below: @staticmethod def ComboLimitOrder(action:str, quantity:float, limitPrice:float, nonGuaranteed:bool):
# ! [combolimit]
order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = limitPrice
if nonGuaranteed:
order.smartComboRoutingParams = []
order.smartComboRoutingParams.append(TagValue("NonGuaranteed", "1"))
# ! [combolimit]
return order
In my own implementation (given above) I did not specify the "smartComboRoutingParams" variable at all. Now, if one would follow the syntax in the native implementation and would try to execute order.smartComboRoutingParams = [] one would get type mismatch error. However, we may use the TagValueList class given in the swigibpy instead of [] and then proceed similarly:
m_contract_object1 = IBcontract()
m_contract_object1.secType = 'STK'
m_contract_object1.symbol = 'EWA'
m_contract_object1.currency = 'USD'
m_contract_object1.exchange = 'SMART'
m_contract_object2 = IBcontract()
m_contract_object2.secType = 'STK'
m_contract_object2.symbol = 'EWC'
m_contract_object2.currency = 'USD'
m_contract_object2.exchange = 'SMART'
cdetails1 = client.get_contract_details(m_contract_object1)
cdetails2 = client.get_contract_details(m_contract_object2)
print cdetails1['conId']
print cdetails2['conId']
leg1 = ComboLeg()
leg2 = ComboLeg()
leg1.conId = cdetails1['conId']
leg1.ratio = 1
leg1.action = 'BUY'
leg1.exchange = 'SMART'
leg1.openClose = 0
leg1.shortSaleSlot = 0
leg1.designatedLocation = ""
leg2.conId = cdetails2['conId']
leg2.ratio = 1
leg2.action = 'SELL'
leg2.exchange = 'SMART'
leg2.openClose = 0
leg2.shortSaleSlot = 0
leg2.designatedLocation = ""
contract = IBcontract()
contract.secType = 'BAG'
contract.symbol = 'EWA'
contract.currency = 'USD'
contract.exchange = 'SMART'
contract.comboLegs = ComboLegList([leg1, leg2])
order = IBOrder()
order.action = 'BUY'
order.totalQuantity = 1
order.orderType = 'MKT'
order.smartComboRoutingParams = TagValueList()
order.smartComboRoutingParams.append(TagValue("NonGuaranteed", "1"))
client.place_order(contract,order)
After I executed this I received an MKT order "EWC,EWA ARCA + EWA - EWC
I still have this problem: Rejected - Invalid value in field # 6079 If someone can help me it would be great
I had the same issue when I was submitting Iron Condor with 4 legs which actually was iron fly. For example I was sending four legs: buy 110, sell 100, sell 100, buy 90. As you can see sell 100 was there twice. So I had to change to three legs buy 110, sell 100, buy 90 but sell 100 leg had ratio of 2. This fixed this error for me