Skip to content

Commit

Permalink
fix: yahoo v10 broke, use v6 (#202)
Browse files Browse the repository at this point in the history
* fix: yahoo v10 broke, use v6

* fix goreleaser?

* list
  • Loading branch information
rssnyder authored Jul 23, 2023
1 parent da97cf6 commit a1048a8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
bin*
test.sh
load.py
state.db
*.db
discord-stock-ticker
test.state
*.state
dist/
5 changes: 3 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ builds:
- goos: windows
goarch: 386
archives:
- replacements:
386: i386
- format_overrides:
- goos: windows
format: zip
changelog:
sort: asc
filters:
Expand Down
28 changes: 28 additions & 0 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion utils/yahoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1048a8

Please sign in to comment.