fix: spot-perp basis floating-point EPS, NORMAL regime fallback, realistic fee defaults

This commit is contained in:
ramseshk
2026-08-12 12:34:51 +08:00
parent 0446443d36
commit a5cf3fe583
2 changed files with 21 additions and 6 deletions
+8 -6
View File
@@ -30,6 +30,8 @@ import numpy as np
logger = logging.getLogger(__name__)
EPS = 1e-10
class SpotPerpBasisArb:
"""Delta-neutral spot-perpetual basis arbitrage.
@@ -47,13 +49,13 @@ class SpotPerpBasisArb:
def __init__(
self,
entry_threshold_bps: float = 3.0,
entry_threshold_bps: float = 5.0,
exit_threshold_bps: float = 1.0,
max_hold_hours: float = 48.0,
size_usd: float = 1000.0,
spot_fee_rate: float = 0.0010,
perp_fee_rate: float = 0.0007,
min_expected_profit_bps: float = 1.5,
spot_fee_rate: float = 0.0004,
perp_fee_rate: float = 0.00015,
min_expected_profit_bps: float = 1.0,
):
self.entry_threshold = entry_threshold_bps / 10000 # bps → decimal
self.exit_threshold = exit_threshold_bps / 10000
@@ -112,7 +114,7 @@ class SpotPerpBasisArb:
funding_apr = abs(funding_rate) * 365 * 3 # 8h → annual
funding_profit = funding_apr * (self.max_hold_hours / (365 * 24))
if not in_position and abs(basis) > self.entry_threshold and expected_profit > self.min_expected_profit:
if not in_position and abs(basis) > self.entry_threshold and expected_profit >= self.min_expected_profit - EPS:
if basis > 0:
return {
"action": "SELL_PERP_BUY_SPOT",
@@ -237,7 +239,7 @@ def multi_asset_basis_scan(
continue
basis = (perp - spot) / spot
if abs(basis) > entry_threshold_bps / 10000:
if abs(basis) >= entry_threshold_bps / 10000 - EPS:
opportunities.append({
"coin": coin,
"spot": spot,