我正在使用node-ib npm,我想发布组合订单。
我做的步骤:
获取两个腿定义的合同ID。
一旦程序获得了每条腿的conId值,我将它包含在ComboLeg对象中。
然后我用合同和订单对象调用placeOrder()方法。
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();
c1,c2值是conIds。
我没有找到一种方法将comboLegs添加到合同中,所以我打开了/node_modules/ib/lib/contract/combo.js,并为函数添加了一个新参数。
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 || []
};
}
最后一个参数是我添加的那个。
我没有收到任何错误,但组合订单未添加到Trader工作站。
正常订单会毫无问题地添加到Trader工作站。
有没有人知道如何使用API通过此npm将组合订单添加到Trader workStation?
全部谢谢:)
答案 0 :(得分:0)
这显然为时已晚,但是对于其他来这里寻求答案的人来说,这就是对我有用的方法。无需更改库文件。只需确保使用reqContractDetails()分别获取c1和c2。
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)
);
这是获取c1和c2的示例:
ib.reqContractDetails(0, ib.contract.option('AAPL', '20210115', 130, 'C'));
ib.reqContractDetails(1, ib.contract.option('AAPL', '20210115', 145, 'C'));