xfunding: pull out premium check to detectPremiumIndex

This commit is contained in:
c9s 2023-03-22 22:17:37 +08:00
parent dc5e0cbcc2
commit 928f668fec
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -206,8 +206,14 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
return return
} }
fundingRate := premiumIndex.LastFundingRate s.detectPremiumIndex(premiumIndex)
}))
return nil
}
func (s *Strategy) detectPremiumIndex(premiumIndex *types.PremiumIndex) {
fundingRate := premiumIndex.LastFundingRate
if s.ShortFundingRate != nil { if s.ShortFundingRate != nil {
if fundingRate.Compare(s.ShortFundingRate.High) >= 0 { if fundingRate.Compare(s.ShortFundingRate.High) >= 0 {
s.positionAction = PositionOpening s.positionAction = PositionOpening
@ -216,9 +222,6 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
s.positionAction = PositionClosing s.positionAction = PositionClosing
} }
} }
}))
return nil
} }
func (s *Strategy) allocateOrderExecutor(ctx context.Context, session *bbgo.ExchangeSession, instanceID string, position *types.Position) *bbgo.GeneralOrderExecutor { func (s *Strategy) allocateOrderExecutor(ctx context.Context, session *bbgo.ExchangeSession, instanceID string, position *types.Position) *bbgo.GeneralOrderExecutor {