Frytrader
中国券商 GUI 交易适配器,支持同花顺远航版免打扰后台只读模式。
Frytrader 是 EasyTrader 的 fork,在保留上游交易核心和 import easytrader 导入名的前提下,增强了验证码识别、表格导出和后台只读能力。发行包名为 frytrader,与 PyPI 上游的 easytrader 区分;Python 导入名仍为 easytrader,已有代码无需修改。
Table of Contents
安全
本库可以驱动真实券商客户端并提交真实委托。误用会造成资金损失。
- 不要将账号、密码、验证码截图或其他凭证提交到 Git、Issue 或日志。
- 不要把交易服务暴露到公网。仓库内的
easytrader/server.py无鉴权且提供/buy、/sell、/cancel_entrust,默认监听0.0.0.0,不要直接对外运行。 - GUI 自动化会遇到弹窗、客户端升级、焦点丢失和结果不明。下单前必须自行验证委托状态,不能仅凭界面返回判断成功,结果未知时不要盲目重试。
- 本软件按 MIT 许可证「按原样」提供,不附带任何担保。交易决策和损失由使用者自行承担。
背景
EasyTrader 提供多种券商 GUI、雪球和 MiniQMT 适配器。Frytrader 保留上游交易核心,并针对通用 Windows GUI 客户端做了三类增强:
- 验证码识别:多图变体 OCR、按位投票,减少误识别。
- 表格导出:修正空行丢弃、陈旧数据判断和失败诊断。
- 后台只读模式:任务视图隔离 + 定向控件消息 + 线程激活保护,在不抢键盘、鼠标、前台和任务视图桌面的前提下读取资金、持仓、委托与成交。
本项目不是券商原生 API。GUI 路线适合低频操作,不适合高频交易。MiniQMT 是可选的另一条路径,安装 Python 依赖不授予券商权限,也不会解除券商端限制。
安装
需要 Python 3.8 或更高。GUI 客户端自动化仅在 Windows 上可用。
从 PyPI 安装:
$ pip install frytrader
从本仓库安装开发版:
$ git clone https://github.com/Fryt1/Frytrader.git
$ cd Frytrader
$ python -m venv .venv
$ .\.venv\Scripts\Activate.ps1
$ python -m pip install -e .
安装后台模式依赖:
$ python -m pip install -e ".[background]"
安装可选 MiniQMT 依赖:
$ python -m pip install -e ".[miniqmt]"
验证码识别需要另行安装 Tesseract OCR,让 tesseract.exe 可从 PATH 访问,或在配置中指定路径。
后台只读模式还需要 AutoHotkey v2。程序按 ahk_path 参数 → FRYTRADER_AHK 环境变量 → %LOCALAPPDATA%\Frytrader\runtime\AutoHotkey64.exe → PATH → 常规安装目录依次查找,不会在运行时自动下载或安装软件。
用法
查询账户:
import easytrader
user = easytrader.use("universal_client")
user.prepare(config_path="config.json")
print(user.balance)
print(user.position)
同花顺远航版后台只读模式(不抢焦点):
import easytrader
user = easytrader.use("ths", background=True)
try:
user.connect() # 连接已登录的远航版,不启动新客户端
print(user.balance)
print(user.position)
print(user.today_entrusts)
print(user.today_trades)
finally:
user.close()
后台模式的用时数据来自本机登录态实测:公开接口连续两轮 8 次读取全部成功,零桌面和前台干扰。资金约 0.44 秒,三类表格 1.2–6.7 秒(取决于验证码重试次数)。详见 docs/background.md。
尚未验证:非空持仓/委托/成交数据、长时间无人值守稳定性、非 x86 客户端、非 Windows 平台。
API
入口为 easytrader.use(broker)。账户对象提供 balance、position、today_entrusts、today_trades 等查询属性,以及上游定义的 buy、sell、撤单等方法。
支持的客户端类型和交易方法见 docs/usage.md,MiniQMT 见 docs/miniqmt.md。
后台只读模式限制:
background=True仅支持ths。传给其他适配器会抛NotImplementedError,不会静默退回前台模式。- 后台模式不继承下单能力,
buy、sell、cancel_entrust、prepare、login、auto_ipo等一律抛PermissionError。 - 默认
close()只停止后台执行器,不取消验证码、不搬回窗口。需要恢复窗口位置时显式调用user.restore_windows()。
配置
复制 config.json.example 为 config.json 并填写账号、密码和客户端路径。config.json 已加入 .gitignore。
验证码选项位于 captcha 对象:
mode:fast、balanced或accuratemanual_input:OCR 失败后是否等待手动输入;无人值守时应保持falsesave_debug_samples:是否把样本保存到本地captcha_debug目录,默认关闭tesseract_path:Tesseract 可执行文件路径;null表示使用系统PATH
这些选项只影响通用 GUI 客户端的 XLS 表格读取器,不改变券商端校验,也不赋予任何交易权限。
测试
运行离线测试(不连接真实账户):
$ python -m unittest discover -s tests -p "test_*.py"
tests/test_easytrader.py 中的集成测试受 EZ_TEST_CLIENTS 环境变量控制,会连接真实账户。没有隔离测试账户时不要启用。不要把真实委托作为 CI 测试。
发布新版本见 docs/publishing.md。
维护者
致谢
感谢 shidenggui 及 EasyTrader 的所有贡献者提供上游项目和交易适配器。Frytrader 的发行基于其 MIT 许可证条款,原始版权声明保留在 LICENSE 中。
贡献
欢迎提交 Issue 和 Pull Request。提交前请:
- 说明使用的券商客户端版本和复现步骤。
- 移除日志、配置和截图中的账号、密码、资金等敏感信息。
- 涉及 GUI 或 OCR 的改动附带脱离真实账户的测试。
Contributors
许可证
MIT © 2018 shidenggui, © 2024-2026 Fryt1。
Metadata
Release files for frytrader 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| frytrader-0.1.1.tar.gz | 134.6 kB | Without provenance | Details for frytrader-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| frytrader-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for frytrader-0.1.1-py3-none-any.whl |
Total release size: 244.6 kB
Release files / frytrader-0.1.1.tar.gz
| Download URL | frytrader-0.1.1.tar.gz |
|---|---|
| Size | 134.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a27218c9e011f80877e7267f99f5289d6c9266313b406f96e386def055afc5f
|
|
BLAKE2b-256 checksum How to use checksums |
4c9971f036d85dfb28dd620118ff5643b1ac3b7deb73af78cdaf4509f409c7e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / frytrader-0.1.1-py3-none-any.whl
| Download URL | frytrader-0.1.1-py3-none-any.whl |
|---|---|
| Size | 110.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a42c7db66aa6481ee307a3dfbec1859836819e38ad04374bb4aeecfd6b935e1
|
|
BLAKE2b-256 checksum How to use checksums |
0d0a91ed9e05cd18e4c3456d02464b5e6fb1076188b0997ac57bc3790be8b9bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Security for frytrader 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.