mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
type: add StrategyStatus type
This commit is contained in:
parent
ce6efd9333
commit
5f7710103d
|
@ -24,7 +24,7 @@ type PositionReader interface {
|
|||
type StrategyController interface {
|
||||
SuspendStrategy(ctx context.Context) error
|
||||
ResumeStrategy() error
|
||||
GetStrategyStatus() bool
|
||||
GetStrategyStatus() types.StrategyStatus
|
||||
EmergencyStop(ctx context.Context) error
|
||||
}
|
||||
|
||||
|
@ -254,9 +254,9 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
kc.RemoveKeyboard()
|
||||
}
|
||||
|
||||
if status {
|
||||
if status == types.StrategyStatusRunning {
|
||||
reply.Message(fmt.Sprintf("Strategy %s is running.", signature))
|
||||
} else {
|
||||
} else if status == types.StrategyStatusStopped {
|
||||
reply.Message(fmt.Sprintf("Strategy %s is not running.", signature))
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
|
||||
// Check strategy status before suspend
|
||||
status := controller.GetStrategyStatus()
|
||||
if !status {
|
||||
if status != types.StrategyStatusRunning {
|
||||
reply.Message(fmt.Sprintf("Strategy %s is not running.", signature))
|
||||
return nil
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
|
||||
// Check strategy status before resume
|
||||
status := controller.GetStrategyStatus()
|
||||
if status {
|
||||
if status != types.StrategyStatusStopped {
|
||||
reply.Message(fmt.Sprintf("Strategy %s is running.", signature))
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ type Strategy struct {
|
|||
trailingStopControl *TrailingStopControl
|
||||
|
||||
// StrategyController
|
||||
status bool
|
||||
status types.StrategyStatus
|
||||
}
|
||||
|
||||
func (s *Strategy) ID() string {
|
||||
|
@ -254,12 +254,12 @@ func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Valu
|
|||
|
||||
// StrategyController
|
||||
|
||||
func (s *Strategy) GetStrategyStatus() bool {
|
||||
func (s *Strategy) GetStrategyStatus() types.StrategyStatus {
|
||||
return s.status
|
||||
}
|
||||
|
||||
func (s *Strategy) SuspendStrategy(ctx context.Context) error {
|
||||
s.status = false
|
||||
s.status = types.StrategyStatusStopped
|
||||
|
||||
var err error
|
||||
// Cancel all order
|
||||
|
@ -285,7 +285,7 @@ func (s *Strategy) SuspendStrategy(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (s *Strategy) ResumeStrategy() error {
|
||||
s.status = true
|
||||
s.status = types.StrategyStatusRunning
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
s.orderExecutor = orderExecutor
|
||||
|
||||
// StrategyController
|
||||
s.status = true
|
||||
s.status = types.StrategyStatusRunning
|
||||
|
||||
// set default values
|
||||
if s.Interval == "" {
|
||||
|
@ -508,7 +508,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
// Update trailing stop when the position changes
|
||||
s.tradeCollector.OnPositionUpdate(func(position *types.Position) {
|
||||
// StrategyController
|
||||
if !s.status {
|
||||
if s.status != types.StrategyStatusRunning {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -558,7 +558,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
|
||||
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
|
||||
// StrategyController
|
||||
if !s.status {
|
||||
if s.status != types.StrategyStatusRunning {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
9
pkg/types/strategy_status.go
Normal file
9
pkg/types/strategy_status.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package types
|
||||
|
||||
// StrategyStatus define strategy status
|
||||
type StrategyStatus string
|
||||
|
||||
const (
|
||||
StrategyStatusRunning StrategyStatus = "RUN"
|
||||
StrategyStatusStopped StrategyStatus = "STOP"
|
||||
)
|
Loading…
Reference in New Issue
Block a user