diff --git a/vnpy/gateway/tora/constant.py b/vnpy/gateway/tora/constant.py new file mode 100644 index 00000000..76a07687 --- /dev/null +++ b/vnpy/gateway/tora/constant.py @@ -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()} \ No newline at end of file diff --git a/vnpy/gateway/tora/md.py b/vnpy/gateway/tora/md.py index c38cc8b9..241b6753 100644 --- a/vnpy/gateway/tora/md.py +++ b/vnpy/gateway/tora/md.py @@ -38,14 +38,7 @@ from vnpy.api.tora.vntora import ( CTORATstpUserLogoutField, CTORATstpRspUserLoginField, ) - - -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()} +from .constant import EXCHANGE_VT2TORA, EXCHANGE_TORA2VT def parse_datetime(date: str, time: str): @@ -96,7 +89,7 @@ class ToraMdSpi(CTORATstpMdSpi): nRequestID: int, bIsLast: bool, ) -> Any: - self.gateway.write_log("OnRspSubMarketData") + self.gateway.write_log(f"OnRspSubMarketData({pRspInfo.ErrorID})") def OnRspUnSubMarketData( self, @@ -180,6 +173,7 @@ class ToraMdSpi(CTORATstpMdSpi): ask_volume_4=data.AskVolume4, ask_volume_5=data.AskVolume5, ) + self.gateway.on_tick(tick_data) self.gateway.write_log("OnRtnDepthMarketData") def OnRtnSpecialMarketData( diff --git a/vnpy/gateway/tora/td.py b/vnpy/gateway/tora/td.py index 541c8366..b235e048 100644 --- a/vnpy/gateway/tora/td.py +++ b/vnpy/gateway/tora/td.py @@ -1,53 +1,17 @@ -from typing import Any, Sequence, List, 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 typing import Optional 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.api.tora.vntora import ( - set_async_callback_exception_handler, - AsyncDispatchException, CTORATstpTraderApi, - CTORATstpMdApi, - CTORATstpMdSpi, CTORATstpTraderSpi, TORA_TSTP_EXD_SSE, - TORA_TSTP_EXD_SZSE, - TORA_TSTP_EXD_HK, - CTORATstpFundsFlowMarketDataField, - CTORATstpEffectVolumeMarketDataField, - CTORATstpEffectPriceMarketDataField, - CTORATstpSpecialMarketDataField, - CTORATstpMarketDataField, - CTORATstpSpecificSecurityField, CTORATstpRspInfoField, - CTORATstpUserLogoutField, CTORATstpRspUserLoginField, CTORATstpQrySecurityField, CTORATstpSecurityField, CTORATstpReqUserLoginField, - TORA_TSTP_LACT_AccountID, CTORATstpQryExchangeField) + TORA_TSTP_LACT_AccountID, CTORATstpQryExchangeField, CTORATstpQryMarketDataField) -from .error_codes import error_codes, 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()} +from .error_codes import get_error_msg class ToraTdSpi(CTORATstpTraderSpi): @@ -69,6 +33,7 @@ class ToraTdSpi(CTORATstpTraderSpi): self.gateway.write_log("交易服务器登录成功") self._api.query_contracts() self._api.query_exchange() + self._api.query_market_data() def OnFrontDisconnected(self, nReason: int) -> None: self.gateway.write_log("交易服务器连接断开") @@ -101,7 +66,7 @@ class ToraTdApi: def query_contracts(self): 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()) self._if_error_write_log(err, "ReqQrySecurity") @@ -109,8 +74,16 @@ class ToraTdApi: info = CTORATstpQryExchangeField() info.ExchangeID = TORA_TSTP_EXD_SSE err = self._native_api.ReqQryExchange(info, self._get_new_req_id()) + 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): if self._native_api: self._native_api.RegisterSpi(None) diff --git a/vnpy/gateway/tora/tora_gateway.py b/vnpy/gateway/tora/tora_gateway.py index 3abaeafe..72b9cab2 100644 --- a/vnpy/gateway/tora/tora_gateway.py +++ b/vnpy/gateway/tora/tora_gateway.py @@ -20,20 +20,13 @@ CTORATstpTraderSpi, ) from .md import ToraMdApi from .td import ToraTdApi -from .error_codes import get_error_msg - - -EXCHANGE_TORA2VT = { - -} -EXCHANGE_VT2TORA = {v:k for k,v in EXCHANGE_TORA2VT.items()} +from .constant import EXCHANGE_VT2TORA def is_valid_front_address(address: str): return address.startswith("tcp://") or address.startswith("udp://") - class ToraGateway(BaseGateway): default_setting = { "账号": "",