A Polymarket Trading bot that trades on Polymarket binary crypto markets (e.g. “Bitcoin up or down in the next 15 minutes”). It connects to Polymarket’s CLOB and real-time data, subscribes to a market by coin and period, and can run configurable strategies.
Not classic arbitrage. The codebase supports two styles of logic:
-
Trend-following (
trade_1indecision.ts)
Detects short-term “trend” from order-book price changes and would buy the UP or DOWN token when the market is trending that way, within a configurable price range. This is directional trading, not arbitrage. -
Binary “arbitrage” (
trade_1inws_clob.ts)
When real-time price velocity exceeds a threshold, it computes prices such that UP + DOWN < 1 −min_arb_price_difference, and would buy both UP and DOWN to lock in a margin. That’s binary market arbitrage (buying both sides when they’re cheap relative to $1).
Current state: Order placement for both strategies is commented out. The bot runs as a framework: it connects, subscribes to markets and RTDS, updates prices, and logs signals; it does not send live orders unless you uncomment and enable the trade calls.
- Market selection: Coin (
btc,eth,sol,xrp) and period (15, 60, 240, 1440 minutes). - Live data: CLOB WebSocket (order book) and RTDS (e.g. BTCUSDT / Chainlink) for price velocity.
- Strategies:
trade_1(time/price exit),trade_2(entry/exit ranges + optional emergency swap). - Config: TOML config (
trade.toml) for strategy, market, trading range, thresholds, simulation. - Simulation: Optional
simulation = trueto skip sending orders.
You can change crypto market ** [market] market_coin = "btc" # btc / eth / sol / xrp market_period = "5" # 5 / 15 / 60 / 240 / 1440 **
- Goal: Hold a position (UP or DOWN) and exit when either time or price threshold is reached.
- Exit: If remaining time ratio (elapsed time / market duration) >
trade_1.exit_time_ratioor up-price ratio (distance of UP bid from 0.5) >trade_1.exit_price_ratio, the bot sells the currently held token:- Holding UP →
sellUpToken() - Holding DOWN →
sellDownToken()
- Holding UP →
- Config (
[trade_1]intrade.toml):exit_time_ratio,exit_price_ratio, plusentry_price_range,swap_price_range,take_profit,stop_lossfor future entry/risk logic.
- Goal: Enter when price and time are in range; exit when price is in an exit band; optionally flip to the opposite side in an “emergency” price band.
- Entry (when not holding): If
remaining_time_ratio>trade_2.entry_time_ratioand up-price ratio is insidetrade_2.entry_price_ratio[min, max], buy the cheaper side (UP ifupBuyPrice>downBuyPrice, else DOWN). - Exit: If up-price ratio falls inside any of the
trade_2.exit_price_ratio_rangeintervals:- Holding UP →
sellUpToken(); if sell succeeds and up-price ratio is intrade_2.emergency_swap_price, thenbuyDownToken(). - Holding DOWN →
sellDownToken(); if sell succeeds and up-price ratio is intrade_2.emergency_swap_price, thenbuyUpToken().
- Holding UP →
- Config (
[trade_2]):entry_price_ratio,entry_time_ratio,exit_price_ratio_range,emergency_swap_price(optional).
- Node.js ≥ 20.6.0
- Wallet: Polymarket proxy wallet and signer (private key) for the CLOB.
-
Clone and install
Ubuntu
git clone https://github.com/Py-Contributors/polymarket-trading-bot cd polymarket-trading-bot npm install -
Environment
Create a
.envin the project root (see.gitignore; do not commit secrets):POLYMARKET_PRIVATE_KEY– EOA private key that signs for the proxy wallet.PROXY_WALLET_ADDRESS– Proxy wallet address used with Polymarket CLOB.
-
Config
Edit
trade.toml:strategy:"trade_1"or"trade_2".trade_usd,max_retries,simulation.[market]:market_coin,market_period.[trade_1]:trading_range,price_change_threshold,min_arb_price_difference, etc.
| Command | Description |
|---|---|
npm run dev |
Run bot: tsx src/index.ts |
npm run log |
Run and log stdout/stderr to log.txt |
npm run check |
Run inspector: tsx src/inspect.ts |
npm run build |
Compile: tsc |
npm start |
Run compiled: node dist/index.js |
src/index.ts– Entry: load config, create CLOB client, resolve market slug, connect WebSockets, instantiateTrade, main loop.src/config/– Env, TOML config, market/slug helpers.src/services/– CLOB client, Gamma API, WebSockets (CLOB + RTDS).src/trade/–Tradeclass: decision logic, prices/trending, order placement (buy/sell UP/DOWN).trade.toml– Strategy and market configuration.
