Files
crypto-price-bot/internal/data/market/spot_prices.go
thuanle f5e2e178e1 refactor: standardize market filenames by data dimension
Split market pair logic into spot and futures files and rename price files to plural data-dimension names without changing behavior.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-27 07:04:37 +07:00

43 lines
929 B
Go

package market
import (
"context"
"strconv"
"time"
"github.com/rs/zerolog/log"
)
func (ms *MarketData) GetSpotPrice(symbol string) (float64, bool) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
prices, err := ms.spotClient.NewListPricesService().Symbol(symbol).Do(ctx)
if err != nil {
log.Error().Err(err).Str("symbol", symbol).Msg("Failed to fetch spot price")
return ms.getAlphaPrice(symbol)
}
if len(prices) == 0 {
return ms.getAlphaPrice(symbol)
}
price, err := strconv.ParseFloat(prices[0].Price, 64)
if err != nil || price == 0 {
return ms.getAlphaPrice(symbol)
}
return price, true
}
func (ms *MarketData) getAlphaPrice(symbol string) (float64, bool) {
if ms.IsAlphaToken(symbol) {
if alphaToken, exists := ms.GetAlphaToken(symbol); exists {
if price := alphaToken.GetPrice(); price > 0 {
return price, true
}
}
}
return 0, false
}