fix: restore canonical token lookup for market caches
Build Docker Image / build (amd64) (push) Successful in 1m25s

This commit is contained in:
2026-06-08 07:17:14 +07:00
parent 3b726311f5
commit e173fd7799
5 changed files with 150 additions and 23 deletions
+41 -10
View File
@@ -1,12 +1,14 @@
package binancex
import (
"sort"
"strings"
"testing"
"me.thuanle/bbot/internal/configs/binance"
"me.thuanle/bbot/internal/data"
"me.thuanle/bbot/internal/data/market"
"me.thuanle/bbot/internal/utils/stringx"
)
type resolverMarketStub struct {
@@ -32,22 +34,51 @@ func (m *resolverMarketStub) GetAlphaPrice(symbol string) (float64, bool) { retu
func (m *resolverMarketStub) IsSpotPair(symbol string) bool { return m.spotPairs[symbol] }
func (m *resolverMarketStub) IsFuturesPair(symbol string) bool { return m.futuresPairs[symbol] }
func (m *resolverMarketStub) GetSpotSymbolByToken(token string) (string, bool) {
token = strings.ToUpper(token)
for sym := range m.spotPairs {
if strings.ToUpper(Symbol2Token(sym)) == token {
return sym, true
}
}
return "", false
return selectCanonicalTestSymbol(token, m.spotPairs, []string{""})
}
func (m *resolverMarketStub) GetFutureSymbolByToken(token string) (string, bool) {
prefixes := append(append([]string{}, binance.SymbolPrefixList...), "")
return selectCanonicalTestSymbol(token, m.futuresPairs, prefixes)
}
func selectCanonicalTestSymbol(token string, pairs map[string]bool, prefixes []string) (string, bool) {
token = strings.ToUpper(token)
for sym := range m.futuresPairs {
candidates := make([]string, 0, len(pairs))
candidateSet := make(map[string]struct{}, len(pairs))
for sym := range pairs {
if strings.ToUpper(Symbol2Token(sym)) == token {
return sym, true
sym = strings.ToUpper(sym)
candidates = append(candidates, sym)
candidateSet[sym] = struct{}{}
}
}
return "", false
if len(candidates) == 0 {
return "", false
}
for _, prefix := range prefixes {
base := strings.ToUpper(prefix) + token
if _, ok := candidateSet[base]; ok {
return base, true
}
for _, quote := range binance.SymbolSuffixList {
target := base + strings.ToUpper(quote)
if _, ok := candidateSet[target]; ok {
return target, true
}
replaced, ok := stringx.ReplaceSuffix(base, strings.ToUpper(binance.SymbolSuffixMap[quote]), strings.ToUpper(quote))
if ok {
if _, exists := candidateSet[replaced]; exists {
return replaced, true
}
}
}
}
sort.Strings(candidates)
return candidates[0], true
}
func (m *resolverMarketStub) RefreshTradingPairCache() error { return nil }