diff --git a/scripts/surfer/crypto_funding_paper.py b/scripts/surfer/crypto_funding_paper.py index 87412200a..7d3339f5e 100644 --- a/scripts/surfer/crypto_funding_paper.py +++ b/scripts/surfer/crypto_funding_paper.py @@ -10,6 +10,7 @@ Sharpe ~2-3.6); this tool tracks the no-capital forward record. python3 crypto_funding_paper.py run daily step: book funding on prior positions, log, persist python3 crypto_funding_paper.py status current book + cumulative track record python3 crypto_funding_paper.py gate Phase-1 -> Phase-2 assessment vs backtest + python3 crypto_funding_paper.py orders [USD] Phase-2: current book -> exact delta-neutral orders python3 crypto_funding_paper.py log [N] last N run-log lines (default 25) (alias: 'paper' == 'run', for the cron) """ @@ -49,11 +50,22 @@ def crypto_native(): return {s["symbol"] for s in info["symbols"] if s.get("underlyingType") == "COIN"} +def spot_symbols(): + """Symbols with a Binance SPOT market — required to build the delta-neutral hedge. + Perp-only coins can't be cash-and-carry harvested (no spot leg); their high funding survives + PRECISELY because the arb is impossible, so they must be excluded.""" + return {x["symbol"] for x in get("https://api.binance.com/api/v3/ticker/price")} + + def universe(): + """Liquid, crypto-native, HEDGEABLE (spot+perp) USDT perps — the only ones that can be + delta-neutral harvested.""" native = crypto_native() + spot = spot_symbols() t = get(f"{FAPI}/fapi/v1/ticker/24hr") return {x["symbol"]: float(x["quoteVolume"]) for x in t - if x["symbol"].endswith("USDT") and x["symbol"] in native and float(x["quoteVolume"]) > LIQ_USD} + if x["symbol"].endswith("USDT") and x["symbol"] in native and x["symbol"] in spot + and float(x["quoteVolume"]) > LIQ_USD} def funding_hist(sym, limit=90): @@ -169,6 +181,38 @@ def cmd_gate(): print(" tail is the real -100% risk (un-modeled); current qualifiers may be small/niche coins.") +def cmd_orders(capital): + """Phase-2 bridge: turn the current paper book into exact delta-neutral orders for `capital`, + and flag coins that are perp-only (no spot leg = can't hedge cleanly on Binance).""" + st = load_state() + book = st.get("positions", {}) + if not book: + print("no current book — run 'snapshot'/'run' first."); return + try: + spot_px = {x["symbol"]: float(x["price"]) for x in get("https://api.binance.com/api/v3/ticker/price")} + except Exception: + spot_px = {} + perp_px = {x["symbol"]: float(x["price"]) for x in get(f"{FAPI}/fapi/v1/ticker/price")} + LEV = 2.0 # conservative perp leverage (avoid liquidation) + n = len(book) + X = capital / (n * (1 + 1 / LEV)) # notional per leg per coin + print(f"=== Phase-2 delta-neutral orders for ${capital:.0f} across {n} coins (perp {LEV:.0f}x) ===") + print(f" per coin: ~${X:.0f} notional/leg, ~${X/LEV:.0f} perp margin, ~${X*(1+1/LEV):.0f} capital") + print(f"{'coin':>14} {'hedge':>6} {'SPOT buy (units @ px)':>26} {'PERP short (units @ px)':>26}") + ok = 0 + for c in sorted(book): + if c in spot_px and c in perp_px: + print(f"{c:>14} {'YES':>6} {X/spot_px[c]:>14.4f} @ {spot_px[c]:<9.5g} {X/perp_px[c]:>14.4f} @ {perp_px[c]:<9.5g}") + ok += 1 + else: + why = "no-spot" if c not in spot_px else "no-perp" + print(f"{c:>14} {'NO':>6} ({why}) cannot delta-neutral hedge on Binance — skip / alt-venue") + print(f"\n {ok}/{n} coins hedgeable on Binance (spot+perp both exist).") + print(" Place SPOT + PERP legs together to stay delta-neutral. Keep perp leverage low; never let the") + print(" perp leg liquidate while holding spot. API keys: ENV ONLY, never commit. Place manually for") + print(" micro-live to validate fills before any automation. DEPLOY ONLY AFTER the Phase-1 gate passes.") + + def cmd_log(n=25): if not os.path.exists(LOG): print(f"(no log yet at {LOG} — cron writes it nightly; 'run' appends when redirected)"); return @@ -186,6 +230,8 @@ def main(): cmd_status() elif cmd == "gate": cmd_gate() + elif cmd == "orders": + cmd_orders(float(sys.argv[2]) if len(sys.argv) > 2 else 2000.0) elif cmd == "log": cmd_log(int(sys.argv[2]) if len(sys.argv) > 2 else 25) else: