mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
feature: make FilterStrategyByInterface a simple function
This commit is contained in:
parent
ecc63f743f
commit
cbf6bf78bc
|
@ -43,10 +43,10 @@ func NewCoreInteraction(environment *Environment, trader *Trader) *CoreInteracti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *CoreInteraction) FilterStrategyByInterface(checkInterface interface{}) (strategies []string, found bool) {
|
func FilterStrategyByInterface(checkInterface interface{}, exchangeStrategies map[string]SingleExchangeStrategy) (strategies []string, found bool) {
|
||||||
found = false
|
found = false
|
||||||
rt := reflect.TypeOf(checkInterface).Elem()
|
rt := reflect.TypeOf(checkInterface).Elem()
|
||||||
for signature, strategy := range it.exchangeStrategies {
|
for signature, strategy := range exchangeStrategies {
|
||||||
if ok := reflect.TypeOf(strategy).Implements(rt); ok {
|
if ok := reflect.TypeOf(strategy).Implements(rt); ok {
|
||||||
strategies = append(strategies, signature)
|
strategies = append(strategies, signature)
|
||||||
found = true
|
found = true
|
||||||
|
@ -112,7 +112,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
i.PrivateCommand("/position", "Show Position", func(reply interact.Reply) error {
|
i.PrivateCommand("/position", "Show Position", func(reply interact.Reply) error {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*PositionReader)(nil)); found {
|
if strategies, found := FilterStrategyByInterface((*PositionReader)(nil), it.exchangeStrategies); found {
|
||||||
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
|
@ -153,7 +153,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
i.PrivateCommand("/closeposition", "Close position", func(reply interact.Reply) error {
|
i.PrivateCommand("/closeposition", "Close position", func(reply interact.Reply) error {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*PositionCloser)(nil)); found {
|
if strategies, found := FilterStrategyByInterface((*PositionCloser)(nil), it.exchangeStrategies); found {
|
||||||
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,7 +222,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
i.PrivateCommand("/status", "Strategy Status", func(reply interact.Reply) error {
|
i.PrivateCommand("/status", "Strategy Status", func(reply interact.Reply) error {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*StrategyStatusReader)(nil)); found {
|
if strategies, found := FilterStrategyByInterface((*StrategyStatusReader)(nil), it.exchangeStrategies); found {
|
||||||
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose a strategy")
|
reply.Message("Please choose a strategy")
|
||||||
} else {
|
} else {
|
||||||
|
@ -260,7 +260,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
i.PrivateCommand("/suspend", "Suspend Strategy", func(reply interact.Reply) error {
|
i.PrivateCommand("/suspend", "Suspend Strategy", func(reply interact.Reply) error {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*StrategyToggler)(nil)); found {
|
if strategies, found := FilterStrategyByInterface((*StrategyToggler)(nil), it.exchangeStrategies); found {
|
||||||
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
|
@ -302,7 +302,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
i.PrivateCommand("/resume", "Resume Strategy", func(reply interact.Reply) error {
|
i.PrivateCommand("/resume", "Resume Strategy", func(reply interact.Reply) error {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*StrategyToggler)(nil)); found {
|
if strategies, found := FilterStrategyByInterface((*StrategyToggler)(nil), it.exchangeStrategies); found {
|
||||||
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
|
@ -344,7 +344,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
||||||
i.PrivateCommand("/emergencystop", "Emergency Stop", func(reply interact.Reply) error {
|
i.PrivateCommand("/emergencystop", "Emergency Stop", func(reply interact.Reply) error {
|
||||||
// it.trader.exchangeStrategies
|
// it.trader.exchangeStrategies
|
||||||
// send symbol options
|
// send symbol options
|
||||||
if strategies, found := it.FilterStrategyByInterface((*EmergencyStopper)(nil)); found {
|
if strategies, found := FilterStrategyByInterface((*EmergencyStopper)(nil), it.exchangeStrategies); found {
|
||||||
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
reply.AddMultipleButtons(GenerateStrategyButtonsForm(strategies))
|
||||||
reply.Message("Please choose one strategy")
|
reply.Message("Please choose one strategy")
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user