Files
winning-wallet-finder/python portfolio.py.md
gavindiaz 125470b24a sync: upstream + our customizations (dashboard, healthcheck, docs)
Synced from github/main: aebcfa2d copybot: live paper feed [skip ci]
Our additions: serve_dashboard.py, bot_dashboard.html, mihomo-healthcheck.sh,
中文文档, 我们的钱包配置
2026-07-21 07:35:48 +08:00

117 lines
7.2 KiB
Markdown
Raw Permalink 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.
---
### 1. 回测的是哪些钱包?
**默认**`live/backtest.json` 里配置的 **10 个钱包**,比你 bot 跟踪的 5 个更多:
| 钱包 | 昵称 |
| ----------------- | -------------------- |
| `0x41558102a...` | **LSB1** |
| `0xd96750bf8d...` | **imwalkinghere** |
| `0xe8ca3f758c...` | **Kruto2027** |
| `0xbadaf31941...` | **0xbadaf319** |
| `0xd7d36345c...` | **gkmgkldfmg** |
| `0x921433c935...` | **AIcAIc** |
| `0xa1d57d3292...` | **1kto1m** |
| `0x2d462b2912...` | **Vahan88** |
| `0x215adbb63b...` | **BikesAreTheBikes** |
| `0x0c3e55cf50...` | **EdwardIN** |
参数:**30 天窗口****$1000 起始资金**volume 类每注 4%。
**也可以手动指定钱包**(不走配置文件):
```powershell
python portfolio.py --wallets 0xe8ca3f758c93f44f3ec210542ab78afb7c0bcccb,0xbadaf319415c17f28824a43ae0cd912b9d84d874 --days 30 --bank 1000 --out result.json
```
---
### 2. 回测结果保存在哪?
```
live/portfolio.json
```
结构大致是:
```json
{
"bank": 1000,
"equity": 3456.78, // 最终权益
"realized": 2456.78, // 已结算盈亏
"deployed": 1000.00, // 当前持仓金额
"days": 30,
"wallets": [ { "name": "Kruto2027", "bets": 23, ... }, ... ]
}
```
同时会在 `live/history/` 目录(如果你之前跑过 daily.sh)追加校准行。
---
### 3. 全流程链
`python portfolio.py` 时内部发生的完整链路:
```
┌─────────────────────────────────────────────────────────────────────┐
│ 1. 读取配置 │
│ → live/backtest.json (10 个钱包 + 30 天窗口 + 4%/注) │
│ → live/copybot.paper.json (读取已 pin 的信念门槛) │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ 2. 拉取每钱包的历史 bets (data-api.polymarket.com) │
│ 每个钱包 → GET /positions?trader=0x...&closed=True │
│ 每笔 bet 含: 市场、方向、入场价、金额、结算状态 │
│ 新钱包首次会慢(全量拉取),后续缓存到本地无需重拉 │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ 3. 过滤"可信结算"的交易 │
│ - 跳过数据 API 无法判断结算时间的条目(高频做市商的"卖出即盈利" │
│ 伪装,这个项目专门用 trust.py 防御) │
│ - 只保留真正已结算(winner 已知)的 bets 参与盈亏计算 │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ 4. 按时间轴"回放"每一笔交易 —— 钱包入场时 bot 也入场 │
│ 对每个钱包的每笔 BUY: │
│ - 检查信念门槛(Kruto2027 是 $80,其他各不相同) │
│ - 检查入场价上限 0.95 │
│ - 计算 stake = 当时权益 × 4% │
│ - 扣除 taker feefee = shares × 0.03 × price × (1-price)
│ - 记录到 paper ledger │
│ 对钱包卖出/结算: │
│ - bot 以同样比例平仓 │
│ - 计算 exit 收益 - 再扣一次 taker fee │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ 5. 实时结算 │
│ 每次市场结算时(链上决定胜负),bot 以该时刻为准: │
│ - 标记 held position 为 WON/LOST │
│ - 释放成本 + 结算盈利 │
│ - 链上赎回免费(无 fee) │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ 6. 输出 portfolio.json │
│ { bank, equity, realized, deployed, per-wallet stats, misseds } │
└─────────────────────────────────────────────────────────────────────┘
```
### 一句话总结
> **读 `live/backtest.json` 的 10 个钱包 → 从 Polymarket 拉取他们过去 30 天的全部 bets → 用与真实 bot 完全相同的"4%/注 + 信念门槛 + taker fee + 价格保护"规则回放 → 结果写入 `live/portfolio.json`**。
所以,`portfolio.py` 的输出数字就是"如果过去 30 天你真的在用 copybot 跟踪这些钱包,你会赚到/亏掉多少钱"的最诚实估计。
现在可以直接跑:
```powershell
cd live
python portfolio.py
```
首次跑需要几分钟拉数据,之后有缓存就快了。跑完后打开 `portfolio.json``equity` 字段。