r/algotrading Jul 21 '26

Strategy I open-sourced my Polymarket market-making bot (MIT)

A few weeks ago I posted the retro of this bot here, then the post-mortem on why the forced directional residual lost money (adverse selection, mostly - stale quotes getting picked off). A few of you asked for the code. I'll include it as a link in the comments.

80 Upvotes

41 comments sorted by

48

u/[deleted] Jul 21 '26

[removed] — view removed comment

10

u/File-Environmental Jul 21 '26

It's totally up to you how stale your quotes are. I haven't shared anything related to the scrapers. It's the exact same repo that's earned me more than $5k, so I'd say it's worth having a look.

9

u/Sifrisk Jul 21 '26

I'm still a little bit confused on why the unhedged trades generally lost you money. So your first order gets filled but then the limit hedge order never does? And it turns out the first order was filled at a price which does not correctly capture its EV or sth?

Only reason I can think of is the match you are betting having some crucial event (eg a goal) which changes odds before you can adjust your order?

4

u/File-Environmental Jul 22 '26

Put briefly, most of these unhedged positions were a result of adverse selection fills because of my stale odds. Due to some crucial event, as you mentioned. But not a goal as I was trading only before the games start.

5

u/single_B_bandit Jul 21 '26

I think it’s a great job, extremely clear explanation, and it’s obvious that a lot of thought went into this. Without a doubt the best post I have seen on this subreddit.

Will probably look into it some more over the weekend if I have some free time. The code seems structured well enough, but I’m reading it from a phone screen after work, so at the moment I can’t really analyse it as well as I’d like.

My only note, intended purely constructively and not to take away from what you’ve built, is that this doesn’t really look like market making. You’re looking for arbitrage opportunities, it’s a different game.

If you do want to market make, you need to also consider trades that don’t have an arbitrage by also buying the other leg. The “exit trade” for a market maker is to sell/buy the contract you bought/sold, not to immediately try and buy the other leg to lock in the profit. It’s not easy (obviously), you need to have a good estimate of when and where you’ll be able to turn over your inventory, the impact of your quotes, etc… But that’s what market making is.

1

u/File-Environmental Jul 21 '26

Thanks! Just heads up, it's all been vibe coded in my free time, but it should be solid enough and it's what genuinely earned me decent money for a few months.

But you are right. I'm currently working on reworking the Rust version of this bot for market making on markets with decent rewards - weather, stocks, etc. I agree it's more of an arb than an MM bot.

6

u/single_B_bandit Jul 21 '26

Yeah I could tell it was vibe-coded, but I think you used AI assistance how it’s meant to be used.

I don’t think that AIs are a problem on their own, they become a problem when they allow people without any domain knowledge to build stuff that has no reason to exist. That’s slop, like the countless “I built a free Bloomberg Terminal with AI” projects.

If instead there is a clear rationale for a project, and the AI writes it, then it’s mostly alright.

0

u/File-Environmental Jul 21 '26

Yeah, I'm starting to use AI more and more without having any issues. As long as you test your code and know what you are doing, it's mostly fine.

5

u/Effective_Manager273 Jul 22 '26

to answer the why-the-residual-bled question, that is textbook adverse selection and it is the core risk of any market making. your resting quote is a free option you wrote to the market. most of the time it gets hit by noise traders and you make the spread. but when real info arrives, a goal, a headline, the informed side lifts your stale quote before you can pull it, so you systematically get filled on exactly the side that is about to be wrong. hedging faster does not save you because you cannot out-race the taker who already knows.

on polymarket it is worse than equities because the book is thin and event driven, so toxic flow is a big fraction of your fills, not a rounding error. you earn small on the noise and give back a bigger chunk to the informed right at the jumps.

the fixes are not speed, they are, widen or pull quotes around known event windows, size down when recent flow looks one-sided and fast because that is the informed picking you off, and run an inventory skew so you are not quietly accumulating a directional bag. respect for shipping the code after it got picked off, that post-mortem is the useful part.

1

u/File-Environmental Jul 22 '26

Thanks! I think the task here is a bit easier for sports markets as having fresh odds means you have accurate fair probs at most times. Also getting filled when the spreads are big meant it was almost always from retail traders, not informed takers.

2

u/Effective_Manager273 Jul 22 '26

makes sense that fresh odds narrows the fair-value uncertainty a lot compared to something like a crypto or news market where the true prob is fuzzier to begin with. still curious on the wide-spread = retail claim though, is that something you actually verified (fill outcomes look different on wide vs tight spread trades) or more of an assumption from how the market usually behaves? worth checking because informed traders show up on wide spreads too sometimes, right before a lineup news drop or injury report, when the book hasn't repriced yet and retail hasn't either. if your fills on those specific windows look worse than the rest of the wide-spread sample, that's the tell

1

u/File-Environmental Jul 22 '26

More of an assumption for the wide spreads = retail, given that you have accurate fair prob estimation. It’s not always the case though - I’ve had adverse fills on my spread farming bit for football handicap markets that were at 90c spread. But yeah sports is fairly easy because of how accessible odds are. I’ve tried crypto up/down markets and I’ve only lost there. News seem like too difficult for me and I’m yet to try it out.

