diff --git a/easyquant/main_engine.py b/easyquant/main_engine.py index 31a2179..c864e03 100644 --- a/easyquant/main_engine.py +++ b/easyquant/main_engine.py @@ -7,6 +7,9 @@ import time from collections import OrderedDict from threading import Thread, Lock +import json +import argparse +from collections import namedtuple import easytrader from logbook import Logger, StreamHandler @@ -25,7 +28,6 @@ ACCOUNT_OBJECT_FILE = 'account.session' - class MainEngine: """主引擎,负责行情 / 事件驱动引擎 / 交易""" @@ -38,10 +40,14 @@ def __init__(self, broker=None, need_data=None, quotation_engines=None, # 登录账户 if (broker is not None) and (need_data is not None): + broker += "_client" self.user = easytrader.use(broker) need_data_file = pathlib.Path(need_data) if need_data_file.exists(): - self.user.prepare(need_data) + with open(need_data_file) as json_data: + need_data = json.load(json_data) + self.user.login(**need_data) + #self.user.prepare(need_data) else: log_handler.warn("券商账号信息文件 %s 不存在, easytrader 将不可用" % need_data) else: diff --git a/ht.json b/ht.json index 48a3a92..64f7894 100644 --- a/ht.json +++ b/ht.json @@ -1,5 +1,6 @@ { - "userName":"用户名", - "servicePwd":"通讯密码", - "trdpwd":"加密后的密码" + "user":"用户名", + "comm_password":"通讯密码", + "password":"交易密码", + "exe_path":"运行路径" } diff --git a/test.py b/test.py index 868e314..7b6a3d4 100644 --- a/test.py +++ b/test.py @@ -42,10 +42,14 @@ def fetch_quotation(self): quotation_engine = DefaultQuotationEngine if quotation_choose == '1' else LFEngine -push_interval = int(input('请输入行情推送间隔(s)\n:')) -quotation_engine.PushInterval = push_interval +push_interval = input('请输入行情推送间隔(s)\n:') +if push_interval == '': + push_interval = 1 +quotation_engine.PushInterval = int(push_interval) log_type_choose = input('请输入 log 记录方式: 1: 显示在屏幕 2: 记录到指定文件\n: ') +if log_type_choose == "": + log_type_choose = '1' log_type = 'stdout' if log_type_choose == '1' else 'file' log_filepath = input('请输入 log 文件记录路径\n: ') if log_type == 'file' else ''