From b067d67eab27e5c0d109f0c6700dec4d20bb4948 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 19 Sep 2022 19:22:08 +0800 Subject: [PATCH] bbgo: drop legacy notification routing --- pkg/bbgo/config.go | 8 +-- pkg/bbgo/config_test.go | 7 -- pkg/bbgo/environment.go | 150 +--------------------------------------- 3 files changed, 2 insertions(+), 163 deletions(-) diff --git a/pkg/bbgo/config.go b/pkg/bbgo/config.go index d5164962e..d0feae563 100644 --- a/pkg/bbgo/config.go +++ b/pkg/bbgo/config.go @@ -77,14 +77,8 @@ type TelegramNotification struct { } type NotificationConfig struct { - Slack *SlackNotification `json:"slack,omitempty" yaml:"slack,omitempty"` - + Slack *SlackNotification `json:"slack,omitempty" yaml:"slack,omitempty"` Telegram *TelegramNotification `json:"telegram,omitempty" yaml:"telegram,omitempty"` - - SymbolChannels map[string]string `json:"symbolChannels,omitempty" yaml:"symbolChannels,omitempty"` - SessionChannels map[string]string `json:"sessionChannels,omitempty" yaml:"sessionChannels,omitempty"` - - Routing *SlackNotificationRouting `json:"routing,omitempty" yaml:"routing,omitempty"` } type Session struct { diff --git a/pkg/bbgo/config_test.go b/pkg/bbgo/config_test.go index 74d13ca66..2598a52fc 100644 --- a/pkg/bbgo/config_test.go +++ b/pkg/bbgo/config_test.go @@ -48,13 +48,6 @@ func TestLoadConfig(t *testing.T) { wantErr: false, f: func(t *testing.T, config *Config) { assert.NotNil(t, config.Notifications) - assert.NotNil(t, config.Notifications.SessionChannels) - assert.NotNil(t, config.Notifications.SymbolChannels) - assert.Equal(t, map[string]string{ - "^BTC": "#btc", - "^ETH": "#eth", - }, config.Notifications.SymbolChannels) - assert.NotNil(t, config.Notifications.Routing) assert.Equal(t, "#dev-bbgo", config.Notifications.Slack.DefaultChannel) assert.Equal(t, "#error", config.Notifications.Slack.ErrorChannel) }, diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index 639a7fbe7..14c214df7 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -30,7 +30,6 @@ import ( "github.com/c9s/bbgo/pkg/slack/slacklog" "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/util" - "github.com/c9s/bbgo/pkg/util/templateutil" ) func init() { @@ -306,146 +305,6 @@ func (environ *Environment) ConfigurePersistence(conf *PersistenceConfig) error // for symbol-based routes, we should register the same symbol rules for each session. // for session-based routes, we should set the fixed callbacks for each session func (environ *Environment) ConfigureNotificationRouting(conf *NotificationConfig) error { - // configure routing here - if conf.SymbolChannels != nil { - Notification.SymbolChannelRouter.AddRoute(conf.SymbolChannels) - } - if conf.SessionChannels != nil { - Notification.SessionChannelRouter.AddRoute(conf.SessionChannels) - } - if conf.Routing != nil { - // configure passive object notification routing - switch conf.Routing.Trade { - case "$silent": // silent, do not setup notification - - case "$session": - defaultTradeUpdateHandler := func(trade types.Trade) { - Notify(&trade) - } - for name := range environ.sessions { - session := environ.sessions[name] - - // if we can route session name to channel successfully... - channel, ok := Notification.SessionChannelRouter.Route(name) - if ok { - session.UserDataStream.OnTradeUpdate(func(trade types.Trade) { - Notification.NotifyTo(channel, &trade) - }) - } else { - session.UserDataStream.OnTradeUpdate(defaultTradeUpdateHandler) - } - } - - case "$symbol": - // configure object routes for Trade - Notification.ObjectChannelRouter.Route(func(obj interface{}) (channel string, ok bool) { - trade, matched := obj.(*types.Trade) - if !matched { - return - } - channel, ok = Notification.SymbolChannelRouter.Route(trade.Symbol) - return - }) - - // use same handler for each session - handler := func(trade types.Trade) { - channel, ok := Notification.RouteObject(&trade) - if ok { - NotifyTo(channel, &trade) - } else { - Notify(&trade) - } - } - for _, session := range environ.sessions { - session.UserDataStream.OnTradeUpdate(handler) - } - } - - switch conf.Routing.Order { - - case "$silent": // silent, do not setup notification - - case "$session": - defaultOrderUpdateHandler := func(order types.Order) { - text := templateutil.Render(TemplateOrderReport, order) - Notify(text, &order) - } - for name := range environ.sessions { - session := environ.sessions[name] - - // if we can route session name to channel successfully... - channel, ok := Notification.SessionChannelRouter.Route(name) - if ok { - session.UserDataStream.OnOrderUpdate(func(order types.Order) { - text := templateutil.Render(TemplateOrderReport, order) - NotifyTo(channel, text, &order) - }) - } else { - session.UserDataStream.OnOrderUpdate(defaultOrderUpdateHandler) - } - } - - case "$symbol": - // add object route - Notification.ObjectChannelRouter.Route(func(obj interface{}) (channel string, ok bool) { - order, matched := obj.(*types.Order) - if !matched { - return - } - channel, ok = Notification.SymbolChannelRouter.Route(order.Symbol) - return - }) - - // use same handler for each session - handler := func(order types.Order) { - text := templateutil.Render(TemplateOrderReport, order) - channel, ok := Notification.RouteObject(&order) - if ok { - NotifyTo(channel, text, &order) - } else { - Notify(text, &order) - } - } - for _, session := range environ.sessions { - session.UserDataStream.OnOrderUpdate(handler) - } - } - - switch conf.Routing.SubmitOrder { - - case "$silent": // silent, do not setup notification - - case "$symbol": - // add object route - Notification.ObjectChannelRouter.Route(func(obj interface{}) (channel string, ok bool) { - order, matched := obj.(*types.SubmitOrder) - if !matched { - return - } - - channel, ok = Notification.SymbolChannelRouter.Route(order.Symbol) - return - }) - - } - - // currently, not used - // FIXME: this is causing cyclic import - /* - switch conf.Routing.PnL { - case "$symbol": - environ.ObjectChannelRouter.Route(func(obj interface{}) (channel string, ok bool) { - report, matched := obj.(*pnl.AverageCostPnlReport) - if !matched { - return - } - channel, ok = environ.SymbolChannelRouter.Route(report.Symbol) - return - }) - } - */ - - } return nil } @@ -773,16 +632,9 @@ func (environ *Environment) syncSession(ctx context.Context, session *ExchangeSe } func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) error { - // setup default notification config if userConfig.Notifications == nil { - userConfig.Notifications = &NotificationConfig{ - Routing: &SlackNotificationRouting{ - Trade: "$session", - Order: "$silent", - SubmitOrder: "$silent", - }, - } + userConfig.Notifications = &NotificationConfig{} } var persistence = PersistenceServiceFacade.Get()