Skip to content

Adidas8023/PolymarketBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PolyBot

PolyBot poster

Rust 1.88+ Polymarket CLOB v2 Axum Paper trading License MIT

Features · Quick Start · Configuration · System Map · Security · 中文说明

PolyBot is a local Rust/Axum web console and automation bot for Polymarket UP/DOWN markets. It watches 5-minute and 15-minute BTC, ETH, SOL, and XRP markets, streams prices and order books, and can run trend or reverse strategies in paper mode or real trading mode.

Trading is risky. This project is software only, not financial advice. Keep paper trading enabled until you understand every setting and endpoint.

Table of Contents

Screenshot

PolyBot dashboard screenshot

The screenshot above is captured from the real local web app using public preview mode, with wallet and secret-bearing fields masked.

Features

  • 15-minute trend strategy for Polymarket UP/DOWN markets.
  • 5-minute trend strategy.
  • 15-minute reverse strategy.
  • 5-minute reverse strategy.
  • Live Chainlink price-to-beat tracking.
  • Live Polymarket CLOB v2 order book streams.
  • User-channel order and fill monitoring.
  • Manual UP/DOWN trading from the dashboard.
  • Paper trading mode, strategy toggles, token disables, and UTC hour filters.
  • Trade history, stats, CSV export, data repair, and on-chain history import.
  • Wallet balance, positions, redeem, sell-all, approvals, USDC.e to pUSD wrap, and pUSD to USDC.e unwrap.
  • Proxy and Shadowsocks helper controls.
  • Telegram notifications.
  • Optional OnchainOS order execution backend.

At a Glance

Area What PolyBot Provides
Markets BTC, ETH, SOL, XRP UP/DOWN markets
Intervals 15-minute and 5-minute windows
Modes Trend, reverse, manual trade, paper trading
Data feeds Chainlink prices, Polymarket CLOB v2 order books, user channel fills
Wallet ops Balance, positions, approvals, redeem, sell-all, wrap, unwrap
Ops helpers Proxy, Shadowsocks, Telegram alerts, local logs

Quick Start

Requirements:

  • Rust 1.88+
  • Polygon RPC access
  • Polymarket-compatible wallet/private key for real trading
  • Optional: Shadowsocks and Telegram Bot credentials
git clone https://github.com/Adidas8023/PolymarketBot.git
cd PolymarketBot
cp .env.example .env

Edit .env, then run:

cargo run --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"

Open:

http://localhost:3000

If the port is occupied:

PORT=3003 cargo run --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"

Configuration

Environment variables are loaded from .env when present.

Variable Required Purpose
PRIVATE_KEY Real trading EOA private key used for signing. Leave empty for read-only/paper use.
DEPOSIT_WALLET_ADDRESS API-only wallet mode Trading wallet/funder address. FUNDER_ADDRESS is also accepted.
POLYMARKET_SIGNATURE_TYPE Optional eoa, proxy, gnosis_safe, or poly1271.
POLYMARKET_CLOB_HOST Optional Defaults to https://clob.polymarket.com.
POLYGON_RPC_URL Optional Defaults to https://polygon-rpc.com.
PROXY_URL Optional Example: socks5://127.0.0.1:1080.
PORT Optional Web server port, default 3000.
RUST_LOG Optional Example: info, warn, debug.
LOG_FILE Optional Also write logs to a local file. Do not commit logs.
RELAYER_API_KEY Relayer flows Polymarket relayer API key.
RELAYER_API_KEY_ADDRESS Relayer flows API key owner address.
POLYMARKET_RELAYER_HOST Optional Overrides relayer host. RELAYER_URL is also accepted.
POLYMARKET_BUILDER_CODE Optional Builder code bytes32. BUILDER_CODE is also accepted.
POLYBOT_ORDER_EXECUTOR Optional Set to onchainos for the optional OnchainOS path.
POLYBOT_ONCHAINOS_DRY_RUN Optional Dry-run mode for OnchainOS execution.
POLYBOT_ONCHAINOS_PLUGIN_BIN Optional Plugin binary, default polymarket-plugin.
POLYBOT_ONCHAINOS_STRATEGY_ID Optional Strategy ID passed to the plugin.

Runtime Data

Mutable bot state is stored in:

examples/arb_strategy/data/

Local files such as config.json, trades.json, stats.json, proxy.json, and console.log can contain private strategy settings, trading history, Telegram tokens, proxy settings, or operational logs. They are intentionally ignored by git.

Use these sanitized examples as shape references:

examples/arb_strategy/data/config.example.json
examples/arb_strategy/data/config_5m.example.json
examples/arb_strategy/data/config_reverse.example.json
examples/arb_strategy/data/config_reverse_5m.example.json
examples/arb_strategy/data/proxy.example.json
examples/arb_strategy/data/stats.example.json
examples/arb_strategy/data/trades.example.json
ss-config.example.json

System Map

flowchart LR
    browser["Browser Dashboard"] --> axum["Axum Web Server"]
    axum --> state["Shared App State"]
    state --> strategies["Trend / Reverse Strategies"]
    state --> wallet["Wallet + Funding Tools"]
    state --> api["HTTP API + WebSockets"]
    price["Chainlink Price Stream"] --> state
    orderbook["Polymarket CLOB v2 Order Books"] --> state
    userws["Polymarket User Channel"] --> state
    strategies --> clob["Authenticated CLOB Client"]
    wallet --> polygon["Polygon RPC"]
    clob --> polymarket["Polymarket CLOB"]
    api --> browser
Loading

Project Layout

src/lib.rs

Compatibility shim that re-exports polymarket_client_sdk_v2.

examples/arb_web_server.rs

