Skip to content

Commit

Permalink
sdk: fix leverage after trade bug (#674)
Browse files Browse the repository at this point in the history
* sdk: fix leverage after trade bug

* use worstCaseBase
  • Loading branch information
lowkeynicc authored Nov 6, 2023
1 parent 6205213 commit 6e5530f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion sdk/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6e5530f

Please sign in to comment.