fix: recognize spot-only tokens in IsToken #25

Merged
thuanle merged 4 commits from fix/issue-24-is-token-spot-only into main 2026-04-27 05:00:41 +07:00
4 changed files with 14 additions and 17 deletions
Showing only changes of commit d6338fa092 - Show all commits
+4
View File
@@ -15,3 +15,7 @@ var QuotePriority = []string{"USDT", "USDC", "FDUSD"}
var FutureToken2SpotTokenMap = map[string]string{ var FutureToken2SpotTokenMap = map[string]string{
"LUNA2": "LUNA", "LUNA2": "LUNA",
} }
var SpotToken2FutureTokenMap = map[string]string{
"LUNA": "LUNA2",
}
+3 -7
View File
@@ -69,7 +69,7 @@ func (ms *MarketData) refreshFuturePairCache() error {
if token == "" { if token == "" {
continue continue
} }
token = normalizeFutureToken(token) token = futureCacheTokenKey(token)
futureTokenCandidates[token] = append(futureTokenCandidates[token], s.Symbol) futureTokenCandidates[token] = append(futureTokenCandidates[token], s.Symbol)
} }
@@ -168,12 +168,8 @@ func selectCanonicalSymbolByQuotePriority(token string, candidates []string) str
return normalized[0] return normalized[0]
} }
func normalizeFutureToken(token string) string { func futureCacheTokenKey(token string) string {
token = strings.ToUpper(token) return strings.ToUpper(token)
if mapped, ok := binance.FutureToken2SpotTokenMap[token]; ok {
return strings.ToUpper(mapped)
}
return token
} }
func (ms *MarketData) IsSpotPair(symbol string) bool { func (ms *MarketData) IsSpotPair(symbol string) bool {
+6 -6
View File
@@ -26,15 +26,15 @@ func TestSelectCanonicalSymbolByQuotePriority_NoPreferredQuote(t *testing.T) {
} }
} }
func TestNormalizeFutureToken_AppliesOverride(t *testing.T) { func TestFutureCacheTokenKey_PreservesRawFutureToken(t *testing.T) {
got := normalizeFutureToken("LUNA2") got := futureCacheTokenKey("LUNA2")
if got != "LUNA" { if got != "LUNA2" {
t.Fatalf("expected LUNA, got %q", got) t.Fatalf("expected LUNA2, got %q", got)
} }
} }
func TestNormalizeFutureToken_NoOverride(t *testing.T) { func TestFutureCacheTokenKey_NoOverride(t *testing.T) {
got := normalizeFutureToken("PEPE") got := futureCacheTokenKey("PEPE")
if got != "PEPE" { if got != "PEPE" {
t.Fatalf("expected PEPE, got %q", got) t.Fatalf("expected PEPE, got %q", got)
} }
+1 -4
View File
@@ -18,10 +18,7 @@ func Token2FutureSymbols(token string) []string {
return []string{mapped} return []string{mapped}
} }
for futureToken, spotToken := range binance.FutureToken2SpotTokenMap { if futureToken, ok := binance.SpotToken2FutureTokenMap[token]; ok {
if strings.ToUpper(spotToken) != token {
continue
}
if mapped, ok := data.Market.GetFutureSymbolByToken(strings.ToUpper(futureToken)); ok { if mapped, ok := data.Market.GetFutureSymbolByToken(strings.ToUpper(futureToken)); ok {
return []string{mapped} return []string{mapped}
} }