[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-80294":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":15,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":16,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":17,"hasPages":17,"topics":19,"createdAt":10,"pushedAt":10,"updatedAt":40,"readmeContent":41,"aiSummary":42,"trendingCount":15,"starSnapshotCount":15,"syncStatus":43,"lastSyncTime":44,"discoverSource":45},80294,"polymarket-kalshi-arbitrage-bot","sanzoI-tech\u002Fpolymarket-kalshi-arbitrage-bot","sanzoI-tech","polymarket trading bot, polymarket bot, polymarket kalshi trading bot, polymarket trading bot, polymarket bot, polymarket kalshi trading bot, polymarket trading bot, polymarket bot, polymarket kalshi trading bot, polymarket trading bot, polymarket bot, polymarket kalshi trading bot, kalshi, prediction-markets, arbitrage, typescript, clob","https:\u002F\u002Fgithub.com\u002FsanzoI-tech\u002Fpolymarket-kalshi-arbitrage-bot",null,"TypeScript",29,1909,77,0,9.84,false,"main",[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],"algorithmic-trading","arbitrage","arbitrage-bot","automated-trading","clob","crypto","defi","event-contracts","kalshi","kalshi-api","kalshi-trading","market-making","nodejs","polymarket","polymarket-bot","polymarket-trading-bot","prediction-markets","spread-trading","trading-bot","typescript","2026-06-12 02:04:00","# Polymarket-Kalshi Arbitrage Bot\n\nProfessional 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.\n\n**Canonical repository:** [github.com\u002FsanzoI-tech\u002Fpolymarket-kalshi-arbitrage-bot](https:\u002F\u002Fgithub.com\u002FsanzoI-tech\u002Fpolymarket-kalshi-arbitrage-bot)\n\nThe 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.\n\n\u003Cp>\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FsanzoI-tech\u002Fpolymarket-kalshi-arbitrage-bot\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FRepository-GitHub-181717?style=for-the-badge&logo=github\" alt=\"GitHub repository\" \u002F>\n  \u003C\u002Fa>\n\u003C\u002Fp>\n\n> 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.\n\n## What This Bot Does\n\n- Monitors a paired Kalshi and Polymarket market on a configurable interval.\n- Pulls Polymarket UP\u002FDOWN token pricing from the Polymarket CLOB.\n- Pulls Kalshi YES\u002FNO pricing and market status from the Kalshi trade API.\n- Waits until a configurable start window has passed before evaluating trades.\n- Emits structured arbitrage signals through `\u002Fstatus`.\n- Places Polymarket buy orders using `@polymarket\u002Fclob-client` when valid trading credentials are configured.\n- Applies order cooldowns to reduce duplicate execution during repeated signals.\n- Runs as a lightweight Express service that can be deployed on a VPS, container, or cloud instance.\n\n## Strategy Overview\n\nThe current strategy focuses on buying the Polymarket UP token when Kalshi is pricing the equivalent outcome materially higher.\n\n### Rule 1: Spread-Based Entry\n\nAfter the configured start delay, the bot checks whether Kalshi YES is inside a target confidence band and whether Polymarket UP is meaningfully cheaper.\n\nDefault thresholds:\n\n- Kalshi YES must be between `93` and `96` cents.\n- Polymarket UP must be at least `10` cents cheaper than Kalshi YES.\n- The bot emits `buy_polymarket` when both conditions are true.\n\nExample:\n\n```text\nKalshi YES:      95 cents\nPolymarket UP:   82 cents\nSpread:          13 cents\nDecision:        BUY Polymarket UP\n```\n\nResulting signal:\n\n```json\n{\n  \"action\": \"buy_polymarket\",\n  \"reason\": \"Kalshi YES 95¢ in [93,96], Polymarket UP 82¢ (spread 13¢ >= 10¢).\",\n  \"kalshiYesCents\": 95,\n  \"polymarketUpCents\": 82,\n  \"spreadCents\": 13\n}\n```\n\n### Rule 2: Late Resolution Opportunity\n\nSome 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.\n\nExample:\n\n```text\nKalshi status:       settled\nPolymarket book:     still has liquidity\nDecision:            BUY Polymarket UP\n```\n\nResulting signal:\n\n```json\n{\n  \"action\": \"buy_polymarket_late\",\n  \"reason\": \"Kalshi market finished (closed\u002Fsettled) while Polymarket still has orders.\",\n  \"kalshiStatus\": \"settled\"\n}\n```\n\n## Demo (Instagram reel — Polymarket vs Kalshi for bots)\n\nPrimary source: [https:\u002F\u002Fwww.instagram.com\u002Freel\u002FDWrBSHxlIZ3\u002F](https:\u002F\u002Fwww.instagram.com\u002Freel\u002FDWrBSHxlIZ3\u002F) (permalink on profile: [@moondevonyt](https:\u002F\u002Fwww.instagram.com\u002Fmoondevonyt\u002Freel\u002FDWrBSHxlIZ3\u002F)).\n\n### Source metadata (public, as shown on Instagram)\n\n- **Account:** [@moondevonyt](https:\u002F\u002Fwww.instagram.com\u002Fmoondevonyt\u002F) — display name *Moon Dev on YT* (verified).\n- **Post type:** Reel \u002F `GraphVideo` clip (vertical 720×1280 class dimensions in embed data).\n- **Published:** April 3, 2026 (Instagram “taken at” timestamp in page metadata).\n- **Caption (verbatim):** *Polymarket or kalshi for trading bots?*\n- **Audio:** Original audio credited to the same account (“Moon Dev on YT on Instagram…” in `og:title`).\n- **Approximate length:** ~39 seconds (progressive clip; duration from Instagram embed payload when the local video was mirrored).\n- **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.\n\nThe 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.\n\n### How that question maps to this repository\n\nThis 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](#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`.\n\n### Local copy (for README \u002F offline use)\n\nMirrored under [`src\u002Fimg and video\u002F`](.\u002Fsrc\u002Fimg%20and%20video\u002F) (shortcode **DWrBSHxlIZ3**):\n\n- **Video:** [`instagram-DWrBSHxlIZ3-demo.mp4`](.\u002Fsrc\u002Fimg%20and%20video\u002Finstagram-DWrBSHxlIZ3-demo.mp4)\n- **Poster \u002F cover frame:** [`instagram-DWrBSHxlIZ3-poster.jpg`](.\u002Fsrc\u002Fimg%20and%20video\u002Finstagram-DWrBSHxlIZ3-poster.jpg)\n\n### Video\n\n\u003Cvideo\n  poster=\".\u002Fsrc\u002Fimg%20and%20video\u002Finstagram-DWrBSHxlIZ3-poster.jpg\"\n  src=\".\u002Fsrc\u002Fimg%20and%20video\u002Finstagram-DWrBSHxlIZ3-demo.mp4\"\n  controls\n  playsinline\n  preload=\"metadata\"\n  width=\"100%\">\n  Your browser cannot play this clip inline. Open the file directly:\n  \u003Ca href=\".\u002Fsrc\u002Fimg%20and%20video\u002Finstagram-DWrBSHxlIZ3-demo.mp4\">instagram-DWrBSHxlIZ3-demo.mp4\u003C\u002Fa>.\n\u003C\u002Fvideo>\n\n### Still frame (preview)\n\n\u003Cp align=\"center\">\n  \u003Cimg\n    src=\".\u002Fsrc\u002Fimg%20and%20video\u002Finstagram-DWrBSHxlIZ3-poster.jpg\"\n    alt=\"Cover frame from the Instagram reel DWrBSHxlIZ3 (Polymarket or Kalshi for trading bots?)\"\n    width=\"100%\" \u002F>\n  \u003Cbr \u002F>\n  \u003Cem>Poster image from the same reel (local mirror; Instagram: \u003Ccode>DWrBSHxlIZ3\u003C\u002Fcode>).\u003C\u002Fem>\n\u003C\u002Fp>\n\n## Architecture\n\n```text\nKalshi API              Polymarket CLOB\n    |                         |\n    |                         |\n    +------ price polling ----+\n              |\n              v\n      Arbitrage decision engine\n              |\n      +-------+--------+\n      |                |\n      v                v\n  \u002Fstatus API     Polymarket order client\n                   authenticated execution\n```\n\nCore modules:\n\n- `src\u002Findex.ts` starts the Express API, polling loop, and optional trading client.\n- `src\u002Fconfig.ts` loads and validates runtime configuration from `.env`.\n- `src\u002Fservices\u002Fkalshi.ts` fetches Kalshi market data.\n- `src\u002Fservices\u002Fpolymarket.ts` fetches Polymarket CLOB prices.\n- `src\u002Fservices\u002Farbitrage.ts` evaluates buy\u002Fno-buy decisions.\n- `src\u002Fservices\u002FpolymarketOrders.ts` places Polymarket orders when trading is enabled.\n\n## Tech Stack\n\n- **Node.js 18+**\n- **TypeScript**\n- **Express** for the HTTP monitoring\u002Fcontrol API\n- **Axios** for Kalshi and Polymarket HTTP requests\n- **@polymarket\u002Fclob-client** for Polymarket order placement\n- **ethers** for wallet\u002Fclient support\n- **dotenv** for environment-based configuration\n\n## Quick Start\n\nInstall dependencies:\n\n```bash\nnpm install\n```\n\nCreate a local environment file:\n\n```bash\ncp .env.example .env\n```\n\nEdit `.env` with your market pair and wallet settings, then run:\n\n```bash\nnpm run build\nnpm start\n```\n\nFor development with auto-reload:\n\n```bash\nnpm run dev\n```\n\nThe service starts polling automatically and exposes the API on `http:\u002F\u002Flocalhost:3000` by default.\n\n## Example `.env`\n\n```env\nPORT=3000\nPOLL_INTERVAL_MS=5000\n\nMARKET_START_TIME=2026-05-11T07:00:00.000Z\nSTART_DELAY_MINS=8\n\nKALSHI_API_BASE=https:\u002F\u002Fapi.elections.kalshi.com\u002Ftrade-api\u002Fv2\nKALSHI_TICKER=KXHIGHNY-24JAN01-T60\n\nPOLYMARKET_CLOB_BASE=https:\u002F\u002Fclob.polymarket.com\nPOLYMARKET_TOKEN_UP=1234567890123456789012345678901234567890\nPOLYMARKET_TOKEN_DOWN=9876543210987654321098765432109876543210\n\nKALSHI_MIN_CENTS=93\nKALSHI_MAX_CENTS=96\nMIN_SPREAD_CENTS=10\n\nPOLYMARKET_PRIVATE_KEY=0x\u003C64_HEX_CHARACTER_PRIVATE_KEY>\nPOLYMARKET_PROXY_WALLET_ADDRESS=0x\u003C40_HEX_CHARACTER_PROXY_WALLET>\nPOLYMARKET_CHAIN_ID=137\nPOLYMARKET_TRADE_USD=10\nPOLYMARKET_BUY_COOLDOWN_SECONDS=60\n```\n\nKeep private keys out of source control. Use a dedicated trading wallet with limited funds.\n\n## Configuration Reference\n\n| Variable | Description | Default \u002F Example |\n| --- | --- | --- |\n| `PORT` | HTTP server port. | `3000` |\n| `POLL_INTERVAL_MS` | Price polling interval in milliseconds. | `5000` |\n| `MARKET_START_TIME` | Market start time in ISO 8601 format. | `2026-05-11T07:00:00.000Z` |\n| `START_DELAY_MINS` | Minutes after market start before evaluating signals. | `8` |\n| `KALSHI_API_BASE` | Kalshi trade API base URL. | `https:\u002F\u002Fapi.elections.kalshi.com\u002Ftrade-api\u002Fv2` |\n| `KALSHI_TICKER` | Kalshi market ticker for the target market. | `KXHIGHNY-24JAN01-T60` |\n| `POLYMARKET_CLOB_BASE` | Polymarket CLOB API base URL. | `https:\u002F\u002Fclob.polymarket.com` |\n| `POLYMARKET_TOKEN_UP` | Polymarket UP\u002FYES token ID. | From the Polymarket market |\n| `POLYMARKET_TOKEN_DOWN` | Polymarket DOWN\u002FNO token ID. | From the Polymarket market |\n| `KALSHI_MIN_CENTS` | Lower Kalshi YES price bound for spread entries. | `93` |\n| `KALSHI_MAX_CENTS` | Upper Kalshi YES price bound for spread entries. | `96` |\n| `MIN_SPREAD_CENTS` | Minimum Kalshi minus Polymarket spread required. | `10` |\n| `POLYMARKET_PRIVATE_KEY` | EOA private key used for trading. | `0x...` |\n| `POLYMARKET_PROXY_WALLET_ADDRESS` | Polymarket proxy wallet \u002F Safe address. | `0x...` |\n| `POLYMARKET_CHAIN_ID` | Chain ID for Polymarket CLOB. | `137` |\n| `POLYMARKET_TRADE_USD` | USD amount per buy order. | `10` |\n| `POLYMARKET_BUY_COOLDOWN_SECONDS` | Minimum seconds between buy orders. | `60` |\n\n## API Reference\n\n### `GET \u002Fhealth`\n\nSimple health check.\n\n```bash\ncurl http:\u002F\u002Flocalhost:3000\u002Fhealth\n```\n\nExample response:\n\n```json\n{\n  \"ok\": true,\n  \"ts\": \"2026-05-11T07:08:14.122Z\"\n}\n```\n\n### `GET \u002Fstatus`\n\nReturns the latest market data, trading state, and current arbitrage signal.\n\n```bash\ncurl http:\u002F\u002Flocalhost:3000\u002Fstatus\n```\n\nExample response:\n\n```json\n{\n  \"tradingEnabled\": true,\n  \"afterStartWindow\": true,\n  \"lastTickAt\": 1778483294122,\n  \"polymarket\": {\n    \"upCents\": 82,\n    \"downCents\": 18,\n    \"hasLiquidity\": true,\n    \"fetchedAt\": 1778483293988\n  },\n  \"kalshi\": {\n    \"yesCents\": 95,\n    \"noCents\": 5,\n    \"status\": \"open\",\n    \"isFinished\": false,\n    \"fetchedAt\": 1778483294041\n  },\n  \"signal\": {\n    \"action\": \"buy_polymarket\",\n    \"reason\": \"Kalshi YES 95¢ in [93,96], Polymarket UP 82¢ (spread 13¢ >= 10¢).\",\n    \"kalshiYesCents\": 95,\n    \"polymarketUpCents\": 82,\n    \"spreadCents\": 13\n  }\n}\n```\n\n### `POST \u002Fpoll\u002Fstart`\n\nStarts the polling loop. Polling starts automatically when the service boots, but this endpoint is useful after manually stopping it.\n\n```bash\ncurl -X POST http:\u002F\u002Flocalhost:3000\u002Fpoll\u002Fstart\n```\n\n### `POST \u002Fpoll\u002Fstop`\n\nStops the polling loop without shutting down the HTTP server.\n\n```bash\ncurl -X POST http:\u002F\u002Flocalhost:3000\u002Fpoll\u002Fstop\n```\n\n## Operating Notes\n\n### Monitoring Signals\n\nThe `\u002Fstatus` 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.\n\nBest for:\n\n- Strategy validation\n- Client demos\n- Reviewing live signal behavior\n- Collecting signal frequency data\n\n### Automated Trading\n\nWhen `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.\n\nExecution protections included in the current code:\n\n- Configurable trade size via `POLYMARKET_TRADE_USD`\n- Configurable buy cooldown via `POLYMARKET_BUY_COOLDOWN_SECONDS`\n- Price validation before submitting a buy\n- In-memory latest state for transparent API inspection\n\n## Example Client Workflow\n\n1. Select a 15-minute event that exists on both Kalshi and Polymarket.\n2. Copy the Kalshi ticker into `KALSHI_TICKER`.\n3. Copy the matching Polymarket UP and DOWN token IDs into `.env`.\n4. Set `MARKET_START_TIME` and confirm `START_DELAY_MINS`.\n5. Run the bot and watch `\u002Fstatus` to confirm price feeds and signal behavior.\n6. Confirm the signal behavior against live market screens.\n7. Use a limited Polymarket wallet and conservative `POLYMARKET_TRADE_USD`.\n8. Monitor logs and the `\u002Fstatus` endpoint during the active market window.\n\n## Sample Logs\n\n```text\nPolymarket-Kalshi arbitrage bot listening on port 3000\n  GET \u002Fhealth  - health check\n  GET \u002Fstatus  - last prices and current signal\n  POST \u002Fpoll\u002Fstart - start price polling\n  POST \u002Fpoll\u002Fstop  - stop price polling\n[Bot] Polymarket order client ready (trading enabled).\n[Bot] Polling every 5000ms\n[Bot] BUY SIGNAL: {\n  \"action\": \"buy_polymarket\",\n  \"kalshiYesCents\": 95,\n  \"polymarketUpCents\": 82,\n  \"spreadCents\": 13\n}\n[Bot] Polymarket BUY order placed: { \"...\": \"...\" }\n```\n\n## Deployment Notes\n\n- Run on a stable machine with reliable network access.\n- Use process supervision such as `pm2`, Docker, systemd, or your cloud provider's runtime manager.\n- Store secrets in environment variables or a managed secret store.\n- Use a dedicated wallet with limited capital.\n- Monitor `\u002Fhealth`, `\u002Fstatus`, application logs, and wallet balances.\n- Keep polling intervals reasonable to avoid unnecessary API load.\n\n## Security Notes\n\n- Never commit `.env` or private keys.\n- Rotate keys if they were ever exposed.\n- Use a dedicated proxy wallet for bot execution.\n- Start with small trade sizes until the full workflow is verified.\n- Review venue rules and local regulations before using automated trading.\n\n## Commands\n\n```bash\nnpm run dev        # Start development server with auto-reload\nnpm run build      # Compile TypeScript to dist\u002F\nnpm start          # Run compiled production build\nnpm run typecheck  # Type-check without emitting files\n```\n\n## Disclaimer\n\nThis 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.\n","该项目是一个用于Polymarket和Kalshi平台上的预测市场套利交易机器人。它使用TypeScript编写，能够实时监控两个平台的市场价格差异，并在满足预设条件时自动执行买入操作。核心功能包括持续比较Kalshi YES与Polymarket UP的价格、通过简单的API暴露监控信息以及支持配置化的订单冷却机制以避免重复执行。此工具特别适用于那些需要快速响应价格变动且交易周期较短（如15分钟）的场景，适合有一定技术基础并对算法交易感兴趣的用户。需要注意的是，虽然提供了自动化交易逻辑，但并不保证盈利或消除所有类型的风险。",2,"2026-06-11 04:00:12","CREATED_QUERY"]