mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
render detector as slack attachment
This commit is contained in:
parent
af76a18deb
commit
9380e10468
|
@ -3,7 +3,7 @@ package bbgo
|
|||
import (
|
||||
"context"
|
||||
"github.com/adshao/go-binance"
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ func (e *BinanceExchange) SubmitOrder(ctx context.Context, order Order) error {
|
|||
}
|
||||
|
||||
retOrder, err := req.Do(ctx)
|
||||
logrus.Infof("order created: %+v", retOrder)
|
||||
log.Infof("order created: %+v", retOrder)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ func (e *BinanceExchange) QueryTrades(ctx context.Context, market string, startT
|
|||
|
||||
// trade time
|
||||
tt := time.Unix(0, t.Time*1000000)
|
||||
|
||||
log.Infof("trade: %d %4s Price: % 13s Volume: % 13s %s", t.ID, side, t.Price, t.Quantity, tt)
|
||||
|
||||
price, err := strconv.ParseFloat(t.Price, 64)
|
||||
|
|
|
@ -335,3 +335,7 @@ func formatVolume(val float64) string {
|
|||
return strconv.FormatFloat(val, 'f', 6, 64)
|
||||
}
|
||||
|
||||
|
||||
func formatFloat(val float64, prec int) string {
|
||||
return strconv.FormatFloat(val, 'f', prec, 64)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ import (
|
|||
"fmt"
|
||||
"github.com/adshao/go-binance"
|
||||
"github.com/c9s/bbgo/pkg/bbgo/types"
|
||||
"github.com/slack-go/slack"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const epsilon = 0.00000001
|
||||
|
@ -31,8 +33,61 @@ type KLineDetector struct {
|
|||
Stop bool `json:"stop"`
|
||||
}
|
||||
|
||||
func (d *KLineDetector) String() (name string) {
|
||||
name = fmt.Sprintf("Detector %s (%f < x < %f)", d.Interval, d.MinPriceChange, d.MaxPriceChange)
|
||||
func (d *KLineDetector) SlackAttachment() slack.Attachment {
|
||||
var name = fmt.Sprintf("Detector %s", d.Interval)
|
||||
if d.EnableLookBack {
|
||||
name = fmt.Sprintf("Detector %s x %d", d.Interval, d.LookBackFrames)
|
||||
}
|
||||
|
||||
if NotZero(d.MaxPriceChange) {
|
||||
name += fmt.Sprintf(" MaxPriceChange %.2f ~ %.2f", d.MinPriceChange, d.MaxPriceChange)
|
||||
} else {
|
||||
name += fmt.Sprintf(" MaxPriceChange %.2f ~ NO LIMIT", d.MinPriceChange)
|
||||
}
|
||||
|
||||
var fields []slack.AttachmentField
|
||||
|
||||
if d.EnableMinThickness {
|
||||
fields = append(fields, slack.AttachmentField{
|
||||
Title: "MinThickness",
|
||||
Value: formatFloat(d.MinThickness, 4),
|
||||
Short: true,
|
||||
})
|
||||
}
|
||||
|
||||
if d.EnableMaxShadowRatio {
|
||||
fields = append(fields, slack.AttachmentField{
|
||||
Title: "MaxShadowRatio",
|
||||
Value: formatFloat(d.MaxShadowRatio, 4),
|
||||
Short: true,
|
||||
})
|
||||
}
|
||||
|
||||
if d.EnableLookBack {
|
||||
fields = append(fields, slack.AttachmentField{
|
||||
Title: "LookBackFrames",
|
||||
Value: strconv.Itoa(d.LookBackFrames),
|
||||
Short: true,
|
||||
})
|
||||
}
|
||||
|
||||
return slack.Attachment{
|
||||
Color: "",
|
||||
Fallback: "",
|
||||
ID: 0,
|
||||
Title: name,
|
||||
Pretext: "",
|
||||
Text: "",
|
||||
Fields: fields,
|
||||
Footer: "",
|
||||
FooterIcon: "",
|
||||
Ts: "",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (d *KLineDetector) String() string {
|
||||
var name = fmt.Sprintf("Detector %s (%f < x < %f)", d.Interval, d.MinPriceChange, d.MaxPriceChange)
|
||||
|
||||
if d.EnableMinThickness {
|
||||
name += fmt.Sprintf(" [MinThickness: %f]", d.MinThickness)
|
||||
|
|
Loading…
Reference in New Issue
Block a user