simplify strategy registration api

This commit is contained in:
c9s 2020-10-29 07:54:59 +08:00
parent c71f013916
commit 19b600bb35
7 changed files with 14 additions and 13 deletions

View File

@ -8,7 +8,7 @@ import (
)
func init() {
RegisterExchangeStrategy("test", &TestStrategy{})
RegisterStrategy("test", &TestStrategy{})
}
type TestStrategy struct {

View File

@ -15,15 +15,16 @@ import (
)
var LoadedExchangeStrategies = make(map[string]SingleExchangeStrategy)
func RegisterExchangeStrategy(key string, configmap SingleExchangeStrategy) {
LoadedExchangeStrategies[key] = configmap
}
var LoadedCrossExchangeStrategies = make(map[string]CrossExchangeStrategy)
func RegisterCrossExchangeStrategy(key string, configmap CrossExchangeStrategy) {
LoadedCrossExchangeStrategies[key] = configmap
func RegisterStrategy(key string, s interface{}) {
switch d := s.(type) {
case SingleExchangeStrategy:
LoadedExchangeStrategies[key] = d
case CrossExchangeStrategy:
LoadedCrossExchangeStrategies[key] = d
}
}
// Environment presents the real exchange data layer

View File

@ -11,7 +11,7 @@ import (
)
func init() {
bbgo.RegisterExchangeStrategy("buyandhold", &Strategy{})
bbgo.RegisterStrategy("buyandhold", &Strategy{})
}
type Strategy struct {

View File

@ -9,7 +9,7 @@ import (
)
func init() {
bbgo.RegisterExchangeStrategy("pricealert", &Strategy{})
bbgo.RegisterStrategy("pricealert", &Strategy{})
}
type Strategy struct {

View File

@ -10,7 +10,7 @@ import (
)
func init() {
bbgo.RegisterExchangeStrategy("skeleton", &Strategy{})
bbgo.RegisterStrategy("skeleton", &Strategy{})
}
type Strategy struct {

View File

@ -12,7 +12,7 @@ import (
)
func init() {
bbgo.RegisterExchangeStrategy("swing", &Strategy{})
bbgo.RegisterStrategy("swing", &Strategy{})
}
type Strategy struct {

View File

@ -13,7 +13,7 @@ import (
)
func init() {
bbgo.RegisterExchangeStrategy("xpuremaker", &Strategy{})
bbgo.RegisterStrategy("xpuremaker", &Strategy{})
}
type Strategy struct {