[Mod]change constant PriceType to OrderType

This commit is contained in:
vn.py 2019-03-21 23:32:39 +08:00
parent 50cb39f11b
commit 20b5ef4e9b
10 changed files with 40 additions and 40 deletions

View File

@ -21,7 +21,7 @@ from vnpy.trader.object import (
BarData
)
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.database import DbTickData, DbBarData
from vnpy.trader.setting import SETTINGS
@ -276,7 +276,7 @@ class CtaEngine(BaseEngine):
exchange=contract.exchange,
direction=direction,
offset=offset,
price_type=PriceType.LIMIT,
type=OrderType.LIMIT,
price=price,
volume=volume,
)

View File

@ -18,7 +18,7 @@ from vnpy.api.websocket import WebsocketClient
from vnpy.trader.constant import (
Direction,
Exchange,
PriceType,
OrderType,
Product,
Status,
)
@ -52,7 +52,7 @@ STATUS_BITMEX2VT = {
DIRECTION_VT2BITMEX = {Direction.LONG: "Buy", Direction.SHORT: "Sell"}
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):
@ -212,14 +212,14 @@ class BitmexRestApi(RestClient):
data = {
"symbol": req.symbol,
"side": DIRECTION_VT2BITMEX[req.direction],
"ordType": PRICETYPE_VT2BITMEX[req.price_type],
"ordType": ORDERTYPE_VT2BITMEX[req.type],
"price": req.price,
"orderQty": int(req.volume),
"clOrdID": orderid,
}
# Only add price for limit order.
if req.price_type == PriceType.LIMIT:
if req.type == OrderType.LIMIT:
data["price"] = req.price
order = req.create_order_data(orderid, self.gateway_name)

View File

@ -41,7 +41,7 @@ from vnpy.trader.constant import (
Direction,
Offset,
Exchange,
PriceType,
OrderType,
Product,
Status,
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_Short] = Direction.SHORT
PRICETYPE_VT2CTP = {
PriceType.LIMIT: THOST_FTDC_OPT_LimitPrice,
PriceType.MARKET: THOST_FTDC_OPT_AnyPrice
ORDERTYPE_VT2CTP = {
OrderType.LIMIT: THOST_FTDC_OPT_LimitPrice,
OrderType.MARKET: THOST_FTDC_OPT_AnyPrice
}
OFFSET_VT2CTP = {
@ -687,7 +687,7 @@ class CtpTdApi(TdApi):
"InstrumentID": req.symbol,
"LimitPrice": req.price,
"VolumeTotalOriginal": int(req.volume),
"OrderPriceType": PRICETYPE_VT2CTP.get(req.price_type, ""),
"OrderPriceType": ORDERTYPE_VT2CTP.get(req.type, ""),
"Direction": DIRECTION_VT2CTP.get(req.direction, ""),
"CombOffsetFlag": OFFSET_VT2CTP.get(req.offset, ""),
"OrderRef": str(self.order_ref),
@ -703,11 +703,11 @@ class CtpTdApi(TdApi):
"MinVolume": 1
}
if req.price_type == PriceType.FAK:
if req.type == OrderType.FAK:
ctp_req["OrderPriceType"] = THOST_FTDC_OPT_LimitPrice
ctp_req["TimeCondition"] = THOST_FTDC_TC_IOC
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["TimeCondition"] = THOST_FTDC_TC_IOC
ctp_req["VolumeCondition"] = THOST_FTDC_VC_CV

View File

@ -244,7 +244,7 @@ class FutuGateway(BaseGateway):
def send_order(self, req: OrderRequest):
""""""
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.
if req.direction is Direction.LONG:
@ -258,7 +258,7 @@ class FutuGateway(BaseGateway):
req.volume,
futu_symbol,
side,
price_type,
futu_order_type,
trd_env=self.env,
adjust_limit=adjust_limit,
)

View File

@ -31,7 +31,7 @@ from vnpy.trader.object import (
)
from vnpy.trader.constant import (
Product,
PriceType,
OrderType,
Direction,
Exchange,
Currency,
@ -39,8 +39,8 @@ from vnpy.trader.constant import (
OptionType,
)
PRICETYPE_VT2IB = {PriceType.LIMIT: "LMT", PriceType.MARKET: "MKT"}
PRICETYPE_IB2VT = {v: k for k, v in PRICETYPE_VT2IB.items()}
ORDERTYPE_VT2IB = {OrderType.LIMIT: "LMT", OrderType.MARKET: "MKT"}
ORDERTYPE_IB2VT = {v: k for k, v in ORDERTYPE_VT2IB.items()}
DIRECTION_VT2IB = {Direction.LONG: "BUY", Direction.SHORT: "SELL"}
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}")
return ""
if req.price_type not in PRICETYPE_VT2IB:
self.gateway.write_log(f"不支持的价格类型:{req.price_type}")
if req.type not in ORDERTYPE_VT2IB:
self.gateway.write_log(f"不支持的价格类型:{req.type}")
return ""
self.orderid += 1
@ -573,7 +573,7 @@ class IbApi(EWrapper):
ib_order.orderId = self.orderid
ib_order.clientId = self.clientid
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.totalQuantity = req.volume

