From 3de3cc01a93d11f355cdb895a4276678aa1ae6a8 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Mon, 30 Dec 2019 23:18:44 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=20tdx=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/data/tdx/tdx_common.py | 4 ++++ vnpy/data/tdx/tdx_future_data.py | 4 ++-- vnpy/data/tdx/tdx_stock_data.py | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/vnpy/data/tdx/tdx_common.py b/vnpy/data/tdx/tdx_common.py index 432dbe1c..2fdbdc6f 100644 --- a/vnpy/data/tdx/tdx_common.py +++ b/vnpy/data/tdx/tdx_common.py @@ -8,6 +8,10 @@ from functools import lru_cache from logging import INFO, ERROR from vnpy.trader.utility import load_json, save_json +# 期货的配置文件 +TDX_FUTURE_CONFIG = 'tdx_future_config.json' +# 股票的配置文件 +TDX_STOCK_CONFIG = 'tdx_stock_config.pkb2' @lru_cache() def get_tdx_market_code(code): diff --git a/vnpy/data/tdx/tdx_future_data.py b/vnpy/data/tdx/tdx_future_data.py index 1aa83b07..b27e3b04 100644 --- a/vnpy/data/tdx/tdx_future_data.py +++ b/vnpy/data/tdx/tdx_future_data.py @@ -37,7 +37,8 @@ from vnpy.data.tdx.tdx_common import ( get_future_contracts, save_future_contracts, get_cache_json, - save_cache_json) + save_cache_json, + TDX_FUTURE_CONFIG) # 每个周期包含多少分钟 (估算值, 没考虑夜盘和10:15的影响) NUM_MINUTE_MAPPING: Dict[str, int] = {} @@ -76,7 +77,6 @@ QSIZE = 500 ALL_MARKET_BEGIN_HOUR = 8 ALL_MARKET_END_HOUR = 16 -TDX_FUTURE_CONFIG = 'tdx_future_config.json' @lru_cache() def get_tdx_marketid(symbol): diff --git a/vnpy/data/tdx/tdx_stock_data.py b/vnpy/data/tdx/tdx_stock_data.py index 96c7245b..1ecdbb08 100644 --- a/vnpy/data/tdx/tdx_stock_data.py +++ b/vnpy/data/tdx/tdx_stock_data.py @@ -27,7 +27,8 @@ from vnpy.data.tdx.tdx_common import ( PERIOD_MAPPING, get_tdx_market_code, get_cache_config, - save_cache_config) + save_cache_config, + TDX_STOCK_CONFIG) # 每个周期包含多少分钟 NUM_MINUTE_MAPPING = {} @@ -41,7 +42,6 @@ NUM_MINUTE_MAPPING['1day'] = 60 * 5.5 # 股票,收盘时间是15:00,开 # 常量 QSIZE = 800 -STOCK_CONFIG_FILE = 'tdx_stock_config.pkb2' # 通达信 <=> 交易所代码 映射 TDX_VN_STOCK_MARKET_MAP = { @@ -74,7 +74,7 @@ class TdxStockData(object): self.symbol_exchange_dict = {} # tdx合约与vn交易所的字典 self.symbol_market_dict = {} # tdx合约与tdx市场的字典 - self.config = get_cache_config(STOCK_CONFIG_FILE) + self.config = get_cache_config(TDX_STOCK_CONFIG) self.symbol_dict = self.config.get('symbol_dict', {}) self.cache_time = self.config.get('cache_time', datetime.now() - timedelta(days=7)) @@ -115,7 +115,7 @@ class TdxStockData(object): from pytdx.util.best_ip import select_best_ip self.best_ip = select_best_ip() self.config.update({'best_ip': self.best_ip}) - save_cache_config(self.config, STOCK_CONFIG_FILE) + save_cache_config(self.config, TDX_STOCK_CONFIG) self.api.connect(self.best_ip.get('ip'), self.best_ip.get('port')) self.write_log(f'创建tdx连接, : {self.best_ip}') @@ -143,7 +143,7 @@ class TdxStockData(object): self.symbol_dict.update({f'{tdx_symbol}_{market_id}': security}) self.config.update({'symbol_dict': self.symbol_dict, 'cache_time': datetime.now()}) - save_cache_config(data=self.config, config_file_name=STOCK_CONFIG_FILE) + save_cache_config(data=self.config, config_file_name=TDX_STOCK_CONFIG) def get_security_list(self, market_id: int = 0): """