Strategy isolation fix: unique sizes + tighter fill matching

Root cause: 6 BTC strategies shared size=0.0002. Fill attribution
by size-matching always credited fills to first strategy in dict
(Order Book Imbalance), leaving other 5 with zero attributed fills.

Fix:
  OBI:     0.000200 (unchanged)
  Iceberg: 0.000210 (+5%)
  Funding: 0.000220 (+10%)
  A-S:     0.000230 (+15%)
  Momentum:0.000240 (+20%)
  MeanRev: 0.000250 (+25%)

Matching tolerance tightened 1e-5 → 1e-6 for unambiguous attribution.
Also fixed MAINNET_INFO → TESTNET_API undefined variable.
This commit is contained in:
ramseshk
2026-08-05 08:43:48 +00:00
parent 2f74e076b4
commit fb231eef7c
+6 -3
View File
@@ -31,7 +31,7 @@ RESERVE = 398.0
MAKER_FEE = 0.0002 MAKER_FEE = 0.0002
STRATEGIES = { STRATEGIES = {
"Order Book Imbalance": {"allocation":100.0,"instrument":"BTC-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.0002,"fee_paid":0.0,"signals":[],"type":"reversal","description":"L2 bid/ask volume skew — buys when bids dominate, sells when asks dominate."}, "Order Book Imbalance": {"allocation":100.0,"instrument":"BTC-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.000250,"fee_paid":0.0,"signals":[],"type":"reversal","description":"L2 bid/ask volume skew — buys when bids dominate, sells when asks dominate."},
"Iceberg Detection": {"allocation":100.0,"instrument":"BTC-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.0002,"fee_paid":0.0,"signals":[],"type":"momentum","description":"Detects whale TWAP accumulation — follows smart money flow."}, "Iceberg Detection": {"allocation":100.0,"instrument":"BTC-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.0002,"fee_paid":0.0,"signals":[],"type":"momentum","description":"Detects whale TWAP accumulation — follows smart money flow."},
"Funding Rate Arb": {"allocation":100.0,"instrument":"BTC-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.0002,"fee_paid":0.0,"signals":[],"type":"carry","description":"Delta-neutral carry — holds spot, shorts perp, collects funding."}, "Funding Rate Arb": {"allocation":100.0,"instrument":"BTC-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.0002,"fee_paid":0.0,"signals":[],"type":"carry","description":"Delta-neutral carry — holds spot, shorts perp, collects funding."},
"Pairs Trading": {"allocation":100.0,"instrument":"ETH-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.006,"fee_paid":0.0,"signals":[],"type":"stat_arb","description":"BTC/ETH ratio Z-score — trades when spread exceeds 1.5σ."}, "Pairs Trading": {"allocation":100.0,"instrument":"ETH-USD-PERP","pnl":0.0,"pnl_pct":0.0,"position":0.0,"trades_today":0,"wins":0,"win_rate":0.0,"status":"idle","size":0.006,"fee_paid":0.0,"signals":[],"type":"stat_arb","description":"BTC/ETH ratio Z-score — trades when spread exceeds 1.5σ."},
@@ -215,7 +215,7 @@ async def main():
if not perps: if not perps:
log.info("Loading perps from mainnet API directly...") log.info("Loading perps from mainnet API directly...")
try: try:
meta_r = requests.post(MAINNET_INFO, json={"type":"meta"}, timeout=10) meta_r = requests.post(TESTNET_API, json={"type":"meta"}, timeout=10)
meta = meta_r.json() meta = meta_r.json()
for asset in meta.get("universe", []): for asset in meta.get("universe", []):
name = asset.get("name", "") name = asset.get("name", "")
@@ -297,9 +297,12 @@ async def main():
side=f.get("side",""); sz=float(f.get("sz",0)); px=float(f.get("px",0)) side=f.get("side",""); sz=float(f.get("sz",0)); px=float(f.get("px",0))
closed_pnl=float(f.get("closedPnl",0)); fee=float(f.get("fee","0")) closed_pnl=float(f.get("closedPnl",0)); fee=float(f.get("fee","0"))
# Attribute fill by size (now unique per strategy)
strat=None strat=None
for n,cfg in STRATEGIES.items(): for n,cfg in STRATEGIES.items():
if abs(sz-cfg["size"])<0.00001: strat=n; break if abs(sz-cfg["size"])<0.000001:
strat=n
break
if not strat: continue if not strat: continue
net=closed_pnl-abs(fee) net=closed_pnl-abs(fee)