[Mod]change constant PriceType to OrderType
This commit is contained in:
parent
50cb39f11b
commit
20b5ef4e9b
@ -21,7 +21,7 @@ from vnpy.trader.object import (
|
|||||||
BarData
|
BarData
|
||||||
)
|
)
|
||||||
from vnpy.trader.event import EVENT_TICK, EVENT_ORDER, EVENT_TRADE
|
from vnpy.trader.event import EVENT_TICK, EVENT_ORDER, EVENT_TRADE
|
||||||
from vnpy.trader.constant import Direction, PriceType, Interval, Exchange
|
from vnpy.trader.constant import Direction, OrderType, Interval, Exchange
|
||||||
from vnpy.trader.utility import load_json, save_json
|
from vnpy.trader.utility import load_json, save_json
|
||||||
from vnpy.trader.database import DbTickData, DbBarData
|
from vnpy.trader.database import DbTickData, DbBarData
|
||||||
from vnpy.trader.setting import SETTINGS
|
from vnpy.trader.setting import SETTINGS
|
||||||
@ -276,7 +276,7 @@ class CtaEngine(BaseEngine):
|
|||||||
exchange=contract.exchange,
|
exchange=contract.exchange,
|
||||||
direction=direction,
|
direction=direction,
|
||||||
offset=offset,
|
offset=offset,
|
||||||
price_type=PriceType.LIMIT,
|
type=OrderType.LIMIT,
|
||||||
price=price,
|
price=price,
|
||||||
volume=volume,
|
volume=volume,
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,7 @@ from vnpy.api.websocket import WebsocketClient
|
|||||||
from vnpy.trader.constant import (
|
from vnpy.trader.constant import (
|
||||||
Direction,
|
Direction,
|
||||||
Exchange,
|
Exchange,
|
||||||
PriceType,
|
OrderType,
|
||||||
Product,
|
Product,
|
||||||
Status,
|
Status,
|
||||||
)
|
)
|
||||||
@ -52,7 +52,7 @@ STATUS_BITMEX2VT = {
|
|||||||
DIRECTION_VT2BITMEX = {Direction.LONG: "Buy", Direction.SHORT: "Sell"}
|
DIRECTION_VT2BITMEX = {Direction.LONG: "Buy", Direction.SHORT: "Sell"}
|
||||||
DIRECTION_BITMEX2VT = {v: k for k, v in DIRECTION_VT2BITMEX.items()}
|
DIRECTION_BITMEX2VT = {v: k for k, v in DIRECTION_VT2BITMEX.items()}
|
||||||
|
|
||||||
PRICETYPE_VT2BITMEX = {PriceType.LIMIT: "Limit", PriceType.MARKET: "Market"}
|
ORDERTYPE_VT2BITMEX = {OrderType.LIMIT: "Limit", OrderType.MARKET: "Market"}
|
||||||
|
|
||||||
|
|
||||||
class BitmexGateway(BaseGateway):
|
class BitmexGateway(BaseGateway):
|
||||||
@ -212,14 +212,14 @@ class BitmexRestApi(RestClient):
|
|||||||
data = {
|
data = {
|
||||||
"symbol": req.symbol,
|
"symbol": req.symbol,
|
||||||
"side": DIRECTION_VT2BITMEX[req.direction],
|
"side": DIRECTION_VT2BITMEX[req.direction],
|
||||||
"ordType": PRICETYPE_VT2BITMEX[req.price_type],
|
"ordType": ORDERTYPE_VT2BITMEX[req.type],
|
||||||
"price": req.price,
|
"price": req.price,
|
||||||
"orderQty": int(req.volume),
|
"orderQty": int(req.volume),
|
||||||
"clOrdID": orderid,
|
"clOrdID": orderid,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only add price for limit order.
|
# Only add price for limit order.
|
||||||
if req.price_type == PriceType.LIMIT:
|
if req.type == OrderType.LIMIT:
|
||||||
data["price"] = req.price
|
data["price"] = req.price
|
||||||
|
|
||||||
order = req.create_order_data(orderid, self.gateway_name)
|
order = req.create_order_data(orderid, self.gateway_name)
|
||||||
|
@ -41,7 +41,7 @@ from vnpy.trader.constant import (
|
|||||||
Direction,
|
Direction,
|
||||||
Offset,
|
Offset,
|
||||||
Exchange,
|
Exchange,
|
||||||
PriceType,
|
OrderType,
|
||||||
Product,
|
Product,
|
||||||
Status,
|
Status,
|
||||||
OptionType
|
OptionType
|
||||||
@ -80,9 +80,9 @@ DIRECTION_CTP2VT = {v: k for k, v in DIRECTION_VT2CTP.items()}
|
|||||||
DIRECTION_CTP2VT[THOST_FTDC_PD_Long] = Direction.LONG
|
DIRECTION_CTP2VT[THOST_FTDC_PD_Long] = Direction.LONG
|
||||||
DIRECTION_CTP2VT[THOST_FTDC_PD_Short] = Direction.SHORT
|
DIRECTION_CTP2VT[THOST_FTDC_PD_Short] = Direction.SHORT
|
||||||
|
|
||||||
PRICETYPE_VT2CTP = {
|
ORDERTYPE_VT2CTP = {
|
||||||
PriceType.LIMIT: THOST_FTDC_OPT_LimitPrice,
|
OrderType.LIMIT: THOST_FTDC_OPT_LimitPrice,
|
||||||
PriceType.MARKET: THOST_FTDC_OPT_AnyPrice
|
OrderType.MARKET: THOST_FTDC_OPT_AnyPrice
|
||||||
}
|
}
|
||||||
|
|
||||||
OFFSET_VT2CTP = {
|
OFFSET_VT2CTP = {
|
||||||
@ -687,7 +687,7 @@ class CtpTdApi(TdApi):
|
|||||||
"InstrumentID": req.symbol,
|
"InstrumentID": req.symbol,
|
||||||
"LimitPrice": req.price,
|
"LimitPrice": req.price,
|
||||||
"VolumeTotalOriginal": int(req.volume),
|
"VolumeTotalOriginal": int(req.volume),
|
||||||
"OrderPriceType": PRICETYPE_VT2CTP.get(req.price_type, ""),
|
"OrderPriceType": ORDERTYPE_VT2CTP.get(req.type, ""),
|
||||||
"Direction": DIRECTION_VT2CTP.get(req.direction, ""),
|
"Direction": DIRECTION_VT2CTP.get(req.direction, ""),
|
||||||
"CombOffsetFlag": OFFSET_VT2CTP.get(req.offset, ""),
|
"CombOffsetFlag": OFFSET_VT2CTP.get(req.offset, ""),
|
||||||
"OrderRef": str(self.order_ref),
|
"OrderRef": str(self.order_ref),
|
||||||
@ -703,11 +703,11 @@ class CtpTdApi(TdApi):
|
|||||||
"MinVolume": 1
|
"MinVolume": 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.price_type == PriceType.FAK:
|
if req.type == OrderType.FAK:
|
||||||
ctp_req["OrderPriceType"] = THOST_FTDC_OPT_LimitPrice
|
ctp_req["OrderPriceType"] = THOST_FTDC_OPT_LimitPrice
|
||||||
ctp_req["TimeCondition"] = THOST_FTDC_TC_IOC
|
ctp_req["TimeCondition"] = THOST_FTDC_TC_IOC
|
||||||
ctp_req["VolumeCondition"] = THOST_FTDC_VC_AV
|
ctp_req["VolumeCondition"] = THOST_FTDC_VC_AV
|
||||||
elif req.price_type == PriceType.FOK:
|
elif req.type == OrderType.FOK:
|
||||||
ctp_req["OrderPriceType"] = THOST_FTDC_OPT_LimitPrice
|
ctp_req["OrderPriceType"] = THOST_FTDC_OPT_LimitPrice
|
||||||
ctp_req["TimeCondition"] = THOST_FTDC_TC_IOC
|
ctp_req["TimeCondition"] = THOST_FTDC_TC_IOC
|
||||||
ctp_req["VolumeCondition"] = THOST_FTDC_VC_CV
|
ctp_req["VolumeCondition"] = THOST_FTDC_VC_CV
|
||||||
|
@ -244,7 +244,7 @@ class FutuGateway(BaseGateway):
|
|||||||
def send_order(self, req: OrderRequest):
|
def send_order(self, req: OrderRequest):
|
||||||
""""""
|
""""""
|
||||||
side = DIRECTION_VT2FUTU[req.direction]
|
side = DIRECTION_VT2FUTU[req.direction]
|
||||||
price_type = OrderType.NORMAL # Only limit order is supported.
|
futu_order_type = OrderType.NORMAL # Only limit order is supported.
|
||||||
|
|
||||||
# Set price adjustment mode to inside adjustment.
|
# Set price adjustment mode to inside adjustment.
|
||||||
if req.direction is Direction.LONG:
|
if req.direction is Direction.LONG:
|
||||||
@ -258,7 +258,7 @@ class FutuGateway(BaseGateway):
|
|||||||
req.volume,
|
req.volume,
|
||||||
futu_symbol,
|
futu_symbol,
|
||||||
side,
|
side,
|
||||||
price_type,
|
futu_order_type,
|
||||||
trd_env=self.env,
|
trd_env=self.env,
|
||||||
adjust_limit=adjust_limit,
|
adjust_limit=adjust_limit,
|
||||||
)
|
)
|
||||||
|
@ -31,7 +31,7 @@ from vnpy.trader.object import (
|
|||||||
)
|
)
|
||||||
from vnpy.trader.constant import (
|
from vnpy.trader.constant import (
|
||||||
Product,
|
Product,
|
||||||
PriceType,
|
OrderType,
|
||||||
Direction,
|
Direction,
|
||||||
Exchange,
|
Exchange,
|
||||||
Currency,
|
Currency,
|
||||||
@ -39,8 +39,8 @@ from vnpy.trader.constant import (
|
|||||||
OptionType,
|
OptionType,
|
||||||
)
|
)
|
||||||
|
|
||||||
PRICETYPE_VT2IB = {PriceType.LIMIT: "LMT", PriceType.MARKET: "MKT"}
|
ORDERTYPE_VT2IB = {OrderType.LIMIT: "LMT", OrderType.MARKET: "MKT"}
|
||||||
PRICETYPE_IB2VT = {v: k for k, v in PRICETYPE_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"}
|
||||||
DIRECTION_IB2VT = {v: k for k, v in DIRECTION_VT2IB.items()}
|
DIRECTION_IB2VT = {v: k for k, v in DIRECTION_VT2IB.items()}
|
||||||
@ -559,8 +559,8 @@ class IbApi(EWrapper):
|
|||||||
self.gateway.write_log(f"不支持的交易所:{req.exchange}")
|
self.gateway.write_log(f"不支持的交易所:{req.exchange}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
if req.price_type not in PRICETYPE_VT2IB:
|
if req.type not in ORDERTYPE_VT2IB:
|
||||||
self.gateway.write_log(f"不支持的价格类型:{req.price_type}")
|
self.gateway.write_log(f"不支持的价格类型:{req.type}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
self.orderid += 1
|
self.orderid += 1
|
||||||
@ -573,7 +573,7 @@ class IbApi(EWrapper):
|
|||||||
ib_order.orderId = self.orderid
|
ib_order.orderId = self.orderid
|
||||||
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 = PRICETYPE_VT2IB[req.price_type]
|
ib_order.orderType = ORDERTYPE_VT2IB[req.type]
|
||||||
ib_order.lmtPrice = req.price
|
ib_order.lmtPrice = req.price
|
||||||
ib_order.totalQuantity = req.volume
|
ib_order.totalQuantity = req.volume
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ from vnpy.api.oes.vnoes import OesApiClientEnvT, OesApiSubscribeInfoT, OesApi_De
|
|||||||
|
|
||||||
from vnpy.gateway.oes.error_code import error_to_str
|
from vnpy.gateway.oes.error_code import error_to_str
|
||||||
from vnpy.gateway.oes.utils import create_remote_config, is_disconnected
|
from vnpy.gateway.oes.utils import create_remote_config, is_disconnected
|
||||||
from vnpy.trader.constant import Direction, Exchange, Offset, PriceType, Product, Status
|
from vnpy.trader.constant import Direction, Exchange, Offset, OrderType, Product, Status
|
||||||
from vnpy.trader.gateway import BaseGateway
|
from vnpy.trader.gateway import BaseGateway
|
||||||
from vnpy.trader.object import AccountData, CancelRequest, ContractData, OrderData, OrderRequest, \
|
from vnpy.trader.object import AccountData, CancelRequest, ContractData, OrderData, OrderRequest, \
|
||||||
PositionData, TradeData
|
PositionData, TradeData
|
||||||
@ -41,8 +41,8 @@ PRODUCT_OES2VT = {
|
|||||||
|
|
||||||
# only limit price can match, all other price types are not perfectly match.
|
# only limit price can match, all other price types are not perfectly match.
|
||||||
ORDER_TYPE_VT2OES = {
|
ORDER_TYPE_VT2OES = {
|
||||||
(Exchange.SSE, PriceType.LIMIT): eOesOrdTypeShT.OES_ORD_TYPE_SH_LMT,
|
(Exchange.SSE, OrderType.LIMIT): eOesOrdTypeShT.OES_ORD_TYPE_SH_LMT,
|
||||||
(Exchange.SZSE, PriceType.LIMIT): eOesOrdTypeSzT.OES_ORD_TYPE_SZ_LMT,
|
(Exchange.SZSE, OrderType.LIMIT): eOesOrdTypeSzT.OES_ORD_TYPE_SZ_LMT,
|
||||||
}
|
}
|
||||||
|
|
||||||
BUY_SELL_TYPE_VT2OES = {
|
BUY_SELL_TYPE_VT2OES = {
|
||||||
@ -623,7 +623,7 @@ class OesTdApi:
|
|||||||
oes_req = OesOrdReqT()
|
oes_req = OesOrdReqT()
|
||||||
oes_req.clSeqNo = seq_id
|
oes_req.clSeqNo = seq_id
|
||||||
oes_req.mktId = EXCHANGE_VT2OES[vt_req.exchange]
|
oes_req.mktId = EXCHANGE_VT2OES[vt_req.exchange]
|
||||||
oes_req.ordType = ORDER_TYPE_VT2OES[(vt_req.exchange, vt_req.price_type)]
|
oes_req.ordType = ORDER_TYPE_VT2OES[(vt_req.exchange, vt_req.type)]
|
||||||
oes_req.bsType = BUY_SELL_TYPE_VT2OES[(vt_req.exchange, vt_req.offset, vt_req.direction)]
|
oes_req.bsType = BUY_SELL_TYPE_VT2OES[(vt_req.exchange, vt_req.offset, vt_req.direction)]
|
||||||
oes_req.invAcctId = ""
|
oes_req.invAcctId = ""
|
||||||
oes_req.securityId = vt_req.symbol
|
oes_req.securityId = vt_req.symbol
|
||||||
|
@ -22,7 +22,7 @@ from tigeropen.trade.domain.order import ORDER_STATUS
|
|||||||
from tigeropen.push.push_client import PushClient
|
from tigeropen.push.push_client import PushClient
|
||||||
from tigeropen.common.exceptions import ApiException
|
from tigeropen.common.exceptions import ApiException
|
||||||
|
|
||||||
from vnpy.trader.constant import Direction, Product, Status, PriceType, Exchange
|
from vnpy.trader.constant import Direction, Product, Status, OrderType, Exchange
|
||||||
from vnpy.trader.gateway import BaseGateway
|
from vnpy.trader.gateway import BaseGateway
|
||||||
from vnpy.trader.object import (
|
from vnpy.trader.object import (
|
||||||
TickData,
|
TickData,
|
||||||
@ -57,9 +57,9 @@ DIRECTION_TIGER2VT = {
|
|||||||
"sell": Direction.SHORT,
|
"sell": Direction.SHORT,
|
||||||
}
|
}
|
||||||
|
|
||||||
PRICETYPE_VT2TIGER = {
|
ORDERTYPE_VT2TIGER = {
|
||||||
PriceType.LIMIT: "LMT",
|
OrderType.LIMIT: "LMT",
|
||||||
PriceType.MARKET: "MKT",
|
OrderType.MARKET: "MKT",
|
||||||
}
|
}
|
||||||
|
|
||||||
STATUS_TIGER2VT = {
|
STATUS_TIGER2VT = {
|
||||||
@ -339,7 +339,7 @@ class TigerGateway(BaseGateway):
|
|||||||
account=self.account,
|
account=self.account,
|
||||||
contract=contract,
|
contract=contract,
|
||||||
action=DIRECTION_VT2TIGER[req.direction],
|
action=DIRECTION_VT2TIGER[req.direction],
|
||||||
order_type=PRICETYPE_VT2TIGER[req.price_type],
|
order_type=ORDERTYPE_VT2TIGER[req.type],
|
||||||
quantity=int(req.volume),
|
quantity=int(req.volume),
|
||||||
limit_price=req.price,
|
limit_price=req.price,
|
||||||
)
|
)
|
||||||
|
@ -53,9 +53,9 @@ class Product(Enum):
|
|||||||
SPREAD = "价差"
|
SPREAD = "价差"
|
||||||
|
|
||||||
|
|
||||||
class PriceType(Enum):
|
class OrderType(Enum):
|
||||||
"""
|
"""
|
||||||
Order price type.
|
Order type.
|
||||||
"""
|
"""
|
||||||
LIMIT = "限价"
|
LIMIT = "限价"
|
||||||
MARKET = "市价"
|
MARKET = "市价"
|
||||||
|
@ -6,7 +6,7 @@ from dataclasses import dataclass
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from logging import INFO
|
from logging import INFO
|
||||||
|
|
||||||
from .constant import Direction, Exchange, Interval, Offset, Status, Product, OptionType, PriceType
|
from .constant import Direction, Exchange, Interval, Offset, Status, Product, OptionType, OrderType
|
||||||
|
|
||||||
ACTIVE_STATUSES = set([Status.SUBMITTING, Status.NOTTRADED, Status.PARTTRADED])
|
ACTIVE_STATUSES = set([Status.SUBMITTING, Status.NOTTRADED, Status.PARTTRADED])
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ class OrderRequest:
|
|||||||
symbol: str
|
symbol: str
|
||||||
exchange: Exchange
|
exchange: Exchange
|
||||||
direction: Direction
|
direction: Direction
|
||||||
price_type: PriceType
|
type: OrderType
|
||||||
volume: float
|
volume: float
|
||||||
price: float = 0
|
price: float = 0
|
||||||
offset: Offset = Offset.NONE
|
offset: Offset = Offset.NONE
|
||||||
|
@ -9,7 +9,7 @@ from typing import Any
|
|||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
from vnpy.event import Event, EventEngine
|
from vnpy.event import Event, EventEngine
|
||||||
from ..constant import Direction, Exchange, Offset, PriceType
|
from ..constant import Direction, Exchange, Offset, OrderType
|
||||||
from ..engine import MainEngine
|
from ..engine import MainEngine
|
||||||
from ..event import (
|
from ..event import (
|
||||||
EVENT_TICK,
|
EVENT_TICK,
|
||||||
@ -597,9 +597,9 @@ class TradingWidget(QtWidgets.QWidget):
|
|||||||
self.offset_combo = QtWidgets.QComboBox()
|
self.offset_combo = QtWidgets.QComboBox()
|
||||||
self.offset_combo.addItems([offset.value for offset in Offset])
|
self.offset_combo.addItems([offset.value for offset in Offset])
|
||||||
|
|
||||||
self.price_type_combo = QtWidgets.QComboBox()
|
self.order_type_combo = QtWidgets.QComboBox()
|
||||||
self.price_type_combo.addItems(
|
self.order_type_combo.addItems(
|
||||||
[price_type.value for price_type in PriceType])
|
[order_type.value for order_type in OrderType])
|
||||||
|
|
||||||
double_validator = QtGui.QDoubleValidator()
|
double_validator = QtGui.QDoubleValidator()
|
||||||
double_validator.setBottom(0)
|
double_validator.setBottom(0)
|
||||||
@ -625,7 +625,7 @@ class TradingWidget(QtWidgets.QWidget):
|
|||||||
form1.addRow("名称", self.name_line)
|
form1.addRow("名称", self.name_line)
|
||||||
form1.addRow("方向", self.direction_combo)
|
form1.addRow("方向", self.direction_combo)
|
||||||
form1.addRow("开平", self.offset_combo)
|
form1.addRow("开平", self.offset_combo)
|
||||||
form1.addRow("类型", self.price_type_combo)
|
form1.addRow("类型", self.order_type_combo)
|
||||||
form1.addRow("价格", self.price_line)
|
form1.addRow("价格", self.price_line)
|
||||||
form1.addRow("数量", self.volume_line)
|
form1.addRow("数量", self.volume_line)
|
||||||
form1.addRow("接口", self.gateway_combo)
|
form1.addRow("接口", self.gateway_combo)
|
||||||
@ -838,7 +838,7 @@ class TradingWidget(QtWidgets.QWidget):
|
|||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
exchange=Exchange(str(self.exchange_combo.currentText())),
|
exchange=Exchange(str(self.exchange_combo.currentText())),
|
||||||
direction=Direction(str(self.direction_combo.currentText())),
|
direction=Direction(str(self.direction_combo.currentText())),
|
||||||
price_type=PriceType(str(self.price_type_combo.currentText())),
|
type=OrderType(str(self.order_type_combo.currentText())),
|
||||||
volume=volume,
|
volume=volume,
|
||||||
price=price,
|
price=price,
|
||||||
offset=Offset(str(self.offset_combo.currentText())),
|
offset=Offset(str(self.offset_combo.currentText())),
|
||||||
|
Loading…
Reference in New Issue
Block a user