From 09d0a9bbc7ed50ea404bb59d076906d7f8850ec5 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 22 Jun 2022 13:45:48 +0800 Subject: [PATCH] pivotshort: clean up ClosePosition method --- pkg/strategy/pivotshort/strategy.go | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/pkg/strategy/pivotshort/strategy.go b/pkg/strategy/pivotshort/strategy.go index 10a4d1b8f..38ce71244 100644 --- a/pkg/strategy/pivotshort/strategy.go +++ b/pkg/strategy/pivotshort/strategy.go @@ -162,35 +162,16 @@ func (s *Strategy) placeMarketSell(ctx context.Context, quantity fixedpoint.Valu }) } +func (s *Strategy) InstanceID() string { + return fmt.Sprintf("%s:%s", ID, s.Symbol) +} + func (s *Strategy) CurrentPosition() *types.Position { return s.Position } func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error { - // Cancel active orders - _ = s.orderExecutor.GracefulCancel(ctx) - - submitOrder := s.Position.NewMarketCloseOrder(percentage) // types.SubmitOrder{ - if submitOrder == nil { - return nil - } - - if s.session.Margin { - submitOrder.MarginSideEffect = s.Exit.MarginSideEffect - } - - bbgo.Notify("Closing %s position by %f", s.Symbol, percentage.Float64()) - log.Infof("Closing %s position by %f", s.Symbol, percentage.Float64()) - _, err := s.orderExecutor.SubmitOrders(ctx, *submitOrder) - if err != nil { - bbgo.Notify("close %s position error", s.Symbol) - log.WithError(err).Errorf("close %s position error", s.Symbol) - } - return err -} - -func (s *Strategy) InstanceID() string { - return fmt.Sprintf("%s:%s", ID, s.Symbol) + return s.orderExecutor.ClosePosition(ctx, percentage) } func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {