# ========== 看日志（Ctrl+C 退出查看，不停服务）==========
journalctl -u copybot-live -f
journalctl -u copybot-paper -f
journalctl -u copybot-dashboard -f
journalctl -u mihomo -f

# ========== 服务管理 ==========
systemctl restart copybot-live
systemctl restart copybot-paper
systemctl restart copybot-dashboard
systemctl restart mihomo
systemctl stop copybot-live
systemctl start copybot-live
systemctl status copybot-live
systemctl status copybot-paper
systemctl status copybot-dashboard
systemctl status mihomo

# ========== 看状态 ==========
# 看 dashboard（浏览器）
# http://45.207.206.36:18080/

# 查 live bot 链上 pUSD 余额
export LIVE_PRIVATE_KEY=$(grep LIVE_PRIVATE_KEY /etc/copybot/live.env | cut -d= -f2-) && export HTTPS_PROXY=http://127.0.0.1:7890 && python3 -c "from polymarket import SecureClient; c=SecureClient.create(private_key='$LIVE_PRIVATE_KEY'); b=c.get_balance_allowance(asset_type='COLLATERAL'); print('pUSD: \$%.2f' % (b.balance/1e6)); c.close()"

# 看 live bot feed JSON
cat /opt/winning-wallet-finder/live/copybot_live_real.json | python3 -m json.tool | head -30

# 看 paper bot feed JSON
cat /opt/winning-wallet-finder/live/copybot_live.json | python3 -m json.tool | head -30

# ========== 代理管理 ==========
# 看当前节点
curl -s http://127.0.0.1:9090/proxies/GLOBAL | python3 -c "import sys,json; print('当前节点:', json.load(sys.stdin).get('now'))"

# 测代理是否通
HTTPS_PROXY=http://127.0.0.1:7890 python3 /opt/winning-wallet-finder/host/geocheck.py | tail -1

# 手动健康检查
/opt/mihomo-healthcheck.sh && echo "代理正常" || echo "代理异常"

# 换节点（替换节点名）
curl -s -X PUT http://127.0.0.1:9090/proxies/GLOBAL -H "Content-Type: application/json" -d '{"name":"🇯🇵日本高速06|BGP|CTCU"}'

# ========== CASH≠CHAIN 修复（出现 drift 时用）==========
# 1. 停 bot
systemctl stop copybot-live
# 2. 查链上实际余额
export LIVE_PRIVATE_KEY=$(grep LIVE_PRIVATE_KEY /etc/copybot/live.env | cut -d= -f2-) && export HTTPS_PROXY=http://127.0.0.1:7890 && python3 -c "from polymarket import SecureClient; c=SecureClient.create(private_key='$LIVE_PRIVATE_KEY'); b=c.get_balance_allowance(asset_type='COLLATERAL'); print('链上 pUSD: %.2f' % (b.balance/1e6)); c.close()"
# 3. 改 bankroll（把 X.XX 换成上面查到的数字）
sed -i 's/"bankroll_usd": [0-9.]*/"bankroll_usd": X.XX/' /opt/winning-wallet-finder/config.live.json
# 4. 清 state
rm -f /opt/winning-wallet-finder/copybot_state.live.json /opt/winning-wallet-finder/copybot_fills.live.jsonl /opt/winning-wallet-finder/live/copybot_live_real.json
# 5. 重启
systemctl start copybot-live

# ========== 更新代码 ==========
cd /opt/winning-wallet-finder && git fetch origin && git reset --hard origin/main

# ========== 改配置 ==========
# 改 live 跟单钱包/金额
nano /opt/winning-wallet-finder/config.live.json
# 改 paper 跟单钱包/金额
nano /opt/winning-wallet-finder/live/copybot.paper.json
# 改密钥/代理/确认短语
nano /etc/copybot/live.env
# 改 Alchemy RPC
nano /etc/copybot/paper.env

# ========== 健康check 一键诊断 ==========
bash /tmp/healthcheck.sh

# ========== Cron ==========
crontab -l

# ========== 完全卸载 ==========
systemctl disable --now copybot-paper copybot-live copybot-dashboard mihomo
rm -f /etc/systemd/system/copybot-*.service /etc/systemd/system/mihomo.service
userdel wwf
rm -rf /opt/winning-wallet-finder