From 928f668fecf21d85b23436310f068a656e3fd137 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 22 Mar 2023 22:17:37 +0800 Subject: [PATCH] xfunding: pull out premium check to detectPremiumIndex --- pkg/strategy/xfunding/strategy.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pkg/strategy/xfunding/strategy.go b/pkg/strategy/xfunding/strategy.go index 7dcf100a5..4fb91a94a 100644 --- a/pkg/strategy/xfunding/strategy.go +++ b/pkg/strategy/xfunding/strategy.go @@ -206,21 +206,24 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order return } - fundingRate := premiumIndex.LastFundingRate - - if s.ShortFundingRate != nil { - if fundingRate.Compare(s.ShortFundingRate.High) >= 0 { - s.positionAction = PositionOpening - s.positionType = types.PositionShort - } else if fundingRate.Compare(s.ShortFundingRate.Low) <= 0 { - s.positionAction = PositionClosing - } - } + s.detectPremiumIndex(premiumIndex) })) return nil } +func (s *Strategy) detectPremiumIndex(premiumIndex *types.PremiumIndex) { + fundingRate := premiumIndex.LastFundingRate + if s.ShortFundingRate != nil { + if fundingRate.Compare(s.ShortFundingRate.High) >= 0 { + s.positionAction = PositionOpening + s.positionType = types.PositionShort + } else if fundingRate.Compare(s.ShortFundingRate.Low) <= 0 { + s.positionAction = PositionClosing + } + } +} + func (s *Strategy) allocateOrderExecutor(ctx context.Context, session *bbgo.ExchangeSession, instanceID string, position *types.Position) *bbgo.GeneralOrderExecutor { orderExecutor := bbgo.NewGeneralOrderExecutor(session, s.Symbol, ID, instanceID, position) orderExecutor.BindEnvironment(s.Environment)