mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
bbgo: add ExchangeSession param to the subscribe method
This commit is contained in:
parent
cb1c5634a2
commit
84083f56b7
|
@ -14,7 +14,7 @@ type ExitMethod struct {
|
||||||
CumulatedVolumeTakeProfit *CumulatedVolumeTakeProfit `json:"cumulatedVolumeTakeProfit"`
|
CumulatedVolumeTakeProfit *CumulatedVolumeTakeProfit `json:"cumulatedVolumeTakeProfit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ExitMethod) Subscribe() {
|
func (m *ExitMethod) Subscribe(session *ExchangeSession) {
|
||||||
// TODO: pull out this implementation as a simple function to reflect.go
|
// TODO: pull out this implementation as a simple function to reflect.go
|
||||||
rv := reflect.ValueOf(m)
|
rv := reflect.ValueOf(m)
|
||||||
rt := reflect.TypeOf(m)
|
rt := reflect.TypeOf(m)
|
||||||
|
@ -22,11 +22,13 @@ func (m *ExitMethod) Subscribe() {
|
||||||
rv = rv.Elem()
|
rv = rv.Elem()
|
||||||
rt = rt.Elem()
|
rt = rt.Elem()
|
||||||
infType := reflect.TypeOf((*types.Subscriber)(nil)).Elem()
|
infType := reflect.TypeOf((*types.Subscriber)(nil)).Elem()
|
||||||
|
|
||||||
|
argValues := toReflectValues(session)
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for i := 0; i < rt.NumField(); i++ {
|
||||||
fieldType := rt.Field(i)
|
fieldType := rt.Field(i)
|
||||||
if fieldType.Type.Implements(infType) {
|
if fieldType.Type.Implements(infType) {
|
||||||
method := rv.Field(i).MethodByName("Subscribe")
|
method := rv.Field(i).MethodByName("Subscribe")
|
||||||
method.Call(nil)
|
method.Call(argValues)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@ import "testing"
|
||||||
|
|
||||||
func TestExitMethod(t *testing.T) {
|
func TestExitMethod(t *testing.T) {
|
||||||
em := &ExitMethod{}
|
em := &ExitMethod{}
|
||||||
em.Subscribe()
|
em.Subscribe(&ExchangeSession{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,3 +110,11 @@ func newTypeValueInterface(typ reflect.Type) interface{} {
|
||||||
dst := reflect.New(typ)
|
dst := reflect.New(typ)
|
||||||
return dst.Interface()
|
return dst.Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toReflectValues(args ...interface{}) (values []reflect.Value) {
|
||||||
|
for _, arg := range args {
|
||||||
|
values = append(values, reflect.ValueOf(arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user