A self-hosted dashboard that puts all your feeds in one place
Go aggregatordashboarddockerfeed-readergohomelabhomepagemonitoringredditrssrss-readerself-hostedstartpageyoutube
Fix markets price precision
Svilen Markovbd020c93f59f
diff --git a/internal/glance/templates.go b/internal/glance/templates.goindex ec8d0f3..699772d 100644--- a/internal/glance/templates.go+++ b/internal/glance/templates.go@@ -27,6 +27,9 @@ var globalTemplateFunctions = template.FuncMap{"formatPrice": func(price float64) string {return intl.Sprintf("%.2f", price)},+ "formatPriceWithPrecision": func(precision int, price float64) string {+ return intl.Sprintf("%."+strconv.Itoa(precision)+"f", price)+ },"dynamicRelativeTimeAttrs": dynamicRelativeTimeAttrs,"formatServerMegabytes": func(mb uint64) template.HTML {var value stringdiff --git a/internal/glance/templates/markets.html b/internal/glance/templates/markets.htmlindex a979321..cd8da49 100644--- a/internal/glance/templates/markets.html+++ b/internal/glance/templates/markets.html@@ -17,7 +17,7 @@<div class="market-values shrink-0"><div class="size-h3 text-right {{ if eq .PercentChange 0.0 }}{{ else if gt .PercentChange 0.0 }}color-positive{{ else }}color-negative{{ end }}">{{ printf "%+.2f" .PercentChange }}%</div>- <div class="text-right">{{ .Currency }}{{ .Price | formatPrice }}</div>+ <div class="text-right">{{ .Currency }}{{ .Price | formatPriceWithPrecision .PriceHint }}</div></div></div>{{ end }}diff --git a/internal/glance/widget-markets.go b/internal/glance/widget-markets.goindex a3bb325..b53b10a 100644--- a/internal/glance/widget-markets.go+++ b/internal/glance/widget-markets.go@@ -79,6 +79,7 @@ type market struct {Name stringCurrency stringPrice float64+ PriceHint intPercentChange float64SvgChartPoints string}@@ -106,6 +107,7 @@ type marketResponseJson struct {RegularMarketPrice float64 `json:"regularMarketPrice"`ChartPreviousClose float64 `json:"chartPreviousClose"`ShortName string `json:"shortName"`+ PriceHint int `json:"priceHint"`} `json:"meta"`Indicators struct {Quote []struct {@@ -152,13 +154,14 @@ func fetchMarketsDataFromYahoo(marketRequests []marketRequest) (marketList, errocontinue}- prices := response.Chart.Result[0].Indicators.Quote[0].Close+ result := &response.Chart.Result[0]+ prices := result.Indicators.Quote[0].Closeif len(prices) > marketChartDays {prices = prices[len(prices)-marketChartDays:]}- previous := response.Chart.Result[0].Meta.RegularMarketPrice+ previous := result.Meta.RegularMarketPriceif len(prices) >= 2 && prices[len(prices)-2] != 0 {previous = prices[len(prices)-2]@@ -166,21 +169,22 @@ func fetchMarketsDataFromYahoo(marketRequests []marketRequest) (marketList, erropoints := svgPolylineCoordsFromYValues(100, 50, maybeCopySliceWithoutZeroValues(prices))- currency, exists := currencyToSymbol[strings.ToUpper(response.Chart.Result[0].Meta.Currency)]+ currency, exists := currencyToSymbol[strings.ToUpper(result.Meta.Currency)]if !exists {- currency = response.Chart.Result[0].Meta.Currency+ currency = result.Meta.Currency}markets = append(markets, market{marketRequest: marketRequests[i],- Price: response.Chart.Result[0].Meta.RegularMarketPrice,+ Price: result.Meta.RegularMarketPrice,Currency: currency,+ PriceHint: result.Meta.PriceHint,Name: ternary(marketRequests[i].CustomName == "",- response.Chart.Result[0].Meta.ShortName,+ result.Meta.ShortName,marketRequests[i].CustomName,),PercentChange: percentChange(- response.Chart.Result[0].Meta.RegularMarketPrice,+ result.Meta.RegularMarketPrice,previous,),SvgChartPoints: points,