init code
This commit is contained in:
95
internal/helper/binancex/symbol.go
Normal file
95
internal/helper/binancex/symbol.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package binancex
|
||||
|
||||
import (
|
||||
"me.thuanle/bbot/internal/configs/binance"
|
||||
"me.thuanle/bbot/internal/data"
|
||||
"me.thuanle/bbot/internal/utils/stringx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Symbol2Token(sym string) string {
|
||||
token := strings.ToUpper(sym)
|
||||
|
||||
for _, prefix := range binance.SymbolPrefixList {
|
||||
token, _ = strings.CutPrefix(token, prefix)
|
||||
}
|
||||
for suffix, abbr := range binance.SymbolSuffixMap {
|
||||
var f bool
|
||||
token, f = stringx.ReplaceSuffix(token, suffix, abbr)
|
||||
if f {
|
||||
break
|
||||
}
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
||||
var (
|
||||
checkingPrefixList = append(binance.SymbolPrefixList, "")
|
||||
)
|
||||
|
||||
func testSym(sym string) bool {
|
||||
_, _, _, test := data.Market.GetFuturePrice(sym)
|
||||
return test
|
||||
}
|
||||
|
||||
func Token2Symbols(token string) []string {
|
||||
var syms []string
|
||||
if !stringx.IsAlphaNumeric(token) {
|
||||
return syms
|
||||
}
|
||||
|
||||
token = strings.ToUpper(token)
|
||||
|
||||
for _, prefix := range checkingPrefixList {
|
||||
prefix = strings.ToUpper(prefix)
|
||||
|
||||
s := prefix + token
|
||||
|
||||
//no suffix
|
||||
if testSym(s) {
|
||||
syms = append(syms, s)
|
||||
continue
|
||||
}
|
||||
|
||||
for suffix, abbr := range binance.SymbolSuffixMap {
|
||||
suffix = strings.ToUpper(suffix)
|
||||
abbr = strings.ToUpper(abbr)
|
||||
|
||||
//suffix
|
||||
sym := s + suffix
|
||||
if testSym(sym) {
|
||||
syms = append(syms, sym)
|
||||
continue
|
||||
}
|
||||
|
||||
//suffix abbr
|
||||
symAbr, found := stringx.ReplaceSuffix(s, abbr, suffix)
|
||||
if found && testSym(symAbr) {
|
||||
syms = append(syms, symAbr)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
return syms
|
||||
}
|
||||
|
||||
func IsToken(s string) bool {
|
||||
return len(Token2Symbols(s)) > 0
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user