From dbc6d4fb44a636fb4aa87fd9df54f4a3a7188447 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 22 Jun 2022 13:44:46 +0800 Subject: [PATCH] bollmaker: refactor ClosePosition method --- pkg/strategy/bollmaker/strategy.go | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/pkg/strategy/bollmaker/strategy.go b/pkg/strategy/bollmaker/strategy.go index a48eba33d..25a7859c3 100644 --- a/pkg/strategy/bollmaker/strategy.go +++ b/pkg/strategy/bollmaker/strategy.go @@ -215,34 +215,7 @@ func (s *Strategy) CurrentPosition() *types.Position { } func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error { - base := s.Position.GetBase() - if base.IsZero() { - return fmt.Errorf("no opened %s position", s.Position.Symbol) - } - - // make it negative - quantity := base.Mul(percentage).Abs() - side := types.SideTypeBuy - if base.Sign() > 0 { - side = types.SideTypeSell - } - - if quantity.Compare(s.Market.MinQuantity) < 0 { - return fmt.Errorf("order quantity %v is too small, less than %v", quantity, s.Market.MinQuantity) - } - - submitOrder := types.SubmitOrder{ - Symbol: s.Symbol, - Side: side, - Type: types.OrderTypeMarket, - Quantity: quantity, - Market: s.Market, - } - - bbgo.Notify("Submitting %s %s order to close position by %v", s.Symbol, side.String(), percentage, submitOrder) - - _, err := s.orderExecutor.SubmitOrders(ctx, submitOrder) - return err + return s.orderExecutor.ClosePosition(ctx, percentage) } // Deprecated: LoadState method is migrated to the persistence struct tag.