2022-04-14 05:44:34 +00:00
|
|
|
package bbgo
|
2022-04-15 08:06:19 +00:00
|
|
|
|
|
|
|
import (
|
2022-04-18 08:41:47 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
2022-04-15 08:06:19 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 09:54:16 +00:00
|
|
|
//go:generate callbackgen -type StrategyController -interface
|
2022-04-15 08:06:19 +00:00
|
|
|
type StrategyController struct {
|
2022-04-18 09:26:43 +00:00
|
|
|
Status types.StrategyStatus
|
|
|
|
|
2022-04-15 09:02:00 +00:00
|
|
|
// Callbacks
|
2022-04-25 10:39:32 +00:00
|
|
|
suspendCallbacks []func()
|
|
|
|
resumeCallbacks []func()
|
|
|
|
emergencyStopCallbacks []func()
|
2022-04-15 09:02:00 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 11:02:15 +00:00
|
|
|
func (s *StrategyController) GetStatus() types.StrategyStatus {
|
|
|
|
return s.Status
|
2022-04-15 09:02:00 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 11:02:15 +00:00
|
|
|
func (s *StrategyController) Suspend() error {
|
|
|
|
s.Status = types.StrategyStatusStopped
|
2022-04-15 09:02:00 +00:00
|
|
|
|
2022-04-21 09:54:16 +00:00
|
|
|
s.EmitSuspend()
|
2022-04-15 09:02:00 +00:00
|
|
|
|
2022-04-21 09:54:16 +00:00
|
|
|
return nil
|
2022-04-15 09:02:00 +00:00
|
|
|
}
|
2022-04-15 08:06:19 +00:00
|
|
|
|
2022-04-20 11:02:15 +00:00
|
|
|
func (s *StrategyController) Resume() error {
|
|
|
|
s.Status = types.StrategyStatusRunning
|
|
|
|
|
2022-04-21 09:54:16 +00:00
|
|
|
s.EmitResume()
|
2022-04-20 11:02:15 +00:00
|
|
|
|
2022-04-21 09:54:16 +00:00
|
|
|
return nil
|
2022-04-15 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 11:02:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-21 08:55:58 +00:00
|
|
|
type StrategyStatusReader interface {
|
2022-04-20 11:02:15 +00:00
|
|
|
GetStatus() types.StrategyStatus
|
2022-04-21 08:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type StrategyToggler interface {
|
|
|
|
StrategyStatusReader
|
2022-04-20 11:02:15 +00:00
|
|
|
Suspend() error
|
|
|
|
Resume() error
|
2022-04-21 08:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type EmergencyStopper interface {
|
2022-04-20 11:02:15 +00:00
|
|
|
EmergencyStop() error
|
2022-04-15 08:06:19 +00:00
|
|
|
}
|