-
-
Notifications
You must be signed in to change notification settings - Fork 273
/
strategy_controller.go
57 lines (41 loc) · 982 Bytes
/
strategy_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
}