From e61f4f21b9ff4bbc0fb610c96572baff9d9a7e24 Mon Sep 17 00:00:00 2001 From: "kingwel.xie@139.com" Date: Sun, 6 Jun 2021 19:21:04 +0800 Subject: [PATCH 01/10] config: add config for TRADE_STOCK_EXCHANGE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 交易所类型。 深圳A股、上海A股 华泰:深圳A,上海A 银河:深A,沪A --- easytrader/clienttrader.py | 4 ++-- easytrader/config/client.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/easytrader/clienttrader.py b/easytrader/clienttrader.py index b0a4b648..f662ff03 100644 --- a/easytrader/clienttrader.py +++ b/easytrader/clienttrader.py @@ -456,9 +456,9 @@ def _set_trade_params(self, security, price, amount): # 设置交易所 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..f32a7c29 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 @@ -104,6 +110,9 @@ class YH(CommonConfig): class HT(CommonConfig): DEFAULT_EXE_PATH = r"C:\htzqzyb2\xiadan.exe" + TRADE_STOCK_EXCHANGE_TYPE_SZA = "深圳A" + TRADE_STOCK_EXCHANGE_TYPE_SHA = "上海A" + BALANCE_CONTROL_ID_GROUP = { "资金余额": 1012, "冻结资金": 1013, From de44b7fcceb73b8132df9a43dc303cef3898a1d5 Mon Sep 17 00:00:00 2001 From: "kingwel.xie@139.com" Date: Sun, 6 Jun 2021 19:25:43 +0800 Subject: [PATCH 02/10] bump lxml -> 4.6.3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a101ca4f..159bff71 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ flask==1.0.2 idna==2.7 itsdangerous==0.24 jinja2==2.10 -lxml==4.2.3 +lxml==4.6.3 markupsafe==1.0 numpy==1.15.0; python_version >= '2.7' pandas==0.23.3 From 87df8a678a2062d2521754bea2c4812717533e23 Mon Sep 17 00:00:00 2001 From: "kingwel.xie@139.com" Date: Sun, 6 Jun 2021 19:25:59 +0800 Subject: [PATCH 03/10] server.py for webapi --- server.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 server.py diff --git a/server.py b/server.py new file mode 100644 index 00000000..11a26316 --- /dev/null +++ b/server.py @@ -0,0 +1,3 @@ +from easytrader import server + +server.run(port=1433) # 默认端口为 1430 From d2607cc3b496accf6a630a995927eaa7940c0ead Mon Sep 17 00:00:00 2001 From: "kingwel.xie@139.com" Date: Mon, 7 Jun 2021 23:42:36 +0800 Subject: [PATCH 04/10] close popup dialog after setting trade params --- easytrader/clienttrader.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/easytrader/clienttrader.py b/easytrader/clienttrader.py index f662ff03..34085601 100644 --- a/easytrader/clienttrader.py +++ b/easytrader/clienttrader.py @@ -454,6 +454,9 @@ 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(self._config.TRADE_STOCK_EXCHANGE_TYPE_SZA) From 8b52899ec3ee44a2358065ae62b5a7a3e1c70bca Mon Sep 17 00:00:00 2001 From: Kingwel Xie Date: Sun, 20 Jun 2021 10:43:36 +0800 Subject: [PATCH 05/10] HT xiadan & REQUYIREMENTS --- easytrader/config/client.py | 2 +- requirements.txt | 42 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/easytrader/config/client.py b/easytrader/config/client.py index f32a7c29..72087475 100644 --- a/easytrader/config/client.py +++ b/easytrader/config/client.py @@ -108,7 +108,7 @@ 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" diff --git a/requirements.txt b/requirements.txt index 159bff71..83e9bbb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,30 +2,32 @@ --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.*' +certifi==2020.12.5 +chardet==4.0.0 +click==7.1.2 +cssselect==1.1.0; 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 +flask==1.1.2 +idna==2.10 +itsdangerous==1.1.0 +jinja2==2.11.3 lxml==4.6.3 -markupsafe==1.0 -numpy==1.15.0; python_version >= '2.7' -pandas==0.23.3 -pillow==5.2.0 +markupsafe==1.1.1 +numpy==1.20.2; python_version >= '2.7' +pandas==1.2.4 +pillow==8.2.0 pyperclip==1.6.4 -pyquery==1.4.0; python_version != '3.0.*' -pytesseract==0.2.4 -python-dateutil==2.7.3 +pyquery==1.4.3; python_version != '3.0.*' +pytesseract==0.3.7 +python-dateutil==2.8.1 python-xlib==0.23 -pytz==2018.5 +pytz==2021.1 +pywin32==300 +pypiwin32==223 pywinauto==0.6.6 -requests==2.19.1 -six==1.11.0 -urllib3==1.23; python_version != '3.1.*' -werkzeug==0.14.1 +requests==2.25.1 +six==1.16.0 +urllib3==1.26.4; python_version != '3.1.*' +werkzeug==1.0.1 From 692cd20276238284c0c48b892090c7920974b44b Mon Sep 17 00:00:00 2001 From: kingwel Date: Thu, 19 Jan 2023 11:35:33 +0800 Subject: [PATCH 06/10] switch to hywt --- easytrader/pop_dialog_handler.py | 5 ++++- server.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/easytrader/pop_dialog_handler.py b/easytrader/pop_dialog_handler.py index bc4ad3fd..537a4922 100644 --- a/easytrader/pop_dialog_handler.py +++ b/easytrader/pop_dialog_handler.py @@ -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() @@ -85,7 +88,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/server.py b/server.py index 11a26316..84a988e8 100644 --- a/server.py +++ b/server.py @@ -1,3 +1,3 @@ from easytrader import server -server.run(port=1433) # 默认端口为 1430 +server.run(port=14433) # 默认端口为 1430 From 45d2b0786f33595b2c1f95d04118189f70ec3509 Mon Sep 17 00:00:00 2001 From: kingwel Date: Thu, 17 Aug 2023 15:44:56 +0800 Subject: [PATCH 07/10] 2023, pywinauto 0.68 --- easytrader/grid_strategies.py | 2 +- easytrader/pop_dialog_handler.py | 6 ++++- easytrader/refresh_strategies.py | 1 - easytrader/utils/win_gui.py | 3 ++- requirements.txt | 41 ++++++++------------------------ 5 files changed, 18 insertions(+), 35 deletions(-) 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/pop_dialog_handler.py b/easytrader/pop_dialog_handler.py index 537a4922..776440d5 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): @@ -67,6 +67,10 @@ 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: 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/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 83e9bbb4..861d3fc6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,33 +1,12 @@ --i http://mirrors.aliyun.com/pypi/simple/ ---trusted-host mirrors.aliyun.com -beautifulsoup4==4.6.0 -bs4==0.0.1 -certifi==2020.12.5 -chardet==4.0.0 -click==7.1.2 -cssselect==1.1.0; python_version != '3.3.*' -dill==0.2.8.2 easyutils==0.1.7 -flask==1.1.2 -idna==2.10 -itsdangerous==1.1.0 -jinja2==2.11.3 -lxml==4.6.3 -markupsafe==1.1.1 -numpy==1.20.2; python_version >= '2.7' -pandas==1.2.4 -pillow==8.2.0 -pyperclip==1.6.4 -pyquery==1.4.3; python_version != '3.0.*' -pytesseract==0.3.7 -python-dateutil==2.8.1 -python-xlib==0.23 -pytz==2021.1 -pywin32==300 -pypiwin32==223 -pywinauto==0.6.6 -requests==2.25.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==1.26.4; python_version != '3.1.*' -werkzeug==1.0.1 - +urllib3==2.0.4 From 99085c930685190621f36e20e314022e45642a33 Mon Sep 17 00:00:00 2001 From: kingwel Date: Thu, 28 Sep 2023 13:03:49 +0800 Subject: [PATCH 08/10] =?UTF-8?q?fix=20=E5=A7=94=E6=89=98=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E7=9A=84=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- easytrader/pop_dialog_handler.py | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/easytrader/pop_dialog_handler.py b/easytrader/pop_dialog_handler.py index 776440d5..eaf22c70 100644 --- a/easytrader/pop_dialog_handler.py +++ b/easytrader/pop_dialog_handler.py @@ -77,7 +77,7 @@ def handle(self, title) -> Optional[dict]: self._submit_by_shortcut() return None - if "委托价格的小数价格应为" in content: + if "委托价格的小数" in content: self._submit_by_shortcut() return None diff --git a/requirements.txt b/requirements.txt index 861d3fc6..ba816e37 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ pytesseract==0.3.10 pywin32==306 pywinauto==0.6.8 Requests==2.31.0 -rqopen_client==0.0.6 +#rqopen_client==0.0.6 setuptools==56.0.0 six==1.16.0 urllib3==2.0.4 From 707114cfc0a5fb128493d1171c212604065e196f Mon Sep 17 00:00:00 2001 From: kingwel Date: Wed, 7 Feb 2024 20:50:56 +0800 Subject: [PATCH 09/10] history entrust --- easytrader/clienttrader.py | 11 +++++++++++ easytrader/server.py | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/easytrader/clienttrader.py b/easytrader/clienttrader.py index 34085601..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() 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(): From e269e8523fc69df941e068234b49b8f3a27f7b96 Mon Sep 17 00:00:00 2001 From: kingwel Date: Thu, 9 May 2024 15:52:45 +0800 Subject: [PATCH 10/10] ht-client doesnt require comm password --- easytrader/ht_clienttrader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()