Orderbook

Core Functionality

The Bulk Exchange trading system is built around a central limit order book (CLOB) for each perpetual contract market. This design mirrors the high-performance order matching systems found on traditional centralized exchanges, ensuring efficient and fair trade execution based on price-time priority.

When a trader submits an order, it is sent to the appropriate matching engine. The engine's primary role is to match incoming orders against resting orders in the book.

Integration with the ClearingHouse

A key aspect of Bulk Exchange's architecture is the deep integration between the order book and the central 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.

  1. 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 ClearingHouse simulates 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.

  2. Trade Reporting and Position Updates: When the matching engine successfully executes a trade, it immediately calls the report_trade function within the ClearingHouse. 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.

Risk Management and Order Lifecycle

The order book is intrinsically linked to the platform's real-time risk management systems.

  • Mark Price Updates: The ClearingHouse constantly receives updated Mark Prices from the MarkPriceCalculator. 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 LiquidationEngine takes control. Its first and most critical action is to send a CancelAllOrders command 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 submits reduce-only market orders to the order book to systematically close the distressed position.

This robust design, with its clear separation of concerns between order matching and state management, ensures that the order book operates with high integrity and that all trades are fully collateralized and correctly reflected in user accounts.

Last updated