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 30 additions and 2 deletions
Showing only changes of commit 06c40ef30f - Show all commits
+13
View File
@@ -47,6 +47,19 @@ func Token2FutureSymbols(token string) []string {
}
func Token2SpotSymbols(token string) []string {
if !stringx.IsAlphaNumeric(token) {
return nil
}
spotOnly := strings.ToUpper(token) + "USDT"
if data.Market.IsSpotPair(spotOnly) {
return []string{spotOnly}
}
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)
+13 -1
View File
@@ -165,13 +165,25 @@ func TestIsToken(t *testing.T) {
}
}
func TestToken2SpotSymbols_AppliesExplicitRemap(t *testing.T) {
func TestToken2SpotSymbols_DoesNotDependOnFutureMappings(t *testing.T) {
withResolverMarketStub(t, &resolverMarketStub{
futuresPairs: map[string]bool{"LUNA2USDT": true},
spotPairs: map[string]bool{"LUNAUSDT": true},
})
spots := Token2SpotSymbols("luna2")
if len(spots) != 0 {
t.Fatalf("expected no direct spot symbols for LUNA2, got %+v", spots)
}
}
func TestToken2RelatedSpotSymbols_AppliesExplicitRemap(t *testing.T) {
withResolverMarketStub(t, &resolverMarketStub{
futuresPairs: map[string]bool{"LUNA2USDT": true},
spotPairs: map[string]bool{"LUNAUSDT": true},
})
spots := Token2RelatedSpotSymbols("luna2")
if len(spots) != 1 || spots[0] != "LUNAUSDT" {
t.Fatalf("expected [LUNAUSDT], got %+v", spots)
}
+3
View File
@@ -30,6 +30,9 @@ var (
)
func IsToken(s string) bool {
if len(Token2FutureSymbols(s)) > 0 {
return true
}
if len(Token2SpotSymbols(s)) > 0 {
return true
}
+1 -1
View File
@@ -87,7 +87,7 @@ func collectRichTokenData(token string) buildRichTokenMessageArgs {
}
}
spotSymbols := binancex.Token2SpotSymbols(token)
spotSymbols := binancex.Token2RelatedSpotSymbols(token)
for _, spotSymbol := range spotSymbols {
if sp, ok := data.Market.GetSpotPrice(spotSymbol); ok {
a.HasSpot = true