Skip to main content

Crate atomr_money

Crate atomr_money 

Source
Expand description

§atomr-money

Exact-decimal monetary primitives for the atomr substrate.

Financial consumers (NAV/GL, OMS fills, fees, PnL/Greeks) need exact money arithmetic — f64 money is a regulatory and P&L-correctness defect. This crate provides a Money type over rust_decimal::Decimal (128-bit) behind a domain-safe API:

  • No defaulted f64 constructor. Lossy f64 ingestion exists only behind the off-by-default f64-lossy feature.
  • String (de)serialization, never float. Money/Price/Qty serialize their amount as a decimal string so nothing is lost in transit or at rest.
  • Checked arithmetic. Currency mismatch and overflow return MoneyError — never a panic or silent truncation.
use atomr_money::{Money, Currency};

let a = Money::from_str_amount("10.25", Currency::USD).unwrap();
let b = Money::from_minor(75, Currency::USD); // 0.75
assert_eq!(a.checked_add(&b).unwrap().to_minor(), 1100);

Structs§

Currency
A currency identified by its ISO 4217 alphabetic code plus the number of minor units (decimal places) it conventionally uses.
Decimal
Re-export of the backing decimal type so consumers can construct exact amounts without taking a direct rust_decimal dependency. Decimal represents a 128 bit representation of a fixed-precision decimal number. The finite set of values of type Decimal are of the form m / 10e, where m is an integer such that -296 < m < 296, and e is an integer between 0 and 28 inclusive.
Money
An exact monetary amount in a specific Currency.
Price
An instrument price. Serializes as a decimal string (never a float).
Qty
An order/position quantity. Serializes as a decimal string (never a float).

Enums§

MoneyError
Failures from Money operations. Arithmetic is always checked: currency mismatch and overflow are errors, never panics or silent truncation.
RoundingMode
Rounding mode for Money::round. Maps onto rust_decimal’s strategies.