Dharun Ashokkumar India

Open Clearing Engine

Rust · clearing infrastructure

An open-source, NSCCL-grade clearing and settlement engine written in Rust.

View source on GitHub

Stack: Rust, clearing house, settlement, novation, multilateral netting, SPAN margin, event sourcing, central counterparty, Apache-2.0

What it is

A clearing house sits between two sides of a trade and guarantees it settles. This engine takes executed trades and turns them into regulator-grade settlement obligations, through the same pipeline a real clearing corporation uses — novation, position keeping, multilateral netting, settlement — with a SPAN portfolio-risk engine sitting on top.

It isn't a toy. It's built for determinism, reproducibility, and scale. The embedded implementations run with zero infrastructure today; the production stack (Kafka/Redpanda, RocksDB, ClickHouse, k3s) plugs in behind the existing ports with no domain rewrite. The codebase is a Cargo workspace laid out hexagonally — ports and adapters — so the financial logic never depends on the plumbing.

The clearing cycle

  • Novation — the clearing house steps in as the counterparty to both sides, so neither side carries the other's default risk
  • Position keeping — net positions tracked per member, per instrument
  • Multilateral netting — collapse a mountain of obligations into the fewest possible settlements
  • SPAN margin — portfolio-level risk margin computed per member
  • Settlement obligations — a deterministic, replayable, regulator-grade output file

Why event sourcing

Every state change is an event. That means the whole settlement run can be replayed from the log and produce a byte-identical result — which is exactly the property a regulator or an auditor wants. It also makes the determinism tests possible: pin a golden obligation file, then prove the engine never drifts from it.

I wanted to understand how money actually settles, not just read about it. Building the cycle end to end — and forcing it to be deterministic — taught me more than any explanation could.

At a glance

LanguageRust
Tests~40, including replay end-to-end
API surfaceREST and WebSocket
LicenceApache-2.0

Scope

Iteration 1 is complete: foundation, ports, market data, the vertical slice, SPAN, API/CLI, dashboard, and a dev deployment — all green. The deferred scaling work is enumerated with its seam in the docs. This is research and learning infrastructure, not a live clearing corporation.