mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add basic notification switch
This commit is contained in:
parent
75b61ea285
commit
4387b078c0
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user