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 spotToken2Symbol map[string]string futureToken2Symbol map[string]string 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), spotToken2Symbol: make(map[string]string), futureToken2Symbol: make(map[string]string), alphaTokens: make(map[string]AlphaTokenInfo), spotClient: binance.NewClient("", ""), futuresClient: futures.NewClient("", ""), } ms.refreshAllCaches() go ms.cacheRefreshLoop() return ms } func (ms *MarketData) alphaCacheRefreshLoop() { ms.refreshAlphaTokenCache() ticker := time.NewTicker(time.Hour) defer ticker.Stop() for range ticker.C { ms.refreshAlphaTokenCache() } }