xfunding: use early return

This commit is contained in:
c9s 2023-03-25 02:56:45 +08:00
parent 300506f9f9
commit 0c6e9496b3
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -718,28 +718,32 @@ func (s *Strategy) detectPremiumIndex(premiumIndex *types.PremiumIndex) bool {
switch s.getPositionState() { switch s.getPositionState() {
case PositionClosed: case PositionClosed:
if fundingRate.Compare(s.ShortFundingRate.High) >= 0 { if fundingRate.Compare(s.ShortFundingRate.High) < 0 {
log.Infof("funding rate %s is higher than the High threshold %s, start opening position...", return false
fundingRate.Percentage(), s.ShortFundingRate.High.Percentage())
s.startOpeningPosition(types.PositionShort, premiumIndex.Time)
return true
} }
log.Infof("funding rate %s is higher than the High threshold %s, start opening position...",
fundingRate.Percentage(), s.ShortFundingRate.High.Percentage())
s.startOpeningPosition(types.PositionShort, premiumIndex.Time)
return true
case PositionReady: case PositionReady:
if fundingRate.Compare(s.ShortFundingRate.Low) <= 0 { if fundingRate.Compare(s.ShortFundingRate.Low) > 0 {
log.Infof("funding rate %s is lower than the Low threshold %s, start closing position...", return false
fundingRate.Percentage(), s.ShortFundingRate.Low.Percentage())
holdingPeriod := premiumIndex.Time.Sub(s.State.PositionStartTime)
if holdingPeriod < time.Duration(s.MinHoldingPeriod) {
log.Warnf("position holding period %s is less than %s, skip closing", holdingPeriod, s.MinHoldingPeriod.Duration())
return false
}
s.startClosingPosition()
return true
} }
log.Infof("funding rate %s is lower than the Low threshold %s, start closing position...",
fundingRate.Percentage(), s.ShortFundingRate.Low.Percentage())
holdingPeriod := premiumIndex.Time.Sub(s.State.PositionStartTime)
if holdingPeriod < time.Duration(s.MinHoldingPeriod) {
log.Warnf("position holding period %s is less than %s, skip closing", holdingPeriod, s.MinHoldingPeriod.Duration())
return false
}
s.startClosingPosition()
return true
} }
return false return false