bbgo: add basic notification switch

This commit is contained in:
c9s 2022-09-19 19:28:29 +08:00
parent 75b61ea285
commit 4387b078c0
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -301,13 +301,6 @@ func (environ *Environment) ConfigurePersistence(conf *PersistenceConfig) error
return nil
}
// ConfigureNotificationRouting configures the notification rules
// 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 {
return nil
}
func (environ *Environment) SetStartTime(t time.Time) *Environment {
environ.startTime = t
return environ
@ -659,7 +652,7 @@ func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) erro
}
if userConfig.Notifications != nil {
if err := environ.ConfigureNotificationRouting(userConfig.Notifications); err != nil {
if err := environ.ConfigureNotification(userConfig.Notifications); err != nil {
return err
}
}
@ -667,6 +660,32 @@ func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) erro
return nil
}
func (environ *Environment) ConfigureNotification(config *NotificationConfig) error {
if config.Switches != nil {
if config.Switches.Trade {
tradeHandler := func(trade types.Trade) {
Notify(trade)
}
for _, session := range environ.sessions {
session.UserDataStream.OnTradeUpdate(tradeHandler)
}
}
if config.Switches.OrderUpdate {
orderUpdateHandler := func(order types.Order) {
Notify(order)
}
for _, session := range environ.sessions {
session.UserDataStream.OnOrderUpdate(orderUpdateHandler)
}
}
}
return nil
}
// getAuthStoreID returns the authentication store id
// if telegram bot token is defined, the bot id will be used.
// if not, env var $USER will be used.