From b6fb5e958d76d3dfc2c15cc44b037fb2ed8ca2de Mon Sep 17 00:00:00 2001 From: zenix Date: Sun, 17 Jul 2022 01:42:45 +0900 Subject: [PATCH] feature: deduct fee from entry, move StopLoss orders cleanup to the begin of close position function --- pkg/strategy/drift/strategy.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/strategy/drift/strategy.go b/pkg/strategy/drift/strategy.go index 80caae415..a93d7d344 100644 --- a/pkg/strategy/drift/strategy.go +++ b/pkg/strategy/drift/strategy.go @@ -120,6 +120,8 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { } func (s *Strategy) ClosePosition(ctx context.Context) (*types.Order, bool) { + // Cleanup pending StopOrders + s.StopOrders = make(map[uint64]types.SubmitOrder) order := s.Position.NewMarketCloseOrder(fixedpoint.One) if order == nil { return nil, false @@ -289,8 +291,6 @@ func (s *Strategy) InitTickerFunctions(ctx context.Context) { log.WithError(err).Errorf("cannot cancel orders") return } - // Cleanup pending StopOrders - s.StopOrders = make(map[uint64]types.SubmitOrder) _, _ = s.ClosePosition(ctx) } @@ -537,8 +537,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se log.WithError(err).Errorf("cannot cancel orders") return } - // Cleanup pending StopOrders - s.StopOrders = make(map[uint64]types.SubmitOrder) _, _ = s.ClosePosition(ctx) } return @@ -571,8 +569,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se log.WithError(err).Errorf("cannot cancel orders") return } - // Cleanup pending StopOrders - s.StopOrders = make(map[uint64]types.SubmitOrder) _, _ = s.ClosePosition(ctx) } if shortCondition { @@ -588,6 +584,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se if source.Compare(price) < 0 { source = price } + source = source.Mul(fixedpoint.NewFromFloat(1.0002)) if s.Market.IsDustQuantity(baseBalance.Available, source) { return @@ -634,6 +631,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se if source.Compare(price) > 0 { source = price } + source = source.Mul(fixedpoint.NewFromFloat(0.9998)) quoteBalance, ok := s.Session.GetAccount().Balance(s.Market.QuoteCurrency) if !ok { log.Errorf("unable to get quoteCurrency")