Application entry point. It loads .env, initializes logging, builds shared state, starts monitors and strategies, and registers HTTP/WebSocket routes.

examples/arb_strategy/

Main bot implementation:

  • api/mod.rs: Axum HTTP handlers and WebSocket endpoints.
  • config.rs: strategy config, trade history, stats, and data persistence.
  • state.rs: shared application state.
  • market.rs: market discovery and balance helpers.
  • monitor/price.rs: Chainlink price stream and PTB updates.
  • monitor/orderbook.rs: 15m and 5m CLOB order book streams.
  • monitor/user_channel.rs: user-channel order/fill stream and caches.
  • strategy.rs: 15m trend and reverse strategy engine.
  • strategy_5m.rs: 5m trend and reverse strategy engine.
  • clob_client.rs: authenticated CLOB v2 client, proxy state, balances, and orders.
  • trade.rs: buy/sell execution helpers and order polling.
  • wallet.rs: wallet, positions, redeem, sell-all, repair, and chain import.
  • funding.rs: USDC.e to pUSD wrap and pUSD unwrap flows.
  • approval.rs: exchange/collateral approval checks and execution.
  • telegram.rs: Telegram notification sender.
  • console.rs: terminal status UI.
  • html/frontend.html: main web console.
  • html/trades.html: trade history and wallet actions page.

Checks

cargo fmt -- --check
cargo test --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"
cargo clippy --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"

clippy is currently warning-heavy because strict pedantic/cargo lint groups are enabled. Treat those warnings as cleanup debt unless a warning points at a runtime risk.

Security Notes

  • Never commit .env, real private keys, Telegram bot tokens, proxy passwords, relayer API keys, live trade history, or logs.
  • This repository ships only sanitized example config files.
  • Telegram request errors are sanitized before being printed or returned.
  • Real trading is possible when PRIVATE_KEY is configured and paper mode is disabled. Review the dashboard state before enabling a strategy or clicking a manual trade button.
Publish safety checklist
  • .env is ignored.
  • Runtime JSON files under examples/arb_strategy/data/ are ignored.
  • ss-config.json is ignored.
  • Local logs are ignored.
  • README screenshots use public preview mode and masked wallet fields.
  • Only .env.example, *.example.json, screenshots, and source files are intended for GitHub.

PolyBot 中文说明

PolyBot 是一个本地运行的 Polymarket UP/DOWN 策略机器人和 Rust/Axum Web 控制台。它监控 BTC、ETH、SOL、XRP 的 5 分钟和 15 分钟市场,实时读取 Chainlink 价格、Polymarket CLOB v2 订单簿,并支持趋势策略、反转策略、模拟交易和实盘交易。

中文目录

功能

  • 15 分钟趋势策略。
  • 5 分钟趋势策略。
  • 15 分钟反转策略。
  • 5 分钟反转策略。
  • Chainlink price-to-beat 实时跟踪。
  • Polymarket CLOB v2 订单簿 WebSocket。
  • 用户频道订单/成交监听。
  • Web 页面手动买入 UP/DOWN。
  • 模拟交易、策略开关、禁用币种、UTC 禁用时段。
  • 交易记录、统计、CSV 导出、数据修复、链上历史导入。
  • 钱包余额、持仓、redeem、sell-all、授权检查、USDC.e wrap 成 pUSD、pUSD unwrap 回 USDC.e。
  • 代理和 Shadowsocks 辅助控制。
  • Telegram 通知。
  • 可选 OnchainOS 下单后端。

功能矩阵

模块 内容
市场 BTC、ETH、SOL、XRP UP/DOWN
周期 15 分钟、5 分钟
模式 趋势、反转、手动、模拟交易
数据 Chainlink 价格、CLOB v2 订单簿、用户成交频道
钱包 余额、持仓、授权、redeem、sell-all、wrap/unwrap
运维 代理、Shadowsocks、Telegram、本地日志

快速启动

git clone https://github.com/Adidas8023/PolymarketBot.git
cd PolymarketBot
cp .env.example .env

编辑 .env 后运行:

cargo run --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"

打开:

http://localhost:3000

端口被占用时:

PORT=3003 cargo run --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"

敏感数据

不要上传 .env、真实私钥、Telegram token、代理密码、relayer key、真实交易记录或日志。 这些本地运行数据已经被 .gitignore 排除。仓库只保留 *.example.json.env.example 作为可复用模板,别人 clone 后可以自己复制并填写。

架构

核心入口是 examples/arb_web_server.rs,策略和业务逻辑在 examples/arb_strategy/src/lib.rs 只是兼容层,重新导出 polymarket_client_sdk_v2,避免继续暴露旧 SDK 源码。

主要模块:

  • api/mod.rs:HTTP API 和 WebSocket。
  • config.rs:配置、交易记录、统计持久化。
  • market.rs:市场发现。
  • monitor/*:价格、订单簿、用户频道监听。
  • strategy.rs / strategy_5m.rs:15m/5m 策略。
  • clob_client.rs:CLOB v2 认证、下单、余额同步。
  • wallet.rs:钱包和持仓操作。
  • funding.rs / approval.rs:资金和授权流程。
  • html/frontend.html / html/trades.html:Web 控制台。

验证

cargo fmt -- --check
cargo test --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"
cargo clippy --example arb_web_server --features "gamma,ws,rtds,data,clob,heartbeats"

当前 clippy 开启了严格 pedantic/cargo lint,警告很多,主要是后续代码洁净度债务; 发布前功能测试和格式检查应通过。

About

PolyBot is a local Rust/Axum web console and automation bot for Polymarket UP/DOWN markets. It watches 5-minute and 15-minute BTC, ETH, SOL, and XRP markets, streams prices and order books, and can run trend or reverse strategies in paper mode or real trading mode.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages