From 74d156b3aebfefa9326f99943f4947dba175709c Mon Sep 17 00:00:00 2001 From: msincenselee Date: Thu, 17 Sep 2020 16:16:57 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E5=BC=BA=E5=8A=9F=E8=83=BD]=20tdx?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=99=AE=E9=80=9A=E5=90=88=E7=BA=A6;?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9C=E7=A8=8B=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AE=BF=E9=97=AE;=E8=82=A1=E7=A5=A8?= =?UTF-8?q?=E7=A0=96=E5=9B=BE=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A81?= =?UTF-8?q?=E5=88=86=E9=92=9F=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prod/jobs/refill_stock_renko.py | 18 ++++++++++++++---- prod/jobs/refill_tdx_stock_bars.py | 3 +-- vnpy/data/tdx/tdx_future_data.py | 7 ++++++- vnpy/trader/utility.py | 25 +++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/prod/jobs/refill_stock_renko.py b/prod/jobs/refill_stock_renko.py index d2668da6..1cac4fce 100644 --- a/prod/jobs/refill_stock_renko.py +++ b/prod/jobs/refill_stock_renko.py @@ -16,7 +16,7 @@ from vnpy.data.renko.rebuild_stock import * if __name__ == "__main__": if len(sys.argv) < 4: - print(u'请输入三个参数 host symbol pricetick') + print(u'请输入三个参数 host symbol pricetick [ bar]') exit() print(sys.argv) host = sys.argv[1] @@ -24,15 +24,25 @@ if __name__ == "__main__": setting = { "host": host, "db_name": STOCK_RENKO_DB_NAME, - "cache_folder": os.path.join(vnpy_root, 'tick_data', 'tdx', 'stock') + "cache_folder": os.path.join(vnpy_root, 'tick_data', 'tdx', 'stock'), + 'bar_folder': os.path.join(vnpy_root,'bar_data') } builder = StockRenkoRebuilder(setting) symbol = sys.argv[2] price_tick = float(sys.argv[3]) + if len(sys.argv) >= 5 and sys.argv[4] == 'bar': + using_bar = True + else: + using_bar = False - print(f'启动期货renko补全,数据库:{host}/{STOCK_RENKO_DB_NAME} 合约:{symbol}') - builder.start(symbol=symbol, price_tick=price_tick, height=['K3', 'K5', 'K10'], refill=True) + if using_bar: + print(f'启动股票bar=> renko补全,数据库:{host}/{STOCK_RENKO_DB_NAME} 合约:{symbol}') + builder.start_with_bar(symbol=symbol, price_tick=price_tick, height=['K3', 'K5', 'K10']) + + else: + print(f'启动股票tick=> renko补全,数据库:{host}/{STOCK_RENKO_DB_NAME} 合约:{symbol}') + builder.start(symbol=symbol, price_tick=price_tick, height=['K3', 'K5', 'K10'], refill=True) print(f'exit refill {symbol} renkos') diff --git a/prod/jobs/refill_tdx_stock_bars.py b/prod/jobs/refill_tdx_stock_bars.py index 2aa20c85..30d0fc45 100644 --- a/prod/jobs/refill_tdx_stock_bars.py +++ b/prod/jobs/refill_tdx_stock_bars.py @@ -35,7 +35,7 @@ stock_list = load_json('stock_list.json') symbol_dict = api_01.symbol_dict -# 逐一指数合约下载并更新 +# 逐一合约下载并更新 for stock_code in stock_list: market_id = get_tdx_market_code(stock_code) if market_id == 0: @@ -108,6 +108,5 @@ for stock_code in stock_list: print(f'更新{stock_code} {stock_name} 数据 => 文件{bar_file_path}, 最后记录:{bars[-1]}') - print('更新完毕') os._exit(0) diff --git a/vnpy/data/tdx/tdx_future_data.py b/vnpy/data/tdx/tdx_future_data.py index b0721c8c..b59c4b37 100644 --- a/vnpy/data/tdx/tdx_future_data.py +++ b/vnpy/data/tdx/tdx_future_data.py @@ -300,8 +300,13 @@ class TdxFutureData(object): if '.' in symbol: symbol = symbol.split('.')[0] tdx_symbol = symbol.upper().replace('_', '') - tdx_symbol = tdx_symbol.replace('99', 'L9') underlying_symbol = get_underlying_symbol(symbol).upper() + + if '99' in tdx_symbol: + tdx_symbol = tdx_symbol.replace('99', 'L9') + else: + tdx_symbol = get_full_symbol(symbol).upper() + tdx_index_symbol = underlying_symbol + 'L9' vn_exchange = self._get_vn_exchange(underlying_symbol) diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index 29fe1f9a..3911f23a 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -1404,3 +1404,28 @@ def get_bars(csv_file: str, count += 1 return bars + + +def get_remote_file(remote_ip, remote_file_path, mode='rb'): + """ + 获取远程服务器的文件 + :param remote_ip: 服务器ip地址 + :param remote_file_path:服务器上文件路径 + :param mode: 打开文件目录 + :return: + """ + try: + import paramiko + pkey = '/home/trade/.ssh/id_rsa' + key = paramiko.RSAKey.from_private_key_file(pkey) + paramiko.util.log_to_file('log/paramiko.log') + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + # ssh.load_system_host_keys() + ssh.connect(remote_ip, username='trade', pkey=key) + sftp_client = ssh.open_sftp() + remote_file = sftp_client.open(remote_file_path, mode) + return remote_file + except Exception as ex: + print(u'打开远程目录异常:{}'.format(str(ex))) + return None