mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
configure notifier and make slack notification optional
This commit is contained in:
parent
ac0a26b005
commit
931c646fde
|
@ -23,14 +23,22 @@ func (m *Notifiability) AddNotifier(notifier Notifier) {
|
||||||
m.notifiers = append(m.notifiers, notifier)
|
m.notifiers = append(m.notifiers, notifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Notifiability) Notify(msg string, args ...interface{}) {
|
func (m *Notifiability) Notify(msg string, args ...interface{}) (err error) {
|
||||||
for _, n := range m.notifiers {
|
for _, n := range m.notifiers {
|
||||||
n.Notify(msg, args...)
|
if err2 := n.Notify(msg, args...); err2 != nil {
|
||||||
|
err = err2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Notifiability) NotifyTo(channel, msg string, args ...interface{}) {
|
func (m *Notifiability) NotifyTo(channel, msg string, args ...interface{}) (err error) {
|
||||||
for _, n := range m.notifiers {
|
for _, n := range m.notifiers {
|
||||||
n.NotifyTo(channel, msg, args...)
|
if err2 := n.NotifyTo(channel, msg, args...); err2 != nil {
|
||||||
|
err = err2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,14 +67,17 @@ func compileRunFile(filepath string, config *config.Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runConfig(ctx context.Context, config *config.Config) error {
|
func runConfig(ctx context.Context, config *config.Config) error {
|
||||||
|
// configure notifiers
|
||||||
slackToken := viper.GetString("slack-token")
|
slackToken := viper.GetString("slack-token")
|
||||||
if len(slackToken) == 0 {
|
if len(slackToken) > 0 {
|
||||||
return errSlackTokenUndefined
|
log.AddHook(slacklog.NewLogHook(slackToken, viper.GetString("slack-error-channel")))
|
||||||
}
|
}
|
||||||
|
|
||||||
log.AddHook(slacklog.NewLogHook(slackToken, viper.GetString("slack-error-channel")))
|
notifierSet := &bbgo.Notifiability{}
|
||||||
|
if len(slackToken) > 0 {
|
||||||
var notifier = slacknotifier.New(slackToken, viper.GetString("slack-channel"))
|
var notifier = slacknotifier.New(slackToken, viper.GetString("slack-channel"))
|
||||||
|
notifierSet.AddNotifier(notifier)
|
||||||
|
}
|
||||||
|
|
||||||
db, err := cmdutil.ConnectMySQL()
|
db, err := cmdutil.ConnectMySQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -82,9 +85,10 @@ func runConfig(ctx context.Context, config *config.Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
environ := bbgo.NewDefaultEnvironment(db)
|
environ := bbgo.NewDefaultEnvironment(db)
|
||||||
environ.ReportTrade(notifier)
|
environ.ReportTrade(notifierSet)
|
||||||
|
|
||||||
trader := bbgo.NewTrader(environ)
|
trader := bbgo.NewTrader(environ)
|
||||||
|
trader.AddNotifier(notifierSet)
|
||||||
|
|
||||||
for _, entry := range config.ExchangeStrategies {
|
for _, entry := range config.ExchangeStrategies {
|
||||||
for _, mount := range entry.Mounts {
|
for _, mount := range entry.Mounts {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user