From d0e4a5e65cac90dab3313000f71beeb119027494 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 16 May 2021 17:05:12 +0800 Subject: [PATCH] move addTrade lock section --- pkg/bbgo/position.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/bbgo/position.go b/pkg/bbgo/position.go index 0dab0a2db..9b9a5d314 100644 --- a/pkg/bbgo/position.go +++ b/pkg/bbgo/position.go @@ -107,9 +107,6 @@ func (p *Position) AddTrades(trades []types.Trade) (fixedpoint.Value, bool) { } func (p *Position) AddTrade(t types.Trade) (fixedpoint.Value, bool) { - p.Lock() - defer p.Unlock() - price := fixedpoint.NewFromFloat(t.Price) quantity := fixedpoint.NewFromFloat(t.Quantity) quoteQuantity := fixedpoint.NewFromFloat(t.QuoteQuantity) @@ -125,6 +122,9 @@ func (p *Position) AddTrade(t types.Trade) (fixedpoint.Value, bool) { } + p.Lock() + defer p.Unlock() + // Base > 0 means we're in long position // Base < 0 means we're in short position switch t.Side {