@drift-labs/sdk 2.36.1-beta.3 → 2.36.1-beta.5
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 +1 -1
- package/lib/user.d.ts +6 -0
- package/lib/user.js +17 -1
- package/package.json +1 -1
- package/src/user.ts +23 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.36.1-beta.
|
|
1
|
+
2.36.1-beta.5
|
package/lib/user.d.ts
CHANGED
|
@@ -188,6 +188,12 @@ export declare class User {
|
|
|
188
188
|
};
|
|
189
189
|
getTotalLiabilityValue(marginCategory?: MarginCategory): BN;
|
|
190
190
|
getTotalAssetValue(marginCategory?: MarginCategory): BN;
|
|
191
|
+
/**
|
|
192
|
+
* Calculates the all time P&L of the user.
|
|
193
|
+
*
|
|
194
|
+
* Net withdraws + Net spot market value + Net unrealized P&L -
|
|
195
|
+
*/
|
|
196
|
+
getTotalAllTimePnl(): BN;
|
|
191
197
|
/**
|
|
192
198
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
193
199
|
* for large sizes where imf factor activates, result is a lower bound
|
package/lib/user.js
CHANGED
|
@@ -815,6 +815,20 @@ class User {
|
|
|
815
815
|
getTotalAssetValue(marginCategory) {
|
|
816
816
|
return this.getSpotMarketAssetValue(undefined, marginCategory, true).add(this.getUnrealizedPNL(true, undefined, marginCategory));
|
|
817
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* Calculates the all time P&L of the user.
|
|
820
|
+
*
|
|
821
|
+
* Net withdraws + Net spot market value + Net unrealized P&L -
|
|
822
|
+
*/
|
|
823
|
+
getTotalAllTimePnl() {
|
|
824
|
+
const netBankValue = this.getNetSpotMarketValue();
|
|
825
|
+
const unrealizedPnl = this.getUnrealizedPNL(true, undefined, undefined);
|
|
826
|
+
const netUsdValue = netBankValue.add(unrealizedPnl);
|
|
827
|
+
const totalDeposits = this.getUserAccount().totalDeposits;
|
|
828
|
+
const totalWithdraws = this.getUserAccount().totalWithdraws;
|
|
829
|
+
const totalPnl = netUsdValue.add(totalWithdraws).sub(totalDeposits);
|
|
830
|
+
return totalPnl;
|
|
831
|
+
}
|
|
818
832
|
/**
|
|
819
833
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
820
834
|
* for large sizes where imf factor activates, result is a lower bound
|
|
@@ -1089,7 +1103,9 @@ class User {
|
|
|
1089
1103
|
.div(numericConstants_1.BASE_PRECISION);
|
|
1090
1104
|
}
|
|
1091
1105
|
if (!orderBaseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
1092
|
-
freeCollateralDelta = freeCollateralDelta.sub(marginRatioQuotePrecision
|
|
1106
|
+
freeCollateralDelta = freeCollateralDelta.sub(marginRatioQuotePrecision
|
|
1107
|
+
.mul(orderBaseAssetAmount.abs())
|
|
1108
|
+
.div(numericConstants_1.BASE_PRECISION));
|
|
1093
1109
|
}
|
|
1094
1110
|
return freeCollateralDelta;
|
|
1095
1111
|
}
|
package/package.json
CHANGED
package/src/user.ts
CHANGED
|
@@ -1487,6 +1487,24 @@ export class User {
|
|
|
1487
1487
|
);
|
|
1488
1488
|
}
|
|
1489
1489
|
|
|
1490
|
+
/**
|
|
1491
|
+
* Calculates the all time P&L of the user.
|
|
1492
|
+
*
|
|
1493
|
+
* Net withdraws + Net spot market value + Net unrealized P&L -
|
|
1494
|
+
*/
|
|
1495
|
+
getTotalAllTimePnl(): BN {
|
|
1496
|
+
const netBankValue = this.getNetSpotMarketValue();
|
|
1497
|
+
const unrealizedPnl = this.getUnrealizedPNL(true, undefined, undefined);
|
|
1498
|
+
|
|
1499
|
+
const netUsdValue = netBankValue.add(unrealizedPnl);
|
|
1500
|
+
const totalDeposits = this.getUserAccount().totalDeposits;
|
|
1501
|
+
const totalWithdraws = this.getUserAccount().totalWithdraws;
|
|
1502
|
+
|
|
1503
|
+
const totalPnl = netUsdValue.add(totalWithdraws).sub(totalDeposits);
|
|
1504
|
+
|
|
1505
|
+
return totalPnl;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1490
1508
|
/**
|
|
1491
1509
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
1492
1510
|
* for large sizes where imf factor activates, result is a lower bound
|
|
@@ -1974,7 +1992,11 @@ export class User {
|
|
|
1974
1992
|
}
|
|
1975
1993
|
|
|
1976
1994
|
if (!orderBaseAssetAmount.eq(ZERO)) {
|
|
1977
|
-
freeCollateralDelta = freeCollateralDelta.sub(
|
|
1995
|
+
freeCollateralDelta = freeCollateralDelta.sub(
|
|
1996
|
+
marginRatioQuotePrecision
|
|
1997
|
+
.mul(orderBaseAssetAmount.abs())
|
|
1998
|
+
.div(BASE_PRECISION)
|
|
1999
|
+
);
|
|
1978
2000
|
}
|
|
1979
2001
|
|
|
1980
2002
|
return freeCollateralDelta;
|