[Mod] ToraGateway: put all constant into constant.py

This commit is contained in:
nanoric 2019-06-05 15:11:05 +08:00
parent a4fbce978f
commit 5f0337e75c
4 changed files with 27 additions and 57 deletions

View File

@ -0,0 +1,10 @@
from vnpy.api.tora.vntora import TORA_TSTP_EXD_SSE, TORA_TSTP_EXD_SZSE, TORA_TSTP_EXD_HK
from vnpy.trader.constant import Exchange
EXCHANGE_TORA2VT = {
TORA_TSTP_EXD_SSE: Exchange.SSE,
TORA_TSTP_EXD_SZSE: Exchange.SZSE,
TORA_TSTP_EXD_HK: Exchange.SEHK,
}
EXCHANGE_VT2TORA = {v: k for k, v in EXCHANGE_TORA2VT.items()}

View File

@ -38,14 +38,7 @@ from vnpy.api.tora.vntora import (
CTORATstpUserLogoutField, CTORATstpUserLogoutField,
CTORATstpRspUserLoginField, CTORATstpRspUserLoginField,
) )
from .constant import EXCHANGE_VT2TORA, EXCHANGE_TORA2VT
EXCHANGE_TORA2VT = {
TORA_TSTP_EXD_SSE: Exchange.SSE,
TORA_TSTP_EXD_SZSE: Exchange.SZSE,
TORA_TSTP_EXD_HK: Exchange.SEHK,
}
EXCHANGE_VT2TORA = {v: k for k, v in EXCHANGE_TORA2VT.items()}
def parse_datetime(date: str, time: str): def parse_datetime(date: str, time: str):
@ -96,7 +89,7 @@ class ToraMdSpi(CTORATstpMdSpi):
nRequestID: int, nRequestID: int,
bIsLast: bool, bIsLast: bool,
) -> Any: ) -> Any:
self.gateway.write_log("OnRspSubMarketData") self.gateway.write_log(f"OnRspSubMarketData({pRspInfo.ErrorID})")
def OnRspUnSubMarketData( def OnRspUnSubMarketData(
self, self,
@ -180,6 +173,7 @@ class ToraMdSpi(CTORATstpMdSpi):
ask_volume_4=data.AskVolume4, ask_volume_4=data.AskVolume4,
ask_volume_5=data.AskVolume5, ask_volume_5=data.AskVolume5,
) )
self.gateway.on_tick(tick_data)
self.gateway.write_log("OnRtnDepthMarketData") self.gateway.write_log("OnRtnDepthMarketData")
def OnRtnSpecialMarketData( def OnRtnSpecialMarketData(

View File

@ -1,53 +1,17 @@
from typing import Any, Sequence, List, Optional from typing import Optional
from datetime import datetime
from threading import Thread
from vnpy.event import EventEngine
from vnpy.trader.event import EVENT_TIMER
from vnpy.trader.constant import Exchange, Product, Direction, OrderType, Status, Offset
from vnpy.trader.gateway import BaseGateway from vnpy.trader.gateway import BaseGateway
from vnpy.trader.object import (
CancelRequest,
OrderRequest,
SubscribeRequest,
TickData,
ContractData,
OrderData,
TradeData,
PositionData,
AccountData,
)
from vnpy.trader.utility import get_folder_path from vnpy.trader.utility import get_folder_path
from vnpy.api.tora.vntora import ( from vnpy.api.tora.vntora import (
set_async_callback_exception_handler,
AsyncDispatchException,
CTORATstpTraderApi, CTORATstpTraderApi,
CTORATstpMdApi,
CTORATstpMdSpi,
CTORATstpTraderSpi, CTORATstpTraderSpi,
TORA_TSTP_EXD_SSE, TORA_TSTP_EXD_SSE,
TORA_TSTP_EXD_SZSE,
TORA_TSTP_EXD_HK,
CTORATstpFundsFlowMarketDataField,
CTORATstpEffectVolumeMarketDataField,
CTORATstpEffectPriceMarketDataField,
CTORATstpSpecialMarketDataField,
CTORATstpMarketDataField,
CTORATstpSpecificSecurityField,
CTORATstpRspInfoField, CTORATstpRspInfoField,
CTORATstpUserLogoutField,
CTORATstpRspUserLoginField, CTORATstpRspUserLoginField,
CTORATstpQrySecurityField, CTORATstpSecurityField, CTORATstpReqUserLoginField, CTORATstpQrySecurityField, CTORATstpSecurityField, CTORATstpReqUserLoginField,
TORA_TSTP_LACT_AccountID, CTORATstpQryExchangeField) TORA_TSTP_LACT_AccountID, CTORATstpQryExchangeField, CTORATstpQryMarketDataField)
from .error_codes import error_codes, get_error_msg from .error_codes import get_error_msg
EXCHANGE_TORA2VT = {
TORA_TSTP_EXD_SSE: Exchange.SSE,
TORA_TSTP_EXD_SZSE: Exchange.SZSE,
TORA_TSTP_EXD_HK: Exchange.SEHK,
}
EXCHANGE_VT2TORA = {v: k for k, v in EXCHANGE_TORA2VT.items()}
class ToraTdSpi(CTORATstpTraderSpi): class ToraTdSpi(CTORATstpTraderSpi):
@ -69,6 +33,7 @@ class ToraTdSpi(CTORATstpTraderSpi):
self.gateway.write_log("交易服务器登录成功") self.gateway.write_log("交易服务器登录成功")
self._api.query_contracts() self._api.query_contracts()
self._api.query_exchange() self._api.query_exchange()
self._api.query_market_data()
def OnFrontDisconnected(self, nReason: int) -> None: def OnFrontDisconnected(self, nReason: int) -> None:
self.gateway.write_log("交易服务器连接断开") self.gateway.write_log("交易服务器连接断开")
@ -101,7 +66,7 @@ class ToraTdApi:
def query_contracts(self): def query_contracts(self):
info = CTORATstpQrySecurityField() info = CTORATstpQrySecurityField()
info.ExchangeID = TORA_TSTP_EXD_SSE # info.ExchangeID = TORA_TSTP_EXD_SSE
err = self._native_api.ReqQrySecurity(info, self._get_new_req_id()) err = self._native_api.ReqQrySecurity(info, self._get_new_req_id())
self._if_error_write_log(err, "ReqQrySecurity") self._if_error_write_log(err, "ReqQrySecurity")
@ -109,8 +74,16 @@ class ToraTdApi:
info = CTORATstpQryExchangeField() info = CTORATstpQryExchangeField()
info.ExchangeID = TORA_TSTP_EXD_SSE info.ExchangeID = TORA_TSTP_EXD_SSE
err = self._native_api.ReqQryExchange(info, self._get_new_req_id()) err = self._native_api.ReqQryExchange(info, self._get_new_req_id())
self._if_error_write_log(err, "ReqQryExchange") self._if_error_write_log(err, "ReqQryExchange")
def query_market_data(self):
info = CTORATstpQryMarketDataField()
info.ExchangeID = TORA_TSTP_EXD_SSE
info.SecurityID = "010303"
err = self._native_api.ReqQryMarketData(info, self._get_new_req_id())
self._if_error_write_log(err, "ReqQryMarketData")
def stop(self): def stop(self):
if self._native_api: if self._native_api:
self._native_api.RegisterSpi(None) self._native_api.RegisterSpi(None)

View File

@ -20,20 +20,13 @@ CTORATstpTraderSpi,
) )
from .md import ToraMdApi from .md import ToraMdApi
from .td import ToraTdApi from .td import ToraTdApi
from .error_codes import get_error_msg from .constant import EXCHANGE_VT2TORA
EXCHANGE_TORA2VT = {
}
EXCHANGE_VT2TORA = {v:k for k,v in EXCHANGE_TORA2VT.items()}
def is_valid_front_address(address: str): def is_valid_front_address(address: str):
return address.startswith("tcp://") or address.startswith("udp://") return address.startswith("tcp://") or address.startswith("udp://")
class ToraGateway(BaseGateway): class ToraGateway(BaseGateway):
default_setting = { default_setting = {
"账号": "", "账号": "",