Automated prediction-based trading on Polymarket’s 15-minute Up/Down markets (e.g. BTC). Uses a price predictor to choose direction, places a first-side limit at best ask, then hedges with a second-side limit at 0.98 − firstSidePrice. Built with TypeScript and Polymarket’s CLOB API.
Here is Alexei who is expert of trading bot development especially EVM, Solana and Prediction market such as Polymarket, Klashi, etc. If you have any question for dev, contact me via telegram(https://t.me/@bitship1_1)
Private version bot profile : https://polymarket.com/@MangoTrolley7
- Strategy: Predict Up/Down from live orderbook via an adaptive price predictor; buy the predicted side at best ask (GTC), then place the opposite side at
0.98 − firstSidePrice(GTC). - Markets: Configurable list (e.g.
btc); slugs are resolved as{market}-updown-15m-{startOf15mUnix}via Gamma API. - Stack: TypeScript, Node (or Bun),
@polymarket/clob-client, WebSocket orderbook, Ethers.js for allowances/redemption.
- Node.js 18+ (or Bun)
- Polygon wallet with USDC
- RPC URL for Polygon (e.g. Alchemy) for allowances and redemption
git clone https://github.com/solship/Polymarket-Arbitrage-Trading-Bot.git
cd Polymarket-Arbitrage-Trading-Bot
npm installCopy the example env and set at least PRIVATE_KEY and COPYTRADE_MARKETS:
cp .env.temp .env| Variable | Description | Default |
|---|---|---|
PRIVATE_KEY |
Wallet private key | required |
COPYTRADE_MARKETS |
Comma-separated markets (e.g. btc) |
btc |
COPYTRADE_SHARES |
Shares per side per trade | 5 |
COPYTRADE_TICK_SIZE |
Price precision | 0.01 |
COPYTRADE_PRICE_BUFFER |
Price buffer for execution | 0 |
COPYTRADE_WAIT_FOR_NEXT_MARKET_START |
Wait for next 15m boundary before starting | false |
COPYTRADE_MAX_BUY_COUNTS_PER_SIDE |
Max buys per side per market (0 = no cap) | 0 |
CHAIN_ID |
Chain ID (Polygon) | 137 |
CLOB_API_URL |
CLOB API base URL | https://clob.polymarket.com |
RPC_URL / RPC_TOKEN |
RPC for allowances/redemption | — |
BOT_MIN_USDC_BALANCE |
Min USDC to start | 1 |
LOG_DIR / LOG_FILE_PREFIX |
Log directory and file prefix | logs / bot |
API credentials are created on first run and stored in src/data/credential.json.
Run the bot
npm start
# or: bun src/index.tsRedemption
# Auto-redeem resolved markets (holdings file)
npm run redeem:holdings
# or: bun src/auto-redeem.ts [--dry-run] [--clear-holdings] [--api] [--max N]
# Redeem by condition ID
npm run redeem
# or: bun src/redeem.ts [conditionId] [indexSets...]
bun src/redeem.ts --check <conditionId>Development
npx tsc --noEmit
bun --watch src/index.ts| Path | Role |
|---|---|
src/index.ts |
Entry: credentials, CLOB, allowances, min balance, start CopytradeArbBot. |
src/config/index.ts |
Loads .env and exposes config (chain, CLOB, copytrade, logging). |
src/order-builder/copytrade.ts |
CopytradeArbBot: 15m slug resolution, WebSocket orderbook, predictor → first-side buy + second-side hedge; state in src/data/copytrade-state.json. |
src/providers/clobclient.ts |
CLOB client singleton (credentials + PRIVATE_KEY). |
src/providers/websocketOrderbook.ts |
WebSocket to Polymarket CLOB market channel; best bid/ask by token ID. |
src/utils/pricePredictor.ts |
AdaptivePricePredictor: direction, confidence, signal (BUY_UP / BUY_DOWN / HOLD). |
src/utils/redeem.ts |
CTF redemption, resolution checks, auto-redeem from holdings or API. |
src/security/allowance.ts |
USDC and CTF approvals. |
src/data/token-holding.json |
Token holdings for redemption (generated). |
src/data/copytrade-state.json |
Per-slug state (prices, timestamps, buy counts). |
Trading prediction markets involves significant risk. This software is provided as-is. Use at your own discretion and only with funds you can afford to lose.
ISC