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/order_executor_general.go b/pkg/bbgo/order_executor_general.go index 540dce477..44ab8bb94 100644 --- a/pkg/bbgo/order_executor_general.go +++ b/pkg/bbgo/order_executor_general.go @@ -125,7 +125,6 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix } submitOrder.Tag = strings.Join(tags, ",") - _, err := e.SubmitOrders(ctx, *submitOrder) return err } 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 +} diff --git a/pkg/strategy/pivotshort/strategy.go b/pkg/strategy/pivotshort/strategy.go index 69cfa6cdb..3fd239cb6 100644 --- a/pkg/strategy/pivotshort/strategy.go +++ b/pkg/strategy/pivotshort/strategy.go @@ -174,7 +174,6 @@ func (s *Strategy) CurrentPosition() *types.Position { } func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error { - bbgo.Notify("Closing position", s.Position) return s.orderExecutor.ClosePosition(ctx, percentage) } @@ -338,7 +337,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se log.Infof("%s breakLow signal detected, closed price %f < breakPrice %f", kline.Symbol, closePrice.Float64(), breakPrice.Float64()) // stop EMA protection - if s.stopEWMA != nil && !s.BreakLow.StopEMARange.IsZero() { + if s.stopEWMA != nil { ema := fixedpoint.NewFromFloat(s.stopEWMA.Last()) if ema.IsZero() { return diff --git a/pkg/types/trade_stats.go b/pkg/types/trade_stats.go index ddc31a8b2..ed459e00a 100644 --- a/pkg/types/trade_stats.go +++ b/pkg/types/trade_stats.go @@ -45,7 +45,7 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) { s.WinningRatio = fixedpoint.NewFromFloat(float64(s.NumOfProfitTrade) / float64(s.NumOfLossTrade)) } - s.ProfitFactor = s.GrossProfit.Div(s.GrossLoss) + s.ProfitFactor = s.GrossProfit.Div(s.GrossLoss.Abs()) } func (s *TradeStats) String() string {