@drift-labs/sdk 2.43.0-beta.7 → 2.43.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.43.0-beta.7
1
+ 2.43.0-beta.8
package/lib/user.js CHANGED
@@ -1564,7 +1564,10 @@ class User {
1564
1564
  this.getEmptyPosition(targetMarketIndex);
1565
1565
  const oracleData = this.getOracleDataForPerpMarket(targetMarketIndex);
1566
1566
  let currentPositionQuoteAmount = this.getPerpPositionValue(targetMarketIndex, oracleData, includeOpenOrders);
1567
- const currentSide = currentPosition && currentPosition.baseAssetAmount.isNeg()
1567
+ const worstCaseBase = (0, margin_1.calculateWorstCaseBaseAssetAmount)(currentPosition);
1568
+ // current side is short if position base asset amount is negative OR there is no position open but open orders are short
1569
+ const currentSide = currentPosition.baseAssetAmount.isNeg() ||
1570
+ (currentPosition.baseAssetAmount.eq(numericConstants_1.ZERO) && worstCaseBase.isNeg())
1568
1571
  ? _1.PositionDirection.SHORT
1569
1572
  : _1.PositionDirection.LONG;
1570
1573
  if (currentSide === _1.PositionDirection.SHORT)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.43.0-beta.7",
3
+ "version": "2.43.0-beta.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
package/src/user.ts CHANGED
@@ -2884,8 +2884,12 @@ export class User {
2884
2884
  includeOpenOrders
2885
2885
  );
2886
2886
 
2887
+ const worstCaseBase = calculateWorstCaseBaseAssetAmount(currentPosition);
2888
+
2889
+ // current side is short if position base asset amount is negative OR there is no position open but open orders are short
2887
2890
  const currentSide =
2888
- currentPosition && currentPosition.baseAssetAmount.isNeg()
2891
+ currentPosition.baseAssetAmount.isNeg() ||
2892
+ (currentPosition.baseAssetAmount.eq(ZERO) && worstCaseBase.isNeg())
2889
2893
  ? PositionDirection.SHORT
2890
2894
  : PositionDirection.LONG;
2891
2895