File size: 1,788 Bytes
81146df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pytest
from src.strategies.arbitrage import CrossPlatformArbitrage, IntraMarketArbitrage

def test_cross_platform_arbitrage_profitable():
    scanner = CrossPlatformArbitrage(min_profit_threshold=0.01)
    
    # State where Arb exists (Polymarket cheaper than Kalshi)
    scanner.update_state('polymarket', '0x217...', bid=0.50, bid_size=1000, ask=0.52, ask_size=1000)
    scanner.update_state('kalshi', 'KXUS2024', bid=0.55, bid_size=1500, ask=0.57, ask_size=500)
    
    opps = scanner.scan_opportunities()
    
    assert len(opps) == 1
    opp = opps[0]
    
    assert opp.buy_platform == 'polymarket'
    assert opp.sell_platform == 'kalshi'
    assert opp.buy_price == 0.52
    assert opp.sell_price == 0.55
    assert opp.buy_size == 1000  # min of 1000 and 1500
    assert opp.expected_profit_margin > 0.01 # Expect profit > min threshold

def test_cross_platform_arbitrage_no_opportunity():
    scanner = CrossPlatformArbitrage(min_profit_threshold=0.01)
    
    # Efficient market state
    scanner.update_state('polymarket', '0x217...', bid=0.53, bid_size=1000, ask=0.54, ask_size=1000)
    scanner.update_state('kalshi', 'KXUS2024', bid=0.53, bid_size=1500, ask=0.54, ask_size=500)
    
    opps = scanner.scan_opportunities()
    assert len(opps) == 0

def test_intra_market_arbitrage():
    scanner = IntraMarketArbitrage(min_profit_threshold=0.01)
    
    # Parity violation: P(Yes) + P(No) = 0.45 + 0.45 = 0.90 < 1.0 (Margin = 0.10)
    margin = scanner.check_parity_violation(ask_yes=0.45, ask_no=0.45)
    
    assert margin is not None
    assert round(margin, 2) == 0.10
    
    # Efficient market: P(Yes) + P(No) = 0.52 + 0.52 = 1.04 > 1.0 (No Arb)
    margin_eff = scanner.check_parity_violation(ask_yes=0.52, ask_no=0.52)
    assert margin_eff is None