refactor: separate direct and related spot resolvers
Keep IsToken checks explicit across futures and direct spot symbols, move futures-derived spot mapping to a clearly named helper, and update token data collection to use related spot resolution. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,19 @@ func Token2FutureSymbols(token string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Token2SpotSymbols(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)
|
futureSymbols := Token2FutureSymbols(token)
|
||||||
spots := make([]string, 0, len(futureSymbols)+1)
|
spots := make([]string, 0, len(futureSymbols)+1)
|
||||||
seen := make(map[string]struct{}, len(futureSymbols)+1)
|
seen := make(map[string]struct{}, len(futureSymbols)+1)
|
||||||
|
|||||||
@@ -165,13 +165,25 @@ func TestIsToken(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToken2SpotSymbols_AppliesExplicitRemap(t *testing.T) {
|
func TestToken2SpotSymbols_DoesNotDependOnFutureMappings(t *testing.T) {
|
||||||
withResolverMarketStub(t, &resolverMarketStub{
|
withResolverMarketStub(t, &resolverMarketStub{
|
||||||
futuresPairs: map[string]bool{"LUNA2USDT": true},
|
futuresPairs: map[string]bool{"LUNA2USDT": true},
|
||||||
spotPairs: map[string]bool{"LUNAUSDT": true},
|
spotPairs: map[string]bool{"LUNAUSDT": true},
|
||||||
})
|
})
|
||||||
|
|
||||||
spots := Token2SpotSymbols("luna2")
|
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" {
|
if len(spots) != 1 || spots[0] != "LUNAUSDT" {
|
||||||
t.Fatalf("expected [LUNAUSDT], got %+v", spots)
|
t.Fatalf("expected [LUNAUSDT], got %+v", spots)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func IsToken(s string) bool {
|
func IsToken(s string) bool {
|
||||||
|
if len(Token2FutureSymbols(s)) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if len(Token2SpotSymbols(s)) > 0 {
|
if len(Token2SpotSymbols(s)) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func collectRichTokenData(token string) buildRichTokenMessageArgs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spotSymbols := binancex.Token2SpotSymbols(token)
|
spotSymbols := binancex.Token2RelatedSpotSymbols(token)
|
||||||
for _, spotSymbol := range spotSymbols {
|
for _, spotSymbol := range spotSymbols {
|
||||||
if sp, ok := data.Market.GetSpotPrice(spotSymbol); ok {
|
if sp, ok := data.Market.GetSpotPrice(spotSymbol); ok {
|
||||||
a.HasSpot = true
|
a.HasSpot = true
|
||||||
|
|||||||
Reference in New Issue
Block a user