mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
feature: create simpleinteract and remove command in notification
This commit is contained in:
parent
90e596f463
commit
6a4eec71d6
|
@ -51,6 +51,27 @@ func NewCoreInteraction(environment *Environment, trader *Trader) *CoreInteracti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SimpleInteraction struct {
|
||||||
|
Command string
|
||||||
|
Description string
|
||||||
|
F interface{}
|
||||||
|
Cmd *interact.Command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *SimpleInteraction) Commands(i *interact.Interact) {
|
||||||
|
it.Cmd = i.PrivateCommand(it.Command, it.Description, it.F)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterCommand(command, desc string, f interface{}) *interact.Command {
|
||||||
|
it := &SimpleInteraction{
|
||||||
|
Command: command,
|
||||||
|
Description: desc,
|
||||||
|
F: f,
|
||||||
|
}
|
||||||
|
interact.AddCustomInteraction(it)
|
||||||
|
return it.Cmd
|
||||||
|
}
|
||||||
|
|
||||||
func getStrategySignatures(exchangeStrategies map[string]SingleExchangeStrategy) []string {
|
func getStrategySignatures(exchangeStrategies map[string]SingleExchangeStrategy) []string {
|
||||||
var strategies []string
|
var strategies []string
|
||||||
for signature := range exchangeStrategies {
|
for signature := range exchangeStrategies {
|
||||||
|
|
|
@ -14,10 +14,6 @@ var Notification = &Notifiability{
|
||||||
ObjectChannelRouter: NewObjectChannelRouter(),
|
ObjectChannelRouter: NewObjectChannelRouter(),
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterCommand(application, command string, handler func(string)) {
|
|
||||||
Notification.RegisterCommand(application, command, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Notify(obj interface{}, args ...interface{}) {
|
func Notify(obj interface{}, args ...interface{}) {
|
||||||
Notification.Notify(obj, args...)
|
Notification.Notify(obj, args...)
|
||||||
}
|
}
|
||||||
|
@ -39,8 +35,6 @@ type Notifier interface {
|
||||||
Notify(obj interface{}, args ...interface{})
|
Notify(obj interface{}, args ...interface{})
|
||||||
SendPhotoTo(channel string, buffer *bytes.Buffer)
|
SendPhotoTo(channel string, buffer *bytes.Buffer)
|
||||||
SendPhoto(buffer *bytes.Buffer)
|
SendPhoto(buffer *bytes.Buffer)
|
||||||
RegisterCommand(command string, handler func(string))
|
|
||||||
ID() string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type NullNotifier struct{}
|
type NullNotifier struct{}
|
||||||
|
@ -53,12 +47,6 @@ func (n *NullNotifier) SendPhoto(buffer *bytes.Buffer) {}
|
||||||
|
|
||||||
func (n *NullNotifier) SendPhotoTo(channel string, buffer *bytes.Buffer) {}
|
func (n *NullNotifier) SendPhotoTo(channel string, buffer *bytes.Buffer) {}
|
||||||
|
|
||||||
func (n *NullNotifier) RegisterCommand(command string, handler func(string)) {}
|
|
||||||
|
|
||||||
func (n *NullNotifier) ID() string {
|
|
||||||
return "null"
|
|
||||||
}
|
|
||||||
|
|
||||||
type Notifiability struct {
|
type Notifiability struct {
|
||||||
notifiers []Notifier
|
notifiers []Notifier
|
||||||
SessionChannelRouter *PatternChannelRouter `json:"-"`
|
SessionChannelRouter *PatternChannelRouter `json:"-"`
|
||||||
|
@ -123,11 +111,3 @@ func (m *Notifiability) SendPhotoTo(channel string, buffer *bytes.Buffer) {
|
||||||
n.SendPhotoTo(channel, buffer)
|
n.SendPhotoTo(channel, buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Notifiability) RegisterCommand(application, command string, handler func(string)) {
|
|
||||||
for _, n := range m.notifiers {
|
|
||||||
if application == n.ID() {
|
|
||||||
n.RegisterCommand(command, handler)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -159,14 +159,6 @@ func (n *Notifier) SendPhotoTo(channel string, buffer *bytes.Buffer) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) ID() string {
|
|
||||||
return "slack"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Notifier) RegisterCommand(command string, simplehandler func(string)) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func (n *Notifier) NotifyTrade(trade *types.Trade) {
|
func (n *Notifier) NotifyTrade(trade *types.Trade) {
|
||||||
_, _, err := n.client.PostMessageContext(context.Background(), n.TradeChannel,
|
_, _, err := n.client.PostMessageContext(context.Background(), n.TradeChannel,
|
||||||
|
|
|
@ -50,17 +50,6 @@ func New(bot *telebot.Bot, options ...Option) *Notifier {
|
||||||
return notifier
|
return notifier
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) ID() string {
|
|
||||||
return "telegram"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Notifier) RegisterCommand(command string, simplehandler func(string)) {
|
|
||||||
handler := func(msg *telebot.Message) {
|
|
||||||
simplehandler(msg.Text)
|
|
||||||
}
|
|
||||||
n.bot.Handle(command, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Notifier) Notify(obj interface{}, args ...interface{}) {
|
func (n *Notifier) Notify(obj interface{}, args ...interface{}) {
|
||||||
n.NotifyTo("", obj, args...)
|
n.NotifyTo("", obj, args...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/bbgo"
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
"github.com/c9s/bbgo/pkg/indicator"
|
"github.com/c9s/bbgo/pkg/indicator"
|
||||||
|
"github.com/c9s/bbgo/pkg/interact"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
"github.com/c9s/bbgo/pkg/util"
|
"github.com/c9s/bbgo/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -859,31 +860,34 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
s.TrailingStopLossType = "kline"
|
s.TrailingStopLossType = "kline"
|
||||||
}
|
}
|
||||||
|
|
||||||
bbgo.RegisterCommand("telegram", "/draw", func(msg string) {
|
bbgo.RegisterCommand("/draw", "Draw Indicators", func(reply interact.Reply) {
|
||||||
canvas := s.DrawIndicators(dynamicKLine.StartTime, priceLine, zeroPoints)
|
canvas := s.DrawIndicators(dynamicKLine.StartTime, priceLine, zeroPoints)
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
if err := canvas.Render(chart.PNG, &buffer); err != nil {
|
if err := canvas.Render(chart.PNG, &buffer); err != nil {
|
||||||
log.WithError(err).Errorf("cannot render indicators in drift")
|
log.WithError(err).Errorf("cannot render indicators in drift")
|
||||||
|
reply.Message(fmt.Sprintf("[error] cannot render indicators in drift: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bbgo.SendPhoto(&buffer)
|
bbgo.SendPhoto(&buffer)
|
||||||
})
|
})
|
||||||
|
|
||||||
bbgo.RegisterCommand("telegram", "/pnl", func(msg string) {
|
bbgo.RegisterCommand("/pnl", "Draw PNL per trade", func(reply interact.Reply) {
|
||||||
canvas := s.DrawPNL(&profit)
|
canvas := s.DrawPNL(&profit)
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
if err := canvas.Render(chart.PNG, &buffer); err != nil {
|
if err := canvas.Render(chart.PNG, &buffer); err != nil {
|
||||||
log.WithError(err).Errorf("cannot render pnl in drift")
|
log.WithError(err).Errorf("cannot render pnl in drift")
|
||||||
|
reply.Message(fmt.Sprintf("[error] cannot render pnl in drift: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bbgo.SendPhoto(&buffer)
|
bbgo.SendPhoto(&buffer)
|
||||||
})
|
})
|
||||||
|
|
||||||
bbgo.RegisterCommand("telegram", "/cumpnl", func(msg string) {
|
bbgo.RegisterCommand("/cumpnl", "Draw Cummulative PNL", func(reply interact.Reply) {
|
||||||
canvas := s.DrawCumPNL(&cumProfit)
|
canvas := s.DrawCumPNL(&cumProfit)
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
if err := canvas.Render(chart.PNG, &buffer); err != nil {
|
if err := canvas.Render(chart.PNG, &buffer); err != nil {
|
||||||
log.WithError(err).Errorf("cannot render cumpnl in drift")
|
log.WithError(err).Errorf("cannot render cumpnl in drift")
|
||||||
|
reply.Message(fmt.Sprintf("[error] canot render cumpnl in drift: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bbgo.SendPhoto(&buffer)
|
bbgo.SendPhoto(&buffer)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user