refactor: use canonical token-to-symbol maps for market lookup
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>
This commit is contained in:
@@ -9,41 +9,25 @@ import (
|
||||
)
|
||||
|
||||
func Token2FutureSymbols(token string) []string {
|
||||
var syms []string
|
||||
if !stringx.IsAlphaNumeric(token) {
|
||||
return syms
|
||||
return nil
|
||||
}
|
||||
|
||||
token = strings.ToUpper(token)
|
||||
if mapped, ok := data.Market.GetFutureSymbolByToken(token); ok {
|
||||
return []string{mapped}
|
||||
}
|
||||
|
||||
for _, prefix := range checkingPrefixList {
|
||||
prefix = strings.ToUpper(prefix)
|
||||
|
||||
s := prefix + token
|
||||
|
||||
if data.Market.IsFuturesPair(s) {
|
||||
syms = append(syms, s)
|
||||
for futureToken, spotToken := range binance.FutureToken2SpotTokenMap {
|
||||
if strings.ToUpper(spotToken) != token {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, suffix := range binance.SymbolSuffixList {
|
||||
suffix = strings.ToUpper(suffix)
|
||||
abbr := strings.ToUpper(binance.SymbolSuffixMap[suffix])
|
||||
|
||||
sym := s + suffix
|
||||
if data.Market.IsFuturesPair(sym) {
|
||||
syms = append(syms, sym)
|
||||
continue
|
||||
}
|
||||
|
||||
symAbr, found := stringx.ReplaceSuffix(s, abbr, suffix)
|
||||
if found && data.Market.IsFuturesPair(symAbr) {
|
||||
syms = append(syms, symAbr)
|
||||
continue
|
||||
}
|
||||
if mapped, ok := data.Market.GetFutureSymbolByToken(strings.ToUpper(futureToken)); ok {
|
||||
return []string{mapped}
|
||||
}
|
||||
}
|
||||
return syms
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Token2SpotSymbols(token string) []string {
|
||||
@@ -51,21 +35,31 @@ func Token2SpotSymbols(token string) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
spotOnly := strings.ToUpper(token) + "USDT"
|
||||
if data.Market.IsSpotPair(spotOnly) {
|
||||
return []string{spotOnly}
|
||||
token = strings.ToUpper(token)
|
||||
if mapped, ok := data.Market.GetSpotSymbolByToken(token); ok {
|
||||
return []string{mapped}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Token2RelatedSpotSymbols(token string) []string {
|
||||
futureSymbols := Token2FutureSymbols(token)
|
||||
spots := make([]string, 0, len(futureSymbols)+1)
|
||||
seen := make(map[string]struct{}, len(futureSymbols)+1)
|
||||
token = strings.ToUpper(token)
|
||||
seen := make(map[string]struct{}, 2)
|
||||
spots := make([]string, 0, 2)
|
||||
|
||||
for _, futureSymbol := range futureSymbols {
|
||||
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
|
||||
}
|
||||
@@ -73,12 +67,5 @@ func Token2RelatedSpotSymbols(token string) []string {
|
||||
spots = append(spots, spotSymbol)
|
||||
}
|
||||
|
||||
spotOnly := strings.ToUpper(token) + "USDT"
|
||||
if data.Market.IsSpotPair(spotOnly) {
|
||||
if _, ok := seen[spotOnly]; !ok {
|
||||
spots = append(spots, spotOnly)
|
||||
}
|
||||
}
|
||||
|
||||
return spots
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user