positionupdater: update quote position

This commit is contained in:
Andy Cheng 2022-07-29 12:00:11 +08:00
parent 8c53c7e575
commit 32b91b67dd

View File

@ -395,7 +395,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
return nil
})
// Position updater
// Position updater: Base
i.PrivateCommand("/updatepositionbase", "Update Strategy Position: Base", func(reply interact.Reply) error {
// it.trader.exchangeStrategies
// send symbol options
@ -444,6 +444,56 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
reply.Message(fmt.Sprintf("Base position of strategy %s updated.", it.updatePositionContext.signature))
return nil
})
// Position updater: Quote
i.PrivateCommand("/updatepositionquote", "Update Strategy Position: Quote", func(reply interact.Reply) error {
// it.trader.exchangeStrategies
// send symbol options
if strategies, found := filterStrategyByInterface((*StrategyPositionUpdater)(nil), it.exchangeStrategies); found {
reply.AddMultipleButtons(generateStrategyButtonsForm(strategies))
reply.Message("Please choose one strategy")
} else {
reply.Message("No strategy supports StrategyPositionUpdater")
}
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)
}
updater, implemented := strategy.(StrategyPositionUpdater)
if !implemented {
reply.Message(fmt.Sprintf("Strategy %s does not support StrategyPositionUpdater", signature))
return fmt.Errorf("strategy %s does not implement StrategyPositionUpdater", signature)
}
it.updatePositionContext.updater = updater
it.updatePositionContext.signature = signature
reply.Message("Enter the amount to change")
return nil
}).Next(func(valueStr string, reply interact.Reply) error {
value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
reply.Message(fmt.Sprintf("%q is not a valid value string", valueStr))
return err
}
if kc, ok := reply.(interact.KeyboardController); ok {
kc.RemoveKeyboard()
}
if err := it.updatePositionContext.updater.UpdateQuote(value); err != nil {
reply.Message(fmt.Sprintf("Failed to update quote position of the strategy, %s", err.Error()))
return err
}
reply.Message(fmt.Sprintf("Quote position of strategy %s updated.", it.updatePositionContext.signature))
return nil
})
}
func (it *CoreInteraction) Initialize() error {