fix: resolve spot and futures symbols via shared resolver
Introduce a shared token symbol resolver for spot and futures lookups while keeping alpha lookup independent, restoring prefix/remap handling and preserving spot-only fallback behavior. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -62,67 +62,53 @@ func showStickerMode(context telebot.Context, token string) {
|
||||
}
|
||||
}
|
||||
|
||||
func OnTokenInfoByToken(context telebot.Context, token string) error {
|
||||
token = strings.ToUpper(token)
|
||||
showStickerMode(context, token)
|
||||
|
||||
var (
|
||||
hasAlpha, hasAlpha24h bool
|
||||
alphaPrice, alpha24h float64
|
||||
hasFuture, hasSpot bool
|
||||
futurePrice float64
|
||||
fundingRate float64
|
||||
fundingTime int64
|
||||
spotPrice float64
|
||||
)
|
||||
func collectRichTokenData(token string) buildRichTokenMessageArgs {
|
||||
a := buildRichTokenMessageArgs{Token: token}
|
||||
|
||||
if alphaToken, ok := data.Market.GetAlphaToken(token); ok {
|
||||
hasAlpha = true
|
||||
alphaPrice = alphaToken.GetPrice()
|
||||
hasAlpha24h = true
|
||||
alpha24h = alphaToken.GetPercentChange24h()
|
||||
a.HasAlpha = true
|
||||
a.AlphaPrice = alphaToken.GetPrice()
|
||||
a.HasAlpha24h = true
|
||||
a.Alpha24h = alphaToken.GetPercentChange24h()
|
||||
}
|
||||
|
||||
symbols := binancex.Token2Symbols(token)
|
||||
if len(symbols) > 0 {
|
||||
fp, fr, ft, ok := data.Market.GetFuturePrice(symbols[0])
|
||||
if ok {
|
||||
hasFuture = true
|
||||
futurePrice = fp
|
||||
fundingRate = fr
|
||||
fundingTime = ft
|
||||
futureSymbols := binancex.Token2FutureSymbols(token)
|
||||
for _, futureSymbol := range futureSymbols {
|
||||
if fp, fr, ft, ok := data.Market.GetFuturePrice(futureSymbol); ok {
|
||||
a.HasFuture = true
|
||||
a.FuturePrice = fp
|
||||
a.FundingRate = fr
|
||||
a.FundingTimeMs = ft
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
sSymbol := binancex.Future2SpotSymbol(symbols[0])
|
||||
if sp, ok := data.Market.GetSpotPrice(sSymbol); ok {
|
||||
hasSpot = true
|
||||
spotPrice = sp
|
||||
}
|
||||
spotSymbols := binancex.Token2SpotSymbols(token)
|
||||
for _, spotSymbol := range spotSymbols {
|
||||
if sp, ok := data.Market.GetSpotPrice(spotSymbol); ok {
|
||||
a.HasSpot = true
|
||||
a.SpotPrice = sp
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
marginRates := data.Market.GetMarginInterestRates()
|
||||
marginAPR := marginRates[token] * 365 * 100
|
||||
hasMarginAPR := marginRates[token] != 0
|
||||
a.MarginAPRPercent = marginRates[token] * 365 * 100
|
||||
a.HasMarginAPR = marginRates[token] != 0
|
||||
|
||||
if !hasSpot && !hasFuture && !hasAlpha {
|
||||
return a
|
||||
}
|
||||
|
||||
func OnTokenInfoByToken(context telebot.Context, token string) error {
|
||||
token = strings.ToUpper(token)
|
||||
showStickerMode(context, token)
|
||||
|
||||
args := collectRichTokenData(token)
|
||||
if !args.HasSpot && !args.HasFuture && !args.HasAlpha {
|
||||
return nil
|
||||
}
|
||||
|
||||
msg := view.RenderRichTokenMessage(buildRichTokenMessageInput(buildRichTokenMessageArgs{
|
||||
Token: token,
|
||||
HasSpot: hasSpot,
|
||||
SpotPrice: spotPrice,
|
||||
HasFuture: hasFuture,
|
||||
FuturePrice: futurePrice,
|
||||
FundingRate: fundingRate,
|
||||
FundingTimeMs: fundingTime,
|
||||
HasAlpha: hasAlpha,
|
||||
AlphaPrice: alphaPrice,
|
||||
HasAlpha24h: hasAlpha24h,
|
||||
Alpha24h: alpha24h,
|
||||
HasMarginAPR: hasMarginAPR,
|
||||
MarginAPRPercent: marginAPR,
|
||||
}))
|
||||
msg := view.RenderRichTokenMessage(buildRichTokenMessageInput(args))
|
||||
|
||||
_ = chat.ReplyMessage(context, msg)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user