1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Superfast primitives and data structures for high frequency trading.
//!
//! # [`Dec`], the number
//!
//! A fixed-scale decimal backed by an `i128` carrying [`Dec::SCALE`] decimal
//! places. Arithmetic is exact within a finite range of roughly +/-1.7e20;
//! anything that leaves that range becomes [`Dec::NAN`], which propagates
//! through every subsequent operation so the fault reaches the boundary where
//! [`Dec::is_finite`] is checked.
//!
//! ```
//! use troy::{Dec, dec};
//!
//! let notional = dec!(104_237.25) * dec!(0.00135);
//! assert_eq!(notional, dec!(140.72028750));
//! assert!(notional.is_finite());
//!
//! // overflow poisons rather than clamping or panicking
//! assert!((Dec::MAX + Dec::ONE).is_nan());
//! ```
//!
//! # [`OrderBook`], the structure
//!
//! A level 2 book built on [`Dec`]. Each side keeps its levels best first, so
//! the best price, the n-th level and the depth cut are index arithmetic
//! rather than searches, and a level enters only if [`PriceAmount::is_valid`]
//! accepts it — a non-finite price would sort against every other level, and a
//! non-finite amount would carry into every statistic taken over the side.
//!
//! ```
//! use troy::{OrderBook, dec};
//!
//! let mut book = OrderBook::new(Some(10));
//! book.bids.set_price_amount(dec!(104_237.25), dec!(3));
//! book.asks.set_price_amount(dec!(104_237.30), dec!(1));
//!
//! assert_eq!(book.mid_price(), Some(dec!(104_237.275)));
//! assert_eq!(book.spread(), Some(dec!(0.05)));
//! ```
//!
//! See the [`design`] module for the reasoning behind the representation, the
//! NaN state, and the ordering.
pub use *;
pub use *;
/// How `Dec` is represented, what the NaN state means, and the rules every
/// operation follows.
/// How `Dec` is laid out in memory, and how that compares with other decimals.
/// Release notes, one section per tagged release.