mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
xfunding: use early return
This commit is contained in:
parent
300506f9f9
commit
0c6e9496b3
|
@ -718,28 +718,32 @@ func (s *Strategy) detectPremiumIndex(premiumIndex *types.PremiumIndex) bool {
|
|||
switch s.getPositionState() {
|
||||
|
||||
case PositionClosed:
|
||||
if fundingRate.Compare(s.ShortFundingRate.High) >= 0 {
|
||||
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
|
||||
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 {
|
||||
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
|
||||
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())
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user