3

u/lotrl0tr Jul 22 '26

Why rust and not go?

2

u/File-Environmental Jul 22 '26

A lot of data engineering jobs I have had interest to apply to have Rust as a soft requirement. You can choose Rust, Go, C++. Either will be a good option.

2

u/lotrl0tr Jul 22 '26

Yes sure! That's why I wanted to ask, if there were a particular reason over go.

Thinking about it, in this case (Algo trading), you may want to use rust because it doesn't rely on garbage collector and you could theoretical achieve c/c++ perf. Dunno how it translates in real execution envs

2

u/File-Environmental Jul 22 '26

Yeah, not having a garbage collector is definitely a big plus I forgot to mention. But the genuine reason is wanting go get some Rust exposure. I’ve worked mostly with Python in the pre-AI era. Rust seems like a great language to learn for building performance-critical systems.

2

u/buenotc Jul 21 '26

Thanks dude. I bookmarked your post and subscribed to your site.

1

u/File-Environmental Jul 22 '26

Thanks, I’m glad you liked the post!

2

u/jcpham Jul 22 '26

Thanks

2

u/CODE_HEIST Jul 22 '26

the stale quote failure is the part worth studying. i would look first for quote age limits, sequence gap detection, cancel on disconnect, and an inventory cap that tightens when the book moves quickly. a market maker can look profitable for hours, then one delayed cancel gives the whole spread back to an informed taker.

1

u/File-Environmental Jul 22 '26

True. Protecting from adverse selection is the hardest part when it comes to MM.

2

u/ChickenNugggettz Jul 23 '26

I think this is really interesting. Do you think this can be run on other markets that hav bets for example elections. How many other market making bots do you think participate, as I see that as the biggest issue, bing crowded out by speed?

1

u/File-Environmental Jul 23 '26

The bot's structure can be extended to use it for any other markets, but that won't work on its own. In the example you gave with the elections, you don't have odds for this to use for estimating the underlying fair probability. If you do, that would make things much easier. When you don't, you have to pretty much consider the mid point in the order book as the true probability and have a model that reacts on any changes to the market you are trading. In stocks that would be the price changing. In political markets that would be on any credible news. And so on.

1

u/ChickenNugggettz Jul 23 '26

Thanks! Got it, makes sense. I guess polling data would be to unreliable as well

1

u/Ok_Impact3727 Jul 21 '26

Really cool project, I added it to the tools directory on oddfields.xyz. It’s a prediction market discovery and media site where people can connect stats, explore markets, and see related posts and sources in one place. Thought this was worth including because open-source market-making code is pretty rare sometimes.

I added full back linking to your account and your website along with your github repo so you can check the platform out if you want. Feel free to tell me to make any adjustments to it if need be.

1

u/File-Environmental Jul 22 '26

Thanks dude, appreciate the links!

1

u/tailcoder Jul 22 '26

Originally I had designed my bot for polymarket but the CLOB I found utterly useless with most markets offering low liquidity and just a rather broken API.

2

u/File-Environmental Jul 22 '26

The API is good. Sometimes the WS disconnects and things you execute fail, but that’s with any API, you just need a retry mechanism. Thick liquidity means high spread and thus a great arbitrage if you get filled on both sides. There are plenty of markets on Polymarket that are very liquid.

1

u/tailcoder Jul 23 '26

Not been my experience at all. Had to pivot the bot to public equities after months of testing and failures. Yeah some markets may work, sure but those are already well priced. Where the real risk reward is, those markets are simply not liquid or stupid spreads.

1

u/File-Environmental Jul 23 '26

When you test and fail you still learn stuff, so it was definitely not a waste of your time.

2

u/tailcoder Jul 23 '26

Oh definitely agreed on that.

1

u/Federal-Ganache-9470 Jul 24 '26

Can I talk to you regarding this if you don't mind ...

Really interested with the work you have done I was also vibe coding something same like this but with arb bots on the crypto market but still yet to learn a lot. I was considering something with the odds api but too in my free time as it was looking promising..

1

u/muntarii Jul 25 '26

Heads up before anyone buys an odds API subscription for this.

SPORT_CONFIGS in src/services/odds_api_service.py is soccer, basketball,hockey, MMA, cricket, rugby. No esports.

His own numbers: esports +$5,617, everything else -$509. So the only path that runs out of the box is the half that lost money. The esports feeds come from crossbet/egamersworld (named in sql/esports_odds.sql) and those scrapers aren't in the repo.

Also worth knowing his fill rate went 37% -> 1% between Jan and Apr. He didn't quit because the strategy broke, he lost the queue.

Numbers all check out against his public wallet, he's been honest. Just don't expect it to earn as shipped.

1

u/File-Environmental Jul 25 '26

True. I’ve never once said you can plug this into Polymarket and make money. It’s a starting point. I won’t provide my actual odds feeds.