ConvexPi

Arena documentation

How the exchange works

The Arena is a real limit-order-book exchange with a matching engine, just like a stock or crypto exchange — only small enough to read in one sitting. This page explains exactly how your orders are matched, so nothing about your fills is a mystery.

1. The order book

Every tradable instrument has one order book: the list of all resting orders nobody has matched yet. Buy orders (bids) sit on one side, sell orders (asks, or offers) on the other, sorted by price.

Price
Size
100.30
4
resting sell orders
100.20
2
100.10
3
best ask
← spread: 100.10 − 100.00 = 0.10
100.00
5
best bid
99.90
2
99.80
6
resting buy orders

The highest bid (best bid) and lowest ask (best ask) are the touch. The gap between them is the spread. The book never “crosses” — if a buyer is ever willing to pay what a seller will accept, they trade immediately and the matched quantity leaves the book. Prices are stored as integer cents, not floats, so two orders at the same price are always exactly equal (a real exchange-engineering lesson hiding in plain sight).

2. Order types

  • Limit order— “buy up to 5 at 100.00 or better.” If part of it can't fill right now, the remainder rests in the book at your price and waits. This is how you provide liquidity.
  • Market order— “buy 5 right now, at whatever it costs.” It takes the best available prices until filled. This is how you take liquidity — fast, but you pay the spread and any slippage.
  • Cancel — pull one of your own resting orders out of the book.

Whoever was already resting in the book is the maker; whoever crosses the spread to hit them is the taker (the aggressor). Real exchanges price these differently; the Arena records which side you were on so you can study the difference.

3. Price-time priority

When an incoming order can match, the engine decides who it trades with using price-time priority — the worldwide standard:

  1. Price first. The best-priced resting order always trades first (highest bid for a seller, lowest ask for a buyer).
  2. Then time. Among orders at the same price, whoever got there first is filled first — a first-in, first-out queue.

That second rule is why queue position matters: post a limit order early and you sit at the front of your price level; arrive late and you wait behind everyone ahead of you.

4. Walking the book: a worked example

Suppose you send a market buy for 6 into the book above. The engine fills you against the asks, cheapest first, until your 6 is done:

market buy 6 →
  • fill 3 @ 100.10  (takes all of the best ask)
  • fill 2 @ 100.20  (next level)
  • fill 1 @ 100.30  (1 of the 4 resting here; 3 remain)
You bought 6 at an average of 100.18, not 100.10. That 0.08 above the best ask is slippage — the cost of demanding immediacy from a finite book.

The deeper the book, the less a large order moves the price. A thin book means the same order walks further up the ladder — this is market impact, and feeling it directly is the whole point of trading on a real book instead of a single price.

5. Discrete ticks and fair ordering

The Arena runs in discrete ticks. Within a tick, every agent submits its orders; the engine then shuffles them with a seeded random order and processes them one by one. The shuffle is deliberate fairness: no agent systematically gets to act first because of where it sits in a list. Given the same seed, a whole session replays identically — so results are reproducible and debuggable.

6. Where the prices come from

The same engine can be driven by three different sources of market reality:

Synthetic

A hidden “fundamental value” follows a jump-diffusion; informed and noise traders trade around it, manufacturing a living book. Fully controllable — great for scenarios like a vol shock or a liquidity pull.

Real price replay

Recorded OHLCV bars from Binance or Coinbase drive the price level, and the background agents build depth around those real prices. You trade against authentic price movement.

Real order-book replay new

Recorded L2 depth snapshots— the exchange's actual bids and asks — become the resting liquidity. Now a market order walks the real ladder and pays real slippage; a limit order queues against real depth. This is as close to a live exchange as a teaching simulator gets.

In every mode you are a marginal participant: your own orders genuinely affect the book, but the bulk of the liquidity is real or realistically modelled, so you can't single-handedly move the market unless it's thin.

7. What your agent sees each tick

Before you act, the engine hands your agent a snapshot of the market:

  • best bid / best ask and the last traded price
  • depth — several price levels of bids and asks, with sizes
  • • the recent trades from the previous tick (the tape)
  • • your own position, cash, and open orders

From that view your agent returns a list of orders. That's the entire contract — the rest is strategy.

8. Concepts you'll feel, not just read

Spread

Crossing it costs money; earning it is a strategy (market making).

Slippage & impact

Big orders into thin books move the price against you.

Queue position

Post early to get filled first at your price level.

Maker vs taker

Provide liquidity patiently, or pay to take it now.

Adverse selection

Your resting order fills exactly when the market moves against it.

Inventory risk

Holding a position exposes you to the next price move.

Now go trade on it

Reading about a matching engine only gets you so far. Write an agent, watch your orders hit the book, and see your fills land exactly where this page says they will.