From 942eaac65994f4b167072438695541b2bef085f4 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 16 May 2021 00:45:08 +0800 Subject: [PATCH] improve message formatting --- pkg/bbgo/position.go | 7 ++++++- pkg/strategy/xbalance/strategy.go | 11 ++++++++--- pkg/types/order.go | 8 +++++--- pkg/types/trade.go | 9 ++++++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/pkg/bbgo/position.go b/pkg/bbgo/position.go index 2bb5b258e..e27d09e9c 100644 --- a/pkg/bbgo/position.go +++ b/pkg/bbgo/position.go @@ -55,7 +55,12 @@ func (p *Position) SlackAttachment() slack.Attachment { } func (p *Position) PlainText() string { - return p.String() + return fmt.Sprintf("Position %s: average cost = %f, base = %f, quote = %f", + p.Symbol, + p.AverageCost.Float64(), + p.Base.Float64(), + p.Quote.Float64(), + ) } func (p *Position) String() string { diff --git a/pkg/strategy/xbalance/strategy.go b/pkg/strategy/xbalance/strategy.go index b443431da..56c881512 100644 --- a/pkg/strategy/xbalance/strategy.go +++ b/pkg/strategy/xbalance/strategy.go @@ -75,7 +75,12 @@ func (r *WithdrawalRequest) String() string { } func (r *WithdrawalRequest) PlainText() string { - return r.String() + return fmt.Sprintf("Withdrawal request: sending %s %s from %s -> %s", + util.FormatFloat(r.Amount.Float64(), 4), + r.Asset, + r.FromSession, + r.ToSession, + ) } func (r *WithdrawalRequest) SlackAttachment() slack.Attachment { @@ -140,7 +145,7 @@ func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.E return } - s.Notifiability.Notify("Found low level %s balance %s", s.Asset, lowLevelBalance.String()) + s.Notifiability.Notify("Found low level %s balance from session %s: %s", s.Asset, lowLevelSession.Name, lowLevelBalance.String()) requiredAmount := s.Middle - lowLevelBalance.Available @@ -273,7 +278,7 @@ func (s *Strategy) LoadState() error { s.state = &state log.Infof("%s %s state is restored: %+v", ID, s.Asset, s.state) - s.Notifiability.Notify("%s %s state is restored => %f", ID, s.Asset, s.state) + s.Notifiability.Notify("%s %s state is restored => ", ID, s.Asset, s.state) } return nil diff --git a/pkg/types/order.go b/pkg/types/order.go index f9f50ee8f..009facb4d 100644 --- a/pkg/types/order.go +++ b/pkg/types/order.go @@ -172,13 +172,15 @@ func (o Order) String() string { return fmt.Sprintf("ORDER %s %s %s %f/%f @ %f -> %s", o.Exchange, o.Symbol, o.Side, o.ExecutedQuantity, o.Quantity, o.Price, o.Status) } +// PlainText is used for telegram-styled messages func (o Order) PlainText() string { - return fmt.Sprintf("%s %s Order %s %s price %s, quantity %s/%s status %s", + return fmt.Sprintf("Order %s %s %s %s @ %s %s/%s -> %s", o.Exchange, - o.Type, o.Symbol, + o.Type, o.Side, util.FormatFloat(o.Price, 2), util.FormatFloat(o.ExecutedQuantity, 2), - util.FormatFloat(o.Quantity, 4), o.Status) + util.FormatFloat(o.Quantity, 4), + o.Status) } diff --git a/pkg/types/trade.go b/pkg/types/trade.go index cc33d664e..355153334 100644 --- a/pkg/types/trade.go +++ b/pkg/types/trade.go @@ -81,8 +81,15 @@ func (trade Trade) String() string { util.FormatFloat(trade.QuoteQuantity, 2)) } +// PlainText is used for telegram-styled messages func (trade Trade) PlainText() string { - return trade.String() + return fmt.Sprintf("Trade %s %s %s %s @ %s, amount %s", + trade.Exchange, + trade.Symbol, + trade.Side, + util.FormatFloat(trade.Quantity, 4), + util.FormatFloat(trade.Price, 3), + util.FormatFloat(trade.QuoteQuantity, 2)) } var slackTradeTextTemplate = ":handshake: {{ .Symbol }} {{ .Side }} Trade Execution @ {{ .Price }}"