mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
bbgo: implement /position command
This commit is contained in:
parent
93722e6db3
commit
2a6b821908
|
@ -43,6 +43,51 @@ func NewCoreInteraction(environment *Environment, trader *Trader) *CoreInteracti
|
|||
}
|
||||
|
||||
func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||
i.PrivateCommand("/position", "show the current position of a strategy", func(reply interact.Reply) error {
|
||||
// it.trader.exchangeStrategies
|
||||
// send symbol options
|
||||
found := false
|
||||
for signature, strategy := range it.exchangeStrategies {
|
||||
if _, ok := strategy.(PositionReader); ok {
|
||||
reply.AddButton(signature)
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
reply.Message("Please choose one strategy")
|
||||
} else {
|
||||
reply.Message("No any strategy supports PositionReader")
|
||||
}
|
||||
return nil
|
||||
}).Next(func(signature string, reply interact.Reply) error {
|
||||
strategy, ok := it.exchangeStrategies[signature]
|
||||
if !ok {
|
||||
reply.Message("Strategy not found")
|
||||
return fmt.Errorf("strategy %s not found", signature)
|
||||
}
|
||||
|
||||
reader, implemented := strategy.(PositionReader)
|
||||
if !implemented {
|
||||
reply.Message(fmt.Sprintf("Strategy %s does not support position close", signature))
|
||||
return fmt.Errorf("strategy %s does not implement PositionCloser interface", signature)
|
||||
}
|
||||
|
||||
position := reader.CurrentPosition()
|
||||
if position != nil {
|
||||
reply.Send("Your current position:")
|
||||
reply.Send(position.String())
|
||||
|
||||
if position.Base == 0 {
|
||||
reply.Message(fmt.Sprintf("Strategy %q has no opened position", signature))
|
||||
return fmt.Errorf("strategy %T has no opened position", strategy)
|
||||
}
|
||||
}
|
||||
|
||||
reply.RemoveKeyboard()
|
||||
return nil
|
||||
})
|
||||
|
||||
i.PrivateCommand("/closeposition", "close the position of a strategy", func(reply interact.Reply) error {
|
||||
// it.trader.exchangeStrategies
|
||||
// send symbol options
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package interact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/scanner"
|
||||
|
||||
"github.com/mattn/go-shellwords"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func parseFuncArgsAndCall(f interface{}, args []string, objects ...interface{}) (State, error) {
|
||||
|
@ -30,7 +30,7 @@ func parseFuncArgsAndCall(f interface{}, args []string, objects ...interface{})
|
|||
objT := reflect.TypeOf(obj)
|
||||
objV := reflect.ValueOf(obj)
|
||||
|
||||
fmt.Println(
|
||||
log.Debugln(
|
||||
at.PkgPath(),
|
||||
at.Name(),
|
||||
objT, "implements", at, "=", objT.Implements(at),
|
||||
|
|
Loading…
Reference in New Issue
Block a user