diff --git a/pkg/style/pnl.go b/pkg/style/pnl.go index 6f5345177..b56cb3316 100644 --- a/pkg/style/pnl.go +++ b/pkg/style/pnl.go @@ -1,6 +1,8 @@ package style import ( + "strings" + "github.com/c9s/bbgo/pkg/fixedpoint" ) @@ -27,40 +29,32 @@ func PnLSignString(pnl fixedpoint.Value) string { } func PnLEmojiSimple(pnl fixedpoint.Value) string { + if pnl.IsZero() { + return "" + } + if pnl.Sign() < 0 { return LossEmoji + } else { + return ProfitEmoji + } +} + +// 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.IsZero() { return "" } - return ProfitEmoji -} - -func PnLEmojiMargin(pnl, margin, resolution fixedpoint.Value) (out 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 + level := min((margin.Neg()).Div(resolution).Int(), MaxEmojiRepeat) + return strings.Repeat(LossEmoji, level) } - if pnl.IsZero() { - return out - } - - out = ProfitEmoji - level := max(margin.Div(resolution).Int(), MaxEmojiRepeat) - for i := 1; i < level; i++ { - out += ProfitEmoji - } - - return out + level := min(margin.Div(resolution).Int(), MaxEmojiRepeat) + return strings.Repeat(ProfitEmoji, level) }