Crate finmoney

Crate finmoney 

Source
Expand description

§Finmoney

A precise, panic-free money library for Rust. It provides safe monetary arithmetic, currency-aware values, configurable rounding strategies, and exchange-grade tick handling. Designed for trading systems, bots, and financial apps where correctness and determinism matter.

§Features

  • Precise arithmetic: Built on rust_decimal for exact decimal calculations
  • Currency safety: Prevents mixing different currencies in operations
  • Configurable rounding: Multiple rounding strategies for different use cases
  • Tick handling: Exchange-grade price/quantity rounding to valid tick sizes
  • Zero panics: All operations return Result types for error handling
  • Serde support: Optional serialization/deserialization (feature-gated)

§Quick Start

use finmoney::{FinMoney, FinMoneyCurrency, FinMoneyRoundingStrategy};
use rust_decimal_macros::dec;

// Create a currency
let usd = FinMoneyCurrency::new(1, "USD".to_string(), Some("US Dollar".to_string()), 2)?;

// Create money values
let price = FinMoney::new(dec!(10.50), usd);
let quantity = FinMoney::new(dec!(3), usd);

// Perform arithmetic
let total = (price + quantity)?;
println!("{}", total); // 13.50 USD

// Round to tick size
let rounded = price.to_tick_nearest(dec!(0.25))?;

Re-exports§

pub use currency::FinMoneyCurrency;
pub use error::FinMoneyError;
pub use money::FinMoney;
pub use rounding::FinMoneyRoundingStrategy;

Modules§

currency
Currency representation and management.
error
Error types for the finmoney library.
money
Core FinMoney type and operations.
rounding
Rounding strategies for monetary calculations.

Macros§

dec
Transform a literal number directly to a Decimal at compile time.

Structs§

Decimal
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.