diff --git a/pkg/bbgo/interact.go b/pkg/bbgo/interact.go index a2a56de59..c44c21eaa 100644 --- a/pkg/bbgo/interact.go +++ b/pkg/bbgo/interact.go @@ -60,7 +60,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { reply.Message("No any strategy supports PositionReader") } return nil - }).Next(func(signature string, reply interact.Reply) error { + }).Cycle(func(signature string, reply interact.Reply) error { strategy, ok := it.exchangeStrategies[signature] if !ok { reply.Message("Strategy not found") diff --git a/pkg/interact/command.go b/pkg/interact/command.go index 08b11223a..9155730aa 100644 --- a/pkg/interact/command.go +++ b/pkg/interact/command.go @@ -54,6 +54,21 @@ func (c *Command) NamedNext(n State, f interface{}) *Command { return c } +func (c *Command) Cycle(f interface{}) *Command { + var curState State + if c.lastState == "" { + curState = State(c.Name + "_" + strconv.Itoa(c.stateID)) + } else { + curState = c.lastState + } + + nextState := curState + c.states[curState] = nextState + c.statesFunc[curState] = f + c.lastState = nextState + return c +} + // Next defines the next state with the transition function from the last defined state. func (c *Command) Next(f interface{}) *Command { var curState State