[更新] tdx数据接口

This commit is contained in:
msincenselee 2019-12-30 23:18:44 +08:00
parent baea2a48e1
commit 3de3cc01a9
3 changed files with 11 additions and 7 deletions

View File

@ -8,6 +8,10 @@ from functools import lru_cache
from logging import INFO, ERROR from logging import INFO, ERROR
from vnpy.trader.utility import load_json, save_json 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() @lru_cache()
def get_tdx_market_code(code): def get_tdx_market_code(code):

View File

@ -37,7 +37,8 @@ from vnpy.data.tdx.tdx_common import (
get_future_contracts, get_future_contracts,
save_future_contracts, save_future_contracts,
get_cache_json, get_cache_json,
save_cache_json) save_cache_json,
TDX_FUTURE_CONFIG)
# 每个周期包含多少分钟 (估算值, 没考虑夜盘和10:15的影响) # 每个周期包含多少分钟 (估算值, 没考虑夜盘和10:15的影响)
NUM_MINUTE_MAPPING: Dict[str, int] = {} NUM_MINUTE_MAPPING: Dict[str, int] = {}
@ -76,7 +77,6 @@ QSIZE = 500
ALL_MARKET_BEGIN_HOUR = 8 ALL_MARKET_BEGIN_HOUR = 8
ALL_MARKET_END_HOUR = 16 ALL_MARKET_END_HOUR = 16
TDX_FUTURE_CONFIG = 'tdx_future_config.json'
@lru_cache() @lru_cache()
def get_tdx_marketid(symbol): def get_tdx_marketid(symbol):

View File

@ -27,7 +27,8 @@ from vnpy.data.tdx.tdx_common import (
PERIOD_MAPPING, PERIOD_MAPPING,
get_tdx_market_code, get_tdx_market_code,
get_cache_config, get_cache_config,
save_cache_config) save_cache_config,
TDX_STOCK_CONFIG)
# 每个周期包含多少分钟 # 每个周期包含多少分钟
NUM_MINUTE_MAPPING = {} NUM_MINUTE_MAPPING = {}
@ -41,7 +42,6 @@ NUM_MINUTE_MAPPING['1day'] = 60 * 5.5 # 股票收盘时间是1500
# 常量 # 常量
QSIZE = 800 QSIZE = 800
STOCK_CONFIG_FILE = 'tdx_stock_config.pkb2'
# 通达信 <=> 交易所代码 映射 # 通达信 <=> 交易所代码 映射
TDX_VN_STOCK_MARKET_MAP = { TDX_VN_STOCK_MARKET_MAP = {
@ -74,7 +74,7 @@ class TdxStockData(object):
self.symbol_exchange_dict = {} # tdx合约与vn交易所的字典 self.symbol_exchange_dict = {} # tdx合约与vn交易所的字典
self.symbol_market_dict = {} # tdx合约与tdx市场的字典 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.symbol_dict = self.config.get('symbol_dict', {})
self.cache_time = self.config.get('cache_time', datetime.now() - timedelta(days=7)) 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 from pytdx.util.best_ip import select_best_ip
self.best_ip = select_best_ip() self.best_ip = select_best_ip()
self.config.update({'best_ip': self.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.api.connect(self.best_ip.get('ip'), self.best_ip.get('port'))
self.write_log(f'创建tdx连接, : {self.best_ip}') 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.symbol_dict.update({f'{tdx_symbol}_{market_id}': security})
self.config.update({'symbol_dict': self.symbol_dict, 'cache_time': datetime.now()}) 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): def get_security_list(self, market_id: int = 0):
""" """