mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
interact: add Cycle state builder
This commit is contained in:
parent
2a6b821908
commit
1c7d4d09cf
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user