Skip to Content
raikiri

Architecture

The programs raikiri is made of, how they share data and what happens when one stops.

raikiri is a few programs on one machine. Gateways talk to the exchanges and write what they learn into shared memory. Everything else reads it from there.

ProgramJob
gatewaydholds one venue's connections for one market and publishes its prices
strategydruns strategies, checks every order, tracks orders and positions
admindlocal HTTP and WebSocket API behind the terminal
apidsigned API for programs
persisterd, candledcopy journals into PostgreSQL and keep one-minute candles

Why one process per venue

Exchanges fail on their own schedule. With a process each, a dropped socket, a rate-limit ban or a crash in one parser stops one market, and readers see that its heartbeat has gone quiet. You can also restart or upgrade one gateway without touching the rest. The price is memory: each gateway holds a 64 MiB segment.

Why shared memory

A strategy reads a quote in place, without a network hop or a message broker between it and the gateway. Quotes and books keep only the newest value, so a slow reader skips ahead instead of falling behind. Trades and order events go through a queue that tells a reader when it has missed something, because a missed fill matters. Benchmarks has the timings.

This also means strategies and gateways must run on the same machine. Programs elsewhere use the client API.

Prices are integers

A price is a count of the instrument's tick and a size is a count of its lot, both 64-bit integers from the venue's message to the database. A value that is not an exact multiple is refused, never rounded. Every record carries two times: ts_event, the venue's clock, and ts_init, when this machine received it.

When something stops

  • A gateway dies. strategyd sends it no new orders. When it returns, it reloads the venue's instruments and books.
  • strategyd restarts. It rebuilds open orders and positions from its journal, and waits for the venue to agree before it opens anything new. See Life of an order.
  • PostgreSQL is down. Trading does not depend on it.
  • Binaries from different releases are mixed. They refuse to share memory instead of misreading each other. Replace them all together.
Edit this page on GitHub

On this page