A combination order is a special type of order that is constructed of many separate legs but executed as a single transaction. Submit combo orders such as calendar spreads, conversions and straddles using the BAG security type (defined in the Contract object). The key to implementing a successful API combination order using the API is to knowing how to place the same order using Trader Workstation. If you are familiar with placing combination orders in TWS, then it will be easier to place the same order using the API, because the API only imitates the behavior of TWS.
In this example, a customer places a BUY order on a calendar spread for GOOG. To buy one calendar spread means:
Leg 1: Sell 1 GOOG OPT SEP 18 '09 150.0 CALL (100)
Leg 2: Buy 1 GOOG OPT JAN 21 '11 150.0 CALL (100)
Here is a summary of the steps required to place a combo order using the API:
· Obtain the contract id (conId) for each leg. Get this number by invoking the reqContractDetails() method.
· Include each leg on the ComboLeg object by populating the related fields.
· Implement the placeOrder() method with the Contract and Order socket client properties.
To place this combo order
Get the Contract IDs for both leg definitions:
//First leg
Contract con1 = new Contract();
con1.m_symbol = "GOOG";
con1.m_secType = "OPT";
con1.m_expiry = “200909”;
con1.m_strike = 150.0
con1.m_right = “C”
con1.m_multiplier = “100”
con1.m_exchange = "SMART”;
con1.m_currency = "USD";
.reqContractDetails(1, con1);
//Second leg
Contract con2 = new Contract();
con2.m_symbol = "GOOG";
con2.m_secType = "OPT";
con2.m_expiry = “201101”;
con2.m_strike = 150.0
con2.m_right = “C”
con2.m_multiplier = “100”
con2.m_exchange = "SMART”;
con2.m_currency = "USD";
.reqContractDetails(2, con2);
//All conId numbers are delivered by the ContractDetail()
static public String contractDetails(int reqId, ContractDetails contractDetails) {
Contract contract = contractDetails.m_summary;
/*Base on the request above,
reqId = 1 is corresponding to the first request or first leg
reqId = 2 is corresponding to the second request or second leg*/
if (reqId == 1)
{ Leg1_conId = contract.m_conId;} // to obtain conId for first leg
if (reqId == 2)
{ Leg2_conId = contract.m_conId;} // to obtain conId for second leg
}
Once the program has acquired the conId value for each leg, include it in the ComboLeg object:
ComboLeg leg1 = new ComboLeg(); // for the first leg
ComboLeg leg2 = new ComboLeg(); // for the second leg
Vector addAllLegs = new Vector();
leg1.m_conId = Leg1_conId;
leg1.m_ratio = 1;
leg1.m_action = "SELL";
leg1.m_exchange = "SMART";
leg1.m_openClose = 0;
leg1.m_shortSaleSlot = 0;
leg1.m_designatedLocation = "";
leg2.m_conId = Leg2_conId;
leg2.m_ratio = 1;
leg2.m_action = "BUY";
leg2.m_exchange = "SMART";
leg2.m_openClose = 0;
leg2.m_shortSaleSlot = 0;
leg2.m_designatedLocation = "";
addAllLegs.add(leg1);
addAllLegs.add(leg2);
Invoke the placeOrder() method with the appropriate contract and order objects:
Contract contract = new Contract();
Order order = new Order();
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 = "SMART";
contract.m_currency = "USD";
contract.m_comboLegs = addAllLegs; //including combo order in contract object
order.m_action = “BUY”;
order.m_totalQuantity = 1;
order.m_orderType = “MKT”
.placeOrder(OrderId, contract, order);
For more information on combination orders, see the TWS Users Guide topic About Combination Orders.