[Add]support for server stop order in bitmex gateway

This commit is contained in:
vn.py 2019-03-22 16:16:01 +08:00
parent 9e91df57d4
commit 8586b5c2fb
2 changed files with 22 additions and 2 deletions

View File

@ -21,6 +21,7 @@ from vnpy.trader.constant import (
OrderType,
Product,
Status,
Offset
)
from vnpy.trader.gateway import BaseGateway
from vnpy.trader.object import (
@ -52,7 +53,12 @@ STATUS_BITMEX2VT = {
DIRECTION_VT2BITMEX = {Direction.LONG: "Buy", Direction.SHORT: "Sell"}
DIRECTION_BITMEX2VT = {v: k for k, v in DIRECTION_VT2BITMEX.items()}
ORDERTYPE_VT2BITMEX = {OrderType.LIMIT: "Limit", OrderType.MARKET: "Market"}
ORDERTYPE_VT2BITMEX = {
OrderType.LIMIT: "Limit",
OrderType.MARKET: "Market",
OrderType.STOP: "Stop"
}
ORDERTYPE_BITMEX2VT = {v: k for k, v in ORDERTYPE_VT2BITMEX.items()}
class BitmexGateway(BaseGateway):
@ -213,14 +219,26 @@ class BitmexRestApi(RestClient):
"symbol": req.symbol,
"side": DIRECTION_VT2BITMEX[req.direction],
"ordType": ORDERTYPE_VT2BITMEX[req.type],
"price": req.price,
"orderQty": int(req.volume),
"clOrdID": orderid,
}
inst = [] # Order special instructions
# Only add price for limit order.
if req.type == OrderType.LIMIT:
data["price"] = req.price
elif req.type == OrderType.STOP:
data["stopPx"] = req.price
inst.append("LastPrice")
# Check for close order
if req.offset == Offset.CLOSE:
inst.append("ReduceOnly")
# Generate execInst
if inst:
data["execInst"] = ",".join(inst)
order = req.create_order_data(orderid, self.gateway_name)
@ -531,6 +549,7 @@ class BitmexWebsocketApi(WebsocketClient):
order = OrderData(
symbol=d["symbol"],
exchange=Exchange.BITMEX,
type=ORDERTYPE_BITMEX2VT[d["ordType"]],
orderid=orderid,
direction=DIRECTION_BITMEX2VT[d["side"]],
price=d["price"],

View File

@ -59,6 +59,7 @@ class OrderType(Enum):
"""
LIMIT = "限价"
MARKET = "市价"
STOP = "STOP"
FAK = "FAK"
FOK = "FOK"