pit

A tiny stock exchange that runs in your browser. Three market-making bots, a crowd of noise traders, and every so often someone who knows something. You have a desk too.

source

book click a price to rest an order

market mid fair value informed flow

the desks

deskposvolumep&ltrend

your desk

tape

    loading the engine...

    bot lab write a desk in javascript. it trades for real, against everyone above.

    Not a coder? Pick a preset, press hire, and watch the "your bot" row in the desks table. The presets are commented line by line, so change one number at a time and see what happens.

    each season is 100,000 ticks, headless, about a second. the live market keeps running.

    Your code runs once per tick through the same matching engine as every other desk, and shows up as "your bot" in the table with its own p&l. Caps: 6 actions per tick, 200 lots per order, and an exception gets the bot fired on the spot. The presets are starting points, and none of them wins as written: try to beat mm-wary over a long stretch, and mind the shaded episodes. The code stays in your browser and survives reloads.

    how to play

    Everything runs in your tab. The seed box picks the run: the same seed always produces the same market, tick for tick, so if something interesting happens, the share button copies a link that replays it exactly. Pause freezes time (space works too), and speed is how many simulation ticks pass per animation frame.

    To trade, set a quantity on your desk, then click a price in the book: the green side rests a buy limit at that price, the red side rests a sell. Your size shows next to the level in amber, like (10). The market buttons cross the spread immediately at the best available prices, join bid and join ask rest a limit at the touch without any aiming, and flatten markets out of your whole position in one click. Open orders sit under your desk with an x to cancel, fills print on the tape tagged you, and the amber squares on the chart are your trades. P&L is marked to the mid, so it moves while you hold.

    Three things worth trying. First, be a market maker: in a calm stretch, rest a buy a couple of ticks below the mid and a sell a couple above, and collect the spread as the crowd trades through you. Second, trade an episode: when the chart shades, the tape will start running one color, so take that side with a market order and flatten when the shading stops. Third, leave your maker quotes out during an episode on purpose, and watch what getting picked off costs. That last one is the reason mm-wary exists.

    Two more things the floor will do to you. If the price moves violently enough, the circuit breaker halts trading, purges every resting order (yours included), and freezes the tape while fair value keeps drifting underneath; the reopen gap is where fortunes change hands, so mind it. And the "today's market" button loads one shared seed per calendar day, the same market for everyone on earth, if you want something to compare runs on.

    The view button on the market panel swaps the price chart for a book heatmap: time runs left to right, price top to bottom, and every resting level glows by its size, so you can watch liquidity pull away before a move and pile back in after. The volatility and informed flow dials in settings change the weather; everything was tuned at 1x, and turning them up is for watching the desks suffer on purpose.

    When clicking gets old, scroll down to the bot lab and put your strategy in code. Your bot becomes a real desk on this floor, and the only real question in this whole toy is whether it can out-trade mm-wary. "Run a season" backtests your code against 100,000 ticks of a fresh copy of the current seed and hands you a report card with an equity curve, plus a run of the same market without you, so you can see what your presence did. "Latency ladder" runs the same season with your bot 0, 2, 5, 10, and 25 ticks behind the market, which is the honest way to find out what speed is worth to you. "Seed sweep" runs eight different markets, because one seed can flatter anyone. And "share bot" copies a link that carries your code and seed, so someone else can rerun your exact season.

    If your first market order shows a small loss right away, that is not a bug. You paid the spread, which is the thing everyone else here is fighting over.

    A few things for comfort, all in settings. The theme switches to a light page, and colors swaps green and red for blue and orange if you have trouble telling them apart (buys also point up and sells point down on the tape and the chart, so the side never depends on color alone). Every control works from the keyboard, including the book: tab to a price and press enter to rest an order there. Hover or focus almost anything for an explanation, and the tour button walks the screen in a minute.

    what am I looking at?

    This is a working limit order book. The matching engine is written in Rust, compiled to WebAssembly, and runs entirely in your browser tab: price-time priority, partial fills, cancels, self-match prevention, the works. Every order you see placed or filled went through it.

    The price is anchored to a hidden fair value that follows a random walk. Twenty noise traders push orders at the book and lean gently toward fair value, which is what keeps price and value tethered. Three market makers quote both sides and try to earn the spread. mm-fixed quotes a constant spread around the mid and nothing else. mm-skew shifts its quotes against its inventory so it never sits on a big position. mm-wary does that too, and also watches order flow: when the flow turns one-sided it widens, and past a threshold it pulls its quotes and walks away.

    Every so often the chart shades: an informed trader has shown up who can see where fair value is going, and leans on the market until the move is done. This is the interesting part. Watch the desks table during a shaded stretch: the informed trader gets paid, and whoever was quoting tight spreads takes the other side of a trade they would not have chosen. Over a long session mm-fixed bleeds, mm-skew grinds out a little, and mm-wary makes about the same as mm-skew on a quarter of the volume, which means it earns several times more on every lot it touches. That is adverse selection, and nobody scripted it: it falls out of the simulation.

    You have a desk too. Click a side of the book to rest a limit order at that price, or hit the market buttons. One honest way to make money: when an episode starts, figure out its direction from the tape and trade with it before the crowd catches on. Another: quote both sides in a calm stretch and earn the spread like the makers do, then get out of the way when the shading starts. Your fills print on the tape with a marker.

    What this toy leaves out, so you don't have to wonder: latency for the built-in desks (they all see the book at the same instant; only your bot can be made slow), fees and rebates, more than one instrument, real order-to-trade ratios, and any claim that the flow model matches real markets. The matching itself is exact. Runs are deterministic: the same seed always produces the same market, tick for tick.

    Numbers are in dollars with a one-cent tick; sizes are lots. Source, tests, and native benchmarks: github.com/prathammukewar/pit.