Spaces:
Sleeping
Sleeping
| class ArbitrageAgent: | |
| """ | |
| Arbitrage Agent (Rule-Based). | |
| Monitors Perp vs Spot prices. | |
| """ | |
| def __init__(self, threshold=0.005): | |
| self.threshold = threshold | |
| def analyze(self, spot_price, perp_price, funding_rate): | |
| """ | |
| Returns Action: | |
| 0: Do Nothing | |
| 1: Long Spot / Short Perp (Basis > Thresh) | |
| 2: Short Spot / Long Perp (Basis < -Thresh) | |
| """ | |
| basis = (perp_price - spot_price) / spot_price | |
| # Funding Arbitrage | |
| # If funding positive -> Shorts pay Longs. We want to be Short Perp. | |
| # So we Long Spot, Short Perp. | |
| if basis > self.threshold: | |
| print(f"Arb Opportunity: Basis {basis:.4f} > {self.threshold}. Action: Long Spot / Short Perp") | |
| return 1 # Cash and Carry | |
| if basis < -self.threshold: | |
| print(f"Arb Opportunity: Basis {basis:.4f} < -{self.threshold}. Action: Short Spot / Long Perp") | |
| return 2 # Reverse Carry? | |
| return 0 | |