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>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user