diff --git a/src/rest/routes.go b/src/rest/routes.go index 08e1664..d386340 100644 --- a/src/rest/routes.go +++ b/src/rest/routes.go @@ -5,6 +5,7 @@ import ( "controtto/src/app/managing" "controtto/src/app/querying" "controtto/src/app/trading" + "controtto/src/rest/ui" "fmt" "log" @@ -15,6 +16,7 @@ import ( func Run(c *config.Manager, m *managing.Service, q *querying.Service, t *trading.Service) { engine := html.New("./views", ".html") engine.Debug(true) + engine.AddFunc("displayPrice", ui.DisplayPrice) app := fiber.New(fiber.Config{ Views: engine, ErrorHandler: func(c *fiber.Ctx, err error) error { diff --git a/src/rest/ui/parsePrice.go b/src/rest/ui/parsePrice.go new file mode 100644 index 0000000..bcf8bcd --- /dev/null +++ b/src/rest/ui/parsePrice.go @@ -0,0 +1,26 @@ +package ui + +import ( + "fmt" + "strings" +) + +func DisplayPrice(v float64) string { + s := fmt.Sprintf("%.2f", v) + n := len(s) + if n <= 6 { // e.g. 999.99 + return s + } + // Insert commas for thousands + parts := strings.Split(s, ".") + intPart := parts[0] + decPart := parts[1] + var out []byte + for i, c := range intPart { + if i != 0 && (len(intPart)-i)%3 == 0 { + out = append(out, ',') + } + out = append(out, byte(c)) + } + return string(out) + "." + decPart +} diff --git a/views/pairCards.html b/views/pairCards.html index ec49369..2c074ab 100644 --- a/views/pairCards.html +++ b/views/pairCards.html @@ -29,7 +29,10 @@

- Current Price + + Current Price ({{ .Pair.QuoteAsset.Symbol }} + {{ displayPrice .Pair.Calculations.BasePrice }}) + {{/* Form targets the main panel now */}}
Profit / Loss - {{ printf "%.2f" .Pair.Calculations.PNLPercent }}% + {{ displayPrice .Pair.Calculations.PNLPercent }}% {{ if (gt .Pair.Calculations.PNLAmount 0.0) }}
- +{{ printf "%.2f" .Pair.Calculations.PNLAmount }} + +{{ displayPrice .Pair.Calculations.PNLAmount }} {{ .Pair.QuoteAsset.Symbol }}
{{ else }}
- {{ printf "%.2f" .Pair.Calculations.PNLAmount }} + {{ displayPrice .Pair.Calculations.PNLAmount }} {{ .Pair.QuoteAsset.Symbol }} @@ -115,13 +118,13 @@

Holdings

- {{ printf "%.6f" .Pair.Calculations.TotalBase }} + {{ displayPrice .Pair.Calculations.TotalBase }} {{ .Pair.BaseAsset.Symbol }}
- Value: {{ printf "%.2f" .Pair.Calculations.TotalBaseInQuote }} + Value: {{displayPrice .Pair.Calculations.TotalBaseInQuote }} {{ .Pair.QuoteAsset.Symbol }} @@ -144,35 +147,35 @@

{{/* Slightly smaller */}} - {{ printf "%.2f" .Pair.Calculations.TotalFeeInQuote }} + {{ displayPrice .Pair.Calculations.TotalFeeInQuote }} {{ .Pair.QuoteAsset.Symbol }}
- ({{ printf "%.6f" .Pair.Calculations.TotalFeeInBase }} + ({{ displayPrice .Pair.Calculations.TotalFeeInBase }} {{ .Pair.BaseAsset.Symbol }} )
- {{/* Current Value */}} + {{/* Holdings Value */}}
- Current Value + Holdings Value
-
- {{ printf "%.2f" .Pair.Calculations.CurrentBaseAmountInQuote }} + {{ displayPrice .Pair.Calculations.CurrentBaseAmountInQuote }} {{ .Pair.QuoteAsset.Symbol }} @@ -195,7 +198,7 @@

- {{ printf "%.7g" .Pair.Calculations.AvgBuyPrice }} + {{ displayPrice .Pair.Calculations.AvgBuyPrice }} {{ .Pair.QuoteAsset.Symbol }}