package market import ( "sync" "time" "github.com/adshao/go-binance/v2" "github.com/adshao/go-binance/v2/futures" "github.com/rs/zerolog/log" ) type MarketData struct { // Trading pair caches spotPairs map[string]bool futuresPairs map[string]bool pairCacheMutex sync.RWMutex lastPairCacheUpdate time.Time // Alpha token cache alphaTokens map[string]AlphaTokenInfo alphaCacheMutex sync.RWMutex lastAlphaCacheUpdate time.Time // Binance REST clients spotClient *binance.Client futuresClient *futures.Client } func NewMarketData() *MarketData { log.Info().Msg("Start market service") ms := &MarketData{ spotPairs: make(map[string]bool), futuresPairs: make(map[string]bool), alphaTokens: make(map[string]AlphaTokenInfo), spotClient: binance.NewClient("", ""), futuresClient: futures.NewClient("", ""), } if err := ms.refreshTradingPairCache(); err != nil { log.Error().Err(err).Msg("Failed initial trading pair cache load") } go ms.pairCacheRefreshLoop() 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() } }