From efca61994982cf5bef5dbfae172dcb2d4c83dcdb Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 11 Jul 2020 13:21:23 +0800 Subject: [PATCH] pull out side type --- types/color.go | 20 +++++++++++++++----- types/order.go | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/types/color.go b/types/color.go index 482c98efe..63ccd71d6 100644 --- a/types/color.go +++ b/types/color.go @@ -1,17 +1,27 @@ package types -import "github.com/adshao/go-binance" - const Green = "#228B22" const Red = "#800000" -func SideToColorName(side binance.SideType) string { - if side == binance.SideTypeBuy { +// SideType define side type of order +type SideType string + +const ( + SideTypeBuy = SideType("BUY") + SideTypeSell = SideType("SELL") +) + +func (side SideType) Color() string { + if side == SideTypeBuy { return Green } - if side == binance.SideTypeSell { + if side == SideTypeSell { return Red } return "#f0f0f0" } + +func SideToColorName(side SideType) string { + return side.Color() +} diff --git a/types/order.go b/types/order.go index 8e050a42b..81e6e0153 100644 --- a/types/order.go +++ b/types/order.go @@ -27,7 +27,7 @@ func (o *Order) SlackAttachment() slack.Attachment { } return slack.Attachment{ - Color: SideToColorName(o.Side), + Color: SideToColorName(SideType(o.Side)), Title: string(o.Type) + " Order " + string(o.Side), // Text: "", Fields: fields,