Table of Contents

Class Level2OrderBookUpdater<TBook, A, L, S, D>

Namespace
Virtufin.Base.OrderBooks
Assembly
Virtufin.Base.dll

Applies Level-2 snapshots and diffs to an L2OrderBook<A, L> using the standard local-order-book-maintenance algorithm: bootstrap from a snapshot, then apply diffs whose first update id brackets the book's previous last update id. A zero size removes a level.

public sealed class Level2OrderBookUpdater<TBook, A, L, S, D> : IOrderBookUpdater<TBook, S, D> where TBook : IL2OrderBook<A, L>, IL2OrderBookWriter<A, L> where A : IFixedPointAmount where L : IFixedPointAmount where S : IL2OrderBookSnapshot<A, L> where D : IL2OrderBookDiff<A, L>

Type Parameters

TBook

Concrete book type.

A

Depth (size) amount type.

L

Level (price) amount type.

S

Snapshot data type.

D

Diff data type.

Inheritance
Level2OrderBookUpdater<TBook, A, L, S, D>
Implements
IOrderBookUpdater<TBook, S, D>
Inherited Members

Remarks

The single bracket check (FirstUpdateId > LastUpdateId + 1) is applied uniformly to every diff, not just the first after a snapshot; after a successful apply the book's LastUpdateId becomes that diff's final id, so the next diff's first id must equal LastUpdateId + 1 to pass the same check.

An exact replay of the most recently applied diff (same first and final id) re-applies its levels and reports Applied rather than Stale. Delivery is at-least-once and callers persist after applying, so without this a retried diff would be dismissed as stale and the update silently lost. Re-application is safe because a level is an absolute assignment and it also repairs a partial apply from a failed attempt.

Stateless: per-book replay and lifecycle state live on the book, so one updater instance can serve many books. The updater is not thread-safe; the caller owns serialisation per book.

Methods

ApplyDiff(TBook, D)

Apply one diff to book.

public OrderBookUpdateStatus ApplyDiff(TBook book, D diff)

Parameters

book TBook

Book to mutate.

diff D

Diff data.

Returns

OrderBookUpdateStatus

The outcome of the application.

ApplySnapshot(TBook, S)

Bootstrap (or re-bootstrap) book from a snapshot.

public void ApplySnapshot(TBook book, S snapshot)

Parameters

book TBook

Book to populate.

snapshot S

Snapshot data.