Module math

Module math 

Source
Expand description

Price and size calculation utilities

Functionsยง

calculate_slippage
Calculate maximum slippage for market order
decimal_to_token_units
Convert decimal to token units (6 decimal places)
is_valid_price
Check if price is within valid range [tick_size, 1-tick_size]
is_valid_price_fast
Check if price is within valid range (FAST VERSION)
mid_price
Calculate mid price (LEGACY - use fixed-point version when possible)
mid_price_fast
Calculate mid price (FAST VERSION)
notional
Calculate notional value (price * size) (LEGACY - use fixed-point version when possible)
notional_fast
Calculate notional value (price * size) (FAST VERSION)
round_to_tick
Round price to tick size (LEGACY - use fixed-point version when possible)
round_to_tick_fast
Round price to tick size (FAST VERSION)
spread_fast
Calculate spread in ticks (FAST VERSION)
spread_pct
Calculate spread as percentage (LEGACY - use fixed-point version when possible)
spread_pct_fast
Calculate spread as percentage (FAST VERSION)
token_units_to_decimal
Convert token units back to decimal