mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
move and rename isSymbolBasedStrategy
This commit is contained in:
parent
3013eeccc7
commit
cf0ca70d24
|
@ -13,6 +13,7 @@ import (
|
|||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/datatype"
|
||||
"github.com/c9s/bbgo/pkg/dynamic"
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/service"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
|
@ -387,7 +388,7 @@ func (c *Config) GetSignature() string {
|
|||
id := strategy.ID()
|
||||
ps = append(ps, id)
|
||||
|
||||
if symbol, ok := isSymbolBasedStrategy(reflect.ValueOf(strategy)); ok {
|
||||
if symbol, ok := dynamic.LookupSymbolField(reflect.ValueOf(strategy)); ok {
|
||||
ps = append(ps, symbol)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package bbgo
|
|||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/dynamic"
|
||||
)
|
||||
|
||||
type InstanceIDProvider interface {
|
||||
|
@ -17,7 +19,7 @@ func callID(obj interface{}) string {
|
|||
return ret[0].String()
|
||||
}
|
||||
|
||||
if symbol, ok := isSymbolBasedStrategy(sv); ok {
|
||||
if symbol, ok := dynamic.LookupSymbolField(sv); ok {
|
||||
m := sv.MethodByName("ID")
|
||||
ret := m.Call(nil)
|
||||
return ret[0].String() + ":" + symbol
|
||||
|
@ -29,20 +31,3 @@ func callID(obj interface{}) string {
|
|||
return ret[0].String() + ":"
|
||||
}
|
||||
|
||||
func isSymbolBasedStrategy(rs reflect.Value) (string, bool) {
|
||||
if rs.Kind() == reflect.Ptr {
|
||||
rs = rs.Elem()
|
||||
}
|
||||
|
||||
field := rs.FieldByName("Symbol")
|
||||
if !field.IsValid() {
|
||||
return "", false
|
||||
}
|
||||
|
||||
if field.Kind() != reflect.String {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return field.String(), true
|
||||
}
|
||||
|
||||
|
|
|
@ -202,7 +202,7 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si
|
|||
return errors.Wrapf(err, "failed to inject OrderExecutor on %T", strategy)
|
||||
}
|
||||
|
||||
if symbol, ok := isSymbolBasedStrategy(rs); ok {
|
||||
if symbol, ok := dynamic.LookupSymbolField(rs); ok {
|
||||
log.Infof("found symbol based strategy from %s", rs.Type())
|
||||
|
||||
market, ok := session.Market(symbol)
|
||||
|
|
|
@ -6,3 +6,21 @@ func HasField(rs reflect.Value, fieldName string) (field reflect.Value, ok bool)
|
|||
field = rs.FieldByName(fieldName)
|
||||
return field, field.IsValid()
|
||||
}
|
||||
|
||||
func LookupSymbolField(rs reflect.Value) (string, bool) {
|
||||
if rs.Kind() == reflect.Ptr {
|
||||
rs = rs.Elem()
|
||||
}
|
||||
|
||||
field := rs.FieldByName("Symbol")
|
||||
if !field.IsValid() {
|
||||
return "", false
|
||||
}
|
||||
|
||||
if field.Kind() != reflect.String {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return field.String(), true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user