mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
positionupdater: update quote position
This commit is contained in:
parent
8c53c7e575
commit
32b91b67dd
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user