diff --git a/internal/helper/binancex/resolver.go b/internal/helper/binancex/resolver.go index c60b0b1..788034d 100644 --- a/internal/helper/binancex/resolver.go +++ b/internal/helper/binancex/resolver.go @@ -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) diff --git a/internal/helper/binancex/resolver_test.go b/internal/helper/binancex/resolver_test.go index 1782b78..165144f 100644 --- a/internal/helper/binancex/resolver_test.go +++ b/internal/helper/binancex/resolver_test.go @@ -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) } diff --git a/internal/helper/binancex/symbol.go b/internal/helper/binancex/symbol.go index ea74329..c79b8b9 100644 --- a/internal/helper/binancex/symbol.go +++ b/internal/helper/binancex/symbol.go @@ -30,6 +30,9 @@ var ( ) func IsToken(s string) bool { + if len(Token2FutureSymbols(s)) > 0 { + return true + } if len(Token2SpotSymbols(s)) > 0 { return true } diff --git a/internal/services/tele/commands/token.go b/internal/services/tele/commands/token.go index 7267264..202e84c 100644 --- a/internal/services/tele/commands/token.go +++ b/internal/services/tele/commands/token.go @@ -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