deploy-bot

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Deploy Polymarket Bot

部署Polymarket交易机器人

WARNING: ALWAYS USE THIS SKILL when deploying changes. Never use manual docker commands.
Safe deployment workflow for the Polymarket arbitrage trading bot that:
  1. Runs regression tests to catch bugs before deployment
  2. Checks for active trades to prevent interrupting pending positions
警告:部署更改时请务必使用本Skill,切勿手动执行docker命令。
这是Polymarket套利交易机器人的安全部署工作流,具备以下特性:
  1. 运行回归测试,在部署前发现bug
  2. 检查活跃交易,避免中断未了结的头寸

Why This Matters

为什么这很重要

The bot executes real-money arbitrage trades on Polymarket. Deploying broken code or restarting during active trades can cause:
  1. Bugs: Untested code can break execution, tracking, or settlement
  2. Lost visibility: Restarting during active trades loses pending position data
  3. Missed resolutions: Container restart can miss market resolution events
  4. Financial losses: All of the above can result in real money losses
该机器人在Polymarket上执行真实资金的套利交易。部署存在问题的代码或在活跃交易期间重启可能导致:
  1. 程序漏洞:未测试的代码可能破坏交易执行、跟踪或结算流程
  2. 数据丢失:活跃交易期间重启会丢失未了结头寸的数据
  3. 错过结算:容器重启可能错过市场结算事件
  4. 资金损失:上述所有情况都可能导致实际资金损失

Quick Deploy

快速部署

bash
undefined
bash
undefined

From the polyjuiced repo root

从polyjuiced仓库根目录执行

./.agents/skills/deploy-bot/deploy.sh
./.agents/skills/deploy-bot/deploy.sh

Skip tests only (still checks active trades)

仅跳过测试(仍会检查活跃交易)

./.agents/skills/deploy-bot/deploy.sh --skip-tests
./.agents/skills/deploy-bot/deploy.sh --skip-tests

Force deploy (DANGEROUS - skips ALL safety checks)

强制部署(危险 - 跳过所有安全检查)

./.agents/skills/deploy-bot/deploy.sh --force
undefined
./.agents/skills/deploy-bot/deploy.sh --force
undefined

What the Script Does

脚本执行流程

  1. Run Regression Tests (Step 0)
    • Builds a fresh container with latest code
    • Runs
      pytest tests/ -v
      to verify all tests pass
    • Blocks deployment if any tests fail
    • Exit code 3 = tests failed
  2. Check Active Trades (Step 1)
    • Runs
      scripts/check_active_trades.py
      in the container
    • Queries the database for unresolved real trades
    • Checks if market has resolved (safe) vs still active (danger)
    • Blocks deployment if active trades exist
    • Exit code 1 = active trades
  3. Deploy (Steps 2-4)
    • Git push + pull to sync code
    • Docker compose rebuild and restart
  4. Verify (Step 5)
    • Shows startup logs to confirm success
  1. 运行回归测试(步骤0)
    • 基于最新代码构建全新容器
    • 运行
      pytest tests/ -v
      验证所有测试通过
    • 若有测试失败则阻止部署
    • 退出码3 = 测试失败
  2. 检查活跃交易(步骤1)
    • 在容器内运行
      scripts/check_active_trades.py
    • 查询数据库中未结算的真实交易
    • 检查市场是否已结算(安全)或仍处于活跃状态(危险)
    • 若存在活跃交易则阻止部署
    • 退出码1 = 存在活跃交易
  3. 执行部署(步骤2-4)
    • 执行Git推送与拉取以同步代码
    • 重新构建并重启Docker Compose容器
  4. 验证部署(步骤5)
    • 显示启动日志以确认部署成功

Manual Pre-Checks

手动预检查

Run the checks independently:
bash
undefined
可独立运行以下检查:
bash
undefined

Run regression tests locally

本地运行回归测试

