anyone know how to create a butterfly spread through IB's api (java or python)?
I can create a 2 legged BAG. I can create a 3 legged BAG but not at different ratio sizes.
here's what I have
I can create a 2 legged BAG. I can create a 3 legged BAG but not at different ratio sizes.
here's what I have
Code:
class BagBuilder(object):
def __init__(self):
self.addAllLegs = []
def addLeg (self,cid,ratio,side,exchange):
leg = ComboLeg()
#print "conid in bag %s" % (cid)
leg.m_conId = cid
leg.m_ratio = ratio
leg.m_action = side
leg.m_exchange = exchange
leg.m_openClose = 0
leg.m_shortSaleSlot = 0
leg.m_designatedLocation = ""
self.addAllLegs.append(leg)
def create(self,symbol):
contract = Contract()
contract.m_symbol = "USD" # For combo order use ?USD? as the symbol value all the time
contract.m_secType = "BAG" # BAG is the security type for COMBO order
contract.m_exchange = self.addAllLegs[0].m_exchange
contract.m_currency = "USD"
contract.m_comboLegs = self.addAllLegs #including combo order in contract object
contract.m_symbol = symbol
return contract
bb = BagBuilder()
bb.addLeg(113982825,1,"SELL",'ECBOT')
bb.addLeg(113982910,1,"SELL",'ECBOT')
bb.addLeg(113983022,2,"BUY",'ECBOT')
bg = bb.create('ZN')