Skip to content

Commit

Permalink
支持同花顺官网下载的客户端(内含对多个券商的支持) (#426)
Browse files Browse the repository at this point in the history
测试国联证券、申万宏源证券通过

Signed-off-by: Jack Huang <[email protected]>
  • Loading branch information
r52097 authored Mar 12, 2021
1 parent ca18e4e commit 376c10a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* 海通客户端(海通网上交易系统独立委托)
* 华泰客户端(网上交易系统(专业版Ⅱ))
* 国金客户端(全能行证券交易终端PC版)
* 其他券商通用同花顺客户端(需要手动登陆)
* 通用同花顺客户端(同花顺免费版)
* 其他券商专用同花顺客户端(需要手动登陆)


### 模拟交易
Expand Down
23 changes: 19 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ user = easytrader.use('gj_client')

**通用同花顺客户端**

```python
user = easytrader.use('universal_client')
```

注: 通用同花顺客户端是指同花顺官网提供的客户端软件内的下单程序,内含对多个券商的交易支持,适用于券商不直接提供同花顺客户端时的后备方案。

**其他券商专用同花顺客户端**

```python
user = easytrader.use('ths')
```

注: 通用同花顺客户端是指对应券商官网提供的基于同花顺修改的软件版本,类似银河的双子星(同花顺版本),国金证券网上交易独立下单程序(核新PC版)等。
注: 其他券商专用同花顺客户端是指对应券商官网提供的基于同花顺修改的软件版本,类似银河的双子星(同花顺版本),国金证券网上交易独立下单程序(核新PC版)等。



**雪球**

Expand All @@ -42,17 +51,23 @@ user = easytrader.use('xq')

## 三、启动并连接客户端

### (一)同花顺客户端
### (一)其他券商专用同花顺客户端

通用同花顺客户端不支持自动登录,需要先手动登录。
其他券商专用同花顺客户端不支持自动登录,需要先手动登录。

请手动打开并登录客户端后,运用connect函数连接客户端。

```python
user.connect(r'客户端xiadan.exe路径') # 类似 r'C:\htzqzyb2\xiadan.exe'
```

### (二)非同花顺客户端
### (二)通用同花顺客户端

需要先手动登录一次:添加券商,填入账户号、密码、验证码,勾选“保存密码”

第一次登录后,上述信息被缓存,可以调用prepare函数自动登录(仅需账户号、客户端路径,密码随意输入)。

### (三)其它

非同花顺的客户端,可以调用prepare函数自动登录。

Expand Down
5 changes: 5 additions & 0 deletions easytrader/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def use(broker, debug=False, **kwargs):

return GFClientTrader()

if broker.lower() in ["universal_client", "通用同花顺客户端"]:
from easytrader.universal_clienttrader import UniversalClientTrader

return UniversalClientTrader()

if broker.lower() in ["ths", "同花顺客户端"]:
from .clienttrader import ClientTrader

Expand Down
15 changes: 15 additions & 0 deletions easytrader/config/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def create(broker):
return WK
if broker == "htzq":
return HTZQ
if broker == "universal":
return UNIVERSAL
raise NotImplementedError


Expand Down Expand Up @@ -176,3 +178,16 @@ class HTZQ(CommonConfig):
}

AUTO_IPO_NUMBER = '可申购数量'


class UNIVERSAL(CommonConfig):
DEFAULT_EXE_PATH = r"c:\\ths\\xiadan.exe"

BALANCE_CONTROL_ID_GROUP = {
"资金余额": 1012,
"可用金额": 1016,
"可取金额": 1017,
"总资产": 1015,
}

AUTO_IPO_NUMBER = '可申购数量'
60 changes: 60 additions & 0 deletions easytrader/universal_clienttrader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-

import pywinauto
import pywinauto.clipboard

from easytrader import grid_strategies
from . import clienttrader


class UniversalClientTrader(clienttrader.BaseLoginClientTrader):
grid_strategy = grid_strategies.Xls

@property
def broker_type(self):
return "universal"

def login(self, user, password, exe_path, comm_password=None, **kwargs):
"""
:param user: 用户名
:param password: 密码
:param exe_path: 客户端路径, 类似
:param comm_password:
:param kwargs:
:return:
"""
self._editor_need_type_keys = False

try:
self._app = pywinauto.Application().connect(
path=self._run_exe_path(exe_path), timeout=1
)
# pylint: disable=broad-except
except Exception:
self._app = pywinauto.Application().start(exe_path)

# wait login window ready
while True:
try:
login_window = pywinauto.findwindows.find_window(class_name='#32770', found_index=1)
break
except:
self.wait(1)

self.wait(1)
self._app.window(handle=login_window).Edit1.set_focus()
self._app.window(handle=login_window).Edit1.type_keys(user)

self._app.window(handle=login_window).button7.click()

# detect login is success or not
# self._app.top_window().wait_not("exists", 100)
self.wait(5)

self._app = pywinauto.Application().connect(
path=self._run_exe_path(exe_path), timeout=10
)

self._close_prompt_windows()
self._main = self._app.window(title="网上股票交易系统5.0")

0 comments on commit 376c10a

Please sign in to comment.