Files
Grid_Trading/README.md
2026-07-08 22:06:39 +08:00

60 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Grid Trading
本项目是一个本地运行的 Python GUI 网格交易管理工具,第一阶段聚焦 A股/ETF 的账户、标的、手工成交、持仓成本、网格收益和回本价计算。
## 第一阶段功能
- 创建/编辑本地账户和初始资金。
- 添加 A股/ETF 标的,维护交易单位和手动估值价格。
- 配置默认网格策略模板。
- 手动录入、编辑、删除买入/卖出成交。
- 自动计算持仓数量、T+1 可用数量、持仓成本、已实现盈亏、累计网格利润、持仓回本价、账户回本价。
- 点击“刷新行情”从腾讯接口获取实时价格,并用实时价更新持仓市值和账户摘要。
- 使用 SQLite 本地保存数据,默认路径为 `data/grid_trading.db`
## 行情说明
行情刷新使用腾讯接口:
```text
http://qt.gtimg.cn/q=<symbol>
```
例如 `000001` 会自动转换为 `sz000001``600000` 会自动转换为 `sh600000`
实时行情只保存在当前程序内存中,用于显示现价、持仓市值、浮动盈亏、总资产和资金使用率;不会覆盖标的里的手动价格,也不会写入 SQLite。关闭软件后再次打开需要重新点击“刷新行情”。
## 开发环境
```powershell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e ".[dev]"
pytest
```
## 启动
```powershell
python -m grid_trading.app
```
也可以指定数据库路径:
```powershell
python -m grid_trading.app --db data/dev.db
```
## 验证
```powershell
pytest -v
python -m grid_trading.app --help
```
如果只想确认 GUI 能构造起来,不打开真实窗口,可以运行测试里的 offscreen smoke
```powershell
pytest tests/test_ui.py -v
```