Skip to main content Crate openpx Copy item path Source error events exchange models timing Comprehensive timing instrumentation for HFT-level latency tracking. utils websocket define_exchange_error Generates a per-exchange error enum with the five variants every exchange
shares (Http, Api, RateLimited, AuthRequired, MarketNotFound),
plus any exchange-specific variants passed in the body. timed Zero-cost timing macro. Expands inline at compile time. ActivityFill ActivityTrade AtomicWebSocketState Lock-free atomic wrapper for WebSocketState.
Enables O(1) reads without acquiring any async lock. Candlestick OHLCV candlestick, normalized across all exchanges.
Prices are decimals (0.0 to 1.0). Timestamp is the period START (not end).
Serialized over the wire as RFC3339 (DateTime) for API consistency. CategoryRateLimiter Holds one RateLimiter per endpoint category for per-category rate limiting.
Indexed by RateLimitCategory discriminant for O(1) lookup. ConcurrentRateLimiter A concurrent rate limiter that enforces a global rate limit across multiple
concurrent streams. Uses a semaphore for concurrency control and an atomic
timestamp to ensure min_interval between ANY two requests globally.
Lock-free: uses AtomicU64 CAS loop instead of a mutex for the timestamp. CryptoPrice CryptoPriceWebSocket Streams real-time crypto prices from a WebSocket feed. EndpointRateLimit Rate limit for a single endpoint category. EventAlias EventAliasOwned ExchangeConfig ExchangeInfo ExchangeManifest Complete auditable manifest for an exchange.
When opened, shows SOURCE and TRANSFORMATION side-by-side. FetchMarketsParams FetchOrdersParams FetchResult Result of a checkpointed fetch operation. FetchUserActivityParams FieldMapping Mapping from raw exchange JSON field to unified field. Fill A single fill (trade execution) from a user’s order. FixedPrice Fixed-point price representation. 1 tick = 0.0001 (scale factor 10,000).
Eliminates f64 comparison issues (no PRICE_EPSILON), enables Ord (no NaN),
and uses integer arithmetic (1-5ns vs 20-100ns for f64 ops). Kalshi KalshiConfig KalshiCredentials Market Unified prediction market model. MarketTrade Normalized public market trade, suitable for “tape” UIs. Opinion OpinionConfig OpinionCredentials Order Orderbook OrderbookHistoryRequest OrderbookRequest Request for fetching an L2 orderbook. OrderbookSnapshot A point-in-time L2 orderbook snapshot, used for historical orderbook data. OutcomeToken PaginationConfig Polymarket PolymarketConfig PolymarketCredentials Position PriceHistoryRequest Request for fetching price history / candlestick data. PriceLevel PriceLevelChange A single price level change. Absolute replacement semantics:
size > 0 = set level to this size, size == 0 = remove level. PricePoint PublicTrade RateLimitConfig Per-category rate limiting configuration for an exchange.
Categories not listed in limits inherit from default_rps/default_burst. RateLimiter RestPriceLevel SportResult Real-time sports score/state from the Polymarket Sports WebSocket.
Serializes as snake_case for end-users; aliases accept the upstream camelCase. SportsWebSocket Streams real-time sports scores from the Polymarket Sports WebSocket. TimingGuard A guard that automatically records timing when dropped.
Useful for measuring the total duration of a scope. TradesRequest Request for fetching recent public trades (“tape”) for a market outcome. WsMessage Envelope wrapping every WebSocket stream item for HFT feed-latency measurement. ActivityEvent CryptoPriceSource ExchangeError ExchangeInner Enum dispatch over all supported exchanges.
Direct match dispatch eliminates vtable indirection and allows the compiler to
monomorphize and inline each exchange method — no heap-allocated Pin<Box<dyn Future>>. LiquidityRole MarketStatus Normalized market status across all exchanges. MarketStatusFilter Filter for market status in fetch queries. MarketType Market type classification. NetworkError OpenPxError OrderSide OrderStatus OrderType Order time-in-force / execution type. OrderbookUpdate Emitted by exchange WS implementations through OrderbookStream. PaginationStyle PriceHistoryInterval PriceLevelSide Bid or ask side. Serializes as “bid”/“ask” on the wire. RateLimitCategory Endpoint category for per-endpoint rate limiting.
Each exchange maps these to its actual documented API rate limits. SigningError Transform Transformation to apply when mapping a field. WebSocketError WebSocketInner Enum dispatch over exchange-specific WebSocket implementations.
Mirrors ExchangeInner but for real-time streaming connections. WebSocketState WS_CRYPTO_PING_INTERVAL WS_MAX_RECONNECT_ATTEMPTS WS_PING_INTERVAL Shared WebSocket reconnect/keepalive constants for all exchange implementations. WS_RECONNECT_BASE_DELAY WS_RECONNECT_MAX_DELAY Exchange MarketFetcher Trait for fetching raw market data from exchanges.
Used by the Bronze layer to collect complete API responses. OrderBookWebSocket aliases_for_event_id Expand canonical event_id into source aliases for exchange queries. canonical_event_id Resolve canonical event_id from source-native identifiers. clamp_price Clamp a price to be within valid bounds. coerce_to_datetime Convert a value to DateTime based on the transform type. coerce_to_float Safe type coercion to f64 with null fallback (never panic). coerce_to_int Safe type coercion to i64 with null fallback (never panic). coerce_to_string Safe type coercion to string. default_event_id Stable fallback when no explicit registry mapping exists. get_nested Extract value from JSON using a dot-notation path.
Supports array indexing with numeric indices (e.g., “events.0.id”). insert_ask Insert a price level into an ask-sorted (ascending) list.
Uses push + sort_unstable for prediction market books (typically < 100 levels). insert_bid Insert a price level into a bid-sorted (descending) list.
Uses push + sort_unstable for prediction market books (typically < 100 levels).
sort_unstable avoids the allocation of a merge-sort buffer and is faster
on small, nearly-sorted arrays than Vec::insert’s O(n) memcpy shift. is_valid_price Check if a price is valid for the given tick size. mid_price Calculate mid price from best bid and ask. round_to_tick_size Round a price to the nearest valid tick increment. sort_asks Sort price levels in ascending order (lowest price first) – ask side ordering.
Uses integer comparison via FixedPrice::Ord (no partial_cmp/NaN handling). sort_bids Sort price levels in descending order (highest price first) – bid side ordering.
Uses integer comparison via FixedPrice::Ord (no partial_cmp/NaN handling). spread_bps Calculate spread in basis points. ActivityStream ChangeVec Stack-allocated change list. Kalshi = 1 change, Polymarket typically 1-3.
Falls back to heap only if > 4 changes in a single update (rare). CheckpointCallback Callback type for checkpoint operations.
Receives the batch of markets and the current cursor value. CryptoPriceStream OrderbookStream SportsStream