Live Demo: Engine

A simulated trading day of about four million stock trades runs through the Precomputing Engine, right here in your browser. The Engine turns the trades into 1-second, 1-minute and 1-hour candles and a quote board, and writes them to its SQLite file five times a second. The chart is drawn from that file with SQL, as it is written. Pull the plug on the Engine whenever you like: the candles come back the same.

Simulated trades, real Engine. The market is a fixed script with invented symbols and prices. The Engine is the real Go program, compiled to WebAssembly, writing into SQLite’s own WebAssembly build.

How to Run It

  1. Press Play. Eight symbols start trading at the 09:30 open, New York time. The day passes in about a minute.
  2. Pull the plug. The Engine is thrown away in the middle of writing a checkpoint, with everything in its memory. A fresh copy opens the file and the feed resends from where the file stands.
  3. Run the race. Pause, then race the Engine against the same policy compiled to SQLite triggers, and compare the two files value by value.
  4. Review the results. The day finishes at full speed and every closed candle is checked against a recount of every trade. Then ask the file in SQL.

On a wide screen the demo can use the whole window: open it full screen.

The Controls

Control What it does
Play, Pause, Resume Starts the day, pauses it and carries on. An uninterrupted day takes about a minute
Stop Ends the day and goes back to the open
Review the results Finishes the day at full speed, then checks every closed candle and the quote board
Symbol Chooses the symbol the chart shows. A row of the quote board does the same
1 s, 1 min, 1 h Shows the last five minutes second by second, or the whole day minute by minute or hour by hour
Up 5%, Down 5% Named for the chosen symbol, as in SIM4 up 5%. Moves its price at once, so the Engine has a price jump to catch
Pull the plug Throws the Engine away in the middle of writing its file. At 13:15 the demo does this once by itself
Run the race While the day is paused: the first 200,332 trades (200,000 rounded up to a whole second) through a fresh Engine and through the compiled triggers, then every value of the two files compared
Run Runs your SQL against the file while the day is paused or finished

The Trading Day

Eight invented symbols, SIM1 to SIM8, trade on 28 September 2026 from 09:30 to 16:00 New York time. Trading is busy at the open and the close and calm at lunch, from about 40 trades a second for the busiest symbol down to 7 for the quietest. Three things happen on schedule:

  • 11:02:17. News lifts SIM4 by 8% in one trade.
  • 12:00. SIM8 is halted for ten minutes and reopens 3.5% lower.
  • 14:31:05. SIM6 drops 6%, and the market stays busier for a while.

The Policy

stream trades {
  key    symbol text
  value  price real
  value  size  integer
  derive notional = price * size

  raw     keep 5m                     # every trade stays whole for five minutes
  rollup  1s keep 1h                  # 1-second candles for an hour
  rollup  1m keep 90d                 # 1-minute candles for 90 days
  rollup  1h keep forever             # hourly candles for good

  anomalies price log change z > 6 memory 500 warmup 200 keep 5 per 1m
}

precompute last_price   = last(trades.price) by symbol
precompute day_open     = first(trades.price) by symbol per day
precompute day_high     = max(trades.price) by symbol per day
precompute day_low      = min(trades.price) by symbol per day
precompute day_volume   = sum(trades.size) by symbol per day
precompute day_turnover = sum(trades.notional) by symbol per day
precompute day_trades   = count(trades) by symbol per day
precompute trades_total = count(trades)

A candle is a window summary. Open, high, low and close are the first, the largest, the smallest and the last price in the window. Volume is the sum of sizes, and VWAP is the sum of price times size divided by volume. The anomaly rule judges each trade by its step from the previous trade of the same symbol, so a jump is one unusual trade and the trades after it are judged from the new price.

What the Numbers Mean

  • Trades a second, now: trades taken in per second of real time, at the demo’s playback speed. It follows the market, busy at the open and calm at lunch.
  • Of the time the Engine is busy: the share of real time the Engine spends taking in trades and writing checkpoints. The rest is idle.
  • Trades a second at full speed on this device: every trade so far divided by the time the Engine spent on them, so it shows how fast the Engine would go flat out. It depends on your device.
  • Trades in memory, not yet in the file: everything since the last checkpoint. These are what a pulled plug throws away, and what the feed resends.
  • The Engine’s file: the SQLite file the Engine writes, in pages in use.

Things to Try

  1. Let the day finish untouched. Press Play and wait, or Review the results at once. All 4,048,210 trades go in, and all 27,150 candles and the quote board match the recount.
  2. Pull the plug at a busy moment. Around the open or just after 14:31, the Engine holds the most trades in memory. The table under Pulling the plug shows how many were lost from memory, how many rows of the half-written checkpoint were rolled back, how many trades the feed resent and how long the Engine took to come back. The candles are checked right after.
  3. Pull it again and again. Every pull is checked. The day still ends with every closed candle equal to the recount.
  4. Move a price. Pick a symbol, press its up 5% button, and watch Price jumps. The trade is kept whole with its z-score, and the trades after it are judged from the new price.
  5. Run the race. Pause during the day and press Run the race. Both runtimes take turns on the same thread in equal slices of time, so the bars show their speeds fairly. In our tests in Chromium the Engine was 12 to 15 times faster, and the two files were identical.
  6. Ask the file. Try “SIM4 around its jump” or “Busiest minutes”. Every candle length is in trades_win, one row per window, symbol and length.

If It Does Not Start

The demo works in any current Chrome, Edge, Firefox or Safari, on a computer or a phone, with JavaScript switched on. It needs WebAssembly, which all of them support. It downloads SQLite (1.5 MB, 577 KB compressed) and the Engine (5.0 MB, 1.3 MB compressed) from this site. If the demo says it could not start, try another browser, or allow scripts on this page if an extension blocks them.

In testing no check has failed. If one ever does, the results say so in red, and the project would be glad to hear about it through the contact page.

What Is Real Here

Real:

  • The Engine: the same Go code as the command-line tool, compiled to WebAssembly.
  • SQLite 3.53.4, SQLite’s own WebAssembly build, and every byte of the Engine’s file.
  • The pulled plug. The Engine really is thrown away mid-write; SQLite really rolls the half-written checkpoint back.
  • The race and the checks: separate code recounts the candles straight from the trades as they were sent.

Simulated:

  • The market, its symbols, prices and news. The day follows a fixed script, so a run left alone ends with the published numbers.
  • Time: six and a half hours pass in about a minute.

The native Engine runs the same day on a server at 258,000 to 337,000 trades a second in our runs, and survives 100 kills: see the Platform page. The market data case study follows the day.