diff --git a/autobasic/cj_clienttrader.py b/autobasic/cj_clienttrader.py index ed47e99..a3f86b6 100644 --- a/autobasic/cj_clienttrader.py +++ b/autobasic/cj_clienttrader.py @@ -108,7 +108,7 @@ class ChangJiangClientTrader: # 获取动态IP new_mac = set_mac.get_macinfos() broker = '长江证券' - proxy_ip,proxy_port = get_proxy_ip(broker,new_mac,account_name) + proxy_ip,proxy_port = get_proxy_ip(broker,new_mac,self.account_name) #设置全局代理 set_proxy(proxy_ip,proxy_port) diff --git a/autobasic/dw_clienttrader.py b/autobasic/dw_clienttrader.py index c429139..4fb6bba 100644 --- a/autobasic/dw_clienttrader.py +++ b/autobasic/dw_clienttrader.py @@ -63,6 +63,7 @@ class DongWuClientTrader: for handler in self.logger.handlers: if hasattr(handler, 'baseFilename') and handler.baseFilename == os.path.abspath(logs_file): account_handler_exists = True + break if not account_handler_exists: @@ -725,6 +726,7 @@ class DongWuClientTrader: if __name__ == '__main__': + setup_logging() # account_name = str('18817026786') # account_name = str('13466839727') diff --git a/autobasic/guojin_clienttrader.py b/autobasic/guojin_clienttrader.py index f37fa44..158c8fe 100644 --- a/autobasic/guojin_clienttrader.py +++ b/autobasic/guojin_clienttrader.py @@ -92,7 +92,7 @@ class GJClientTrader: new_mac = set_mac.get_macinfos() broker = '国金证券' account_name = self.account_name - proxy_ip,proxy_port = get_proxy_ip(broker,new_mac,account_name) + proxy_ip,proxy_port = get_proxy_ip(broker,new_mac,self.account_name) # 设置全局代理 set_proxy(proxy_ip,proxy_port) diff --git a/autobasic/guosheng_clienttrader.py b/autobasic/guosheng_clienttrader.py index e1b1da4..89197d8 100644 --- a/autobasic/guosheng_clienttrader.py +++ b/autobasic/guosheng_clienttrader.py @@ -19,8 +19,8 @@ import datetime from tools import * from config import ssid,password warnings.filterwarnings('ignore') -scripts_path = os.path.dirname(os.path.realpath(__file__)) -root_path = scripts_path[:scripts_path.find(project_name)+len(project_name)] +from pathlib import Path +root_path = Path(__file__).parent.parent path = r'C:\国盛证券同花顺新一代\xiadan.exe' engine = create_engine( diff --git a/autobasic/gx_clienttrader.py b/autobasic/gx_clienttrader.py index 13386dc..eeaf744 100644 --- a/autobasic/gx_clienttrader.py +++ b/autobasic/gx_clienttrader.py @@ -19,8 +19,8 @@ import datetime from tools import * warnings.filterwarnings('ignore') -scripts_path = os.path.dirname(os.path.realpath(__file__)) -root_path = scripts_path[:scripts_path.find(project_name)+len(project_name)] +from pathlib import Path +root_path = Path(__file__).parent.parent path = r'C:\goldsun\TdxW.exe' engine = create_engine( diff --git a/autobasic/huatai_clienttrader.py b/autobasic/huatai_clienttrader.py index 2951c85..567800c 100644 --- a/autobasic/huatai_clienttrader.py +++ b/autobasic/huatai_clienttrader.py @@ -126,6 +126,7 @@ class HTClientTrader: # 关闭弹窗 self._close_prompt_windows() + time.sleep(7) #设置主窗口及菜单窗口 self.main_wnd = self._app.window(title='网上股票交易系统5.0') self.left_wnd = self.main_wnd.window(class_name='AfxWnd140s', control_id=0xC8,found_index=0).window(class_name='SysTreeView32',control_id=0x81) diff --git a/tools.py b/tools.py index a7df9c5..18d78a3 100644 --- a/tools.py +++ b/tools.py @@ -192,6 +192,36 @@ def connect_wifi(ssid: str = 'MaxEntropy', password: str = 'cskj12345678') -> bo print(f"清理wifi连接的临时文件失败: {str(e)}") +def setup_logging(): + """统一配置日志系统""" + root_logger = logging.getLogger() + root_logger.setLevel(logging.DEBUG) + + # 移除所有现有处理器(避免重复) + for handler in root_logger.handlers[:]: + root_logger.removeHandler(handler) + + # 控制台处理器 + console_handler = logging.StreamHandler() + console_handler.setLevel(logging.INFO) # 控制台只显示INFO及以上级别 + + # 文件处理器 + file_handler = logging.FileHandler('Auto_Trade_Log.log', encoding='utf-8') + file_handler.setLevel(logging.DEBUG) # 文件记录所有DEBUG及以上级别 + + # 格式化 + formatter = logging.Formatter( + '%(asctime)s - %(name)s - %(levelname)s - %(message)s' + ) + console_handler.setFormatter(formatter) + file_handler.setFormatter(formatter) + + root_logger.addHandler(console_handler) + root_logger.addHandler(file_handler) + + + + # 设置代理 # 设置代理 def set_proxy(proxy_ip: str, proxy_port: str): @@ -348,6 +378,7 @@ def set_proxy(proxy_ip: str, proxy_port: str): def get_proxy_ip(broker,new_mac,account_name) -> tuple: + start_time = time.time() get_ip_times = 0 while get_ip_times<10: try: @@ -366,7 +397,7 @@ def get_proxy_ip(broker,new_mac,account_name) -> tuple: 'Mac': new_mac, 'IP': proxy_ip, 'Port': proxy_port, - 'Location': item['prov'] + ':' + item['city']}]) + 'Location': item['prov'] + ':' + item['city']}],) # 尝试写入数据库: while True: