GBoarse
A stock market simulation.
Markets are one of the three things I keep coming back to. This is that interest turned into a simulation.
What it is
A full recreation of a stock market, built for a handful of humans and up to about fifty bots, with no compromises on feature fidelity.
Markets are one of the three things I keep coming back to. This is that interest turned into a simulation.
What "full" means
A central limit order book with price-time priority, partial fills and call auctions. Every order type: market, limit, stop, stop-limit, trailing stop, iceberg and OCO, across GTC, DAY, IOC and FOK.
Instruments are not just equities. Stocks with share classes, ETFs, bonds, options both American and European, futures, FX pairs and indices. Multiple currencies, each with its own central bank setting policy rates and minting or burning.
Corporate actions are modelled rather than hand-waved: dividends, splits, IPOs, offerings, buybacks, mergers and delistings. So are margin, short selling with borrow and locate, and settlement cycles at T+0, T+1 and T+2.
Underneath that is an economic simulation with sectors, company fundamentals, earnings measured against analyst consensus, and news carrying sentiment. Strategy bots ship built in, and there is an external bot API over WebSocket and REST for writing your own.
The two rules everything else follows from
Money is double-entry, in bigint. Every mutation is a balanced posting. Every asset total sums to zero, and no account goes negative except the central bank and the manipulation account. Any change that moves money needs a test asserting the books still balance. Floating point money and single-entry money both fail the same way, quietly and late.
The replayed core is deterministic. Seeded RNG only. No wall clock and no unseeded randomness anywhere in command or handler logic. IDs come from sequence state. Iteration is sorted, so nothing financial ever depends on map insertion order.
Determinism is what makes the rest of it debuggable. A market that cannot be replayed exactly is a market where "that shouldn't have happened" is unanswerable.
How it runs
The engine is a Fastify and WebSocket service with a single serialised sequencer: validate, apply in memory, journal in one database transaction, then publish. A projector turns events into read-model rows inside that same transaction.
State lives in memory. PostgreSQL is the durable log and the projection, not the working set.
The web app never touches PostgreSQL. Everything it shows comes through the engine's HTTP and WebSocket API, which means there is one place where market state is interpreted rather than two.
Modes
Each instrument runs in one of four modes. Study allows full admin manipulation. Basic and Standard sit in between. Production allows none at all.
The point is being able to teach with the same engine that runs clean, without maintaining a second dishonest copy of it for demonstrations.
Stack
pnpm and Turborepo, TypeScript in strict mode. Next.js for the web app, Fastify and WebSockets for the engine, PostgreSQL and Redis behind it. Shared UI is hand-built rather than pulled from a component library.
Status
In build. The engine, the ledger and the order book are working and under test.
Legal: Terms · Privacy notice · Processing agreement