-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: estimatePosition GraphQL API returns error #8313
Comments
@MuthuVega - please can you catch up with @bglownia and see if we can reproduce this in tests. |
After reading through the code for the
func calculateLiquidationPrice(openVolume num.Decimal, currentPrice, collateralAvailable num.Decimal, linearSlippageFactor, quadraticSlippageFactor, riskFactorLong, riskFactorShort num.Decimal) (num.Decimal, error) {
rf := riskFactorLong
if openVolume.IsNegative() {
rf = riskFactorShort
}
denominator := calculateSlippageFactor(openVolume, linearSlippageFactor, quadraticSlippageFactor).Add(openVolume.Abs().Mul(rf)).Sub(openVolume)
if denominator.IsZero() {
return num.DecimalZero(), fmt.Errorf("liquidation price not defined")
}
ret := collateralAvailable.Sub(openVolume.Mul(currentPrice)).Div(denominator)
if ret.IsNegative() {
return num.DecimalZero(), nil
}
return ret, nil
} Which is passed back up to var liquidationEstimate *v2.LiquidationEstimate
if req.CollateralAvailable != nil && len(*req.CollateralAvailable) > 0 {
liquidationEstimate, err = t.computeLiquidationPriceRange(
collateralAvailable,
req.OpenVolume,
buyOrders,
sellOrders,
marketObservable,
positionFactor,
linearSlippageFactor,
quadraticSlippageFactor,
rf)
if err != nil {
return nil, err
}
} Where we just check |
API fails also with
but not with
|
Tests for this can be seen in the market sim: |
Problem encountered
Graphql request to https://api.n07.testnet.vega.xyz/graphql
returns error
It happens when openPosition + remaining can be zero. Open volume = 1 and order remaining is 1 on sell side .
The text was updated successfully, but these errors were encountered: