From 3048a13f0b7a4c283b07f67b8caadbaa9c26b6f5 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 8 Dec 2023 00:21:53 +0800 Subject: [PATCH] xdepthmaker: replace AtomicAdd with Add --- pkg/fixedpoint/dec.go | 4 ++-- pkg/strategy/xdepthmaker/strategy.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/fixedpoint/dec.go b/pkg/fixedpoint/dec.go index 41318f76d..17c66cac3 100644 --- a/pkg/fixedpoint/dec.go +++ b/pkg/fixedpoint/dec.go @@ -1197,7 +1197,7 @@ func align(x, y *Value) bool { } yshift = e // check(0 <= yshift && yshift <= 20) - //y.coef = (y.coef + halfpow10[yshift]) / pow10[yshift] + // y.coef = (y.coef + halfpow10[yshift]) / pow10[yshift] y.coef = (y.coef) / pow10[yshift] // check(int(y.exp)+yshift == int(x.exp)) return true @@ -1364,4 +1364,4 @@ func (x Value) Clamp(min, max Value) Value { return max } return x -} \ No newline at end of file +} diff --git a/pkg/strategy/xdepthmaker/strategy.go b/pkg/strategy/xdepthmaker/strategy.go index a446a1289..eb7d2a923 100644 --- a/pkg/strategy/xdepthmaker/strategy.go +++ b/pkg/strategy/xdepthmaker/strategy.go @@ -148,7 +148,8 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize( // 1) short position -> reduce short position // 2) short position -> increase short position if trade.Exchange == s.hedgeSession.ExchangeName { - s.CoveredPosition.AtomicAdd(c) + // TODO: make this atomic + s.CoveredPosition = s.CoveredPosition.Add(c) } s.ProfitStats.AddTrade(trade) @@ -557,9 +558,9 @@ func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) { // if the hedge is on sell side, then we should add positive position switch side { case types.SideTypeSell: - s.CoveredPosition.AtomicAdd(quantity) + s.CoveredPosition = s.CoveredPosition.Add(quantity) case types.SideTypeBuy: - s.CoveredPosition.AtomicAdd(quantity.Neg()) + s.CoveredPosition = s.CoveredPosition.Add(quantity.Neg()) } }