[Add] support for stop order of ib gateway

This commit is contained in:
vn.py 2019-08-26 21:40:20 +08:00
parent dd1039a880
commit bdfa2bd895

View File

@ -43,7 +43,11 @@ from vnpy.trader.constant import (
Interval Interval
) )
ORDERTYPE_VT2IB = {OrderType.LIMIT: "LMT", OrderType.MARKET: "MKT"} ORDERTYPE_VT2IB = {
OrderType.LIMIT: "LMT",
OrderType.MARKET: "MKT",
OrderType.STOP: "STP"
}
ORDERTYPE_IB2VT = {v: k for k, v in ORDERTYPE_VT2IB.items()} ORDERTYPE_IB2VT = {v: k for k, v in ORDERTYPE_VT2IB.items()}
DIRECTION_VT2IB = {Direction.LONG: "BUY", Direction.SHORT: "SELL"} DIRECTION_VT2IB = {Direction.LONG: "BUY", Direction.SHORT: "SELL"}
@ -493,6 +497,7 @@ class IbApi(EWrapper):
pricetick=contractDetails.minTick, pricetick=contractDetails.minTick,
net_position=True, net_position=True,
history_data=True, history_data=True,
stop_supported=True,
gateway_name=self.gateway_name, gateway_name=self.gateway_name,
) )
@ -642,9 +647,13 @@ class IbApi(EWrapper):
ib_order.clientId = self.clientid ib_order.clientId = self.clientid
ib_order.action = DIRECTION_VT2IB[req.direction] ib_order.action = DIRECTION_VT2IB[req.direction]
ib_order.orderType = ORDERTYPE_VT2IB[req.type] ib_order.orderType = ORDERTYPE_VT2IB[req.type]
ib_order.lmtPrice = req.price
ib_order.totalQuantity = req.volume ib_order.totalQuantity = req.volume
if req.type == OrderType.LIMIT:
ib_order.lmtPrice = req.price
elif req.type == OrderType.STOP:
ib_order.auxPrice = req.price
self.client.placeOrder(self.orderid, ib_contract, ib_order) self.client.placeOrder(self.orderid, ib_contract, ib_order)
self.client.reqIds(1) self.client.reqIds(1)