Arbitrage Detection Logic¶
Goal¶
Detect negative spread opportunities between Polymarket and Kalshi.
Strategy¶
- Input: Two
OrderBooksnapshots (Leg 1, Leg 2). - Logic:
- Best Bid Leg 1 vs Best Ask Leg 2.
- Best Bid Leg 2 vs Best Ask Leg 1.
- Calculate Spread %
- If Spread > Threshold (e.g., 0% or configured), return
Opportunity.
- Output:
Opportunitystruct containing:- Buy Leg (Market ID, Price, Size)
- Sell Leg (Market ID, Price, Size)
- Expected Profit
Implementation¶
- File:
src/execution/detector.rs - Function:
detect_arbitrage
TDD¶
- Test Case 1: No overlap (Spread < 0). Result: None.
- Test Case 2: Profitable overlap (Spread > 0). Result: Some(Opportunity).
- Test Case 3: Zero spread. Result: None.