Skip to main content

同花顺交易自动化系统

Project description

PyPI Version Python Version License CI

FastAPI pywinauto Pydantic Uvicorn

EasyTHS - 同花顺交易自动化系统

基于 pywinauto 的同花顺交易软件自动化项目,提供 RESTful API 接口,通过操作队列确保高并发下的操作顺序和一致性。

项目特点

  • 操作串行化:所有 GUI 操作串行执行,避免并发冲突
  • 队列管理:支持优先级的任务队列,确保操作顺序
  • 错误恢复:完整的错误处理和恢复机制
  • 实时监控:详细的日志记录和状态监控
  • RESTful API:完整的 HTTP 接口,支持各种语言集成
  • MCP 支持:支持 Model Context Protocol,可被 AI 助手(如 Claude Desktop)直接调用
  • 验证码识别:内置 CRNN 模型,支持自定义微调适配特定验证码样式

文档

详细文档请访问:https://noimank.github.io/easyths/

快速开始

环境要求

  • Windows 10/11
  • Python 3.12+
  • 同花顺交易客户端

请一定一定要根据项目要求设置下单客户端,否则不保证可用

安装

# 使用 uvx 一键运行服务端(推荐),需要已经打开下单软件并登录进入页面
uvx easyths[server]

# 或使用 pip 安装服务端
pip install easyths[server]
easyths

服务默认运行在 http://127.0.0.1:7648

更多安装方式请参考 安装指南

支持的操作

操作 说明 参考操作耗时(秒)
买入 (buy) 股票买入委托 1.5~2.0
卖出 (sell) 股票卖出委托 1.5~2.0
持仓查询 (holding_query) 查询当前持仓 1.6~3.2
资金查询 (funds_query) 查询账户资金 0.6~1.0
委托查询 (order_query) 查询委托记录 2.8~3.3
撤单 (order_cancel) 撤销委托 1.0~1.6
历史委托查询 (historical_commission_query) 模拟账号不支持 查询历史成交 2.8~3.3
国债逆回购购买 (reverse_repo_buy) 购买国债逆回购 1.8~2.2
国债逆回购年化利率查询 (reverse_repo_query) 查询国债逆回购年化利率 0.9~1.3
条件买入 (condition_buy) 设置条件买入策略 2.4~3.1
止盈止损 (stop_loss_profit) 设置止盈止损策略 2.6~3.2
条件单查询 (condition_order_query) 查询现有的条件单 1.7~2.1
条件单删除 (condition_order_cancel) 删除指定条件单 2.0~2.5

详细的 API 接口和参数说明请参考 API 文档

快速示例

使用 Python SDK(推荐)

# 仅安装客户端 SDK(轻量级,跨平台)
pip install easyths
from easyths import TradeClient

# 创建客户端
with TradeClient(host="127.0.0.1", port=7648, api_key="your-api-key") as client:
    # 买入股票
    result = client.buy("000001", 10.50, 100)
    if result["success"]:
        print("买入成功")

    # 查询持仓
    result = client.query_holdings()
    holdings = result["data"]["holdings"]
    print(f"持仓数: {len(holdings)}")

更多 SDK 用法请参考 Client SDK 文档

使用 cURL API

# 启动服务
uvx easyths[server]

# 买入股票
curl -X POST http://127.0.0.1:7648/api/v1/operations/buy \
  -H "Content-Type: application/json" \
  -d '{"params": {"stock_code": "000001", "price": 10.50, "quantity": 100}}'

# 查询持仓
curl -X POST http://127.0.0.1:7648/api/v1/operations/holding_query \
  -H "Content-Type: application/json" \
  -d '{}'

更多使用示例请参考 基础用法

使用 MCP(AI 助手集成)

EasyTHS 支持 MCP (Model Context Protocol),可以让 Claude Desktop 等 AI 助手直接调用交易功能。

Claude Desktop 配置示例

{
  "mcpServers": {
    "easyths": {
      "transport": {
        "type": "http",
        "url": "http://localhost:7648/api/mcp-server/"
      }
    }
  }
}

配置后,你可以在 Claude Desktop 中直接对话:

  • "查询我的账户资金"
  • "买入 100 股平安银行,价格 10.5 元"
  • "当贵州茅台低于 1500 元时买入 100 股"

详细的 MCP 配置和使用说明请参考 MCP 服务文档

系统要求

  • 操作系统: Windows 10/11(必须,pywinauto 要求)
  • Python: 3.12+
  • 交易软件: 同花顺交易客户端

同花顺客户端设置

详细的配置步骤请查看 客户端设置指南

必须完成的设置:

  1. 关闭悬浮工具栏
  2. 关闭所有交易确认对话框
  3. 开启"切换页面清空代码"
  4. 清空默认买入/卖出价格

这些设置对于自动化交易系统的正常运行至关重要,请务必按照文档完成配置。

验证码模型微调

EasyTHS 内置 CRNN 验证码识别模型,支持微调以适配特定的验证码样式。

快速微调

cd captcha_model

# 1. 生成训练数据
python data_generate.py --num_samples 2000 --output_dir data/train
python data_generate.py --num_samples 500 --output_dir data/val
python data_generate.py --num_samples 500 --output_dir data/test

# 2. 将预训练模型放到 outputs 目录
# cp your_pretrained_model.pt outputs/best_model.pt

# 3. 开始微调
python train.py --config config_finetune.yaml

# 4. 评估模型
python eval.py --model outputs/best_model.pt

关键配置

微调使用 config_finetune.yaml,主要区别于从头训练:

  • 更低学习率0.00001 vs 0.0001,避免破坏预训练权重
  • 固定学习率调度constant 调度器,适合微调稳定阶段
  • 更强数据增强:噪声强度更高,提升泛化能力

详细配置说明和高级用法请参考 captcha_model/README.md

安全须知

  • 本系统仅供学习和研究使用
  • 自动化交易存在风险,请谨慎使用
  • 建议先在模拟环境测试
  • 请保护好 API 密钥安全

许可证

MIT License

联系方式


如果这个项目对您有帮助,请给个 ⭐ Star 支持一下!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easyths-1.6.3.tar.gz (7.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easyths-1.6.3-py3-none-any.whl (7.9 MB view details)

Uploaded Python 3

File details

Details for the file easyths-1.6.3.tar.gz.

File metadata

  • Download URL: easyths-1.6.3.tar.gz
  • Upload date:
  • Size: 7.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for easyths-1.6.3.tar.gz
Algorithm Hash digest
SHA256 00686188aa49f85c1c0706d8b84558cb3dd34f4dcca7714ff0201ad87d418355
MD5 6ae913399e5fc2e5727022ad36f47f54
BLAKE2b-256 05b82783c7ac6da672bc0de6f435724cb09b3865e86dc6bf103db449db959872

See more details on using hashes here.

Provenance

The following attestation bundles were made for easyths-1.6.3.tar.gz:

Publisher: publish.yml on noimank/easyths

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file easyths-1.6.3-py3-none-any.whl.

File metadata

  • Download URL: easyths-1.6.3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for easyths-1.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e547cc2ec36888a83641ad18d1d3640991b1511e9e22d9bd5c70ff93c5b3d8d0
MD5 367dd0c1dc712c34d60fc3cade01c0c5
BLAKE2b-256 20c5b162b1ee7a497bf5499a7856d4509de77a3dc14bb85c84205545b4b0729a

See more details on using hashes here.

Provenance

The following attestation bundles were made for easyths-1.6.3-py3-none-any.whl:

Publisher: publish.yml on noimank/easyths

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page