Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Aug 28, 2023
1 parent c38f3ab commit 47a962c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions client/core/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ func (ord *OrderReader) SimpleRateString() string {
func (ord *OrderReader) RateString() string {
rateStr := ord.formatRate(ord.Rate)
if ord.Type == order.MarketOrderType {
nMatches := len(ord.Matches)
if nMatches == 0 {
return "market" // "market" is better than 0 BTC/ETH ?
}
rateStr = ord.AverageRateString()
if len(ord.Matches) > 1 {
rateStr = "~ " + rateStr // "~" only makes sense if the order has more than one match.
} else {
return "market" // "market" is better than 0 BTC/ETH ?
}
}
return fmt.Sprintf("%s %s/%s", rateStr, ord.QuoteSymbol, ord.BaseSymbol)
Expand All @@ -333,17 +335,15 @@ func (ord *OrderReader) RateString() string {
// AverageRateString returns a formatting string containing the average rate of
// the matches that have been filled in an order.
func (ord *OrderReader) AverageRateString() string {
nMatch := len(ord.Matches)
if nMatch == 0 {
if len(ord.Matches) == 0 {
return "0"
}
var baseQty, rateProduct uint64
for _, match := range ord.Matches {
baseQty += match.Qty
rateProduct += match.Rate * match.Qty // order ~ 1e16
}
rateStr := ord.formatRate(rateProduct / baseQty)
return rateStr
return ord.formatRate(rateProduct / baseQty)
}

// SwapFeesString is a formatted string of the paid swap fees.
Expand Down

0 comments on commit 47a962c

Please sign in to comment.