fix trade slack formatting

This commit is contained in:
c9s 2020-11-17 15:48:18 +08:00
parent 8f5491d818
commit c40982164a
3 changed files with 7 additions and 19 deletions

View File

@ -15,6 +15,7 @@ type AverageCostPnlReport struct {
CurrentPrice float64 CurrentPrice float64
StartTime time.Time StartTime time.Time
Symbol string Symbol string
Market types.Market
NumTrades int NumTrades int
Profit float64 Profit float64
@ -51,11 +52,6 @@ func (report AverageCostPnlReport) SlackAttachment() slack.Attachment {
color = slackstyle.Green color = slackstyle.Green
} }
market, ok := types.FindMarket(report.Symbol)
if !ok {
return slack.Attachment{}
}
return slack.Attachment{ return slack.Attachment{
Title: report.Symbol + " Profit and Loss report", Title: report.Symbol + " Profit and Loss report",
Text: "Profit " + types.USD.FormatMoney(report.Profit), Text: "Profit " + types.USD.FormatMoney(report.Profit),
@ -65,8 +61,8 @@ func (report AverageCostPnlReport) SlackAttachment() slack.Attachment {
Fields: []slack.AttachmentField{ Fields: []slack.AttachmentField{
{Title: "Profit", Value: types.USD.FormatMoney(report.Profit)}, {Title: "Profit", Value: types.USD.FormatMoney(report.Profit)},
{Title: "Unrealized Profit", Value: types.USD.FormatMoney(report.UnrealizedProfit)}, {Title: "Unrealized Profit", Value: types.USD.FormatMoney(report.UnrealizedProfit)},
{Title: "Current Price", Value: market.FormatPrice(report.CurrentPrice), Short: true}, {Title: "Current Price", Value: report.Market.FormatPrice(report.CurrentPrice), Short: true},
{Title: "Average Cost", Value: market.FormatPrice(report.AverageBidCost), Short: true}, {Title: "Average Cost", Value: report.Market.FormatPrice(report.AverageBidCost), Short: true},
{Title: "Fee (USD)", Value: types.USD.FormatMoney(report.FeeInUSD), Short: true}, {Title: "Fee (USD)", Value: types.USD.FormatMoney(report.FeeInUSD), Short: true},
{Title: "Stock", Value: strconv.FormatFloat(report.Stock, 'f', 8, 64), Short: true}, {Title: "Stock", Value: strconv.FormatFloat(report.Stock, 'f', 8, 64), Short: true},
{Title: "Number of Trades", Value: strconv.Itoa(report.NumTrades), Short: true}, {Title: "Number of Trades", Value: strconv.Itoa(report.NumTrades), Short: true},

View File

@ -170,9 +170,9 @@ func convertWebSocketTrade(t max.TradeUpdate) (*types.Trade, error) {
return &types.Trade{ return &types.Trade{
ID: int64(t.ID), ID: int64(t.ID),
OrderID: t.OrderID, OrderID: t.OrderID,
Price: price,
Symbol: toGlobalSymbol(t.Market), Symbol: toGlobalSymbol(t.Market),
Exchange: "max", Exchange: "max",
Price: price,
Quantity: quantity, Quantity: quantity,
Side: side, Side: side,
IsBuyer: side == "bid", IsBuyer: side == "bid",

View File

@ -37,23 +37,15 @@ func (trade Trade) SlackAttachment() slack.Attachment {
color = "#228B22" color = "#228B22"
} }
market, ok := FindMarket(trade.Symbol)
if !ok {
return slack.Attachment{
Text: fmt.Sprintf("*%s* Trade %s", trade.Symbol, trade.Side),
Color: color,
}
}
return slack.Attachment{ return slack.Attachment{
Text: fmt.Sprintf("*%s* Trade %s", trade.Symbol, trade.Side), Text: fmt.Sprintf("*%s* Trade %s", trade.Symbol, trade.Side),
Color: color, Color: color,
// Pretext: "", // Pretext: "",
// Text: "", // Text: "",
Fields: []slack.AttachmentField{ Fields: []slack.AttachmentField{
{Title: "Price", Value: market.FormatPrice(trade.Price), Short: true}, {Title: "Price", Value: util.FormatFloat(trade.Price, 2), Short: true},
{Title: "Volume", Value: market.FormatVolume(trade.Quantity), Short: true}, {Title: "Volume", Value: util.FormatFloat(trade.Quantity, 4), Short: true},
{Title: "Amount", Value: market.FormatPrice(trade.QuoteQuantity)}, {Title: "Amount", Value: util.FormatFloat(trade.QuoteQuantity, 1)},
{Title: "Fee", Value: util.FormatFloat(trade.Fee, 4), Short: true}, {Title: "Fee", Value: util.FormatFloat(trade.Fee, 4), Short: true},
{Title: "FeeCurrency", Value: trade.FeeCurrency, Short: true}, {Title: "FeeCurrency", Value: trade.FeeCurrency, Short: true},
}, },