I'm using node-ib npm, i want to place a Combination Order.
The steps i made:
getting the contract IDs for both leg definitions.
Once the program has acquired the conId value for each leg, i include it in the ComboLeg object.
Then i invoke the placeOrder() method with the contract and order objects.
var leg1 = {
conId: c1,
ratio: 1,
action: "SELL",
exchange: "SMART",
openClose: 0,
shortSaleSlot: 0,
designatedLocation: ""
}
var leg2 = {
conId: c2,
ratio: 1,
action: "BUY",
exchange: "SMART",
openClose: 0,
shortSaleSlot: 0,
designatedLocation: ""
}
var legs = [leg1, leg2];
ib.placeOrder(
6,
ib.contract.combo("USD", "USD", "SMART", legs),
ib.order.limit("BUY", 1, 1)
);
ib.reqOpenOrders();
the c1, c2 values are the conIds.
i didn't find a way to add comboLegs to the contract so i opened /node_modules/ib/lib/contract/combo.js and i added a new argument to the function.
function combo(symbol, currency, exchange, comboLegs) {
assert(_.isString(symbol), 'Symbol must be a string.');
return {
currency: currency || 'USD',
exchange: exchange || 'SMART',
secType: 'BAG',
symbol: symbol,
comboLegs: comboLegs || []
};
}
The last argument is the one i added.
i get no error, but the combo order doesn't added to the Trader workStation.
The normal order get added to the Trader workStation without problems.
Does anyone know how to add combo order to the Trader workStation using API by this npm?
Thanks all:)
This is obviously too late, but for others who come looking for an answer here, this is what worked for me. There is no need to change a library file. Just make sure you get your c1 and c2 using reqContractDetails() for each.
var leg1 = {
conId: c1,
ratio: 1,
action: "BUY",
exchange: "SMART",
}
var leg2 = {
conId: c2,
ratio: 1,
action: "SELL",
exchange: "SMART",
}
var contract = ib.contract.combo(symbol);
contract.comboLegs = [leg1, leg2];
console.log(`contract = `, contract);
ib.placeOrder(
601,
contract,
ib.order.limit("BUY", 1, 1)
);
Here's an example of getting c1 and c2:
ib.reqContractDetails(0, ib.contract.option('AAPL', '20210115', 130, 'C'));
ib.reqContractDetails(1, ib.contract.option('AAPL', '20210115', 145, 'C'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With