The Problem
Polymarket’s 15‑minute prediction markets require fast, repeatable signal generation and optional order execution. Manual monitoring is error‑prone and cannot keep up with the rapid market cycles, leading to missed opportunities or unintended exposure.
What This Does
The repo implements a TypeScript bot that computes RSI, MACD, and Momentum indexes for ETH and BTC 15‑minute markets and decides whether to place a trade. Core logic lives in src/indicators.ts (rolling calculations) and src/strategies.ts (decision engine). Configuration and CLI parsing are in src/config.ts; API interaction with Polymarket’s Gamma and CLOB endpoints is in src/api.ts. A simulation mode (--simulation) logs signals only, while --live forwards decisions to src/clob.ts for real order placement.
How It Is Wired
- Entry point –
src/main.ts(mainat line 26) parses CLI flags viaparseArgs(inconfig.ts), loadsconfig.json, and runsdiscoverMarket(monitor.ts). - Market discovery –
discoverMarketcallsPolymarketApi.getMarketBySlug(api.ts) to obtain market metadata, then creates a dummy market object (createDummyMarket) for simulation or real use. - Snapshot loop –
getSnapshot(main.ts) repeatedly invokesfetchSnapshot(monitor.ts) →fetchMarketData(monitor.ts) →PolymarketApi.getSidePrice. The snapshot is converted to aPricePointbysnapshotToPricePoint(simulation.ts). - Indicator update – Each new price is fed to
addPrice(indicators.ts), which updates RSI (getRSI), MACD (getMACD), and Momentum (getMomentum). These functions are each called from two places (simulation loop and strategy decision). - Decision –
decide(strategies.ts) receives the current index viacalculateIndex(strategies.ts) and the indicator state. It returns aTradeAction(BuyUp/BuyDown/Neutral). - Execution – In live mode, the returned action routes to
placeLimitOrder(clob.ts), which builds a signed order using the private key fromconfig.json. In simulation mode the action is only logged.
Call‑graph hot spots
mainreaches 36 functions, the widest blast radius.src/config.tsis imported by five other modules, making it a stability anchor (instability 0).src/indicators.tshosts 17 functions and is called from two files, central to the bot’s calculations.
No circular dependencies were detected, but src/simulation.ts and src/clob.ts contain dense branching (≈30 branches over 76 lines), raising cognitive load.
How To Use It
# Clone the repo
git clone https://github.com/moses-y/Polymarket-rsi-macd-index-trading-bot
cd Polymarket-rsi-macd-index-trading-bot
# Install dependencies
npm install
# Prepare configuration
cp config.json.example config.json
# Edit config.json – at minimum set polymarket.private_key for live mode
# Run simulation (default)
npm run dev # or: npx tsx src/main.ts --simulation
# Run live trading
npx tsx src/main.ts --live
The CLI accepts --config /path/to/config.json to point at an alternative config file.
Real‑World Use
A market‑making service can embed this bot in a container that runs continuously. The service starts the bot with --live, monitors the log for “BuyUp” signals, and the bot automatically places limit orders via the CLOB client, keeping exposure aligned with the configured position_size and risk thresholds.
Code Health & Issues
- High – Missing LICENSE – No licence file at repository root; legal reuse is blocked.
- High – No CI pipeline – No
.github/workflowsor other CI config; builds and tests are never automatically verified. - High – Dependabot not configured – No
dependabot.yml; dependencies (@types/node,typescript,ethers) are several major versions behind. - Medium – Duplicated code – Repeated 6‑line blocks in
src/config.tsandsrc/strategies.ts; extract to a shared helper. - Medium – High branching density –
src/clob.tsandsrc/simulation.tseach have ~30 branch points in <80 lines; refactor into smaller, testable functions. - Medium – No tests – Repository contains no test files, leaving core calculation paths unvalidated.
The Bottom Line
The bot provides a functional, TypeScript‑based implementation of Polymarket RSI/MACD trading logic with clear separation of config, API, indicator, and strategy layers. It is ready for simulation but requires engineering effort to add licensing, CI, dependency updates, and test coverage before being safe for production deployment. Suitable for teams that can invest in these missing engineering practices.