diff --git a/fiat/coingecko.go b/fiat/coingecko.go index 2b0592e3..5b5789a4 100644 --- a/fiat/coingecko.go +++ b/fiat/coingecko.go @@ -105,7 +105,7 @@ func (cg *Coingecko) makeReq(url string) ([]byte, error) { return nil, err } // if there is a throttling error, wait 60 seconds and retry - glog.Errorf("Coingecko makeReq %v error %v, will retry in 60 seconds", url, err) + glog.Warningf("Coingecko makeReq %v error %v, will retry in 60 seconds", url, err) time.Sleep(60 * time.Second) } } diff --git a/fiat/fiat_rates.go b/fiat/fiat_rates.go index f7a4ac36..a920cb19 100644 --- a/fiat/fiat_rates.go +++ b/fiat/fiat_rates.go @@ -95,7 +95,9 @@ func (rd *RatesDownloader) Run() error { rd.callbackOnNewTicker(tickers) } } - if time.Now().UTC().YearDay() != lastHistoricalTickers.YearDay() || time.Now().UTC().Year() != lastHistoricalTickers.Year() { + now := time.Now().UTC() + // once a day, 1 hour after UTC midnight (to let the provider prepare historical rates) update historical tickers + if (now.YearDay() != lastHistoricalTickers.YearDay() || now.Year() != lastHistoricalTickers.Year()) && now.Hour() > 0 { err = rd.downloader.UpdateHistoricalTickers() if err != nil { glog.Error("FiatRatesDownloader: UpdateHistoricalTickers error ", err) @@ -127,10 +129,10 @@ func (rd *RatesDownloader) Run() error { } } // wait for the next run with a slight random value to avoid too many request at the same time - now := time.Now().Unix() - next := now + rd.periodSeconds + unix := time.Now().Unix() + next := unix + rd.periodSeconds next -= next % rd.periodSeconds next += int64(rand.Intn(12)) - time.Sleep(time.Duration(next-now) * time.Second) + time.Sleep(time.Duration(next-unix) * time.Second) } }