xdepthmaker: remove shared mutex lock usage

This commit is contained in:
c9s 2024-09-23 18:28:46 +08:00
parent 345c92c295
commit b02580f9f6
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -487,10 +487,8 @@ func (s *Strategy) CrossRun(
position := s.Position.GetBase() position := s.Position.GetBase()
s.mu.Lock()
coveredPosition := s.CoveredPosition.Get() coveredPosition := s.CoveredPosition.Get()
uncoverPosition := position.Sub(coveredPosition) uncoverPosition := position.Sub(coveredPosition)
s.mu.Unlock()
absPos := uncoverPosition.Abs() absPos := uncoverPosition.Abs()
if absPos.Compare(s.hedgeMarket.MinQuantity) > 0 { if absPos.Compare(s.hedgeMarket.MinQuantity) > 0 {
@ -537,17 +535,18 @@ func (s *Strategy) CrossRun(
} }
func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) { func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) {
side := types.SideTypeBuy
if pos.IsZero() { if pos.IsZero() {
return return
} }
quantity := pos.Abs() // the default side
side := types.SideTypeBuy
if pos.Sign() < 0 { if pos.Sign() < 0 {
side = types.SideTypeSell side = types.SideTypeSell
} }
quantity := pos.Abs()
lastPrice := s.lastPrice lastPrice := s.lastPrice
sourceBook := s.pricingBook.CopyDepth(1) sourceBook := s.pricingBook.CopyDepth(1)
switch side { switch side {