move addTrade lock section

This commit is contained in:
c9s 2021-05-16 17:05:12 +08:00
parent e636a5008d
commit d0e4a5e65c

View File

@ -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 {