docker compose run --rm --build polymarket-bot python3 -m pytest tests/ -v
docker compose run --rm --build polymarket-bot python3 -m pytest tests/ -v

Check active trades (requires running container)

检查活跃交易(需容器处于运行状态)

docker exec polymarket-bot python3 /app/scripts/check_active_trades.py
docker exec polymarket-bot python3 /app/scripts/check_active_trades.py

Exit codes:

退出码说明:

0 = Safe to deploy

0 = 可安全部署

1 = Active trades exist (don't deploy)

1 = 存在活跃交易(请勿部署)

2 = Error checking

2 = 检查过程出错

3 = Tests failed

3 = 测试失败

undefined
undefined

When to Skip Tests

何时可跳过测试

Use
--skip-tests
when:
  • You've already run tests manually
  • Making config-only changes (.env)
  • Urgent fix with verified minimal change
在以下场景使用
--skip-tests
参数:
  • 已手动运行过测试
  • 仅进行配置文件修改(如.env文件)
  • 紧急修复且已确认修改范围极小

When to Force Deploy

何时可强制部署

Only use
--force
when:
  • The bot is crashed/hung and needs restart
  • You're certain any active trades are already lost
  • Emergency security fix is needed
  • User explicitly approves the risk
仅在以下极端场景使用
--force
参数:
  • 机器人崩溃/挂起,需要重启
  • 确认所有活跃交易已无法挽回
  • 需要紧急安全修复
  • 用户明确同意承担风险

Trade Lifecycle

交易生命周期

Trade Executed → status='pending' → Market Resolves → status='won'/'lost'
                     ↑                                      ↓
              ⚠️ DANGER ZONE                          Safe to deploy
交易执行 → 状态='pending' → 市场结算 → 状态='won'/'lost'
                     ↑                                      ↓
              ⚠️ 危险区域                          可安全部署

Troubleshooting

故障排查

"Regression tests failed"

"回归测试失败"

Fix the failing tests before deploying:
bash
docker compose run --rm --build polymarket-bot python3 -m pytest tests/ -v --tb=long
修复失败的测试后再进行部署:
bash
docker compose run --rm --build polymarket-bot python3 -m pytest tests/ -v --tb=long

"Container may not be running"

"容器可能未运行"

The pre-check failed because the bot isn't running. This is safe to deploy.
预检查失败是因为机器人未在运行,这种情况下可安全部署。

Stuck in "not safe" state

卡在"不安全"状态

If trades are stuck as pending after market resolution:
bash
undefined
若市场结算后交易仍处于pending状态:
bash
undefined

Check database state

检查数据库状态

docker exec polymarket-bot python3 -c " import asyncio import aiosqlite async def check(): async with aiosqlite.connect('/app/data/gabagool.db') as db: db.row_factory = aiosqlite.Row async with db.execute('SELECT id, asset, status, market_end_time FROM trades WHERE dry_run=0 ORDER BY created_at DESC LIMIT 5') as cur: for row in await cur.fetchall(): print(dict(row)) asyncio.run(check()) "
undefined
docker exec polymarket-bot python3 -c " import asyncio import aiosqlite async def check(): async with aiosqlite.connect('/app/data/gabagool.db') as db: db.row_factory = aiosqlite.Row async with db.execute('SELECT id, asset, status, market_end_time FROM trades WHERE dry_run=0 ORDER BY created_at DESC LIMIT 5') as cur: for row in await cur.fetchall(): print(dict(row)) asyncio.run(check()) "
undefined

Related Files

相关文件

  • tests/
    - Regression test suite
  • scripts/check_active_trades.py
    - Pre-deployment trade check
  • src/persistence.py
    - Database schema
  • src/strategies/gabagool.py
    - Trading logic
  • tests/
    - 回归测试套件
  • scripts/check_active_trades.py
    - 部署前交易检查脚本
  • src/persistence.py
    - 数据库 schema
  • src/strategies/gabagool.py
    - 交易逻辑