How I Built the Hedge Logic for My Polymarket Straddle Bot

The concept is simple. Buy YES and NO on the same market. Keep combined cost below $1.00. Collect at settlement. No directional bet required.

The implementation is not simple. Here's exactly how I built the hedge logic step by step.

Step 1: Track Two Legs Independently

First thing the bot needs: separate state for each side of the same candle.

Each leg tracks:

  • shares held
  • total cost paid
  • VWAP (total cost / shares)

Combined VWAP = Up VWAP + Down VWAP

That combined number is the only number that actually matters. Below $1.00 means you have a locked spread. Above $1.00 means you're in the red on the hedge and need price to bail you out.

I got this wrong in the first version. I was tracking a single position and trying to calculate the hedge after the fact. Doesn't work. You need two independent ledgers from the start.

Step 2: Define What a Signal Actually Is

The bot scans the CLOB every second. Each scan runs through a fixed priority list and returns the first matching condition. One signal per tick, no exceptions.

I ended up with six signal types after a lot of iteration:

dip - either side below 55¢ when already hedged. Rebalance toward the cheaper or underweight leg.

stack - one leg exists, other doesn't yet. Add to held leg while it's still cheap (≤55¢). Build size before committing to the second leg.

late-tail - final 60 seconds, cheapest side at 32¢ or below. Small convex bet. If the underdog wins, return is clean. If not, cost was minimal.

no-signal - nothing fits, skip the tick.

Priority is fixed. Every tick, evaluate top to bottom, take the first match. No combining signals, no weighted scoring. Simple to reason about, easy to debug.

Step 3: The Combined VWAP Guard

This is the core of the hedge logic and the thing I underbuilt first.

Before any clip fires on a hedged position, the bot calculates what the new combined VWAP would be if this clip went through:

newCombined = newSideVwap + otherSideVwap

If newCombined > 1.00, the clip is blocked. No exceptions for dip, stack, or late-tail.

Build and complete bypass this guard. Those clips exist specifically to finish an incomplete hedge - if the bot blocked them on combined cost, you'd end up permanently one-sided on candles where prices drifted up mid-candle.

The guard is what separates a straddle arb from just buying both sides randomly. Without it the bot will happily accumulate a $1.08 combined position and call it a hedge.

Step 4: One-Sided Limits

Before I had position limits, bad candles were ugly. Thin books, one side drying up, bot stacking 150 shares of YES with no NO hedge in sight. That's just a directional bet with worse fees.

Hard limit: 90 shares max on one leg before the other leg exists. Once you hit 90 one-sided shares, only build and complete signals are allowed through - the ones specifically designed to finish the hedge.

Also: one-sided clips are capped at 55¢. If you're holding one leg and the market is only offering the same leg at 70¢, the bot waits. Paying 70¢ for a one-sided position with no hedge yet is how you lose money on a strategy that's supposed to be market-neutral.

Step 5: Rate Limits and the Late Window

Two different modes depending on time remaining.

Normal mode: 7 second cooldown between clips. Max 40 clips per candle. Max 12 clips per side. This pacing came directly from studying the trade history - the reference trader averaged roughly one clip every 7 seconds, not hammering the book continuously.

Late window (final 60 seconds): cooldown drops to 50ms on the same side. Late-tail and urgent complete signals get priority. Budget reserved - bot won't use more than 25 clips before the late window opens, leaving at least 15 clips for the final minute.

The late window matters more than it sounds. A significant portion of fills happen in the final 60 seconds. Prices move as the candle closes, cheap tails appear briefly, and urgent completes need to fire fast. 7 second cooldown in that window is too slow.

Step 6: Settlement

After candle close, bot waits at least 60 seconds then polls the Gamma oracle every 5 seconds.

Requires two conditions before settling:

  • closed === true
  • prices approximately 1.00 / 0.00

Winner gets $1.00 per share. Loser gets $0.00. Fees were already paid at entry so settlement is clean.

Positions still unresolved 15 minutes past close get marked expired. Settlement keeps retrying - Gamma occasionally takes longer on volatile candles.

One thing I missed early: redemption gas on Polygon. Small positions get eaten disproportionately. Below $8.00 effective position the gas cost as a percentage gets ugly. Minimum position size is enforced now, not optional.

What Took the Longest

Not the signal logic. Not the VWAP tracking.

The hardest part was getting the combined guard to interact correctly with the build and complete bypasses. Early versions had a bug where a build clip would push combined to $1.06, then the next tick a dip signal would fire on the other side and get through because it saw the other leg as "underweight." Bot would just keep adding to whichever leg looked cheap without the guard catching it.

Fix: guard recalculates combined from current state every tick, not from state at signal time. Sounds obvious. Took me longer than it should have to find it.

Where It Is Now

Hedge logic is stable. Six signal types, fixed priority, combined guard, one-sided limits, two-speed rate limiting. Paper mode running on live CLOB data with realistic slippage simulation before any real capital goes in.

Next thing to solve: maker/taker split. Maker fills at bid+1¢ carry about 10% of taker fee. In a strategy where fee drag compounds across 40 clips per candle, shifting more fills to maker could meaningfully change the return profile. Current version is almost entirely taker because the window is short. Testing that next.

My another strategy reference: github.com/casatrick/polymarket-arbitrage-bot

Comments

Popular posts from this blog

How a Polymarket Arbitrage Bot Actually Works: 5 Strategies Explained

Why Every Polymarket Trading Bot Needs to Adapt to TWAP

Building a Polymarket Trading Bot: Order Book Monitoring, Slippage Handling, and Position Sizing