Minimal bot that mirrors trades from one or more Polymarket traders, with spend limits and automatic cashout after resolution.
npm install
cp .env.example .envnpm run build
npm run startIn .env:
PRIVATE_KEY: private key for the wallet linked to your Polymarket account (needed to sign orders).PROFILE_ADDRESS: the Polymarket address visible in your account (proxy/profile wallet).COPY_TRADERS: comma‑separated list of trader addresses to copy.MAX_DAILY_VOLUME_USD: daily USD cap for buys.MAX_POSITION_SIZE_USD: per‑position USD cap for buys.
COPY_STRATEGY:PERCENT_USD(default),PERCENT_SHARES,FIXED_USD,FIXED_SHARESCOPY_RATIO: ratio for percent strategies (e.g.0.25= 25%)FIXED_TRADE_USD: fixed amount ifFIXED_USDMIN_TRADE_USD,MAX_TRADE_USDCOPY_SIDE:BUY,SELL,BOTH
To auto‑redeem when a market is resolved:
AUTO_REDEEM=trueRPC_URL: Polygon RPC URL- Local builder creds:
BUILDER_API_KEY,BUILDER_API_SECRET,BUILDER_API_PASSPHRASE- or remote signer:
BUILDER_SIGNING_URL,BUILDER_SIGNING_TOKEN
- or remote signer:
- Open
polymarket.com/settings?tab=builder. - Create a Builder Profile if needed, then click “+ Create New”.
- You’ll get
apiKey,secret, andpassphrase(keep them private).
- Open
https://reveal.magic.link/polymarket. - Confirm the warnings and reveal your private key.
- Paste it into
PRIVATE_KEYin your.env.
These all have defaults in code. Only set them if you want overrides:
CLOB_HOST(default:https://clob.polymarket.com): CLOB endpoint.DATA_API_HOST(default:https://data-api.polymarket.com): Data API endpoint.CHAIN_ID(default:137): Polygon chain id.POLL_INTERVAL_MS(default:5000): trade polling frequency.TRADE_LOOKBACK_SEC(default:300): startup catch‑up window.STATE_FILE(default:./data/state.json): local persistence file.MAX_SEEN_TRADES_AGE_SEC(default:604800): retention for seen trades.CLOB_API_KEY,CLOB_API_SECRET,CLOB_API_PASSPHRASE: use if you want to avoid auto‑derivation at startup.RELAYER_URL(default:https://relayer-v2.polymarket.com): redeem relayer endpoint.RELAYER_TX_TYPE(default:PROXY): relayer transaction type.SIGNATURE_TYPE(default:1): wallet signature type.FUNDER_ADDRESS: profile/funder address if needed (otherwisePROFILE_ADDRESS).
Use the Polymarket address visible in your account (proxy/profile wallet):
- Put it in
PROFILE_ADDRESS. - You do not need to put your EOA address in
.env. - You still need the
PRIVATE_KEYof the wallet linked to your Polymarket account to sign orders.
PRIVATE_KEY=0x...
PROFILE_ADDRESS=0x... # Polymarket-visible address
COPY_TRADERS=0x123...,0x456...
MAX_DAILY_VOLUME_USD=200
MAX_POSITION_SIZE_USD=500
COPY_STRATEGY=PERCENT_USD
COPY_RATIO=0.25Railway makes it easy to host a long‑running bot. Deploy this repo, set env vars, and add a volume:
- Mount a volume at
/data - Set
STATE_FILE=/data/state.jsonfor persistence - Set
RAILPACK_NODE_VERSION=22to force Node 22