Skip to content

v0.7.0

Latest

Choose a tag to compare

@joaquinbejar joaquinbejar released this 25 Feb 12:23
8821b28

PriceLevel v0.7.0

Breaking release — This version introduces significant API changes to improve type safety, correctness, and ergonomics for downstream consumers. See the Migration Guide in the crate docs for full details.

Breaking Changes

Execution Domain Rename (#17 / #8)

  • TransactionTrade
  • TransactionListTradeList
  • transaction_id field → trade_id
  • Parsing prefix Transaction:Trade:

Unified Identifier Type (#18 / #9)

  • Raw Uuid replaced with Id enum supporting UUID, ULID, and sequential (u64) formats.
  • UuidGenerator for deterministic trade ID generation.
  • Id::new(), Id::from_u64(), Id::sequential(), Id::from_uuid(), Id::from_ulid().

Domain Newtypes (#19 / #10)

  • u128 price → Price newtype (Price::new(), Price::as_u128())
  • u64 quantity → Quantity newtype (Quantity::new(), Quantity::as_u64())
  • u64 timestamp → TimestampMs newtype (TimestampMs::new(), TimestampMs::as_u64())
  • All support Display, FromStr, Serialize, Deserialize, from_f64(), to_f64_lossy().

Checked Arithmetic (#20 / #11)

  • PriceLevel::total_quantity()Result<u64, PriceLevelError>
  • MatchResult::executed_quantity()Result<u64, PriceLevelError>
  • MatchResult::executed_value()Result<u128, PriceLevelError>
  • MatchResult::average_price()Result<Option<f64>, PriceLevelError>
  • MatchResult::add_trade()Result<(), PriceLevelError>
  • PriceLevelStatistics::record_execution()Result<(), PriceLevelError>
  • No silent saturation or wrapping in financial-critical paths.

Panic-Free Library (#21 / #12)

  • Removed all .unwrap() / .expect() from production modules.
  • All fallible paths return Result with typed PriceLevelError variants.

Compiler Attributes (#22 / #13)

  • #[must_use] on all pure/computed public methods.
  • #[repr(u8)] on Side and TimeInForce enums.

Hot-Path Allocation Reduction (#23 / #14)

  • PriceLevel::iter_orders() now returns impl Iterator (was Vec).
  • New PriceLevel::snapshot_orders() for when a materialized Vec is needed.

Private Fields & Accessor Methods (#24 / #15)

  • Trade fields privatized → accessor methods (trade_id(), price(), quantity(), etc.)
  • MatchResult fields privatized → accessor methods (order_id(), trades(), remaining_quantity(), etc.)
  • TradeList fields privatized → as_vec(), into_vec(), add(), len(), is_empty()
  • PriceLevelSnapshot fields privatized → accessor methods
  • PriceLevelSnapshotPackage fields privatized → accessor methods (version(), snapshot(), checksum())

New Error Variants

  • PriceLevelError::InvalidOperation — checked arithmetic overflow, invalid state transitions
  • PriceLevelError::SerializationError — JSON/serde serialization failures
  • PriceLevelError::DeserializationError — JSON/serde deserialization failures
  • PriceLevelError::ChecksumMismatch — snapshot integrity validation failure

New Features

Snapshot Persistence & Recovery

  • PriceLevelSnapshotPackage with SHA-256 checksum protection.
  • PriceLevel::snapshot_to_json() / PriceLevel::from_snapshot_json() for full roundtrip.
  • PriceLevelSnapshotPackage::validate() for checksum verification.

Migration Documentation (#25)

  • Comprehensive migration guide added to crate-level docs.
  • Old → new API mapping tables with intra-doc links.
  • 3 runnable doctest examples (newtypes, checked arithmetic, snapshots).
  • Module-level rustdocs for execution, orders, and price_level modules.

Integration Examples (#31)

  • 6 new executable integration examples in examples/src/bin/:
    • integration_basic_lifecycle — add/update/cancel/match lifecycle
    • integration_trade_roundtrip — Trade/TradeList/MatchResult serialization
    • integration_newtypes_contract — Price/Quantity/TimestampMs/Id validation
    • integration_special_orders — Iceberg/Reserve/PostOnly/TrailingStop/Pegged/MarketToLimit
    • integration_snapshot_recovery — snapshot persistence, checksum, and corruption detection
    • integration_checked_arithmetic — checked arithmetic APIs and error propagation

Benchmark Coverage (#34)

  • 6 new benchmark modules in benches/price_level/:
    • snapshot_recovery — snapshot package creation, JSON roundtrip, checksum validation
    • checked_arithmetic — total_quantity, executed_quantity, executed_value, average_price
    • serialization — Trade/TradeList/MatchResult Display/FromStr and serde roundtrips
    • newtypes — Price/Quantity/TimestampMs/Id construction and parsing
    • special_orders — PostOnly, TrailingStop, Pegged, MarketToLimit matching
    • lifecycle — full add/update/cancel/match/stats cycle benchmarks

Infrastructure

  • Upgraded to Rust 2024 edition.
  • Version bumped to 0.7.0.
  • Workspace dependencies consolidated.

Migration Checklist

  1. Replace Transaction / TransactionList with Trade / TradeList.
  2. Replace raw Uuid with Id; use UuidGenerator for trade IDs.
  3. Wrap raw price/quantity/timestamp literals with Price::new(), Quantity::new(), TimestampMs::new().
  4. Replace direct field access on Trade, MatchResult, TradeList with accessor methods.
  5. Handle Result returns from total_quantity(), executed_quantity(), executed_value(), average_price(), and add_trade().
  6. Replace iter_orders() collecting into Vec with snapshot_orders() if needed.
  7. Update snapshot code to use PriceLevelSnapshotPackage for checksum validation.
  8. Address new #[must_use] warnings on query methods.