Repository navigation
v0.15.0
orderbook-rs v0.15.0
The stop-protection release: elected trailing stops can be bounded by a per-book protection collar (#302). Without a collar, behaviour is unchanged from 0.14.0. It is a breaking release (new public fields, a new CancelReason variant, snapshot format 6); see the migration table in the "What's New in Version 0.15.0" section of src/lib.rs (docs.rs).
- Design:
doc/adr/0001-stop-protection-collar.md,doc/matching.md - Benchmarks:
BENCH.md(pending stops with a protection collar)
[0.15.0] - 2026-09-30
The stop-protection release. Elected trailing stops (#286) can be bounded
by a per-book protection collar (#302): with a collar configured, an
elected stop's child is an immediate-or-cancel limit order at the trailed
stop price minus (sell) or plus (buy) the collar, instead of an unpriced
market order. Without a collar, behaviour is unchanged from 0.14.0.
Breaking: new public fields on OrderBookSnapshotPackage,
ReplayBookConfig and OrderStatus::Triggered, a new
CancelReason::StopProtectionBand variant, and snapshot format 6.
Added
- Protection collar for elected stop orders (#302).
StopProtection
(try_new(collar),new(NonZeroU128),collar(),limit_price(side, stop),check_tick_size) andOrderBook::set_stop_protection/
stop_protection. With a collar, an elected trailing stop
(special_orders) executes as an immediate-or-cancel limit order at
stop - collar(sell) orstop + collar(buy),stopbeing its trailed
stop price at election and the collar an absolute offset in price units
(like CME protection points, except that the remainder is cancelled,
not rested: a stop whose band is exhausted leaves its position
unprotected); nothing rests. A remainder the collar cut (liquidity left
beyond the limit, including an empty band) endsCancelled { reason: StopProtectionBand }; one left because the side ran out within the band
keepsInsufficientLiquidity.OrderStatus::Triggeredrecords the
child'slimit_price.StopProtectionis re-exported from the prelude.
The collar must be a multiple of the
tick size (InvalidTickSize; a laterset_tick_sizedoes not
re-validate it) and cannot be zero (new
OrderBookError::InvalidStopProtection, reject codeOther(0): a
configuration error). A band that reaches or passes the representable
bound (sellcollar >= stop, buystop + collar >= u128::MAX) has the
bound,0/u128::MAX, as its limit. Unset (the default) keeps the 0.14.0 unpriced IOC
market child. The type is available withoutspecial_orders, so
snapshots and replay configurations are identical in every build.
ReplayBookConfig::with_stop_protectioncarries it into replay. The
pending_stops_hdrbench gains*_collar_*elect and cascade
scenarios;special_orders_demoshows a collar.
Changed (breaking)
- Snapshot format 6 (#302).
ORDERBOOK_SNAPSHOT_FORMAT_VERSIONis6
andOrderBookSnapshotPackage::validatereads2..=6. Packages carry
stop_protection: Option<StopProtection>(#[serde(default)]),
written bycreate_snapshot_packageand installed by
restore_from_snapshot_package(as captured, without the tick-size
check). The snapshot payload and its checksum are unchanged from
version 5; config fields are not checksummed, as before.- Migration: version-5 packages (0.14.0) keep verifying and restore with
no collar (covered by a verbatim 0.14.0 fixture); a package below
version 6 that carries a collar is rejected. A 0.14 reader rejects
every version-6 package ("Unsupported snapshot version") instead of
silently dropping the collar, so upgrade readers before writers. A
zero collar does not deserialize.
- Migration: version-5 packages (0.14.0) keep verifying and restore with
ReplayBookConfig::stop_protection(#302). New public field; code
building the struct with an exhaustive literal must set it (or use
..Default::default()).ReplayBookConfig::newleaves itNone.OrderBookSnapshotPackage::stop_protection(#302). New public
field; exhaustive literals must set it.CancelReason::StopProtectionBand(#302). New variant, appended
(bincode index 10, JSON"StopProtectionBand"); exhaustive matches need
the arm. The collared child's terminal reason when the collar cut its
sweep;InsufficientLiquidityotherwise.OrderStatus::Triggered::limit_price(#302). New field
(Option<u128>,#[serde(default)]): the child's collar limit,None
for a market child. 0.14 JSON decodes withNone; bincodeTriggered
payloads do not decode across 0.14 / 0.15. Patterns and literals naming
every field must add it.Displayappends, limit=<price>when set.
Nothing journaled or on the wire carriesOrderStatus(ExecReport
keeps status code 5).
Known limitations
- Stop protection collar (#302). A gap of more than one collar through
a stop's price always consumes the stop with zero fill
(StopProtectionBand), leaving the position unprotected. The collar
bounds each child, not the cascade: a ladder of stops spaced one collar
apart still walks the bookk × collarin one call (no cascade depth
limit or velocity pause). A sell collar that reaches or exceeds the stop
price (limit 0), or a buystop + collarthat reaches or exceeds
u128::MAX, does not protect that stop. Replay needs the
source book's collar, constant over the replayed range. A mismatch is
not anOutcomeMismatch, andsnapshots_matchcatches it only when it
changed an outcome (the snapshot does not carry the collar; with no
election in the range, or coinciding fills, the snapshots match while
future elections differ): compare the replayed book's
stop_protection()with the source book's (or the snapshot package's
stop_protection).