mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
style: fix PnLEmojiMargin
This commit is contained in:
parent
02151afc2d
commit
8922ed78bf
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user