diff --git a/internal/assets/templates/stocks.html b/internal/assets/templates/stocks.html index 2bdb02e..f8ea9b2 100644 --- a/internal/assets/templates/stocks.html +++ b/internal/assets/templates/stocks.html @@ -15,7 +15,7 @@
{{ printf "%+.2f" .PercentChange }}%
-
${{ .Price | formatPrice }}
+
{{ .Currency }}{{ .Price | formatPrice }}
{{ end }} diff --git a/internal/feed/primitives.go b/internal/feed/primitives.go index 7f4f464..99d6763 100644 --- a/internal/feed/primitives.go +++ b/internal/feed/primitives.go @@ -59,9 +59,35 @@ type Video struct { type Videos []Video +var currencyToSymbol = map[string]string{ + "USD": "$", + "EUR": "€", + "JPY": "¥", + "CAD": "C$", + "AUD": "A$", + "GBP": "£", + "CHF": "Fr", + "NZD": "N$", + "INR": "₹", + "BRL": "R$", + "RUB": "₽", + "TRY": "₺", + "ZAR": "R", + "CNY": "¥", + "KRW": "₩", + "HKD": "HK$", + "SGD": "S$", + "SEK": "kr", + "NOK": "kr", + "DKK": "kr", + "PLN": "zł", + "PHP": "₱", +} + type Stock struct { Name string Symbol string + Currency string Price float64 PercentChange float64 SvgChartPoints string diff --git a/internal/feed/yahoo.go b/internal/feed/yahoo.go index 9412665..a8106d7 100644 --- a/internal/feed/yahoo.go +++ b/internal/feed/yahoo.go @@ -10,6 +10,7 @@ type stockResponseJson struct { Chart struct { Result []struct { Meta struct { + Currency string `json:"currency"` Symbol string `json:"symbol"` RegularMarketPrice float64 `json:"regularMarketPrice"` ChartPreviousClose float64 `json:"chartPreviousClose"` @@ -78,10 +79,17 @@ func FetchStocksDataFromYahoo(stockRequests []StockRequest) (Stocks, error) { points := SvgPolylineCoordsFromYValues(100, 50, maybeCopySliceWithoutZeroValues(prices)) + currency, exists := currencyToSymbol[response.Chart.Result[0].Meta.Currency] + + if !exists { + currency = response.Chart.Result[0].Meta.Currency + } + stocks = append(stocks, Stock{ - Name: stockRequests[i].Name, - Symbol: response.Chart.Result[0].Meta.Symbol, - Price: response.Chart.Result[0].Meta.RegularMarketPrice, + Name: stockRequests[i].Name, + Symbol: response.Chart.Result[0].Meta.Symbol, + Price: response.Chart.Result[0].Meta.RegularMarketPrice, + Currency: currency, PercentChange: percentChange( response.Chart.Result[0].Meta.RegularMarketPrice, previous,