Complete Funding Rate Arb: real API data for live + paper
New module: strategies/funding_arb.py
- get_funding_rates(): fetches predicted funding from Hyperliquid
Uses metaAndAssetCtxs (primary) + predictedFundings (fallback)
- funding_arb_signal(): generates entry/exit signals
Entry: |annual_rate| > threshold (3% testnet, 5% mainnet)
Exit: rate drops below 2% or flips sign
- 30s cache to avoid rate-limiting
Live node:
- Replaced proxy-based funding (20-period return) with real API
- Calls get_funding_rates(use_testnet=True) every compute_signals()
- Lowered threshold to 3% APR for testnet (lower liquidity)
Paper trader:
- Replaced manual funding calc with unified funding_arb_signal()
- Proper entry/exit logic with position tracking
- 5% APR threshold for mainnet data
Current rates: BTC +0.87% APR, ETH -0.82% APR
(Arb fires when rates exceed threshold during volatility)
This commit is contained in:
+17
-11
@@ -127,18 +127,24 @@ def compute_signals():
|
||||
if up>=5: STRATEGIES["Iceberg Detection"]["signals"].append({"time":time.time(),"signal":"BUY","strength":up/10})
|
||||
elif up<=5: STRATEGIES["Iceberg Detection"]["signals"].append({"time":time.time(),"signal":"SELL","strength":1-up/10})
|
||||
|
||||
# Funding Arb: use real funding rate if available, else wider proxy
|
||||
if len(btc_prices)>=20:
|
||||
try:
|
||||
fr = requests.post(TESTNET_API, json={"type":"funding","coin":"BTC"}, timeout=5).json()
|
||||
if isinstance(fr, list) and fr:
|
||||
rate = float(fr[0].get("funding_rate", 0))
|
||||
else:
|
||||
rate = (btc/btc_prices[-20]-1)/20
|
||||
except:
|
||||
# Funding Rate Arb: real API data
|
||||
try:
|
||||
from strategies.funding_arb import get_funding_rates
|
||||
rates = get_funding_rates(use_testnet=True)
|
||||
annual_rate = rates.get("BTC", 0)
|
||||
if abs(annual_rate) > 0.03: # >3% APR threshold (testnet: lower liquidity = lower threshold)
|
||||
sig = "SELL" if annual_rate > 0 else "BUY"
|
||||
STRATEGIES["Funding Rate Arb"]["signals"].append({
|
||||
"time":time.time(), "signal":sig,
|
||||
"strength": min(1.0, abs(annual_rate) * 10),
|
||||
"reason": f"funding_{annual_rate*100:.1f}pct_apr"
|
||||
})
|
||||
except Exception:
|
||||
# Fallback: use price proxy if module unavailable
|
||||
if len(btc_prices)>=20:
|
||||
rate = (btc/btc_prices[-20]-1)/20
|
||||
if abs(rate)>0.0001:
|
||||
STRATEGIES["Funding Rate Arb"]["signals"].append({"time":time.time(),"signal":"SELL" if rate>0 else "BUY","strength":abs(rate)*10000})
|
||||
if abs(rate)>0.0005:
|
||||
STRATEGIES["Funding Rate Arb"]["signals"].append({"time":time.time(),"signal":"SELL" if rate>0 else "BUY","strength":abs(rate)*10000})
|
||||
|
||||
# Pairs: ratio Z-score
|
||||
if len(btc_prices)>=20 and len(eth_prices)>=20:
|
||||
|
||||
Reference in New Issue
Block a user