Fix 8 bugs from code review
B#1 — sigCh shared across goroutines, SIGINT unreliable
→ context.WithCancel: main loop cancels ctx on SIGINT,
4 WS goroutines select on ctx.Done() instead of shared sigCh
B#3 — restoreOpenPositions missing LastScaleAt
→ Set LastScaleAt = tr.OpenedAt on restore so scale-in cooldown works
B#4 — dYdX heartbeat goroutine leaks on reconnect
→ Added stopHeartbeat chan + heartbeatMu mutex; close old channel
before spawning new heartbeat goroutine
B#5 — GetBitgetSize fmt.Sprintf rounds up, may exceed amountUSD
→ Added math.Floor(sz*multiplier)/multiplier before format to round
DOWN to nearest valid step size for every coin
B#6 — netProfit and CalcNetProfit duplicate formula
→ scanner.go netProfit now delegates to exchange.CalcNetProfit
B#7 — Aevo Run callback only 2 params, incompatible with startExchange
→ Changed to 4-arg callback func(coin, price, bid, ask) with bid=ask=0
B#8 — parseFloat uses fmt.Sscanf (slow, locale-sensitive)
→ Replaced with strconv.ParseFloat
B#9 — dYdX receives hlSymbols instead of its own symbol list
→ Added dydxSymbols var, built from c.HL like other exchanges
This commit is contained in:
+4
-9
@@ -4,6 +4,8 @@ import (
|
||||
"log"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"exchange-monitor/exchange"
|
||||
)
|
||||
|
||||
// Exchange names
|
||||
@@ -44,16 +46,9 @@ var TrackedCoins = []TrackedCoin{
|
||||
}
|
||||
|
||||
// netProfit calculates net profit % after fees for a complete round trip (entry + exit).
|
||||
// B#6: Delegates to exchange.CalcNetProfit to eliminate formula duplication.
|
||||
func netProfit(buyPrice, sellPrice, buyFee, sellFee float64) float64 {
|
||||
if buyPrice <= 0 || sellPrice <= 0 {
|
||||
return 0
|
||||
}
|
||||
// Entry: buy at buyPrice (pay buyFee), sell short at sellPrice (pay sellFee)
|
||||
cost := buyPrice * (1 + buyFee/100)
|
||||
revenue := sellPrice * (1 - sellFee/100)
|
||||
// Exit: sell long (pay sellFee), buy back short (pay buyFee)
|
||||
// Total fees = 2 * (buyFee + sellFee), first round already in formula above
|
||||
return (revenue/cost - 1)*100 - (buyFee + sellFee)
|
||||
return exchange.CalcNetProfit(buyPrice, sellPrice, buyFee, sellFee, buyFee, sellFee)
|
||||
}
|
||||
|
||||
// ScanArbWithFees checks all coins for arbitrage opportunities using a custom fee map.
|
||||
|
||||
Reference in New Issue
Block a user