bbgo_origin/pkg/bbgo/strategy_controller.go
2022-04-26 18:29:22 +08:00

58 lines
982 B
Go

package bbgo
import (
"github.com/c9s/bbgo/pkg/types"
)
//go:generate callbackgen -type StrategyController -interface
type StrategyController struct {
Status types.StrategyStatus
// Callbacks
SuspendCallbacks []func()
ResumeCallbacks []func()
EmergencyStopCallbacks []func()
}
func (s *StrategyController) GetStatus() types.StrategyStatus {
return s.Status
}
func (s *StrategyController) Suspend() error {
s.Status = types.StrategyStatusStopped
s.EmitSuspend()
return nil
}
func (s *StrategyController) Resume() error {
s.Status = types.StrategyStatusRunning
s.EmitResume()
return nil
}
func (s *StrategyController) EmergencyStop() error {
s.Status = types.StrategyStatusStopped
s.EmitEmergencyStop()
return nil
}
type StrategyStatusReader interface {
GetStatus() types.StrategyStatus
}
type StrategyToggler interface {
StrategyStatusReader
Suspend() error
Resume() error
}
type EmergencyStopper interface {
EmergencyStop() error
}