Merge pull request #564 from andycheng123/improve/strategy-controller

This commit is contained in:
Yo-An Lin 2022-04-26 21:08:40 +08:00 committed by GitHub
commit f8141173a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,10 +65,11 @@ func filterStrategyByInterface(checkInterface interface{}, exchangeStrategies ma
return strategies, found return strategies, found
} }
func generateStrategyButtonsForm(strategies []string) [][3]string { func generateStrategyButtonsForm(strategies map[string]SingleExchangeStrategy) [][3]string {
var buttonsForm [][3]string var buttonsForm [][3]string
for _, strategy := range strategies { signatures := getStrategySignatures(strategies)
buttonsForm = append(buttonsForm, [3]string{strategy, "strategy", strategy}) for _, signature := range signatures {
buttonsForm = append(buttonsForm, [3]string{signature, "strategy", signature})
} }
return buttonsForm return buttonsForm
@ -122,7 +123,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
// it.trader.exchangeStrategies // it.trader.exchangeStrategies
// send symbol options // send symbol options
if strategies, found := filterStrategyByInterface((*PositionReader)(nil), it.exchangeStrategies); found { if strategies, found := filterStrategyByInterface((*PositionReader)(nil), it.exchangeStrategies); found {
reply.AddMultipleButtons(generateStrategyButtonsForm(getStrategySignatures(strategies))) reply.AddMultipleButtons(generateStrategyButtonsForm(strategies))
reply.Message("Please choose one strategy") reply.Message("Please choose one strategy")
} else { } else {
reply.Message("No strategy supports PositionReader") reply.Message("No strategy supports PositionReader")
@ -163,7 +164,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
// it.trader.exchangeStrategies // it.trader.exchangeStrategies
// send symbol options // send symbol options
if strategies, found := filterStrategyByInterface((*PositionCloser)(nil), it.exchangeStrategies); found { if strategies, found := filterStrategyByInterface((*PositionCloser)(nil), it.exchangeStrategies); found {
reply.AddMultipleButtons(generateStrategyButtonsForm(getStrategySignatures(strategies))) reply.AddMultipleButtons(generateStrategyButtonsForm(strategies))
reply.Message("Please choose one strategy") reply.Message("Please choose one strategy")
} else { } else {
reply.Message("No strategy supports PositionCloser") reply.Message("No strategy supports PositionCloser")
@ -232,7 +233,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
// it.trader.exchangeStrategies // it.trader.exchangeStrategies
// send symbol options // send symbol options
if strategies, found := filterStrategyByInterface((*StrategyStatusReader)(nil), it.exchangeStrategies); found { if strategies, found := filterStrategyByInterface((*StrategyStatusReader)(nil), it.exchangeStrategies); found {
reply.AddMultipleButtons(generateStrategyButtonsForm(getStrategySignatures(strategies))) reply.AddMultipleButtons(generateStrategyButtonsForm(strategies))
reply.Message("Please choose a strategy") reply.Message("Please choose a strategy")
} else { } else {
reply.Message("No strategy supports StrategyStatusReader") reply.Message("No strategy supports StrategyStatusReader")
@ -270,7 +271,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
// it.trader.exchangeStrategies // it.trader.exchangeStrategies
// send symbol options // send symbol options
if strategies, found := filterStrategyByInterface((*StrategyToggler)(nil), it.exchangeStrategies); found { if strategies, found := filterStrategyByInterface((*StrategyToggler)(nil), it.exchangeStrategies); found {
reply.AddMultipleButtons(generateStrategyButtonsForm(getStrategySignatures(strategies))) reply.AddMultipleButtons(generateStrategyButtonsForm(strategies))
reply.Message("Please choose one strategy") reply.Message("Please choose one strategy")
} else { } else {
reply.Message("No strategy supports StrategyToggler") reply.Message("No strategy supports StrategyToggler")
@ -312,7 +313,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
// it.trader.exchangeStrategies // it.trader.exchangeStrategies
// send symbol options // send symbol options
if strategies, found := filterStrategyByInterface((*StrategyToggler)(nil), it.exchangeStrategies); found { if strategies, found := filterStrategyByInterface((*StrategyToggler)(nil), it.exchangeStrategies); found {
reply.AddMultipleButtons(generateStrategyButtonsForm(getStrategySignatures(strategies))) reply.AddMultipleButtons(generateStrategyButtonsForm(strategies))
reply.Message("Please choose one strategy") reply.Message("Please choose one strategy")
} else { } else {
reply.Message("No strategy supports StrategyToggler") reply.Message("No strategy supports StrategyToggler")
@ -354,7 +355,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
// it.trader.exchangeStrategies // it.trader.exchangeStrategies
// send symbol options // send symbol options
if strategies, found := filterStrategyByInterface((*EmergencyStopper)(nil), it.exchangeStrategies); found { if strategies, found := filterStrategyByInterface((*EmergencyStopper)(nil), it.exchangeStrategies); found {
reply.AddMultipleButtons(generateStrategyButtonsForm(getStrategySignatures(strategies))) reply.AddMultipleButtons(generateStrategyButtonsForm(strategies))
reply.Message("Please choose one strategy") reply.Message("Please choose one strategy")
} else { } else {
reply.Message("No strategy supports EmergencyStopper") reply.Message("No strategy supports EmergencyStopper")
@ -419,7 +420,8 @@ func getStrategySignature(strategy SingleExchangeStrategy) (string, error) {
for i := 0; i < rv.NumField(); i++ { for i := 0; i < rv.NumField(); i++ {
field := rv.Field(i) field := rv.Field(i)
if field.Kind() == reflect.String { fieldName := rv.Type().Field(i).Name
if field.Kind() == reflect.String && fieldName != "Status" {
str := field.String() str := field.String()
if len(str) > 0 { if len(str) > 0 {
signature += "." + field.String() signature += "." + field.String()