diff --git a/vnpy/gateway/ib/ib_gateway.py b/vnpy/gateway/ib/ib_gateway.py index 4b8996cf..1f0387d7 100644 --- a/vnpy/gateway/ib/ib_gateway.py +++ b/vnpy/gateway/ib/ib_gateway.py @@ -43,7 +43,11 @@ from vnpy.trader.constant import ( 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()} DIRECTION_VT2IB = {Direction.LONG: "BUY", Direction.SHORT: "SELL"} @@ -493,6 +497,7 @@ class IbApi(EWrapper): pricetick=contractDetails.minTick, net_position=True, history_data=True, + stop_supported=True, gateway_name=self.gateway_name, ) @@ -642,9 +647,13 @@ class IbApi(EWrapper): ib_order.clientId = self.clientid ib_order.action = DIRECTION_VT2IB[req.direction] ib_order.orderType = ORDERTYPE_VT2IB[req.type] - ib_order.lmtPrice = req.price 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.reqIds(1)