qbtrade/pkg/strategy/elliottwave/output.go
2024-06-27 22:42:38 +08:00

44 lines
1.2 KiB
Go

package elliottwave
import (
"bytes"
"io"
"strconv"
"git.qtrade.icu/lychiyu/qbtrade/pkg/dynamic"
"git.qtrade.icu/lychiyu/qbtrade/pkg/interact"
"git.qtrade.icu/lychiyu/qbtrade/pkg/qbtrade"
"git.qtrade.icu/lychiyu/qbtrade/pkg/style"
"github.com/jedib0t/go-pretty/v6/table"
)
func (s *Strategy) initOutputCommands() {
qbtrade.RegisterCommand("/config", "Show latest config", func(reply interact.Reply) {
var buffer bytes.Buffer
s.Print(&buffer, false)
reply.Message(buffer.String())
})
qbtrade.RegisterCommand("/dump", "Dump internal params", func(reply interact.Reply) {
reply.Message("Please enter series output length:")
}).Next(func(length string, reply interact.Reply) {
var buffer bytes.Buffer
l, err := strconv.Atoi(length)
if err != nil {
dynamic.ParamDump(s, &buffer)
} else {
dynamic.ParamDump(s, &buffer, l)
}
reply.Message(buffer.String())
})
qbtrade.RegisterModifier(s)
}
func (s *Strategy) Print(f io.Writer, pretty bool, withColor ...bool) {
var tableStyle *table.Style
if pretty {
tableStyle = style.NewDefaultTableStyle()
}
dynamic.PrintConfig(s, f, tableStyle, len(withColor) > 0 && withColor[0], dynamic.DefaultWhiteList()...)
}