style: fix PnLEmojiMargin

This commit is contained in:
c9s 2024-11-15 15:56:17 +08:00
parent 02151afc2d
commit 8922ed78bf
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

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