ranaroussi / ezibpy

ezIBpy, a Pythonic Client for Interactive Brokers API
Apache License 2.0
324 stars 116 forks source link

Bracket orders for combo legs #35

Open simonskok opened 4 years ago

simonskok commented 4 years ago

Hi Ran,

thank you for writing this great module! It makes interaction with IB much easier. As I am focused towards automating placing option spread combos, I have encountered the following issue: Combining your two examples from Readme file on placing an option combo and a bracket order, I get the following:

`import ezibpy import time

ibConn = ezibpy.ezIBpy() ibConn.connect(clientId=100, host="localhost", port=7496)

contract_to_buy = ibConn.createOptionContract("AAPL", expiry=20191101, strike=250, otype="CALL") contract_to_sell = ibConn.createOptionContract("AAPL", expiry=20191101, strike=252.5, otype="CALL")

leg1 = ibConn.createComboLeg(contract_to_buy , "SELL", ratio=1) leg2 = ibConn.createComboLeg(contract_to_sell , "BUY", ratio=1) contract = ibConn.createComboContract("AAPL", [leg1, leg2])

order = ibConn.createBracketOrder(contract, quantity = 1, entry = 0.02, target = 0.05, stop = 0.01)
`

Missing or invalid NonGuaranteed value. REL+MKT, LMT+MKT, and REL+LMT order of two legs can only be set as non-guaranteed.

I have configured my API setting in IB TWS to allow Non-guaranteed execution, but the error remains. Looking through your source code, I also havent been able to locate the variable corresponding to this setting.

Any idea how to solve this?