fix import sorting

This commit is contained in:
c9s 2020-08-11 08:41:01 +08:00
parent e2fef7b6d2
commit b02c2ae16c

View File

@ -3,11 +3,13 @@ package bbgo
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/c9s/bbgo/pkg/bbgo/types" "time"
"github.com/c9s/bbgo/pkg/util"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/slack-go/slack" "github.com/slack-go/slack"
"time"
"github.com/c9s/bbgo/pkg/bbgo/types"
"github.com/c9s/bbgo/pkg/util"
) )
type Notifier interface { type Notifier interface {
@ -31,7 +33,7 @@ type SlackNotifier struct {
InfoChannel string InfoChannel string
} }
func (t *SlackNotifier) Notify(format string, args ...interface{}) { func (n *SlackNotifier) Notify(format string, args ...interface{}) {
var slackAttachments []slack.Attachment var slackAttachments []slack.Attachment
var slackArgsOffset = -1 var slackArgsOffset = -1
@ -63,7 +65,7 @@ func (t *SlackNotifier) Notify(format string, args ...interface{}) {
logrus.Infof(format, nonSlackArgs...) logrus.Infof(format, nonSlackArgs...)
_, _, err := t.Slack.PostMessageContext(context.Background(), t.InfoChannel, _, _, err := n.Slack.PostMessageContext(context.Background(), n.InfoChannel,
slack.MsgOptionText(fmt.Sprintf(format, nonSlackArgs...), true), slack.MsgOptionText(fmt.Sprintf(format, nonSlackArgs...), true),
slack.MsgOptionAttachments(slackAttachments...)) slack.MsgOptionAttachments(slackAttachments...))
if err != nil { if err != nil {
@ -71,8 +73,8 @@ func (t *SlackNotifier) Notify(format string, args ...interface{}) {
} }
} }
func (t *SlackNotifier) ReportTrade(trade *types.Trade) { func (n *SlackNotifier) ReportTrade(trade *types.Trade) {
_, _, err := t.Slack.PostMessageContext(context.Background(), t.TradingChannel, _, _, err := n.Slack.PostMessageContext(context.Background(), n.TradingChannel,
slack.MsgOptionText(util.Render(`:handshake: {{ .Symbol }} {{ .Side }} Trade Execution @ {{ .Price }}`, trade), true), slack.MsgOptionText(util.Render(`:handshake: {{ .Symbol }} {{ .Side }} Trade Execution @ {{ .Price }}`, trade), true),
slack.MsgOptionAttachments(trade.SlackAttachment())) slack.MsgOptionAttachments(trade.SlackAttachment()))
@ -81,10 +83,10 @@ func (t *SlackNotifier) ReportTrade(trade *types.Trade) {
} }
} }
func (t *SlackNotifier) ReportPnL(report *ProfitAndLossReport) { func (n *SlackNotifier) ReportPnL(report *ProfitAndLossReport) {
attachment := report.SlackAttachment() attachment := report.SlackAttachment()
_, _, err := t.Slack.PostMessageContext(context.Background(), t.TradingChannel, _, _, err := n.Slack.PostMessageContext(context.Background(), n.TradingChannel,
slack.MsgOptionText(util.Render( slack.MsgOptionText(util.Render(
`:heavy_dollar_sign: Here is your *{{ .symbol }}* PnL report collected since *{{ .startTime }}*`, `:heavy_dollar_sign: Here is your *{{ .symbol }}* PnL report collected since *{{ .startTime }}*`,
map[string]interface{}{ map[string]interface{}{
@ -97,3 +99,13 @@ func (t *SlackNotifier) ReportPnL(report *ProfitAndLossReport) {
logrus.WithError(err).Errorf("slack send error") logrus.WithError(err).Errorf("slack send error")
} }
} }
type SlackInteraction struct {
Client *slack.Client
Trader *Trader
TradingContext *TradingContext
}
func (i *SlackInteraction) Connect() {
}