# I cloned a Polymarket market-making bot and ran it: Here’s what I learned Source: https://tezlee.substack.com/p/i-cloned-a-polymarket-market-making?triedRedirect=true Credit: ChatGPT and Grok Prediction markets weren’t on my radar until a close friend mentioned them on our November 2024 guys’ trip. Initially, I dismissed them as gambling platforms like DraftKings or bet365. However, the post-US election hype around massive Polymarket gains changed my perspective. By May 2025, I came across a Substack post about earning from liquidity provision on Polymarket which sparked my interest. I forked the shared GitHub repo (shoutout to @defiance_cr and huge thank you) and dove in. Polymarket appealed to me because competition is relatively lower than TradFi/DeFi, Polymarket’s maker rewards are attractive and the binary YES/NO outcomes simplify risk management. Source: Automated Market Making on Polymarket by @defiance_cr The core idea of the tool is simple: find an edge by providing liquidity on Polymarket. You can earn both the spread on each market and Polymarket’s liquidity rewards. Beyond the original tool’s functionality, I added several new features as well. The below shows all summarised features: Diagram 1: Overall bot functionality The diagram illustrates the end-to-end flow of the bot. A brief outline of each component is as follows: The bot scrapes all active Polymarket markets via API and populates them into a Google sheet, forming the foundation for market selection. Diagram 2: All active markets in Google Sheets [All Markets tab] It then computes volatility, rewards and spreads. The reward formula sourced from Polymarket’s website is: S = ((v - s) / v)² * b where: S = Reward score (0 to 1) v = max_spread / 100 (e.g., 0.05 for 5%) s = |price - mid-price| (distance from mid) b = in-game multiplier The metric forms the basis for identifying high-reward markets. The closer to the mid, the higher the rewards. The bot applies filters, calculates a profitability score, ranks the markets and populates the results into a “Specific Markets” tab. This tab serves as the automated execution input. The trade execution is handled through a WebSocket connection that streams price updates and maintains a local order book state. Decision logic layer → checks if a market is in “Selected Markets”. Position sizing logic → determines buy/sell amounts and ensures position limits are respected. Order management layer → monitors existing orders and cancels them if price moves beyond configured thresholds. Execution layer → places orders, listens for fills, updates positions and places hedge orders when necessary. Diagram 3: Limit orders should be ideally placed on both sides to max out the rewards provided by Polymarket. The bot includes a position-merging logic that checks for YES and NO share inventory. If both sides match (e.g., 100 YES and 100 NO), it merges them into USDC without incurring slippage. Position merging logic: pos_yes = get_position(token1)[’size’] pos_no = get_position(token2)[’size’] # Step 2: Calculate mergeable amount amount_to_merge = min(pos_yes, pos_no) # Step 3: Decision point if amount_to_merge > MIN_MERGE_SIZE: # MIN_MERGE_SIZE = 20 # MERGE else: pass #too small to merge The bot includes a stop-loss and take-profit logic. For instance, Stop loss logic triggers when: PnL < stop-loss threshold and spread ≤ spread_threshold or volatility > volatility threshold Take profit logic triggers when: tp_price = avgPrice + (avgPrice * take_profit_threshold / 100) Diagram 4: Summary of the trading lifecycle Low-volatility and tight-spread markets are far more forgiving. You can offload directional risk quickly because there is liquidity to absorb it. One of my early mistakes was participating in volatile markets where I couldn’t hedge fast enough. Directional risk is the real P&L killer. While earning rewards from passive limit orders is great, a single adverse move of 30–40% can wipe out accumulated gains within minutes. I experienced this first-hand during testing multiple times. Also, I realised how crucial real-time inventory tracking is. Earlier versions of the bot didn’t maintain accurate net position snapshots and mixing manual bets made it worse. As a result, the bot kept adding to losing sides. After implementing proper position snapshots, I could offset risk sensibly and make sure it doesn’t concentrate too much risk into a single position. Technical aspect lessons: $20/month on AI coding tools turned out to be the highest-ROI spend of the entire experiment. It dramatically sped up debugging and iteration. Adding extensive logging across the execution flow also allowed tools like Claude or Cursor to assist with debugging far more effectively. I now agree with the view that you should pilot this manually before automating anything. Observe how adverse selection impacts your earnings and understand how market-order slippage affects P&L. Only after learning these lessons first-hand does automation truly make sense. One important takeaway from this experiment is that I didn’t end up making any net profit overall. While the bot did generate maker rewards and some spread earnings, most of those gains were offset, if not completely wiped out by early mistakes, execution bugs, misconfigured logic and trial-and-error testing. The accumulated cost of these errors ate directly into whatever edge the strategy produced. This made it clear that in market-making, the operational layer is just as important as the strategy itself; even small inaccuracies can compound quickly and overwhelm potential returns. Nonetheless, this is still something worth working on and I plan to continue iterating on it. I have published my repository on GitHub, please feel free to explore or fork it. https://github.com/terrytrl100/polymarket-automated-mm and please follow me on X: https://x.com/terrytakes101 for more. [1] [2] https://docs.polymarket.com/developers/rewards/overview [3] https://github.com/warproxxx/poly-maker