diff --git a/CHANGELOG.md b/CHANGELOG.md index b749df6c4..1d6a1779a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features ### Fixes +- sdk: fix bug which incorrectly calculated leverage after trade for a market with no position but short orders open ### Breaking diff --git a/sdk/src/user.ts b/sdk/src/user.ts index 05db9ca11..acfa0a007 100644 --- a/sdk/src/user.ts +++ b/sdk/src/user.ts @@ -2884,8 +2884,12 @@ export class User { includeOpenOrders ); + const worstCaseBase = calculateWorstCaseBaseAssetAmount(currentPosition); + + // current side is short if position base asset amount is negative OR there is no position open but open orders are short const currentSide = - currentPosition && currentPosition.baseAssetAmount.isNeg() + currentPosition.baseAssetAmount.isNeg() || + (currentPosition.baseAssetAmount.eq(ZERO) && worstCaseBase.isNeg()) ? PositionDirection.SHORT : PositionDirection.LONG;