711721c1ee
Build canonical spot/future token maps with quote priority, unify cache refresh scheduling, and switch resolver/token tests to map-based token lookups. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package binancex
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"me.thuanle/bbot/internal/configs/binance"
|
|
"me.thuanle/bbot/internal/data"
|
|
"me.thuanle/bbot/internal/utils/stringx"
|
|
)
|
|
|
|
func Symbol2Token(sym string) string {
|
|
token := strings.ToUpper(sym)
|
|
|
|
for _, prefix := range binance.SymbolPrefixList {
|
|
token, _ = strings.CutPrefix(token, prefix)
|
|
}
|
|
for _, suffix := range binance.SymbolSuffixList {
|
|
abbr := binance.SymbolSuffixMap[suffix]
|
|
var f bool
|
|
token, f = stringx.ReplaceSuffix(token, suffix, abbr)
|
|
if f {
|
|
break
|
|
}
|
|
}
|
|
return token
|
|
}
|
|
|
|
var (
|
|
checkingPrefixList = append(binance.SymbolPrefixList, "")
|
|
)
|
|
|
|
func IsToken(s string) bool {
|
|
if len(Token2FutureSymbols(s)) > 0 {
|
|
return true
|
|
}
|
|
if len(Token2SpotSymbols(s)) > 0 {
|
|
return true
|
|
}
|
|
|
|
s = strings.ToUpper(s)
|
|
return data.Market.IsAlphaToken(s)
|
|
}
|
|
|
|
// Future2SpotSymbol convert future symbol to spot symbol
|
|
func Future2SpotSymbol(sym string) string {
|
|
for _, prefix := range binance.SymbolPrefixList {
|
|
var f bool
|
|
sym, f = strings.CutPrefix(sym, prefix)
|
|
if f {
|
|
break
|
|
}
|
|
}
|
|
|
|
token := Symbol2Token(sym)
|
|
if mapped, ok := binance.FutureToken2SpotTokenMap[token]; ok {
|
|
token = strings.ToUpper(mapped)
|
|
}
|
|
return token + "USDT"
|
|
}
|