Professional TypeScript bot for monitoring short-duration prediction markets across Polymarket and Kalshi, detecting pricing gaps, and placing buy orders on Polymarket when configured arbitrage rules are satisfied.
Canonical repository: github.com/defi-ape/polymarket-kalshi-arbitrage-bot
The bot is designed for 15-minute markets where fast pricing updates, clear execution rules, and transparent runtime status matter. It continuously compares Kalshi YES pricing against Polymarket UP pricing, exposes a simple monitoring API, and can initialize an authenticated Polymarket order client for automated execution.
Important: Prediction market trading involves risk. This project provides configurable automation and monitoring logic; it does not guarantee profit or eliminate execution, liquidity, market, regulatory, or operational risk.
- Monitors a paired Kalshi and Polymarket market on a configurable interval.
- Pulls Polymarket UP/DOWN token pricing from the Polymarket CLOB.
- Pulls Kalshi YES/NO pricing and market status from the Kalshi trade API.
- Waits until a configurable start window has passed before evaluating trades.
- Emits structured arbitrage signals through
/status. - Places Polymarket buy orders using
@polymarket/clob-clientwhen valid trading credentials are configured. - Applies order cooldowns to reduce duplicate execution during repeated signals.
- Runs as a lightweight Express service that can be deployed on a VPS, container, or cloud instance.
The current strategy focuses on buying the Polymarket UP token when Kalshi is pricing the equivalent outcome materially higher.
After the configured start delay, the bot checks whether Kalshi YES is inside a target confidence band and whether Polymarket UP is meaningfully cheaper.
Default thresholds:
- Kalshi YES must be between
93and96cents. - Polymarket UP must be at least
10cents cheaper than Kalshi YES. - The bot emits
buy_polymarketwhen both conditions are true.
Example:
Kalshi YES: 95 cents
Polymarket UP: 82 cents
Spread: 13 cents
Decision: BUY Polymarket UP
Resulting signal:
{
"action": "buy_polymarket",
"reason": "Kalshi YES 95¢ in [93,96], Polymarket UP 82¢ (spread 13¢ >= 10¢).",
"kalshiYesCents": 95,
"polymarketUpCents": 82,
"spreadCents": 13
}Some short-duration markets can close or settle on one venue while the other still has an active order book. If Kalshi is finished but Polymarket still has liquidity, the bot emits a late-entry signal.
Example:
Kalshi status: settled
Polymarket book: still has liquidity
Decision: BUY Polymarket UP
Resulting signal:
{
"action": "buy_polymarket_late",
"reason": "Kalshi market finished (closed/settled) while Polymarket still has orders.",
"kalshiStatus": "settled"
}Primary source: https://www.instagram.com/reel/DWrBSHxlIZ3/ (permalink on profile: @moondevonyt).
- Account: @moondevonyt — display name Moon Dev on YT (verified).
- Post type: Reel /
GraphVideoclip (vertical 720×1280 class dimensions in embed data). - Published: April 3, 2026 (Instagram “taken at” timestamp in page metadata).
- Caption (verbatim): Polymarket or kalshi for trading bots?
- Audio: Original audio credited to the same account (“Moon Dev on YT on Instagram…” in
og:title). - Approximate length: ~39 seconds (progressive clip; duration from Instagram embed payload when the local video was mirrored).
- Engagement (snapshot only — changes on Instagram over time): on the order of hundreds of reel plays and a few dozen likes on the public counter at mirror time; use the live post for current numbers.
The spoken rundown is only in the clip (Instagram’s public HTML does not ship a full transcript). In short: the hook is choosing one venue versus wiring both when automation and cross-platform prices matter.
This repo is not the app from the reel; it is a standalone TypeScript service. It still illustrates one concrete answer for cross-venue work: the bot polls both venues (Kalshi trade API + Polymarket CLOB), runs the spread and late-resolution rules in Strategy Overview, and, when trading is enabled, places Polymarket buy orders. So for “Polymarket or Kalshi?” in the sense of mispricing between books, this code assumes both feeds for signals and Polymarket for the automated buy side wired in polymarketOrders.ts.
Mirrored under src/img and video/ (shortcode DWrBSHxlIZ3):
- Video:
instagram-DWrBSHxlIZ3-demo.mp4 - Poster / cover frame:
instagram-DWrBSHxlIZ3-poster.jpg
Poster image from the same reel (local mirror; Instagram: DWrBSHxlIZ3).
Kalshi API Polymarket CLOB
| |
| |
+------ price polling ----+
|
v
Arbitrage decision engine
|
+-------+--------+
| |
v v
/status API Polymarket order client
authenticated execution
Core modules:
src/index.tsstarts the Express API, polling loop, and optional trading client.src/config.tsloads and validates runtime configuration from.env.src/services/kalshi.tsfetches Kalshi market data.src/services/polymarket.tsfetches Polymarket CLOB prices.src/services/arbitrage.tsevaluates buy/no-buy decisions.src/services/polymarketOrders.tsplaces Polymarket orders when trading is enabled.
- Node.js 18+
- TypeScript
- Express for the HTTP monitoring/control API
- Axios for Kalshi and Polymarket HTTP requests
- @polymarket/clob-client for Polymarket order placement
- ethers for wallet/client support
- dotenv for environment-based configuration
Install dependencies:
npm installCreate a local environment file:
cp .env.example .envEdit .env with your market pair and wallet settings, then run:
npm run build
npm startFor development with auto-reload:
npm run devThe service starts polling automatically and exposes the API on http://localhost:3000 by default.
PORT=3000
POLL_INTERVAL_MS=5000
MARKET_START_TIME=2026-05-11T07:00:00.000Z
START_DELAY_MINS=8
KALSHI_API_BASE=https://api.elections.kalshi.com/trade-api/v2
KALSHI_TICKER=KXHIGHNY-24JAN01-T60
POLYMARKET_CLOB_BASE=https://clob.polymarket.com
POLYMARKET_TOKEN_UP=1234567890123456789012345678901234567890
POLYMARKET_TOKEN_DOWN=9876543210987654321098765432109876543210
KALSHI_MIN_CENTS=93
KALSHI_MAX_CENTS=96
MIN_SPREAD_CENTS=10
POLYMARKET_PRIVATE_KEY=0x<64_HEX_CHARACTER_PRIVATE_KEY>
POLYMARKET_PROXY_WALLET_ADDRESS=0x<40_HEX_CHARACTER_PROXY_WALLET>
POLYMARKET_CHAIN_ID=137
POLYMARKET_TRADE_USD=10
POLYMARKET_BUY_COOLDOWN_SECONDS=60Keep private keys out of source control. Use a dedicated trading wallet with limited funds.
| Variable | Description | Default / Example |
|---|---|---|
PORT |
HTTP server port. | 3000 |
POLL_INTERVAL_MS |
Price polling interval in milliseconds. | 5000 |
MARKET_START_TIME |
Market start time in ISO 8601 format. | 2026-05-11T07:00:00.000Z |
START_DELAY_MINS |
Minutes after market start before evaluating signals. | 8 |
KALSHI_API_BASE |
Kalshi trade API base URL. | https://api.elections.kalshi.com/trade-api/v2 |
KALSHI_TICKER |
Kalshi market ticker for the target market. | KXHIGHNY-24JAN01-T60 |
POLYMARKET_CLOB_BASE |
Polymarket CLOB API base URL. | https://clob.polymarket.com |
POLYMARKET_TOKEN_UP |
Polymarket UP/YES token ID. | From the Polymarket market |
POLYMARKET_TOKEN_DOWN |
Polymarket DOWN/NO token ID. | From the Polymarket market |
KALSHI_MIN_CENTS |
Lower Kalshi YES price bound for spread entries. | 93 |
KALSHI_MAX_CENTS |
Upper Kalshi YES price bound for spread entries. | 96 |
MIN_SPREAD_CENTS |
Minimum Kalshi minus Polymarket spread required. | 10 |
POLYMARKET_PRIVATE_KEY |
EOA private key used for trading. | 0x... |
POLYMARKET_PROXY_WALLET_ADDRESS |
Polymarket proxy wallet / Safe address. | 0x... |
POLYMARKET_CHAIN_ID |
Chain ID for Polymarket CLOB. | 137 |
POLYMARKET_TRADE_USD |
USD amount per buy order. | 10 |
POLYMARKET_BUY_COOLDOWN_SECONDS |
Minimum seconds between buy orders. | 60 |
Simple health check.
curl http://localhost:3000/healthExample response:
{
"ok": true,
"ts": "2026-05-11T07:08:14.122Z"
}Returns the latest market data, trading state, and current arbitrage signal.
curl http://localhost:3000/statusExample response:
{
"tradingEnabled": true,
"afterStartWindow": true,
"lastTickAt": 1778483294122,
"polymarket": {
"upCents": 82,
"downCents": 18,
"hasLiquidity": true,
"fetchedAt": 1778483293988
},
"kalshi": {
"yesCents": 95,
"noCents": 5,
"status": "open",
"isFinished": false,
"fetchedAt": 1778483294041
},
"signal": {
"action": "buy_polymarket",
"reason": "Kalshi YES 95¢ in [93,96], Polymarket UP 82¢ (spread 13¢ >= 10¢).",
"kalshiYesCents": 95,
"polymarketUpCents": 82,
"spreadCents": 13
}
}Starts the polling loop. Polling starts automatically when the service boots, but this endpoint is useful after manually stopping it.
curl -X POST http://localhost:3000/poll/startStops the polling loop without shutting down the HTTP server.
curl -X POST http://localhost:3000/poll/stopThe /status endpoint always exposes the latest evaluated signal, including no-buy reasons. This is useful for validating market pairing, reviewing spreads, and demonstrating the strategy logic before increasing capital allocation.
Best for:
- Strategy validation
- Client demos
- Reviewing live signal behavior
- Collecting signal frequency data
When POLYMARKET_PRIVATE_KEY and POLYMARKET_PROXY_WALLET_ADDRESS are valid, the bot initializes the Polymarket order client and places buy orders when a buy signal appears. Use a dedicated wallet and conservative trade size while validating behavior.
Execution protections included in the current code:
- Configurable trade size via
POLYMARKET_TRADE_USD - Configurable buy cooldown via
POLYMARKET_BUY_COOLDOWN_SECONDS - Price validation before submitting a buy
- In-memory latest state for transparent API inspection
- Select a 15-minute event that exists on both Kalshi and Polymarket.
- Copy the Kalshi ticker into
KALSHI_TICKER. - Copy the matching Polymarket UP and DOWN token IDs into
.env. - Set
MARKET_START_TIMEand confirmSTART_DELAY_MINS. - Run the bot and watch
/statusto confirm price feeds and signal behavior. - Confirm the signal behavior against live market screens.
- Use a limited Polymarket wallet and conservative
POLYMARKET_TRADE_USD. - Monitor logs and the
/statusendpoint during the active market window.
Polymarket-Kalshi arbitrage bot listening on port 3000
GET /health - health check
GET /status - last prices and current signal
POST /poll/start - start price polling
POST /poll/stop - stop price polling
[Bot] Polymarket order client ready (trading enabled).
[Bot] Polling every 5000ms
[Bot] BUY SIGNAL: {
"action": "buy_polymarket",
"kalshiYesCents": 95,
"polymarketUpCents": 82,
"spreadCents": 13
}
[Bot] Polymarket BUY order placed: { "...": "..." }
- Run on a stable machine with reliable network access.
- Use process supervision such as
pm2, Docker, systemd, or your cloud provider's runtime manager. - Store secrets in environment variables or a managed secret store.
- Use a dedicated wallet with limited capital.
- Monitor
/health,/status, application logs, and wallet balances. - Keep polling intervals reasonable to avoid unnecessary API load.
- Never commit
.envor private keys. - Rotate keys if they were ever exposed.
- Use a dedicated proxy wallet for bot execution.
- Start with small trade sizes until the full workflow is verified.
- Review venue rules and local regulations before using automated trading.
npm run dev # Start development server with auto-reload
npm run build # Compile TypeScript to dist/
npm start # Run compiled production build
npm run typecheck # Type-check without emitting filesThis repository is provided for software engineering and automation purposes. Markets can move quickly, APIs can fail, liquidity can disappear, and automated orders can execute at unfavorable times. Review the code, test carefully, and trade only with capital you can afford to risk.