Skip to content

Commit

Permalink
style: fix PnLEmojiMargin
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Nov 15, 2024
1 parent 02151af commit 8922ed7
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions pkg/style/pnl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package style

import (
"strings"

"github.com/c9s/bbgo/pkg/fixedpoint"
)

Expand All @@ -27,40 +29,32 @@ func PnLSignString(pnl fixedpoint.Value) string {
}

func PnLEmojiSimple(pnl fixedpoint.Value) string {
if pnl.Sign() < 0 {
return LossEmoji
}

if pnl.IsZero() {
return ""
}

return ProfitEmoji
if pnl.Sign() < 0 {
return LossEmoji
} else {
return ProfitEmoji
}
}

func PnLEmojiMargin(pnl, margin, resolution fixedpoint.Value) (out string) {
// PnLEmojiMargin returns the emoji representation of the PnL with margin and resolution
func PnLEmojiMargin(pnl, margin, resolution fixedpoint.Value) string {
if margin.IsZero() {
return PnLEmojiSimple(pnl)
}

if pnl.Sign() < 0 {
out = LossEmoji
level := max((margin.Neg()).Div(resolution).Int(), MaxEmojiRepeat)
for i := 1; i < level; i++ {
out += LossEmoji
}
return out
}

if pnl.IsZero() {
return out
return ""
}

out = ProfitEmoji
level := max(margin.Div(resolution).Int(), MaxEmojiRepeat)
for i := 1; i < level; i++ {
out += ProfitEmoji
if pnl.Sign() < 0 {
level := min((margin.Neg()).Div(resolution).Int(), MaxEmojiRepeat)
return strings.Repeat(LossEmoji, level)
}

return out
level := min(margin.Div(resolution).Int(), MaxEmojiRepeat)
return strings.Repeat(ProfitEmoji, level)
}

0 comments on commit 8922ed7

Please sign in to comment.