Metadata-Version: 2.5
Name: niutrader
Version: 0.0.22
Summary: 同花顺自动交易系统
Project-URL: homepage, https://github.com/axiaoqi/niutrader
Project-URL: documentation, https://github.com/axiaoqi/niutrader/blob/main/README.md
Project-URL: Bug Tracker, https://github.com/axiaoqi/niutrader/issues
Author-email: NiuGe <1091874347@qq.com>
License: MIT License
        
        Copyright (c) 2024 axiaoqi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Requires-Dist: easyutils
Requires-Dist: pandas>=1.0.0
Requires-Dist: pillow
Requires-Dist: pytesseract
Requires-Dist: pywin32
Requires-Dist: pywinauto==0.6.6
Requires-Dist: urllib3
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# niutrader

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

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

## 快速开始

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

```python
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 秒，详见 [性能与耗时](https://github.com/axiaoqi/niutrader/blob/main/docs/performance.md)。

## 文档

- [使用指南](https://github.com/axiaoqi/niutrader/blob/main/docs/usage.md)：准备工作、全部接口说明、返回值
- [工作原理](https://github.com/axiaoqi/niutrader/blob/main/docs/architecture.md)：模块结构、控件定位、验证码处理、下单流程
- [常见问题](https://github.com/axiaoqi/niutrader/blob/main/docs/troubleshooting.md)：报错与处理方法
- [性能与耗时](https://github.com/axiaoqi/niutrader/blob/main/docs/performance.md)：各操作实测耗时、下单耗时拆分、优化方向
- [开发指南](https://github.com/axiaoqi/niutrader/blob/main/docs/development.md)：查找控件 ID、测试、发布流程
- [AI skill](https://github.com/axiaoqi/niutrader/blob/main/skills/README.md)：让 Claude Code、Codex、Cursor 等 AI 助手查询账户、按确认规则交易
- [更新日志](https://github.com/axiaoqi/niutrader/blob/main/CHANGELOG.md)

## 风险提示

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

## 许可证

[MIT](https://github.com/axiaoqi/niutrader/blob/main/LICENSE)
