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,
中文文档, 我们的钱包配置
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
部署路径有两条:**用现成云服务器**(你已经测过能通)或**用 Fly.io**(项目里已经配好了 `fly.toml`)。下面分开讲。
|
||||
|
||||
---
|
||||
|
||||
## 路径 A:用你自己的云服务器(推荐,国内用户)
|
||||
|
||||
你之前测过 `C202607051339911` 那台机能直连 Polymarket,且没有 `HTTPS_PROXY`,直接复用。
|
||||
|
||||
### A.1 paper bot(先跑这个,验证部署链路)
|
||||
|
||||
**步骤 1:装依赖**
|
||||
|
||||
```bash
|
||||
ssh root@你的服务器
|
||||
# 假设你已有 git/python3(Ubuntu/Debian)
|
||||
apt-get update && apt-get install -y git python3 python3-pip
|
||||
pip3 install duckdb
|
||||
|
||||
# paper 不需要 py-clob-client/web3,只跑 copybot.py 的 paper 路径
|
||||
```
|
||||
|
||||
**步骤 2:clone 仓库**
|
||||
|
||||
```bash
|
||||
cd /opt
|
||||
git clone https://github.com/jaxperro/winning-wallet-finder.git
|
||||
cd winning-wallet-finder
|
||||
```
|
||||
|
||||
**步骤 3:编辑 paper 配置**
|
||||
|
||||
```bash
|
||||
cd live
|
||||
nano copybot.paper.json
|
||||
# 改 "wallets",加/减跟单目标
|
||||
```
|
||||
|
||||
**步骤 4:先做一次回测,确认链路通**
|
||||
|
||||
```bash
|
||||
python3 portfolio.py --days 30
|
||||
# 应该看到:portfolio[30d rolling]: equity $... | ... -> portfolio.json
|
||||
```
|
||||
|
||||
**步骤 5:以后台进程跑 paper bot**
|
||||
|
||||
```bash
|
||||
nohup python3 ../copybot.py --config live/copybot.paper.json --poll 60 \
|
||||
> /var/log/copybot-paper.log 2>&1 &
|
||||
echo $! > /var/run/copybot-paper.pid
|
||||
```
|
||||
|
||||
看日志:
|
||||
|
||||
```bash
|
||||
tail -f /var/log/copybot-paper.log
|
||||
```
|
||||
|
||||
停止:
|
||||
|
||||
```bash
|
||||
kill $(cat /var/run/copybot-paper.pid)
|
||||
```
|
||||
|
||||
**步骤 6:开机自启(systemd)**
|
||||
|
||||
新建 `/etc/systemd/system/copybot-paper.service`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Polymarket Paper Copybot
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/opt/winning-wallet-finder
|
||||
ExecStart=/usr/bin/python3 copybot.py --config live/copybot.paper.json --poll 60
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=append:/var/log/copybot-paper.log
|
||||
StandardError=append:/var/log/copybot-paper.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
启用:
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now copybot-paper
|
||||
systemctl status copybot-paper
|
||||
```
|
||||
|
||||
**步骤 7(可选):让 bot 把状态 commit 回 GitHub**
|
||||
|
||||
`host/start.sh` 注释里写了:bot 通过 commit `copybot_state.json` + `copybot_live.json` + `copybot_fills.jsonl` 持久化——**这样服务器重启用最新 commit 恢复,不用挂 volume**。
|
||||
|
||||
要支持 commit:
|
||||
```bash
|
||||
git config user.name "copybot[bot]"
|
||||
git config user.email "copybot@users.noreply.github.com"
|
||||
# 把你的 fine-grained PAT 写到 ~/.netrc
|
||||
echo "machine github.com login YOUR_PAT password x-oauth-basic" > ~/.netrc
|
||||
chmod 600 ~/.netrc
|
||||
```
|
||||
|
||||
bot 自己会推,不用 cron。
|
||||
|
||||
---
|
||||
|
||||
### A.2 live bot(**真钱**,先确认服务器位置可下单)
|
||||
|
||||
**A.2.1 检查你的服务器能否下单**
|
||||
|
||||
```bash
|
||||
python3 host/geocheck.py
|
||||
```
|
||||
|
||||
期望输出 `VERDICT: TRADABLE`。如果显示 `BLOCKED`,live 不能在这台机上跑(paper 不受影响)。
|
||||
|
||||
**已知限制**(`fly.toml:1-7` 注释里列的):US/UK/法国/德国/意大利/荷兰/波兰/新加坡/澳大利亚/加拿大安大略/巴西 都禁。所以你得查一下你那台机的实际位置。
|
||||
|
||||
**A.2.2 准备凭证**
|
||||
|
||||
按 `实盘配置.md` 走路径 A(邮箱登录):
|
||||
1. https://reveal.magic.link/polymarket 导私钥
|
||||
2. polymarket.com/settings 拿 funder address
|
||||
|
||||
**A.2.3 systemd unit**
|
||||
|
||||
新建 `/etc/systemd/system/copybot-live.service`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Polymarket LIVE Copybot (real money)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/opt/winning-wallet-finder
|
||||
Environment="LIVE_PRIVATE_KEY=0x..."
|
||||
Environment="LIVE_FUNDER_ADDRESS=0x..."
|
||||
Environment="LIVE_SIGNATURE_TYPE=1"
|
||||
Environment="LIVE_CONFIRM=I understand real money is at risk"
|
||||
ExecStart=/usr/bin/python3 copybot.py --config config.live.json --live --poll 60
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
> 把 `0x...`、`funder` 换成你自己的。**绝不要 commit 这些值**——`Environment=` 写进 systemd 文件本身 ok,因为 `/etc/systemd/system/` 不在仓库里。但**别把这个 unit 文件 commit 到仓库**。
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now copybot-live
|
||||
systemctl status copybot-live
|
||||
```
|
||||
|
||||
**A.2.4 第一次开火务必小金额**
|
||||
|
||||
把 `config.live.json` 的 `bankroll_usd` 设成你实际钱包余额(比如 $20–$30),验证几笔成交后再加。
|
||||
|
||||
---
|
||||
|
||||
## 路径 B:用 Fly.io(项目已配好)
|
||||
|
||||
项目里已经有完整的 Fly 配置:`fly.toml`(paper worker `wwf-copybot`)+ `fly.live.toml`(live worker `wwf-copybot-live`),region 都固定 `arn`(Stockholm,绕开禁单区)。`host/start.sh` 在 boot 时自动 clone + 装依赖。
|
||||
|
||||
### B.1 装 flyctl
|
||||
|
||||
```bash
|
||||
curl -L https://fly.io/install.sh | sh
|
||||
fly auth signup # 或 login
|
||||
```
|
||||
|
||||
### B.2 部署 paper worker
|
||||
|
||||
```bash
|
||||
cd /path/to/winning-wallet-finder
|
||||
fly apps create wwf-copybot
|
||||
fly secrets set GITHUB_TOKEN=ghp_你的fine_grained_PAT_内容读写权限
|
||||
fly deploy --config fly.toml
|
||||
fly open # 看 dashboard
|
||||
fly logs --app wwf-copybot # 实时日志
|
||||
```
|
||||
|
||||
`host/start.sh:6` 设计:每次启动都从 GitHub clone 最新代码 + 拉最新 `copybot_state.json`——**改完 `copybot.paper.json` 直接 `fly apps restart wwf-copybot` 即可**(见 `live/deploy_bot.sh`),不用重新 `fly deploy`,除非改了 `host/` 或 `fly.toml`。
|
||||
|
||||
### B.3 部署 live worker(**真钱**)
|
||||
|
||||
```bash
|
||||
fly apps create wwf-copybot-live
|
||||
fly secrets set --app wwf-copybot-live \
|
||||
GITHUB_TOKEN=ghp_... \
|
||||
LIVE_PRIVATE_KEY=0x... \
|
||||
LIVE_FUNDER_ADDRESS=0x... \
|
||||
LIVE_SIGNATURE_TYPE=1 \
|
||||
LIVE_CONFIRM="I understand real money is at risk"
|
||||
|
||||
fly deploy --config fly.live.toml --app wwf-copybot-live
|
||||
```
|
||||
|
||||
- 这是**与 paper 完全独立的 app**,状态文件 `copybot_state.live.json` 单独走
|
||||
- 没设齐三个 LIVE_* 变量时,机器会**自动 idle 不下单**(`start.sh:50-55`)——这是故意设计的安全网
|
||||
|
||||
### B.4 改 follow set(paper)
|
||||
|
||||
```bash
|
||||
# 1. 改 live/copybot.paper.json 的 wallets
|
||||
# 2. 一键部署:
|
||||
./live/deploy_bot.sh
|
||||
```
|
||||
|
||||
它会自动:校验 JSON、commit+push、重启 Fly worker、等新 banner。详见 `live/deploy_bot.sh`。
|
||||
|
||||
---
|
||||
|
||||
## 路径选择建议
|
||||
|
||||
| 你的情况 | 推荐路径 |
|
||||
| ------------------------------------- | ----------------------------------------- |
|
||||
| 已有国外云服务器、想省钱、运维可控 | **路径 A**(你测过能通的那台 `C202...`) |
|
||||
| 不想管服务器、24/7 不间断、愿付 $5/月 | **路径 B Fly.io**(`arn` region + 512MB) |
|
||||
| 跑 paper / 回测,不跑实盘 | 任意一条服务器都行,不用 geocheck |
|
||||
| 跑实盘(真钱) | 必须先 `python3 host/geocheck.py` 通过 |
|
||||
|
||||
---
|
||||
|
||||
## 部署后的检查清单
|
||||
|
||||
1. **paper bot 起活**:`tail -f /var/log/copybot-paper.log` 看 `watching N wallets · ...`,`drift` 一直是 0
|
||||
2. **每天 `./live/daily.sh`**:cron 跑数据刷新(10:00)
|
||||
3. **仪表盘最新**:`dashboard.html` 双击打开,看 `Live` 栏是 bot 当前的书
|
||||
4. **commit 回了 GitHub**:`copybot_state.json` 和 `live/copybot_live.json` 应该每几分钟有 commit
|
||||
5. **live bot 额外检查**:`fly logs` 或 `journalctl -u copybot-live` 看 `geo gate PASS` + `cash≠chain OK`(启动时 `host/start.sh:39` 已经过了一遍 geocheck,但 copybot.py 还会再过一遍——见 `LIVE_ROLLOUT.md` Phase 1.5)
|
||||
|
||||
要我帮你直接在那台 `C202...` 云服务器上把 paper bot 装起来吗?
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sudo install -d -m 750 -o wwf -g wwf /etc/copybot
|
||||
sudo tee /etc/copybot/paper.env > /dev/null <<EOF
|
||||
ALCHEMY_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/zRBlLYCNBZHqbz_0LK66L
|
||||
EOF
|
||||
sudo chown wwf:wwf /etc/copybot/paper.env
|
||||
sudo chmod 600 /etc/copybot/paper.env
|
||||
Reference in New Issue
Block a user