0705e909dc
Gate token detection via spot symbol resolution so chat flow accepts spot-only tokens, and add regression coverage for the fallback path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
1.1 KiB
Go
57 lines
1.1 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(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
|
|
}
|
|
}
|
|
|
|
spotSym, ok := binance.Future2SpotSymbolMap[sym]
|
|
if !ok {
|
|
return sym
|
|
}
|
|
return spotSym
|
|
}
|