diff --git a/pkg/bbgo/exit.go b/pkg/bbgo/exit.go index b931de880..98404ddbf 100644 --- a/pkg/bbgo/exit.go +++ b/pkg/bbgo/exit.go @@ -14,7 +14,7 @@ type ExitMethod struct { 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 rv := reflect.ValueOf(m) rt := reflect.TypeOf(m) @@ -22,11 +22,13 @@ func (m *ExitMethod) Subscribe() { rv = rv.Elem() rt = rt.Elem() infType := reflect.TypeOf((*types.Subscriber)(nil)).Elem() + + argValues := toReflectValues(session) for i := 0; i < rt.NumField(); i++ { fieldType := rt.Field(i) if fieldType.Type.Implements(infType) { method := rv.Field(i).MethodByName("Subscribe") - method.Call(nil) + method.Call(argValues) } } } diff --git a/pkg/bbgo/exit_test.go b/pkg/bbgo/exit_test.go index 607eda489..12fda5bec 100644 --- a/pkg/bbgo/exit_test.go +++ b/pkg/bbgo/exit_test.go @@ -4,5 +4,5 @@ import "testing" func TestExitMethod(t *testing.T) { em := &ExitMethod{} - em.Subscribe() + em.Subscribe(&ExchangeSession{}) } diff --git a/pkg/bbgo/reflect.go b/pkg/bbgo/reflect.go index c9cb5a33b..f83da274d 100644 --- a/pkg/bbgo/reflect.go +++ b/pkg/bbgo/reflect.go @@ -110,3 +110,11 @@ func newTypeValueInterface(typ reflect.Type) interface{} { dst := reflect.New(typ) return dst.Interface() } + +func toReflectValues(args ...interface{}) (values []reflect.Value) { + for _, arg := range args { + values = append(values, reflect.ValueOf(arg)) + } + + return values +}