mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
58 lines
982 B
Go
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
|
|
}
|