Hi. I am trying to submit a calendar equity option trade using the API and have been getting 2 kinds of errors-duplicate ID which is strange because I increment the id every time I submit an order. In addition, I also get a " security definition not found" even though I get the contract ID from TWs using the .reqcontractdetailsEx method. Here is my code in VB 6. I would sincerely appreciate any suggestions on how I can fire off a simple buy order of a calendar spread. I am a mid level Vb6 programmer but am pretty new w/ TWS.
Private Sub Command2_Click()
Dim x As Integer
Set SpreadList = Tws1.createComboLegList
Dim leg As twslib.IComboLeg
Set leg = SpreadList.Add()
leg.conId = 47857680
leg.ratio = 1
leg.Action = "BUY"
leg.exchange = "SMART"
leg.openClose = 0
'Dim leg As twslib.IComboLeg
Set leg = SpreadList.Add()
leg.conId = 47857767
leg.ratio = 1
leg.Action = "SELL"
leg.exchange = "SMART"
leg.openClose = 0
Set x_contInfo = Tws1.createContract
x_contInfo.symbol = "QQQQ"
x_contInfo.secType = "BAG"
x_contInfo.exchange = "SMART"
x_contInfo.comboLegs = SpreadList
Set x_OrderTix = Tws1.createOrder
x_OrderTix.Action = "BUY"
x_contInfo.conId = 0
x_OrderTix.lmtPrice = 0.04
x_OrderTix.totalQuantity = 1
x_OrderTix.orderType = "LMT"
x_OrderTix.timeInForce = "GTC"
x_OrderTix.orderId = txtRow.Text
Call Tws1.placeOrderEx(txtRow.Text, x_contInfo, x_OrderTix)
End Sub
Private Sub Command2_Click()
Dim x As Integer
Set SpreadList = Tws1.createComboLegList
Dim leg As twslib.IComboLeg
Set leg = SpreadList.Add()
leg.conId = 47857680
leg.ratio = 1
leg.Action = "BUY"
leg.exchange = "SMART"
leg.openClose = 0
'Dim leg As twslib.IComboLeg
Set leg = SpreadList.Add()
leg.conId = 47857767
leg.ratio = 1
leg.Action = "SELL"
leg.exchange = "SMART"
leg.openClose = 0
Set x_contInfo = Tws1.createContract
x_contInfo.symbol = "QQQQ"
x_contInfo.secType = "BAG"
x_contInfo.exchange = "SMART"
x_contInfo.comboLegs = SpreadList
Set x_OrderTix = Tws1.createOrder
x_OrderTix.Action = "BUY"
x_contInfo.conId = 0
x_OrderTix.lmtPrice = 0.04
x_OrderTix.totalQuantity = 1
x_OrderTix.orderType = "LMT"
x_OrderTix.timeInForce = "GTC"
x_OrderTix.orderId = txtRow.Text
Call Tws1.placeOrderEx(txtRow.Text, x_contInfo, x_OrderTix)
End Sub