2022-05-05 04:53:48 +00:00
|
|
|
package bbgo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2022-06-29 10:51:22 +00:00
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/dynamic"
|
2022-05-05 04:53:48 +00:00
|
|
|
)
|
|
|
|
|
2022-05-17 10:10:37 +00:00
|
|
|
type InstanceIDProvider interface {
|
2022-05-05 04:53:48 +00:00
|
|
|
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()
|
|
|
|
}
|
2022-06-22 07:19:22 +00:00
|
|
|
|
2022-06-29 10:51:22 +00:00
|
|
|
if symbol, ok := dynamic.LookupSymbolField(sv); ok {
|
2022-06-22 07:19:22 +00:00
|
|
|
m := sv.MethodByName("ID")
|
|
|
|
ret := m.Call(nil)
|
|
|
|
return ret[0].String() + ":" + symbol
|
|
|
|
}
|
|
|
|
|
|
|
|
// fallback to just ID
|
|
|
|
m := sv.MethodByName("ID")
|
|
|
|
ret := m.Call(nil)
|
|
|
|
return ret[0].String() + ":"
|
2022-05-05 04:53:48 +00:00
|
|
|
}
|
|
|
|
|