Skip to content

Design decisions

Why the library's core types are built the way they are.

Why EAV?

The trading platform's domain has many "kinds of things" (orders, positions, scenarios, contracts, accounts, ...). A traditional ORM would model each as a separate class. The EAV model instead:

  • Unifies the access pattern: every "thing" is an entity, looked up by name.
  • Allows dynamic schemas: new attributes can be added without changing the class hierarchy.
  • Enables attribute-level caching: the registry caches per-attribute, per-entity values; if a last-trade value hasn't changed, downstream consumers don't recompute.
  • Decouples computation from declaration: a value provider can be a static config today and a market data feed tomorrow, with no change to the entity declaration.

The cost is that the CLR can't statically enforce that "an order has a quantity attribute" — that's a runtime check. We accept this trade-off for the flexibility.

The EAV types: Core EAV.

Why IObservable<T>?

The .NET reactive extensions (System.Reactive) are the idiomatic way to express asynchronous streams. Every consumer of streaming data in the platform already uses IObservable<T> — the adapters integrate without glue code.

For more complex stream combinators (filter, merge, throttle), use System.Reactive:

var fastTrades = observable
    .Where(t => t.Symbol == "BTCUSDT")
    .Throttle(TimeSpan.FromMilliseconds(100))
    .Select(t => t.Price);

The adapters: Observables.

Why not decimal?

System.Decimal is the obvious choice for financial math, but it has limitations:

Concern decimal DecimalAmount
Precision fixed 28 digits arbitrary (N field)
Cross-language .NET only serializes via FlatBuffers (C# / Python / TypeScript)
Equality at different precisions 1.0m != 1.00m (false) 1.0 != 1.00 (true) — precision is part of the value
Sub-millisecond conversions implicit scale-of-10 math explicit N carries the scale
Memory 16 bytes 16 bytes (3 fields, but smaller N is a byte)

DecimalAmount is the type the trading platform uses for prices, quantities, fees, P&L — anywhere precision matters. The decimal type is only used in legacy API surfaces.

The type: DecimalAmount.