style: set emoji repeat limit

This commit is contained in:
c9s 2024-11-15 10:49:56 +08:00
parent 838efe8295
commit 70c10cf6f9
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -6,8 +6,12 @@ import (
var LossEmoji = "🔥" var LossEmoji = "🔥"
var ProfitEmoji = "💰" var ProfitEmoji = "💰"
// 0.1% = 10 bps
var DefaultPnLLevelResolution = fixedpoint.NewFromFloat(0.001) var DefaultPnLLevelResolution = fixedpoint.NewFromFloat(0.001)
const MaxEmojiRepeat = 6
func PnLColor(pnl fixedpoint.Value) string { func PnLColor(pnl fixedpoint.Value) string {
if pnl.Sign() > 0 { if pnl.Sign() > 0 {
return GreenColor return GreenColor
@ -41,7 +45,7 @@ func PnLEmojiMargin(pnl, margin, resolution fixedpoint.Value) (out string) {
if pnl.Sign() < 0 { if pnl.Sign() < 0 {
out = LossEmoji out = LossEmoji
level := (margin.Neg()).Div(resolution).Int() level := max((margin.Neg()).Div(resolution).Int(), MaxEmojiRepeat)
for i := 1; i < level; i++ { for i := 1; i < level; i++ {
out += LossEmoji out += LossEmoji
} }
@ -53,9 +57,10 @@ func PnLEmojiMargin(pnl, margin, resolution fixedpoint.Value) (out string) {
} }
out = ProfitEmoji out = ProfitEmoji
level := margin.Div(resolution).Int() level := max(margin.Div(resolution).Int(), MaxEmojiRepeat)
for i := 1; i < level; i++ { for i := 1; i < level; i++ {
out += ProfitEmoji out += ProfitEmoji
} }
return out return out
} }