Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combo Leg Order: Rejected - Invalid value in field # 6079 #54

Open
jshellen opened this issue May 31, 2017 · 3 comments
Open

Combo Leg Order: Rejected - Invalid value in field # 6079 #54

jshellen opened this issue May 31, 2017 · 3 comments

Comments

@jshellen
Copy link

jshellen commented May 31, 2017

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)

@jshellen jshellen changed the title Combo Leg Order: Combo Leg Order: Rejected - Invalid value in field # 6079 May 31, 2017
@jshellen
Copy link
Author

jshellen commented May 31, 2017

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

@PedroTayer
Copy link

I still have this problem: Rejected - Invalid value in field # 6079
If someone can help me it would be great

@petrochuk
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants