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§
Sourcefn execute_match(
&self,
lp_program: &[u8; 32],
lp_context: &[u8; 32],
lp_account_id: u64,
oracle_price: u64,
size: i128,
) -> Result<TradeExecution>
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 IDlp_context- The LP’s matching engine context accountlp_account_id- Unique ID of the LP account (never recycled)oracle_price- Current oracle price for referencesize- Requested position size (positive = long, negative = short)
§Returns
Ok(TradeExecution)with actual executed price and sizeErr(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.