From e431572dbfd4a2346a175fad552262fbaf834147 Mon Sep 17 00:00:00 2001 From: 0xfatman <0xfatman@proton.me> Date: Sat, 26 Oct 2024 07:09:18 +0100 Subject: [PATCH] update candles faster for bybit and polygon --- store/store.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/store/store.go b/store/store.go index a2e7c45..70ec518 100644 --- a/store/store.go +++ b/store/store.go @@ -227,7 +227,7 @@ func (s *Store) AggregateCandles() { func (s *Store) SyncCandles() { go func() { - for range time.NewTicker(time.Second * 15).C { + for range time.NewTicker(time.Second).C { oldestTimestamp := time.Now().Add(-s.intervals[0].Retention).UnixMilli() for _, config := range s.config { go func() { @@ -236,7 +236,22 @@ func (s *Store) SyncCandles() { candles = s.bybitClient.GetLatestCandles(config.Symbol) } else if config.PriceSource == Polygon { candles = s.polygonClient.GetLatestCandles(config.Symbol) - } else if config.PriceSource == TwelveData { + } + for _, candle := range candles { + candle.MarketId = config.MarketId + if int64(candle.ClosingTimestamp) >= oldestTimestamp { + s.SaveCandle(candle) + } + } + }() + } + } + for range time.NewTicker(time.Second * 15).C { + oldestTimestamp := time.Now().Add(-s.intervals[0].Retention).UnixMilli() + for _, config := range s.config { + go func() { + candles := make([]*data.Candle, 0) + if config.PriceSource == TwelveData { candles = s.twelveDataClient.GetLatestCandles(config.Symbol, config.MicCode) } for _, candle := range candles {