From db62352e6e077d8aeae746449eb38ee169302b8c Mon Sep 17 00:00:00 2001 From: Andy Cheng Date: Tue, 17 May 2022 10:43:18 +0800 Subject: [PATCH] strategy: temp vars for faster calculation --- pkg/strategy/bollmaker/strategy.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/strategy/bollmaker/strategy.go b/pkg/strategy/bollmaker/strategy.go index b6cd287c0..a46b6f43c 100644 --- a/pkg/strategy/bollmaker/strategy.go +++ b/pkg/strategy/bollmaker/strategy.go @@ -672,11 +672,14 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se } // Update spreads + high := kline.GetHigh().Float64() + open := kline.GetOpen().Float64() + low := kline.GetLow().Float64() if s.DynamicSpreadWindow > 0 && kline.Direction() == types.DirectionUp { - s.DynamicAskSpread.Update(kline.GetHigh().Sub(kline.GetOpen()).Div(kline.GetOpen()).Float64()) + s.DynamicAskSpread.Update((high - open) / open) } if s.DynamicSpreadWindow > 0 && kline.Direction() == types.DirectionDown { - s.DynamicBidSpread.Update(kline.GetOpen().Sub(kline.GetLow()).Div(kline.GetOpen()).Float64()) + s.DynamicBidSpread.Update((open - low) / open) } if s.DynamicSpreadWindow > 0 && s.DynamicBidSpread.Length() >= s.DynamicSpreadWindow { dynamicBidSpread := fixedpoint.NewFromFloat(s.DynamicBidSpread.Last())