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,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)