@strobelabs/perpcity-sdk 0.6.0 → 0.6.1
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/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -6489,7 +6489,7 @@ declare function calculateLeverage(positionValue: number, effectiveMargin: numbe
|
|
|
6489
6489
|
* @param isLong - Whether the position is long
|
|
6490
6490
|
* @returns Liquidation price in USD, or null if cannot be calculated
|
|
6491
6491
|
*/
|
|
6492
|
-
declare function calculateLiquidationPrice(rawData: PositionRawData, isLong: boolean): number | null;
|
|
6492
|
+
declare function calculateLiquidationPrice(rawData: PositionRawData, isLong: boolean, effectiveMargin?: number): number | null;
|
|
6493
6493
|
declare function calculatePnlPercentage(pnl: number, funding: number, margin: number): number;
|
|
6494
6494
|
/**
|
|
6495
6495
|
* Calculates ClosePositionParams for a position close, handling the difference
|
package/dist/index.d.ts
CHANGED
|
@@ -6489,7 +6489,7 @@ declare function calculateLeverage(positionValue: number, effectiveMargin: numbe
|
|
|
6489
6489
|
* @param isLong - Whether the position is long
|
|
6490
6490
|
* @returns Liquidation price in USD, or null if cannot be calculated
|
|
6491
6491
|
*/
|
|
6492
|
-
declare function calculateLiquidationPrice(rawData: PositionRawData, isLong: boolean): number | null;
|
|
6492
|
+
declare function calculateLiquidationPrice(rawData: PositionRawData, isLong: boolean, effectiveMargin?: number): number | null;
|
|
6493
6493
|
declare function calculatePnlPercentage(pnl: number, funding: number, margin: number): number;
|
|
6494
6494
|
/**
|
|
6495
6495
|
* Calculates ClosePositionParams for a position close, handling the difference
|
package/dist/index.js
CHANGED
|
@@ -4178,19 +4178,20 @@ function calculateLeverage(positionValue, effectiveMargin) {
|
|
|
4178
4178
|
}
|
|
4179
4179
|
return positionValue / effectiveMargin;
|
|
4180
4180
|
}
|
|
4181
|
-
function calculateLiquidationPrice(rawData, isLong) {
|
|
4181
|
+
function calculateLiquidationPrice(rawData, isLong, effectiveMargin) {
|
|
4182
4182
|
const entryPrice = calculateEntryPrice(rawData);
|
|
4183
4183
|
const positionSize = Math.abs(calculatePositionSize(rawData));
|
|
4184
|
-
|
|
4184
|
+
const margin = effectiveMargin ?? rawData.margin;
|
|
4185
|
+
if (positionSize === 0 || margin <= 0) {
|
|
4185
4186
|
return null;
|
|
4186
4187
|
}
|
|
4187
4188
|
const liqMarginRatio = rawData.marginRatios.liq / 1e6;
|
|
4188
4189
|
const entryNotional = positionSize * entryPrice;
|
|
4189
4190
|
if (isLong) {
|
|
4190
|
-
const liqPrice = entryPrice - (
|
|
4191
|
+
const liqPrice = entryPrice - (margin - liqMarginRatio * entryNotional) / positionSize;
|
|
4191
4192
|
return Math.max(0, liqPrice);
|
|
4192
4193
|
} else {
|
|
4193
|
-
const liqPrice = entryPrice + (
|
|
4194
|
+
const liqPrice = entryPrice + (margin - liqMarginRatio * entryNotional) / positionSize;
|
|
4194
4195
|
return liqPrice;
|
|
4195
4196
|
}
|
|
4196
4197
|
}
|