From 5cfb6afa55d2bd32e4c73449798dd578a9a49be7 Mon Sep 17 00:00:00 2001 From: jackyu66git Date: Sun, 3 May 2026 20:28:27 +0800 Subject: [PATCH] Fix SpreadWindow: use netProfit() for fee accuracy, track real peak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace manual spread-fee calc with netProfit() call — matches scanner's exact fee model (round-trip 0.07%) - Each direction gets correct buy/sell fee pairing - Add PeakNet field to record true max during window, not close-time value - Log peak net with +/- sign instead of approx symbol --- types.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/types.go b/types.go index d7d2d7e..ea3c6cd 100644 --- a/types.go +++ b/types.go @@ -128,6 +128,7 @@ type SpreadWindow struct { Coin string Direction string // "BG->HL" or "HL->BG" Since time.Time + PeakNet float64 // highest netProfit % observed during this window } type SpreadWindowTracker struct { @@ -151,18 +152,22 @@ func (swt *SpreadWindowTracker) Tick(snap map[string]map[string]float64, thresho continue } - // Check both directions - for _, dir := range []struct { - name string - low float64 - high float64 - }{ - {"BG->HL", bgP, hlP}, - {"HL->BG", hlP, bgP}, + // Check both directions — use netProfit() for exact fee model match + // BG→HL: buy BG (Bitget 0.020%), sell HL (HL 0.015%) + // HL→BG: buy HL (HL 0.015%), sell BG (Bitget 0.020%) + type dirCheck struct { + name string + buyPrice float64 + sellPrice float64 + buyFee float64 + sellFee float64 + } + for _, dir := range []dirCheck{ + {"BG->HL", bgP, hlP, makerFees[ExBitget], makerFees[ExHyperLiquid]}, + {"HL->BG", hlP, bgP, makerFees[ExHyperLiquid], makerFees[ExBitget]}, } { key := coin.Name + ":" + dir.name - spread := (dir.high - dir.low) / dir.low * 100 - netSpr := spread - (makerFees[ExBitget] + makerFees[ExHyperLiquid]) // rough net + netSpr := netProfit(dir.buyPrice, dir.sellPrice, dir.buyFee, dir.sellFee) w, exists := swt.windows[key] if netSpr >= threshold { @@ -171,14 +176,17 @@ func (swt *SpreadWindowTracker) Tick(snap map[string]map[string]float64, thresho Coin: coin.Name, Direction: dir.name, Since: now, + PeakNet: netSpr, } + } else if netSpr > w.PeakNet { + w.PeakNet = netSpr } } else { if exists { dur := now.Sub(w.Since) if dur > 100*time.Millisecond { - log.Printf("[SpreadWindow] %s %s exceeded threshold for %v (peak net≈%.4f%%)", - w.Coin, w.Direction, dur.Round(time.Millisecond), netSpr) + log.Printf("[SpreadWindow] %s %s exceeded threshold for %v (peak net=%+.4f%%)", + w.Coin, w.Direction, dur.Round(time.Millisecond), w.PeakNet) } delete(swt.windows, key) }