Skip to main content

Module utils

Module utils 

Source

Functions§

clamp_price
Clamp a price to be within valid bounds.
is_valid_price
Check if a price is valid for the given tick size.
mid_price
Calculate mid price from best bid and ask.
pick_active_and_next
Active market plus the next one queued behind it, sorted by ascending close time. Useful for zero-downtime rollover: subscribe to both, drop the front one when its close_time passes.
pick_active_market
Pick the currently-active market in a list — Active status with a future close time. When several qualify, returns the one with the soonest close_time (in a rolling series this is the next-to-resolve market — i.e. the one a trader should be subscribed to). Markets without a close_time are treated as still open (Polymarket events occasionally omit it).
round_to_tick_size
Round a price to the nearest valid tick increment.
spread_bps
Calculate spread in basis points.