View File

@ -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.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.object import AccountData, CancelRequest, ContractData, OrderData, OrderRequest, \
PositionData, TradeData
@ -41,8 +41,8 @@ PRODUCT_OES2VT = {
# only limit price can match, all other price types are not perfectly match.
ORDER_TYPE_VT2OES = {
(Exchange.SSE, PriceType.LIMIT): eOesOrdTypeShT.OES_ORD_TYPE_SH_LMT,
(Exchange.SZSE, PriceType.LIMIT): eOesOrdTypeSzT.OES_ORD_TYPE_SZ_LMT,
(Exchange.SSE, OrderType.LIMIT): eOesOrdTypeShT.OES_ORD_TYPE_SH_LMT,
(Exchange.SZSE, OrderType.LIMIT): eOesOrdTypeSzT.OES_ORD_TYPE_SZ_LMT,
}
BUY_SELL_TYPE_VT2OES = {
@ -623,7 +623,7 @@ class OesTdApi:
oes_req = OesOrdReqT()
oes_req.clSeqNo = seq_id
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.invAcctId = ""
oes_req.securityId = vt_req.symbol

View File

@ -22,7 +22,7 @@ from tigeropen.trade.domain.order import ORDER_STATUS
from tigeropen.push.push_client import PushClient
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.object import (
TickData,
@ -57,9 +57,9 @@ DIRECTION_TIGER2VT = {
"sell": Direction.SHORT,
}
PRICETYPE_VT2TIGER = {
PriceType.LIMIT: "LMT",
PriceType.MARKET: "MKT",
ORDERTYPE_VT2TIGER = {
OrderType.LIMIT: "LMT",
OrderType.MARKET: "MKT",
}
STATUS_TIGER2VT = {
@ -339,7 +339,7 @@ class TigerGateway(BaseGateway):
account=self.account,
contract=contract,
action=DIRECTION_VT2TIGER[req.direction],
order_type=PRICETYPE_VT2TIGER[req.price_type],
order_type=ORDERTYPE_VT2TIGER[req.type],
quantity=int(req.volume),
limit_price=req.price,
)

View File

@ -53,9 +53,9 @@ class Product(Enum):
SPREAD = "价差"
class PriceType(Enum):
class OrderType(Enum):
"""
Order price type.
Order type.
"""
LIMIT = "限价"
MARKET = "市价"

View File

@ -6,7 +6,7 @@ from dataclasses import dataclass
from datetime import datetime
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])
@ -265,7 +265,7 @@ class OrderRequest:
symbol: str
exchange: Exchange
direction: Direction
price_type: PriceType
type: OrderType
volume: float
price: float = 0
offset: Offset = Offset.NONE

View File

@ -9,7 +9,7 @@ from typing import Any
from PyQt5 import QtCore, QtGui, QtWidgets
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 ..event import (
EVENT_TICK,
@ -597,9 +597,9 @@ class TradingWidget(QtWidgets.QWidget):
self.offset_combo = QtWidgets.QComboBox()
self.offset_combo.addItems([offset.value for offset in Offset])
self.price_type_combo = QtWidgets.QComboBox()
self.price_type_combo.addItems(
[price_type.value for price_type in PriceType])
self.order_type_combo = QtWidgets.QComboBox()
self.order_type_combo.addItems(
[order_type.value for order_type in OrderType])
double_validator = QtGui.QDoubleValidator()
double_validator.setBottom(0)
@ -625,7 +625,7 @@ class TradingWidget(QtWidgets.QWidget):
form1.addRow("名称", self.name_line)
form1.addRow("方向", self.direction_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.volume_line)
form1.addRow("接口", self.gateway_combo)
@ -838,7 +838,7 @@ class TradingWidget(QtWidgets.QWidget):
symbol=symbol,
exchange=Exchange(str(self.exchange_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,
price=price,
offset=Offset(str(self.offset_combo.currentText())),