improve kline attachment display

This commit is contained in:
c9s 2020-08-06 12:51:48 +08:00
parent 80f50ecb19
commit fc82f446f5

View File

@ -157,7 +157,7 @@ func (k KLine) Color() string {
func (k KLine) SlackAttachment() slack.Attachment {
return slack.Attachment{
Text: "KLine",
Text: fmt.Sprintf("KLine %s %s", k.Symbol, k.Interval),
Color: k.Color(),
Fields: []slack.AttachmentField{
{
@ -165,11 +165,6 @@ func (k KLine) SlackAttachment() slack.Attachment {
Value: k.Open,
Short: true,
},
{
Title: "Close",
Value: k.Close,
Short: true,
},
{
Title: "High",
Value: k.High,
@ -180,6 +175,11 @@ func (k KLine) SlackAttachment() slack.Attachment {
Value: k.Low,
Short: true,
},
{
Title: "Close",
Value: k.Close,
Short: true,
},
{
Title: "Mid",
Value: util.FormatFloat(k.Mid(), 2),
@ -379,8 +379,14 @@ func (k KLineWindow) GetLowerShadowHeight() float64 {
}
func (k KLineWindow) SlackAttachment() slack.Attachment {
var first KLine
var windowSize = len(k)
if windowSize > 0 {
first = k[0]
}
return slack.Attachment{
Text: "KLine",
Text: fmt.Sprintf("KLine %s %s x %d", first.Symbol, first.Interval, windowSize),
Color: k.Color(),
Fields: []slack.AttachmentField{
{
@ -388,11 +394,6 @@ func (k KLineWindow) SlackAttachment() slack.Attachment {
Value: util.FormatFloat(k.GetOpen(), 2),
Short: true,
},
{
Title: "Close",
Value: util.FormatFloat(k.GetClose(), 2),
Short: true,
},
{
Title: "High",
Value: util.FormatFloat(k.GetHigh(), 2),
@ -403,6 +404,11 @@ func (k KLineWindow) SlackAttachment() slack.Attachment {
Value: util.FormatFloat(k.GetLow(), 2),
Short: true,
},
{
Title: "Close",
Value: util.FormatFloat(k.GetClose(), 2),
Short: true,
},
{
Title: "Mid",
Value: util.FormatFloat(k.Mid(), 2),