xfunding: improve checkAndRestorePositionRisks

This commit is contained in:
c9s 2023-03-29 21:36:29 +08:00
parent 8257c4ffbe
commit c437837210
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -1027,12 +1027,21 @@ func (s *Strategy) checkAndRestorePositionRisks(ctx context.Context) error {
} }
for _, positionRisk := range positionRisks { for _, positionRisk := range positionRisks {
if positionRisk.Symbol == s.Symbol { if positionRisk.Symbol != s.Symbol {
s.FuturesPosition.Base = positionRisk.PositionAmount continue
s.FuturesPosition.AverageCost = positionRisk.EntryPrice }
}
if positionRisk.PositionAmount.IsZero() || positionRisk.EntryPrice.IsZero() {
continue
}
s.FuturesPosition.Base = positionRisk.PositionAmount
s.FuturesPosition.AverageCost = positionRisk.EntryPrice
log.Infof("restored futures position from positionRisk: base=%s, average_cost=%s, position_risk=%+v",
s.FuturesPosition.Base.String(),
s.FuturesPosition.AverageCost.String(),
positionRisk)
} }
log.Infof("positions: %+v", positionRisks)
return nil return nil
} }