ClearingHouse. The ClearingHouse is the authoritative source for all account management, position tracking, and risk calculations. Every action that affects a user’s position or risk profile must pass through it.
- Pre-Flight Margin Check: Before a new order is accepted and placed on the order book, it undergoes a critical pre-flight margin check. The
ClearingHousesimulates the impact of the order on the user’s account to verify that sufficient Initial Margin is available. This proactive check is a crucial feature that ensures system solvency by preventing users from opening positions they cannot collateralize. - Trade Reporting and Position Updates: When the matching engine successfully executes a trade, it immediately calls the
report_tradefunction within theClearingHouse. This function updates the core parameters for both the maker and taker positions involved in the trade, including:- Position Size: Correctly adjusted for increasing, decreasing, or flipping a position’s direction.
- Entry Price: The volume-weighted average entry price of the position is recalculated.
- Mark Price Updates: The
ClearingHouseconstantly receives updated Mark Prices from theMarkPriceCalculator. This ensures that all margin calculations are based on the most current and fair valuation of the contract. - Liquidation Engine Interaction: If an account’s equity falls below its Maintenance Margin requirement, the
LiquidationEnginetakes control. Its first and most critical action is to send aCancelAllOrderscommand to every matching engine where the user has open orders. This immediately neutralizes the risk of the user increasing their position size during a liquidation event. Following the cancellation, the engine submitsreduce-onlymarket orders to the order book to systematically close the distressed position.