mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
separate Run and CrossRun
so that we mount one strategy as cross strategy or single exchange strategy
This commit is contained in:
parent
d60a82256d
commit
ef03c0cf20
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user