首先感谢原作者的辛苦编辑这个库
但是这个库已经过期了,现在同花顺版本已经来到了7.72版本了。很多控件都有变化,也有地方加了验证码。所以要改写。我这里有个简单调用例子是广发证券的核新科技版本,
import easytrader
from easytrader.utils.stock import get_today_ipo_data
user = easytrader.use("gf_client")
user.prepare(user='你帐号',password='你密码',exe_path=r'D:\gfzqrzrq\xiadan.exe')
balance = user.balance
print(balance)
position = user.position
print(position)
print(user.auto_ipo())
print(get_today_ipo_data())#这个需要根据之前的帖子改写了。
#user.sell('204001', price=2.55, amount=100)
首先下载pip install easytrader
找到python目录 lib/site-packages/easytrader
找到gf_clienttrader.py 这个是广发证券的自动化下单代码,里面 login() 没考虑到长时间不操作客户端进入锁屏状态,只需要输入密码就可以了。
我们加入
self._app = pywinauto.Application().connect(
path=self._run_exe_path(exe_path), timeout=1
)下面加入下面两行。
if self._app.top_window().window(control_id=0x410, class_name="Static").window_text() == '请输入您的交易密码':
self.type_edit_control_keys(self._app.top_window().Edit1, password)
self._app.top_window()["确定"].click()
拷贝grid控件的验证码长度不对。
找到grid_strategies.py
首先import time
因为很多时候要等待弹出窗口
在def _get_clipboard_data(self) -> str:函数里面找到while count > 0: 在下面加入
rect1 =self._trader.app.top_window().window(control_id=0x965, class_name="Static").rectangle()
rect1.right = rect1.right+30
#print(rect1)保存的验证码要大一点区域。
self._trader.app.top_window().window(
control_id=0x965, class_name="Static"
).capture_as_image(rect=rect1).save(
file_path
) # 保存验证码
time.sleep(0.2)
判断验证码长度不能等于4,现在都等于5了。
if len(captcha_num) >3: