
Using Orderbook Imbalance (OBI) for Polymarket Arbitrage Bots
Hey all. I've been working on an arbitrage strategy for Polymarket's 5-minute crypto up/down markets and after the move to TWAP settlement earlier this month, I've been reevaluating what indicators are best to trigger trade signals within my bot. I wrote this artwork for the members over at Poly Research & Robotics and figured I would share it too incase it helps anymore.
Order-book imbalance is the indicator/signal that my arb bot fires on. We compute it from Binance's order-book depth feed and use it to decide when to open a position on the Polymarket contract, which is a detail worth stating up front because it turns out to matter more than anything else here.
To find out what the indicator is actually worth, we pulled a month of full-depth books, roughly 52,000 markets and 13 million seconds of order book. That tape is from April, which puts it squarely in the old settlement regime. For this particular indicator that matters less than you might expect, because order-book imbalance describes what the book is doing inside the cycle rather than how the market eventually resolves, and the mechanism behind it has nothing to do with settlement. Anything specific to the closing minute is a different story and should be treated with suspicion until somebody re-runs it on post-TWAP data.
The short answer on the indicator itself is that it gives you around 1-1.5 seconds of warning before the price moves on polymarket (it ranges quite a bit).
WHAT OBI IS:
Order-book imbalance is a single number describing how lopsided the order book is.
An order book is really just two queues: the people waiting to buy on one side, and the people waiting to sell on the other. OBI compares how big those two lines are. A book made up entirely of buyers reads +1, a book made up entirely of sellers reads -1, and a balanced book reads zero. It counts the shares waiting at each level and never looks at prices.
You can run the same calculation on any order book you can get depth for. Ours runs on Binance's book for the underlying coin, because that is where the size and the price discovery are. The alternative is to run it on Polymarket's own book for the contract you are trading, and the difference between those two choices is the single most important decision in this whole setup. More on that below.
Here is a real Polymarket book from the tape, taken from an ETH market on april 12:
bid 0.33 456.87 shares
ask 0.35 5.00 shares OBI +0.80
There were 456 shares trying to get in against 5 shares willing to sell to them. One second later the offer had been cleared, the price had moved three and a half cents, and the imbalance itself had already halved.
That is the entire mechanism. An extreme reading is not a forecast in any deep sense; it is a statement that one side of the book is about to run out. Once the thin side gets cleared the price moves by construction, and the imbalance that predicted the move is consumed in the same instant.
This also explains a property that catches people out, which is that OBI is not a trend indicator. Measured against the price change at every offset around the reading, the correlation is negative at every point before it. The lopsided book appears after price has been pushing the other way, rather than before it. If you are using OBI to confirm a trend, you are using it backwards.
HOW MUCH WARNING YOU GET:
Once the order book tips heavily to one side, how long is it before the price on Polymarket actually moves?
the short answer is that you get about two seconds of useful warning, and the whole effect is spent inside fifteen.
the clearest way to see it is to follow a single spike forward in time. Each figure below is the share of spikes that had produced a full one-cent price move by that point, either in the direction the imbalance was leaning or against it.
After 1 second, 36% of spikes have already produced a one-cent move in the predicted direction, against only 10% that have moved a cent the other way. This is the point at which the relationship between the imbalance and the price is at its strongest, and nothing that happens later is anywhere near as clean.
After 2 seconds, 44% have moved a cent in the predicted direction and 16% have moved against it. Starting from a randomly chosen second instead of a spike, the equivalent figure is 19%. Counting only the spikes that produce a move at all, the typical wait is two seconds, where from a random starting point the same wait runs to eight.
after 5 seconds, 56% have moved in the predicted direction and 29% have moved against it. This is the widest that gap ever becomes, and it narrows steadily from here.
After 7 seconds, the imbalance reading has decayed to half its original strength. The book you measured has largely been traded away by this point.
These measurements are obviously specific to this one moment that I'm featuring here for this article, but you get the idea. Many times the signal has decayed much quicker than 7 seconds. This example is an extreme imbalance.
HOW TO PUT IT IN YOUR BOT:
The calculation is small. This is the version I run:
n = min(10, len(bids), len(asks))
bidW = sum(bid_size[i] * (n - i) for i in range(n))
askW = sum(ask_size[i] * (n - i) for i in range(n))
obi = (bidW - askW) / (bidW + askW) # -1 to +1
Take the top ten levels of each side, weight them so the front of the queue counts heaviest, and then compare the two totals. Use the resting sizes only and never the prices they sit at. Every reading is computed fresh from a single snapshot, with no memory of the one before it.
The way you set up your config and what OBI values trigger different actions in your bot make a world of difference. Similar to any betting model, it's all about how you weight the data that makes the difference, not the data itself.
For me, I'm building an arbitrage trading bot on the polymarket up / down crypto markets, so I am using this signal to trigger a buy on one of the sides (mostly the dominant side for my opening trade of the pair) and then once the polymarket price catches up the OBI we observed on Binance, then we capture the other site for a share price that is within range for a profitable pair to be captured.
EXAMPLE:
- Observe OBI +.8 (we see that way more people are trying to buy than sell...)
- Bot purchases Up share at .60 a share (down is currently .40/.41)
- OBI evens out, buyers get in, price moves up...
- Down share price drops to .35, and we buy for a captured spread of 5% on the money we deployed into that pair.
now keep in mind, this isn't perfect and I'm still deep in development but I wanted to share this technique because it's been by far the most helpful and reliable indicator/signal for successfully capturing these pairs, and if you've build arbitrage bots before you know it's incredibly hard to main consistent pair accumliation.
If you're interested in polymarket trading bot development, and you're working on something similar...join us over at Poly Research & Robotics. We're a 1,500+ member free community dedicated to developing trading bots and strategies. We offer free guides, free trader reports, and polymarket historical data of many market categories that you can use to test out the above mentioned OBI (or use it to backtest any strategy you're working on).
If you have any tips or suggestions please leave them in the comments!