Skip to main content

MatchingEngine

Trait MatchingEngine 

Source
pub trait MatchingEngine {
    // Required method
    fn execute_match(
        &self,
        lp_program: &[u8; 32],
        lp_context: &[u8; 32],
        lp_account_id: u64,
        oracle_price: u64,
        size: i128,
    ) -> Result<TradeExecution>;
}
Expand description

Trait for pluggable matching engines

Implementers can provide custom order matching logic via CPI. The matching engine is responsible for validating and executing trades according to its own rules (CLOB, AMM, RFQ, etc).

Required Methods§

Source

fn execute_match( &self, lp_program: &[u8; 32], lp_context: &[u8; 32], lp_account_id: u64, oracle_price: u64, size: i128, ) -> Result<TradeExecution>

Execute a trade between LP and user

§Arguments
  • lp_program - The LP’s matching engine program ID
  • lp_context - The LP’s matching engine context account
  • lp_account_id - Unique ID of the LP account (never recycled)
  • oracle_price - Current oracle price for reference
  • size - Requested position size (positive = long, negative = short)
§Returns
  • Ok(TradeExecution) with actual executed price and size
  • Err(RiskError) if the trade is rejected
§Safety

The matching engine MUST verify user authorization before approving trades. The risk engine will check solvency after the trade executes.

Implementors§