c5c1cdf0d5
Build Docker Image / build (amd64) (push) Successful in 58s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
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 and refresh every hour
|
|
go ms.alphaCacheRefreshLoop()
|
|
|
|
return ms
|
|
}
|
|
|
|
func (ms *MarketData) alphaCacheRefreshLoop() {
|
|
ms.refreshAlphaTokenCache()
|
|
ticker := time.NewTicker(time.Hour)
|
|
defer ticker.Stop()
|
|
for range ticker.C {
|
|
ms.refreshAlphaTokenCache()
|
|
}
|
|
}
|