Remove Alpha token price caching in spotPrice map
Build Docker Image / build (amd64) (push) Successful in 2m21s
Build Docker Image / build (amd64) (push) Successful in 2m21s
Alpha token prices are now looked up directly from Alpha data instead of being cached into spotPrice. Remove unused ensureAlphaCacheLoaded and shouldRefreshAlphaCache functions. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -132,16 +132,6 @@ func (ms *MarketData) refreshAlphaTokenCache() {
|
||||
ms.alphaTokens[symbol] = token
|
||||
}
|
||||
|
||||
// Update spot prices for Alpha tokens (separate lock to avoid holding both mutexes)
|
||||
ms.mu.Lock()
|
||||
for _, token := range tokens {
|
||||
symbol := token.Symbol
|
||||
if price := token.GetPrice(); price > 0 {
|
||||
ms.spotPrice[symbol] = price
|
||||
}
|
||||
}
|
||||
ms.mu.Unlock()
|
||||
|
||||
ms.lastAlphaCacheUpdate = time.Now()
|
||||
log.Info().Int("count", len(tokens)).Msg("Alpha token cache refreshed successfully")
|
||||
}
|
||||
@@ -160,20 +150,3 @@ func (ms *MarketData) IsAlphaToken(symbol string) bool {
|
||||
_, exists := ms.GetAlphaToken(symbol)
|
||||
return exists
|
||||
}
|
||||
|
||||
// shouldRefreshAlphaCache checks if the Alpha cache should be refreshed
|
||||
func (ms *MarketData) shouldRefreshAlphaCache() bool {
|
||||
// Refresh if cache is empty (first time) or if it's older than 30 minutes
|
||||
if len(ms.alphaTokens) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return time.Since(ms.lastAlphaCacheUpdate) > 30*time.Minute
|
||||
}
|
||||
|
||||
// ensureAlphaCacheLoaded ensures Alpha cache is loaded, refreshes if needed
|
||||
func (ms *MarketData) ensureAlphaCacheLoaded() {
|
||||
if ms.shouldRefreshAlphaCache() {
|
||||
ms.refreshAlphaTokenCache()
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,10 @@ func (ms *MarketData) GetSpotPrice(symbol string) (float64, bool) {
|
||||
return p, true
|
||||
}
|
||||
|
||||
// If not found, check if it's an Alpha token and ensure cache is loaded
|
||||
ms.ensureAlphaCacheLoaded()
|
||||
// If not found, check if it's an Alpha token
|
||||
if ms.IsAlphaToken(symbol) {
|
||||
if alphaToken, exists := ms.GetAlphaToken(symbol); exists {
|
||||
price := alphaToken.GetPrice()
|
||||
if price > 0 {
|
||||
ms.mu.Lock()
|
||||
ms.spotPrice[symbol] = price
|
||||
ms.mu.Unlock()
|
||||
if price := alphaToken.GetPrice(); price > 0 {
|
||||
return price, true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user