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>
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package binancex
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"me.thuanle/bbot/internal/configs/binance"
|
|
"me.thuanle/bbot/internal/data"
|
|
"me.thuanle/bbot/internal/utils/stringx"
|
|
)
|
|
|
|
func Token2FutureSymbols(token string) []string {
|
|
if !stringx.IsAlphaNumeric(token) {
|
|
return nil
|
|
}
|
|
|
|
token = strings.ToUpper(token)
|
|
if mapped, ok := data.Market.GetFutureSymbolByToken(token); ok {
|
|
return []string{mapped}
|
|
}
|
|
|
|
for futureToken, spotToken := range binance.FutureToken2SpotTokenMap {
|
|
if strings.ToUpper(spotToken) != token {
|
|
continue
|
|
}
|
|
if mapped, ok := data.Market.GetFutureSymbolByToken(strings.ToUpper(futureToken)); ok {
|
|
return []string{mapped}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Token2SpotSymbols(token string) []string {
|
|
if !stringx.IsAlphaNumeric(token) {
|
|
return nil
|
|
}
|
|
|
|
token = strings.ToUpper(token)
|
|
if mapped, ok := data.Market.GetSpotSymbolByToken(token); ok {
|
|
return []string{mapped}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Token2RelatedSpotSymbols(token string) []string {
|
|
token = strings.ToUpper(token)
|
|
seen := make(map[string]struct{}, 2)
|
|
spots := make([]string, 0, 2)
|
|
|
|
for _, futureSymbol := range Token2FutureSymbols(token) {
|
|
spotSymbol := Future2SpotSymbol(futureSymbol)
|
|
if _, ok := seen[spotSymbol]; ok {
|
|
continue
|
|
}
|
|
if data.Market.IsSpotPair(spotSymbol) {
|
|
seen[spotSymbol] = struct{}{}
|
|
spots = append(spots, spotSymbol)
|
|
}
|
|
}
|
|
|
|
for _, spotSymbol := range Token2SpotSymbols(token) {
|
|
if _, ok := seen[spotSymbol]; ok {
|
|
continue
|
|
}
|
|
seen[spotSymbol] = struct{}{}
|
|
spots = append(spots, spotSymbol)
|
|
}
|
|
|
|
return spots
|
|
}
|