440fa3bacd
Add sync.RWMutex to protect future and spot price maps accessed by WebSocket handlers (writers) and Telegram bot handlers (readers). Also adds Alpha token support with caching. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
42 lines
916 B
Go
42 lines
916 B
Go
package market
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type MarketData struct {
|
|
mu sync.RWMutex
|
|
futureMarkPrice map[string]float64
|
|
futureFundingRate map[string]float64
|
|
futureNextFundingTime map[string]int64
|
|
|
|
spotPrice map[string]float64
|
|
|
|
// Alpha token cache
|
|
alphaTokens map[string]AlphaTokenInfo
|
|
alphaCacheMutex sync.RWMutex
|
|
lastAlphaCacheUpdate time.Time
|
|
}
|
|
|
|
func NewMarketData() *MarketData {
|
|
log.Info().Msg("Start market service")
|
|
ms := &MarketData{
|
|
futureMarkPrice: make(map[string]float64),
|
|
futureFundingRate: make(map[string]float64),
|
|
futureNextFundingTime: make(map[string]int64),
|
|
|
|
spotPrice: make(map[string]float64),
|
|
alphaTokens: make(map[string]AlphaTokenInfo),
|
|
}
|
|
_ = ms.StartFutureWsMarkPrice()
|
|
_ = ms.StartSpotWsMarkPrice()
|
|
|
|
// Initialize Alpha token cache
|
|
go ms.refreshAlphaTokenCache()
|
|
|
|
return ms
|
|
}
|