diff --git a/pkg/bbgo/interact.go b/pkg/bbgo/interact.go index d7017575a..d828462e2 100644 --- a/pkg/bbgo/interact.go +++ b/pkg/bbgo/interact.go @@ -24,7 +24,7 @@ type PositionReader interface { type StrategyController interface { SuspendStrategy(ctx context.Context) error ResumeStrategy() error - GetStrategyStatus() bool + GetStrategyStatus() types.StrategyStatus EmergencyStop(ctx context.Context) error } @@ -254,9 +254,9 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { kc.RemoveKeyboard() } - if status { + if status == types.StrategyStatusRunning { reply.Message(fmt.Sprintf("Strategy %s is running.", signature)) - } else { + } else if status == types.StrategyStatusStopped { reply.Message(fmt.Sprintf("Strategy %s is not running.", signature)) } @@ -295,7 +295,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { // Check strategy status before suspend status := controller.GetStrategyStatus() - if !status { + if status != types.StrategyStatusRunning { reply.Message(fmt.Sprintf("Strategy %s is not running.", signature)) return nil } @@ -347,7 +347,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { // Check strategy status before resume status := controller.GetStrategyStatus() - if status { + if status != types.StrategyStatusStopped { reply.Message(fmt.Sprintf("Strategy %s is running.", signature)) return nil } diff --git a/pkg/strategy/support/strategy.go b/pkg/strategy/support/strategy.go index d726de78d..7af576b96 100644 --- a/pkg/strategy/support/strategy.go +++ b/pkg/strategy/support/strategy.go @@ -181,7 +181,7 @@ type Strategy struct { trailingStopControl *TrailingStopControl // StrategyController - status bool + status types.StrategyStatus } func (s *Strategy) ID() string { @@ -254,12 +254,12 @@ func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Valu // StrategyController -func (s *Strategy) GetStrategyStatus() bool { +func (s *Strategy) GetStrategyStatus() types.StrategyStatus { return s.status } func (s *Strategy) SuspendStrategy(ctx context.Context) error { - s.status = false + s.status = types.StrategyStatusStopped var err error // Cancel all order @@ -285,7 +285,7 @@ func (s *Strategy) SuspendStrategy(ctx context.Context) error { } func (s *Strategy) ResumeStrategy() error { - s.status = true + s.status = types.StrategyStatusRunning return nil } @@ -437,7 +437,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se s.orderExecutor = orderExecutor // StrategyController - s.status = true + s.status = types.StrategyStatusRunning // set default values if s.Interval == "" { @@ -508,7 +508,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se // Update trailing stop when the position changes s.tradeCollector.OnPositionUpdate(func(position *types.Position) { // StrategyController - if !s.status { + if s.status != types.StrategyStatusRunning { return } @@ -558,7 +558,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se session.MarketDataStream.OnKLineClosed(func(kline types.KLine) { // StrategyController - if !s.status { + if s.status != types.StrategyStatusRunning { return } diff --git a/pkg/types/strategy_status.go b/pkg/types/strategy_status.go new file mode 100644 index 000000000..06fa03462 --- /dev/null +++ b/pkg/types/strategy_status.go @@ -0,0 +1,9 @@ +package types + +// StrategyStatus define strategy status +type StrategyStatus string + +const ( + StrategyStatusRunning StrategyStatus = "RUN" + StrategyStatusStopped StrategyStatus = "STOP" +)