diff --git a/easytrader/clienttrader.py b/easytrader/clienttrader.py index b0a4b648..6bed1cf1 100644 --- a/easytrader/clienttrader.py +++ b/easytrader/clienttrader.py @@ -153,12 +153,23 @@ def today_entrusts(self): return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID) + @property + def history_entrusts(self): + self._switch_left_menus(["查询[F4]", "历史委托"]) + + return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID) + @property def today_trades(self): self._switch_left_menus(["查询[F4]", "当日成交"]) return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID) + def history_trades(self): + self._switch_left_menus(["查询[F4]", "历史成交"]) + + return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID) + @property def cancel_entrusts(self): self.refresh() @@ -454,11 +465,14 @@ def _set_trade_params(self, security, price, amount): # wait security input finish self.wait(0.1) + # close the popup dialog to prompt selecting stock exchange type + self._handle_pop_dialogs() + # 设置交易所 if security.lower().startswith("sz"): - self._set_stock_exchange_type("深圳A股") + self._set_stock_exchange_type(self._config.TRADE_STOCK_EXCHANGE_TYPE_SZA) if security.lower().startswith("sh"): - self._set_stock_exchange_type("上海A股") + self._set_stock_exchange_type(self._config.TRADE_STOCK_EXCHANGE_TYPE_SHA) self.wait(0.1) diff --git a/easytrader/config/client.py b/easytrader/config/client.py index a028ecef..72087475 100644 --- a/easytrader/config/client.py +++ b/easytrader/config/client.py @@ -26,6 +26,9 @@ class CommonConfig: # 交易所类型。 深圳A股、上海A股 TRADE_STOCK_EXCHANGE_CONTROL_ID = 1003 + TRADE_STOCK_EXCHANGE_TYPE_SZA = "深圳A股" + TRADE_STOCK_EXCHANGE_TYPE_SHA = "上海A股" + # 撤销界面上, 全部撤销按钮 TRADE_CANCEL_ALL_ENTRUST_CONTROL_ID = 30001 @@ -82,7 +85,10 @@ class CommonConfig: class YH(CommonConfig): - DEFAULT_EXE_PATH = r"C:\双子星-中国银河证券\Binarystar.exe" + DEFAULT_EXE_PATH = r"C:\双子星金融终端独立交易-中国银河证券\xiadan.exe" + + TRADE_STOCK_EXCHANGE_TYPE_SZA = "深A" + TRADE_STOCK_EXCHANGE_TYPE_SHA = "沪A" BALANCE_GRID_CONTROL_ID = 1308 @@ -102,7 +108,10 @@ class YH(CommonConfig): class HT(CommonConfig): - DEFAULT_EXE_PATH = r"C:\htzqzyb2\xiadan.exe" + DEFAULT_EXE_PATH = r"C:\htwt\xiadan.exe" + + TRADE_STOCK_EXCHANGE_TYPE_SZA = "深圳A" + TRADE_STOCK_EXCHANGE_TYPE_SHA = "上海A" BALANCE_CONTROL_ID_GROUP = { "资金余额": 1012, diff --git a/easytrader/grid_strategies.py b/easytrader/grid_strategies.py index b294b967..2ba7adc6 100644 --- a/easytrader/grid_strategies.py +++ b/easytrader/grid_strategies.py @@ -63,7 +63,7 @@ def _set_foreground(self, grid=None): if grid.has_style(win32defines.WS_MINIMIZE): # if minimized ShowWindow(grid.wrapper_object(), 9) # restore window state else: - SetForegroundWindow(grid.wrapper_object()) # bring to front + SetForegroundWindow(grid.wrapper_object().handle) # bring to front except: pass diff --git a/easytrader/ht_clienttrader.py b/easytrader/ht_clienttrader.py index b1b0e869..5057dcd8 100644 --- a/easytrader/ht_clienttrader.py +++ b/easytrader/ht_clienttrader.py @@ -46,7 +46,7 @@ def login(self, user, password, exe_path, comm_password=None, **kwargs): self._app.top_window().Edit1.type_keys(user) self._app.top_window().Edit2.type_keys(password) - self._app.top_window().Edit3.set_edit_text(comm_password) + #self._app.top_window().Edit3.set_edit_text(comm_password) self._app.top_window().button0.click() diff --git a/easytrader/pop_dialog_handler.py b/easytrader/pop_dialog_handler.py index bc4ad3fd..eaf22c70 100644 --- a/easytrader/pop_dialog_handler.py +++ b/easytrader/pop_dialog_handler.py @@ -17,7 +17,7 @@ def _set_foreground(window): if window.has_style(win32defines.WS_MINIMIZE): # if minimized ShowWindow(window.wrapper_object(), 9) # restore window state else: - SetForegroundWindow(window.wrapper_object()) # bring to front + SetForegroundWindow(window.wrapper_object().handle) # bring to front @perf_clock def handle(self, title): @@ -37,6 +37,9 @@ def handle(self, title): def _extract_content(self): return self._app.top_window().Static.window_text() + def _extract_content_edit(self): + return self._app.top_window().Edit.window_text() + @staticmethod def _extract_entrust_id(content): return re.search(r"[\da-zA-Z]+", content).group() @@ -64,13 +67,17 @@ def handle(self, title) -> Optional[dict]: self._submit_by_shortcut() return None + if title == "风险提示": + self._submit_by_click() + return None + if title == "提示信息": content = self._extract_content() if "超出涨跌停" in content: self._submit_by_shortcut() return None - if "委托价格的小数价格应为" in content: + if "委托价格的小数" in content: self._submit_by_shortcut() return None @@ -85,7 +92,7 @@ def handle(self, title) -> Optional[dict]: return None if title == "提示": - content = self._extract_content() + content = self._extract_content_edit() if "成功" in content: entrust_no = self._extract_entrust_id(content) self._submit_by_click() diff --git a/easytrader/refresh_strategies.py b/easytrader/refresh_strategies.py index e638c359..4c7b2099 100644 --- a/easytrader/refresh_strategies.py +++ b/easytrader/refresh_strategies.py @@ -12,7 +12,6 @@ from easytrader.log import logger from easytrader.utils.captcha import captcha_recognize -from easytrader.utils.win_gui import SetForegroundWindow, ShowWindow, win32defines if TYPE_CHECKING: # pylint: disable=unused-import diff --git a/easytrader/server.py b/easytrader/server.py index 02ce98d6..91a4dc13 100644 --- a/easytrader/server.py +++ b/easytrader/server.py @@ -72,6 +72,15 @@ def get_today_entrusts(): return jsonify(today_entrusts), 200 +@app.route("/history_entrusts", methods=["GET"]) +@error_handle +def get_history_entrusts(): + user = global_store["user"] + history_entrusts = user.history_entrusts + + return jsonify(history_entrusts), 200 + + @app.route("/today_trades", methods=["GET"]) @error_handle def get_today_trades(): @@ -81,6 +90,14 @@ def get_today_trades(): return jsonify(today_trades), 200 +@app.route("/history_trades", methods=["GET"]) +@error_handle +def get_history_trades(): + user = global_store["user"] + history_trades = user.history_trades + + return jsonify(history_trades), 200 + @app.route("/cancel_entrusts", methods=["GET"]) @error_handle def get_cancel_entrusts(): diff --git a/easytrader/utils/win_gui.py b/easytrader/utils/win_gui.py index 903c5f91..c0a7f2d5 100644 --- a/easytrader/utils/win_gui.py +++ b/easytrader/utils/win_gui.py @@ -1,3 +1,4 @@ # coding:utf-8 from pywinauto import win32defines -from pywinauto.win32functions import SetForegroundWindow, ShowWindow +from pywinauto.win32functions import ShowWindow +from win32gui import SetForegroundWindow diff --git a/requirements.txt b/requirements.txt index a101ca4f..ba816e37 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,31 +1,12 @@ --i http://mirrors.aliyun.com/pypi/simple/ ---trusted-host mirrors.aliyun.com -beautifulsoup4==4.6.0 -bs4==0.0.1 -certifi==2018.4.16 -chardet==3.0.4 -click==6.7 -cssselect==1.0.3; python_version != '3.3.*' -dill==0.2.8.2 easyutils==0.1.7 -flask==1.0.2 -idna==2.7 -itsdangerous==0.24 -jinja2==2.10 -lxml==4.2.3 -markupsafe==1.0 -numpy==1.15.0; python_version >= '2.7' -pandas==0.23.3 -pillow==5.2.0 -pyperclip==1.6.4 -pyquery==1.4.0; python_version != '3.0.*' -pytesseract==0.2.4 -python-dateutil==2.7.3 -python-xlib==0.23 -pytz==2018.5 -pywinauto==0.6.6 -requests==2.19.1 -six==1.11.0 -urllib3==1.23; python_version != '3.1.*' -werkzeug==0.14.1 - +Flask==2.3.2 +pandas==2.0.3 +Pillow==10.0.0 +pytesseract==0.3.10 +pywin32==306 +pywinauto==0.6.8 +Requests==2.31.0 +#rqopen_client==0.0.6 +setuptools==56.0.0 +six==1.16.0 +urllib3==2.0.4 diff --git a/server.py b/server.py new file mode 100644 index 00000000..84a988e8 --- /dev/null +++ b/server.py @@ -0,0 +1,3 @@ +from easytrader import server + +server.run(port=14433) # 默认端口为 1430