bbgo_origin/pkg/bbgo/strategy_controller.go

58 lines
982 B
Go
Raw Normal View History

package bbgo
import (
2022-04-18 08:41:47 +00:00
"github.com/c9s/bbgo/pkg/types"
)
2022-04-21 09:54:16 +00:00
//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
2022-04-21 09:54:16 +00:00
s.EmitSuspend()
2022-04-21 09:54:16 +00:00
return nil
}
func (s *StrategyController) Resume() error {
s.Status = types.StrategyStatusRunning
2022-04-21 09:54:16 +00:00
s.EmitResume()
2022-04-21 09:54:16 +00:00
return nil
}
func (s *StrategyController) EmergencyStop() error {
s.Status = types.StrategyStatusStopped
2022-04-21 09:54:16 +00:00
s.EmitEmergencyStop()
2022-04-18 08:41:47 +00:00
2022-04-21 09:54:16 +00:00
return nil
2022-04-18 08:41:47 +00:00
}
type StrategyStatusReader interface {
GetStatus() types.StrategyStatus
}
type StrategyToggler interface {
StrategyStatusReader
Suspend() error
Resume() error
}
type EmergencyStopper interface {
EmergencyStop() error
}