mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
interact: refactor
This commit is contained in:
parent
63e8850cc3
commit
3a6f34330b
|
@ -61,9 +61,8 @@ func NewCoreInteraction(environment *Environment, trader *Trader) *CoreInteracti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *CoreInteraction) FilterStrategyByInterface(checkInterface interface{}) ([]string, bool) {
|
func (it *CoreInteraction) FilterStrategyByInterface(checkInterface interface{}) (strategies []string, found bool) {
|
||||||
found := false
|
found = false
|
||||||
var strategies []string
|
|
||||||
rt := reflect.TypeOf(checkInterface).Elem()
|
rt := reflect.TypeOf(checkInterface).Elem()
|
||||||
for signature, strategy := range it.exchangeStrategies {
|
for signature, strategy := range it.exchangeStrategies {
|
||||||
if ok := reflect.TypeOf(strategy).Implements(rt); ok {
|
if ok := reflect.TypeOf(strategy).Implements(rt); ok {
|
||||||
|
@ -75,7 +74,7 @@ func (it *CoreInteraction) FilterStrategyByInterface(checkInterface interface{})
|
||||||
return strategies, found
|
return strategies, found
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *CoreInteraction) GenerateStrategyButtonsForm(strategies []string) [][3]string {
|
func GenerateStrategyButtonsForm(strategies []string) [][3]string {
|
||||||
var buttonsForm [][3]string
|
var buttonsForm [][3]string
|
||||||
for _, strategy := range strategies {
|
for _, strategy := range strategies {
|
||||||
buttonsForm = append(buttonsForm, [3]string{strategy, "strategy", strategy})
|
buttonsForm = append(buttonsForm, [3]string{strategy, "strategy", strategy})
|
||||||
|
@ -132,7 +131,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*PositionReader)(nil)); found {
|
if strategies, found := it.FilterStrategyByInterface((*PositionReader)(nil)); found {
|
||||||
reply.AddMultipleButtons(it.GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
reply.Message("No any strategy supports PositionReader")
|
reply.Message("No any strategy supports PositionReader")
|
||||||
|
@ -173,7 +172,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*PositionCloser)(nil)); found {
|
if strategies, found := it.FilterStrategyByInterface((*PositionCloser)(nil)); found {
|
||||||
reply.AddMultipleButtons(it.GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
reply.Message("No any strategy supports PositionCloser")
|
reply.Message("No any strategy supports PositionCloser")
|
||||||
|
@ -242,7 +241,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*StrategyStatusProvider)(nil)); found {
|
if strategies, found := it.FilterStrategyByInterface((*StrategyStatusProvider)(nil)); found {
|
||||||
reply.AddMultipleButtons(it.GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
reply.Message("No any strategy supports StrategyStatusProvider")
|
reply.Message("No any strategy supports StrategyStatusProvider")
|
||||||
|
@ -280,7 +279,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*StrategyController)(nil)); found {
|
if strategies, found := it.FilterStrategyByInterface((*StrategyController)(nil)); found {
|
||||||
reply.AddMultipleButtons(it.GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
reply.Message("No any strategy supports StrategyController")
|
reply.Message("No any strategy supports StrategyController")
|
||||||
|
@ -325,7 +324,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*StrategyController)(nil)); found {
|
if strategies, found := it.FilterStrategyByInterface((*StrategyController)(nil)); found {
|
||||||
reply.AddMultipleButtons(it.GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
reply.Message("No any strategy supports StrategyController")
|
reply.Message("No any strategy supports StrategyController")
|
||||||
|
@ -370,7 +369,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*EmergencyStopper)(nil)); found {
|
if strategies, found := it.FilterStrategyByInterface((*EmergencyStopper)(nil)); found {
|
||||||
reply.AddMultipleButtons(it.GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
reply.Message("No any strategy supports EmergencyStopper")
|
reply.Message("No any strategy supports EmergencyStopper")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user