diff --git a/pkg/bbgo/interact.go b/pkg/bbgo/interact.go index 52cdfc6b9..d39cff261 100644 --- a/pkg/bbgo/interact.go +++ b/pkg/bbgo/interact.go @@ -145,16 +145,14 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { } position := reader.CurrentPosition() - if position != nil { - reply.Send("Your current position:") - reply.Send(position.PlainText()) - - if position.Base.IsZero() { - reply.Message(fmt.Sprintf("Strategy %q has no opened position", signature)) - return fmt.Errorf("strategy %T has no opened position", strategy) - } + if position == nil || position.Base.IsZero() { + reply.Message(fmt.Sprintf("Strategy %q has no opened position", signature)) + return fmt.Errorf("strategy %T has no opened position", strategy) } + reply.Send("Your current position:") + reply.Message(position.PlainText()) + if kc, ok := reply.(interact.KeyboardController); ok { kc.RemoveKeyboard() } @@ -285,6 +283,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { } return nil }).Next(func(signature string, reply interact.Reply) error { + defer func() { + if kc, ok := reply.(interact.KeyboardController); ok { + kc.RemoveKeyboard() + } + }() + strategy, ok := it.exchangeStrategies[signature] if !ok { reply.Message("Strategy not found") @@ -299,10 +303,6 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { status := controller.GetStatus() - if kc, ok := reply.(interact.KeyboardController); ok { - kc.RemoveKeyboard() - } - if status == types.StrategyStatusRunning { reply.Message(fmt.Sprintf("Strategy %s is running.", signature)) } else if status == types.StrategyStatusStopped { @@ -323,6 +323,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { } return nil }).Next(func(signature string, reply interact.Reply) error { + defer func() { + if kc, ok := reply.(interact.KeyboardController); ok { + kc.RemoveKeyboard() + } + }() + strategy, ok := it.exchangeStrategies[signature] if !ok { reply.Message("Strategy not found") @@ -341,16 +347,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { return nil } - if kc, ok := reply.(interact.KeyboardController); ok { - kc.RemoveKeyboard() - } - if err := controller.Suspend(); err != nil { reply.Message(fmt.Sprintf("Failed to suspend the strategy, %s", err.Error())) return err } - reply.Message(fmt.Sprintf("Strategy %s suspended.", signature)) + reply.Message(fmt.Sprintf("Strategy %s is now suspended.", signature)) return nil }) @@ -365,6 +367,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { } return nil }).Next(func(signature string, reply interact.Reply) error { + defer func() { + if kc, ok := reply.(interact.KeyboardController); ok { + kc.RemoveKeyboard() + } + }() + strategy, ok := it.exchangeStrategies[signature] if !ok { reply.Message("Strategy not found") @@ -383,16 +391,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { return nil } - if kc, ok := reply.(interact.KeyboardController); ok { - kc.RemoveKeyboard() - } - if err := controller.Resume(); err != nil { reply.Message(fmt.Sprintf("Failed to resume the strategy, %s", err.Error())) return err } - reply.Message(fmt.Sprintf("Strategy %s resumed.", signature)) + reply.Message(fmt.Sprintf("Strategy %s is now resumed.", signature)) return nil }) diff --git a/pkg/interact/telegram.go b/pkg/interact/telegram.go index 464e9b763..9d4cfc7c6 100644 --- a/pkg/interact/telegram.go +++ b/pkg/interact/telegram.go @@ -157,7 +157,9 @@ func (tm *Telegram) Start(context.Context) { if reply.set { reply.build() - checkSendErr(tm.Bot.Send(m.Chat, reply.message, reply.menu)) + if len(reply.message) > 0 || reply.menu != nil { + checkSendErr(tm.Bot.Send(m.Chat, reply.message, reply.menu)) + } } })