Skip to main content

niutrader

同花顺自动化交易系统:用 Python 操作 Windows 上的同花顺下单程序(网上股票交易系统 5.0),实现查询资金持仓、下单、撤单。

由于 easytrader 无法使用,精简了其中功能,只保留了同花顺客户端交易功能。已经修复了其中的错误,验证码识别正常。

快速开始

  1. 安装同花顺电脑版,打开下单程序并登录资金账户(可以先用模拟炒股账户)。
  2. 同花顺下单程序设置:
    • 交易设置 → 默认交易费率:万一
    • 交易设置 → 默认买入价格 / 买入数量 / 卖出价格 / 卖出数量:都设为空
    • 界面设置 → 显示悬浮工具栏:否
  3. Windows 显示缩放:100%、125%、150%、175% 均已实测可用;改了缩放后要重启同花顺下单程序。
  4. 安装验证码识别工具 tesseract,并添加到系统环境变量 PATH:
  5. 安装 niutrader:在项目根目录执行 pip install .(开发时用 pip install -e .)。
  6. 测试连接:
from niutrader.niutrader import connect_ths

user = connect_ths(r'C:\同花顺远航版\transaction\xiadan.exe')  # 改成你的 xiadan.exe 路径
print(user.balance)   # 资金
print(user.position)  # 持仓

# 下单:客户端会按代码自动选择市场,前缀 sz / sh 可写可不写
# user.buy(security='000001', price=10.00, amount=100)

同花顺可以最小化或放在其他窗口后面,运行时会自动切到前台;运行期间不要点击鼠标或敲键盘,也不要锁屏。

查资金约 0.5 秒,查持仓/委托约 1.2 秒(含自动识别验证码),限价下单约 4 秒,详见 性能与耗时。

文档

风险提示

本项目通过模拟界面操作下单,可能因客户端版本、界面变化、操作干扰等原因出错。下单前请先在模拟账户中充分测试,实盘使用风险自负。

许可证

MIT

Metadata

Release files for niutrader 0.0.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for niutrader 0.0.22
File Size Uploaded
niutrader-0.0.22.tar.gz 69.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for niutrader 0.0.22
File Interpreter ABI Platform
niutrader-0.0.22-py3-none-any.whl Python 3 none any Details

Total release size: 103.3 kB

Release files / niutrader-0.0.22.tar.gz

Download URL niutrader-0.0.22.tar.gz
Size 69.8 kB
Tags Source
SHA-256 checksum
How to use checksums
809b986de801e581df18c14096d841457f45520d29a3fa7ebfb5b1b3cb08a714
BLAKE2b-256 checksum
How to use checksums
a95c3a13eebc027fc3fb0d35273b2920ab722b0724dbeda7e373fac81b1e24f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / niutrader-0.0.22-py3-none-any.whl

Download URL niutrader-0.0.22-py3-none-any.whl
Size 33.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe978164284f7ed4f6c9086f034246bb8701c58663ce59f02e9248b3db61a25e
BLAKE2b-256 checksum
How to use checksums
254ae31dc37bceea07e94c6e451cd44d7134da47a8e2791430576cef67cc616b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.22 This release

2 release files

0.0.16

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page