Price Indices
Overview
To ensure a fair, stable, and manipulation-resistant trading environment, Bulk Exchange utilizes a sophisticated system of price indices. These indices are essential for all critical platform functions, from calculating PnL to triggering liquidations. The two primary price indices are the Oracle Price and the Mark Price.
Oracle Price
The Oracle Price serves as the system's link to the broader global market.
Purpose: Its primary role is to provide a reliable, external benchmark for the true underlying asset price. It is used as a key input for calculating the Mark Price and for determining the premium/discount component in the funding rate calculation.
Mechanism: The Oracle Price is sourced from a reliable external oracle provider (e.g., Pyth). This decouples the core price feed from Bulk Exchange's internal order book, making it highly resistant to local market manipulation.
Updates: The
ClearingHouse
receives Oracle Price updates via a dedicated channel, which in turn triggers a recalculation of the Mark Price.
Mark Price
The Mark Price is the most critical price index on Bulk Exchange, used as the basis for all margin and PnL calculations, as well as for triggering liquidations and Take Profit/Stop Loss orders. The system uses a robust model, inspired by Hyperliquid, that calculates the Mark Price as the median of three distinct components. This approach ensures the price is anchored to the global market while still being responsive to local conditions.
The MarkPriceCalculator
is the component responsible for this vital calculation.
Component 1: Adjusted Oracle Price
Purpose: To anchor the Mark Price to the true underlying asset price from a reliable external source.
Mechanic: This component starts with the external Oracle Price and adjusts it using a 150-second Exponential Moving Average (EMA) of the difference between the local order book's mid-price and the Oracle Price. This allows the Mark Price to slowly and smoothly account for any persistent premium or discount on Bulk Exchange without being swayed by temporary volatility.
Numerical Stability: The EMA calculation is performed on unscaled
f64
values to maintain precision and avoid potential errors from integer arithmetic on scaled prices.
Component 2: Local Order Book Median
Purpose: To reflect the immediate, actionable price on the exchange itself.
Mechanic: This component is the median of three values from the local order book: the current best bid, the best ask, and the last traded price. Using the median of these three values provides a more stable local price indicator than using the mid-price alone.
Component 3: Smoothed Local Price
Purpose: To provide a stabilizing factor and dampen noise from rapid, short-term price fluctuations on the local market.
Mechanic: This component is a 30-second EMA of the Local Order Book Median (Component 2). It acts as a slightly lagging, smoothed representation of the local market price.
Final Calculation and Data Handling
The calculate
function within the MarkPriceCalculator
computes these three components, sorts them, and selects the median value. The result is a scaled Decimal
that represents the final, robust Mark Price. The implementation includes sensible fallbacks, such as using the Smoothed Local Price (Component 3), to avoid using volatile data in the case of thin order books.
Whenever the MarkPriceCalculator
computes a new Mark Price, it is immediately sent back to the ClearingHouse
, ensuring the central risk engine always has the latest and most accurate price for all its calculations.
Last updated