mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +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
|
Run(ctx context.Context, orderExecutor OrderExecutor, session *ExchangeSession) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StrategyInitializer's Initialize method is called before the Subscribe method call.
|
||||||
type StrategyInitializer interface {
|
type StrategyInitializer interface {
|
||||||
Initialize() error
|
Initialize() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StrategyDefaulter interface {
|
||||||
|
Defaults() error
|
||||||
|
}
|
||||||
|
|
||||||
// ExchangeSessionSubscriber provides an interface for collecting subscriptions from different strategies
|
// ExchangeSessionSubscriber provides an interface for collecting subscriptions from different strategies
|
||||||
// Subscribe method will be called before the user data stream connection is created.
|
// Subscribe method will be called before the user data stream connection is created.
|
||||||
type ExchangeSessionSubscriber interface {
|
type ExchangeSessionSubscriber interface {
|
||||||
|
@ -153,6 +158,12 @@ func (trader *Trader) Subscribe() {
|
||||||
for sessionName, strategies := range trader.exchangeStrategies {
|
for sessionName, strategies := range trader.exchangeStrategies {
|
||||||
session := trader.environment.sessions[sessionName]
|
session := trader.environment.sessions[sessionName]
|
||||||
for _, strategy := range strategies {
|
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 initializer, ok := strategy.(StrategyInitializer); ok {
|
||||||
if err := initializer.Initialize(); err != nil {
|
if err := initializer.Initialize(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user