mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-24 15:55:14 +00:00
43 lines
799 B
Go
43 lines
799 B
Go
package bbgo
|
|
|
|
import (
|
|
"reflect"
|
|
)
|
|
|
|
type InstanceIDProvider interface {
|
|
InstanceID() string
|
|
}
|
|
|
|
func callID(obj interface{}) string {
|
|
sv := reflect.ValueOf(obj)
|
|
st := reflect.TypeOf(obj)
|
|
if st.Implements(reflect.TypeOf((*InstanceIDProvider)(nil)).Elem()) {
|
|
m := sv.MethodByName("InstanceID")
|
|
ret := m.Call(nil)
|
|
return ret[0].String()
|
|
}
|
|
return ""
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func hasField(rs reflect.Value, fieldName string) (field reflect.Value, ok bool) {
|
|
field = rs.FieldByName(fieldName)
|
|
return field, field.IsValid()
|
|
}
|