From 8af2f2f83faf9365f8263d9474f9bd6ce7760343 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 19 Jul 2022 16:59:56 +0800 Subject: [PATCH] add defaulter interface --- pkg/bbgo/trader.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/bbgo/trader.go b/pkg/bbgo/trader.go index e8cbc13ed..57dcca7f4 100644 --- a/pkg/bbgo/trader.go +++ b/pkg/bbgo/trader.go @@ -24,10 +24,15 @@ type SingleExchangeStrategy interface { Run(ctx context.Context, orderExecutor OrderExecutor, session *ExchangeSession) error } +// StrategyInitializer's Initialize method is called before the Subscribe method call. type StrategyInitializer interface { Initialize() error } +type StrategyDefaulter interface { + Defaults() error +} + // ExchangeSessionSubscriber provides an interface for collecting subscriptions from different strategies // Subscribe method will be called before the user data stream connection is created. type ExchangeSessionSubscriber interface { @@ -153,6 +158,12 @@ func (trader *Trader) Subscribe() { for sessionName, strategies := range trader.exchangeStrategies { session := trader.environment.sessions[sessionName] for _, strategy := range strategies { + if defaulter, ok := strategy.(StrategyDefaulter) ; ok { + if err := defaulter.Defaults(); err != nil { + panic(err) + } + } + if initializer, ok := strategy.(StrategyInitializer); ok { if err := initializer.Initialize(); err != nil { panic(err)