2020-06-18 10:56:54 +00:00
|
|
|
package bbgo
|
|
|
|
|
2020-06-19 01:30:27 +00:00
|
|
|
import (
|
|
|
|
"github.com/adshao/go-binance"
|
|
|
|
"github.com/slack-go/slack"
|
|
|
|
)
|
|
|
|
|
|
|
|
const Green = "#228B22"
|
|
|
|
const Red = "#800000"
|
2020-06-18 10:56:54 +00:00
|
|
|
|
|
|
|
type Order struct {
|
|
|
|
Symbol string
|
|
|
|
Side binance.SideType
|
|
|
|
Type binance.OrderType
|
|
|
|
VolumeStr string
|
|
|
|
PriceStr string
|
|
|
|
|
|
|
|
TimeInForce binance.TimeInForceType
|
|
|
|
}
|
|
|
|
|
2020-06-19 01:30:27 +00:00
|
|
|
func (o *Order) SlackAttachment() slack.Attachment {
|
2020-06-19 01:32:57 +00:00
|
|
|
var fields = []slack.AttachmentField{
|
|
|
|
{Title: "Symbol", Value: o.Symbol, Short: true},
|
|
|
|
{Title: "Side", Value: string(o.Side), Short: true},
|
|
|
|
{Title: "Volume", Value: o.VolumeStr, Short: true},
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(o.PriceStr) > 0 {
|
|
|
|
fields = append(fields, slack.AttachmentField{Title: "Price", Value: o.PriceStr, Short: true})
|
|
|
|
}
|
|
|
|
|
2020-06-19 01:30:27 +00:00
|
|
|
return slack.Attachment{
|
|
|
|
Color: SideToColorName(o.Side),
|
2020-06-19 01:32:57 +00:00
|
|
|
Title: string(o.Type) + " Order " + string(o.Side),
|
2020-06-19 01:30:27 +00:00
|
|
|
// Text: "",
|
2020-06-19 01:32:57 +00:00
|
|
|
Fields: fields,
|
2020-06-19 01:30:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func SideToColorName(side binance.SideType) string {
|
|
|
|
if side == binance.SideTypeBuy {
|
|
|
|
return Green
|
|
|
|
}
|
|
|
|
if side == binance.SideTypeSell {
|
|
|
|
return Red
|
|
|
|
}
|
|
|
|
|
|
|
|
return "#f0f0f0"
|
|
|
|
}
|