mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
add defaulter interface
This commit is contained in:
parent
808ba2fc02
commit
8af2f2f83f
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user