xfunding: fix position sync bug

This commit is contained in:
c9s 2023-03-29 23:05:31 +08:00
parent 0efb56c43e
commit 7c975da575
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -703,12 +703,19 @@ func (s *Strategy) syncFuturesPosition(ctx context.Context) {
return
}
log.Infof("calculated futures account quote value = %s", quoteValue.String())
if quoteValue.IsZero() {
return
}
// max futures base position (without negative sign)
maxFuturesBasePosition := fixedpoint.Min(
spotBase.Mul(s.Leverage),
s.State.TotalBaseTransfer.Mul(s.Leverage))
if maxFuturesBasePosition.IsZero() {
return
}
// if - futures position < max futures position, increase it
if futuresBase.Neg().Compare(maxFuturesBasePosition) >= 0 {
s.setPositionState(PositionReady)