Files
crypto-price-bot/internal/helper/binancex/symbol.go
T

59 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 {
// First check regular symbols
if len(Token2FutureSymbols(s)) > 0 {
return true
}
// Then check Alpha tokens
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
}