deploy-bot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeploy 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:
- Runs regression tests to catch bugs before deployment
- Checks for active trades to prevent interrupting pending positions
警告:部署更改时请务必使用本Skill,切勿手动执行docker命令。
这是Polymarket套利交易机器人的安全部署工作流,具备以下特性:
- 运行回归测试,在部署前发现bug
- 检查活跃交易,避免中断未了结的头寸
Why This Matters
为什么这很重要
The bot executes real-money arbitrage trades on Polymarket. Deploying broken code or restarting during active trades can cause:
- Bugs: Untested code can break execution, tracking, or settlement
- Lost visibility: Restarting during active trades loses pending position data
- Missed resolutions: Container restart can miss market resolution events
- Financial losses: All of the above can result in real money losses
该机器人在Polymarket上执行真实资金的套利交易。部署存在问题的代码或在活跃交易期间重启可能导致:
- 程序漏洞:未测试的代码可能破坏交易执行、跟踪或结算流程
- 数据丢失:活跃交易期间重启会丢失未了结头寸的数据
- 错过结算:容器重启可能错过市场结算事件
- 资金损失:上述所有情况都可能导致实际资金损失
Quick Deploy
快速部署
bash
undefinedbash
undefinedFrom 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
undefinedWhat the Script Does
脚本执行流程
-
Run Regression Tests (Step 0)
- Builds a fresh container with latest code
- Runs to verify all tests pass
pytest tests/ -v - Blocks deployment if any tests fail
- Exit code 3 = tests failed
-
Check Active Trades (Step 1)
- Runs in the container
scripts/check_active_trades.py - 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
- Runs
-
Deploy (Steps 2-4)
- Git push + pull to sync code
- Docker compose rebuild and restart
-
Verify (Step 5)
- Shows startup logs to confirm success
-
运行回归测试(步骤0)
- 基于最新代码构建全新容器
- 运行验证所有测试通过
pytest tests/ -v - 若有测试失败则阻止部署
- 退出码3 = 测试失败
-
检查活跃交易(步骤1)
- 在容器内运行
scripts/check_active_trades.py - 查询数据库中未结算的真实交易
- 检查市场是否已结算(安全)或仍处于活跃状态(危险)
- 若存在活跃交易则阻止部署
- 退出码1 = 存在活跃交易
- 在容器内运行
-
执行部署(步骤2-4)
- 执行Git推送与拉取以同步代码
- 重新构建并重启Docker Compose容器
-
验证部署(步骤5)
- 显示启动日志以确认部署成功
Manual Pre-Checks
手动预检查
Run the checks independently:
bash
undefined可独立运行以下检查:
bash
undefinedRun 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 = 测试失败
undefinedundefinedWhen to Skip Tests
何时可跳过测试
Use when:
--skip-tests- 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 when:
--force- 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
undefinedCheck 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())
"
undefineddocker 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())
"
undefinedRelated Files
相关文件
- - Regression test suite
tests/ - - Pre-deployment trade check
scripts/check_active_trades.py - - Database schema
src/persistence.py - - Trading logic
src/strategies/gabagool.py
- - 回归测试套件
tests/ - - 部署前交易检查脚本
scripts/check_active_trades.py - - 数据库 schema
src/persistence.py - - 交易逻辑
src/strategies/gabagool.py