From a1048a82ce396dfa7b8cfab0b3dfb7075c5ff052 Mon Sep 17 00:00:00 2001 From: Riley Snyder Date: Sun, 23 Jul 2023 16:38:08 -0500 Subject: [PATCH] fix: yahoo v10 broke, use v6 (#202) * fix: yahoo v10 broke, use v6 * fix goreleaser? * list --- .gitignore | 4 ++-- .goreleaser.yaml | 5 +++-- manager.go | 28 ++++++++++++++++++++++++++++ ticker.go | 8 +++++++- utils/yahoo.go | 2 +- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b3dcc13..222ebb3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ bin* test.sh load.py -state.db +*.db discord-stock-ticker -test.state +*.state dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 95aebee..0c2b1cf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -35,8 +35,9 @@ builds: - goos: windows goarch: 386 archives: - - replacements: - 386: i386 + - format_overrides: + - goos: windows + format: zip changelog: sort: asc filters: diff --git a/manager.go b/manager.go index ddefe55..4c9290d 100644 --- a/manager.go +++ b/manager.go @@ -83,6 +83,30 @@ var ( Help: "Number of times the cache lacked data", }, ) + yahooHits = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "yahoo_hits", + Help: "Number of times we got data from yahoo", + }, + ) + yahooMisses = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "yahoo_misses", + Help: "Number of times we failed to get data from yahoo", + }, + ) + coingeckoHits = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "coingecko_hits", + Help: "Number of times we got data from coingecko", + }, + ) + coingeckoMisses = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "coingecko_misses", + Help: "Number of times we failed to get data from coingecko", + }, + ) rateLimited = prometheus.NewCounter( prometheus.CounterOpts{ Name: "ratelimited", @@ -212,6 +236,10 @@ func NewManager(address string, dbFile string, count prometheus.Gauge, cache *re prometheus.MustRegister(lastUpdate) prometheus.MustRegister(cacheHits) prometheus.MustRegister(cacheMisses) + prometheus.MustRegister(yahooHits) + prometheus.MustRegister(yahooMisses) + prometheus.MustRegister(coingeckoHits) + prometheus.MustRegister(coingeckoMisses) prometheus.MustRegister(rateLimited) prometheus.MustRegister(updateError) diff --git a/ticker.go b/ticker.go index dcecf4b..de6b729 100644 --- a/ticker.go +++ b/ticker.go @@ -93,11 +93,13 @@ func (s *Ticker) watchStockPrice() { exData, err := utils.GetStockPrice(s.Currency + "=X") if err != nil { logger.Errorf("Unable to fetch exchange rate for %s, default to USD.", s.Currency) + yahooMisses.Inc() } else { if len(exData.QuoteSummary.Results) > 0 { s.Exrate = exData.QuoteSummary.Results[0].Price.RegularMarketPrice.Raw * float64(s.Multiplier) } else { logger.Errorf("Bad exchange rate for %s, default to USD.", s.Currency) + yahooMisses.Inc() } } } @@ -185,13 +187,16 @@ func (s *Ticker) watchStockPrice() { priceData, err := utils.GetStockPrice(s.Ticker) if err != nil { logger.Errorf("Unable to fetch yahoo stock price for %s", s.Name) + yahooMisses.Inc() continue } if len(priceData.QuoteSummary.Results) == 0 { logger.Errorf("Yahoo returned bad data for %s", s.Name) + yahooMisses.Inc() continue } + yahooHits.Inc() fmtPrice = priceData.QuoteSummary.Results[0].Price.RegularMarketPrice.Fmt // Check if conversion is needed @@ -453,10 +458,11 @@ func (s *Ticker) watchCryptoPrice() { if strings.Contains(err.Error(), "rate limited") { rateLimited.Inc() } else { - updateError.Inc() + coingeckoMisses.Inc() } continue } + coingeckoHits.Inc() // Check if conversion is needed if s.Exrate > 1.0 { diff --git a/utils/yahoo.go b/utils/yahoo.go index 7717487..467568c 100644 --- a/utils/yahoo.go +++ b/utils/yahoo.go @@ -8,7 +8,7 @@ import ( ) const ( - YahooURL = "https://query1.finance.yahoo.com/v10/finance/quoteSummary/%s?modules=price" + YahooURL = "https://query1.finance.yahoo.com/v6/finance/quoteSummary/%s?modules=price" ) // The following is the API response yahoo gives