From 648a9f26bc2c45d8af47a12279a0957e2bb6f14b Mon Sep 17 00:00:00 2001 From: Contre Date: Sun, 24 Aug 2025 12:48:13 +0200 Subject: [PATCH 1/3] feat: Add function displayPrice as an ui helper --- src/rest/routes.go | 2 ++ src/rest/ui/parsePrice.go | 26 ++++++++++++++++++++++++++ views/pairCards.html | 24 ++++++++++++------------ 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 src/rest/ui/parsePrice.go 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..de6a493 100644 --- a/views/pairCards.html +++ b/views/pairCards.html @@ -78,20 +78,20 @@

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 +115,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 +144,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 +195,7 @@

- {{ printf "%.7g" .Pair.Calculations.AvgBuyPrice }} + {{ displayPrice .Pair.Calculations.AvgBuyPrice }} {{ .Pair.QuoteAsset.Symbol }} From c57c0eba83b5044d5a3c268caf19a4eb240d996f Mon Sep 17 00:00:00 2001 From: Contre Date: Sun, 24 Aug 2025 12:58:44 +0200 Subject: [PATCH 2/3] feat: Add price on top of current price input --- views/pairCards.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/views/pairCards.html b/views/pairCards.html index de6a493..8abf17a 100644 --- a/views/pairCards.html +++ b/views/pairCards.html @@ -29,7 +29,11 @@

- Current Price + + Current Price ( + {{ .Pair.QuoteAsset.Symbol }} + {{ displayPrice .Pair.Calculations.BasePrice }}) +

{{/* Form targets the main panel now */}}
Date: Sun, 24 Aug 2025 13:22:32 +0200 Subject: [PATCH 3/3] fix: current price spacing --- views/pairCards.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/views/pairCards.html b/views/pairCards.html index 8abf17a..2c074ab 100644 --- a/views/pairCards.html +++ b/views/pairCards.html @@ -30,8 +30,7 @@

- Current Price ( - {{ .Pair.QuoteAsset.Symbol }} + Current Price ({{ .Pair.QuoteAsset.Symbol }} {{ displayPrice .Pair.Calculations.BasePrice }})