separate Run and CrossRun

so that we mount one strategy as cross strategy or single exchange strategy
This commit is contained in:
c9s 2020-12-03 09:31:40 +08:00
parent d60a82256d
commit ef03c0cf20
2 changed files with 6 additions and 6 deletions

View File

@ -24,11 +24,11 @@ type ExchangeSessionSubscriber interface {
}
type CrossExchangeSessionSubscriber interface {
Subscribe(sessions map[string]*ExchangeSession)
CrossSubscribe(sessions map[string]*ExchangeSession)
}
type CrossExchangeStrategy interface {
Run(ctx context.Context, orderExecutionRouter OrderExecutionRouter, sessions map[string]*ExchangeSession) error
CrossRun(ctx context.Context, orderExecutionRouter OrderExecutionRouter, sessions map[string]*ExchangeSession) error
}
//go:generate callbackgen -type Graceful
@ -130,7 +130,7 @@ func (trader *Trader) Run(ctx context.Context) error {
for _, strategy := range trader.crossExchangeStrategies {
if subscriber, ok := strategy.(CrossExchangeSessionSubscriber); ok {
subscriber.Subscribe(trader.environment.sessions)
subscriber.CrossSubscribe(trader.environment.sessions)
}
}
@ -250,7 +250,7 @@ func (trader *Trader) Run(ctx context.Context) error {
}
if err := strategy.Run(ctx, router, trader.environment.sessions); err != nil {
if err := strategy.CrossRun(ctx, router, trader.environment.sessions); err != nil {
return err
}
}

View File

@ -63,7 +63,7 @@ type Strategy struct {
order types.Order
}
func (s *Strategy) Subscribe(sessions map[string]*bbgo.ExchangeSession) {
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
sourceSession := sessions[s.SourceExchangeName]
sourceSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval.String()})
sourceSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.MovingAverageInterval.String()})
@ -136,7 +136,7 @@ func (s *Strategy) handleOrderUpdate(order types.Order) {
}
}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession) error {
func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession) error {
// source session
sourceSession := sessions[s.SourceExchangeName]