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,16 +718,21 @@ func (s *Strategy) detectPremiumIndex(premiumIndex *types.PremiumIndex) bool {
switch s.getPositionState() {
case PositionClosed:
if fundingRate.Compare(s.ShortFundingRate.High) >= 0 {
if fundingRate.Compare(s.ShortFundingRate.High) < 0 {
return false
}
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:
if fundingRate.Compare(s.ShortFundingRate.Low) <= 0 {
if fundingRate.Compare(s.ShortFundingRate.Low) > 0 {
return false
}
log.Infof("funding rate %s is lower than the Low threshold %s, start closing position...",
fundingRate.Percentage(), s.ShortFundingRate.Low.Percentage())
@ -740,7 +745,6 @@ func (s *Strategy) detectPremiumIndex(premiumIndex *types.PremiumIndex) bool {
s.startClosingPosition()
return true
}
}
return false
}