@pear-protocol/utils
Advanced tools
@@ -10,2 +10,6 @@ import type { InstrumentId } from '@pear-protocol/types'; | ||
| }; | ||
| export type AssetRealization = { | ||
| fillId: string; | ||
| gross: BigNumber; | ||
| }; | ||
| export type AssetRealizedPnL = { | ||
@@ -19,2 +23,3 @@ id: InstrumentId; | ||
| pearFees: BigNumber; | ||
| realizations: AssetRealization[]; | ||
| }; |
@@ -1,2 +0,2 @@ | ||
| export type { AssetRealizedPnL, AssetUnrealizedPnL } from './asset.types'; | ||
| export type { AssetRealization, AssetRealizedPnL, AssetUnrealizedPnL } from './asset.types'; | ||
| export * from './compute'; |
+8
-6
@@ -188,3 +188,3 @@ import BigNumber9 from 'bignumber.js'; | ||
| const totalFees = tradeFees.plus(pearFees); | ||
| const { gross: grossPnl, undeterminedSize } = walkAssetFills(assetFills); | ||
| const { gross: grossPnl, undeterminedSize, realizations } = walkAssetFills(assetFills); | ||
| const netPnl = grossPnl.minus(totalFees); | ||
@@ -198,3 +198,4 @@ result.push({ | ||
| tradeFees, | ||
| pearFees | ||
| pearFees, | ||
| realizations | ||
| }); | ||
@@ -210,2 +211,3 @@ } | ||
| let undeterminedSize = ZERO; | ||
| const realizations = []; | ||
| for (const fill of fills) { | ||
@@ -220,6 +222,6 @@ const price = parse(fill.price); | ||
| undeterminedSize = add(undeterminedSize, closedQty); | ||
| } else if (isPositive(positionSize)) { | ||
| gross = add(gross, multiply(closedQty, subtract(price, entryPrice))); | ||
| } else { | ||
| gross = add(gross, multiply(closedQty, subtract(entryPrice, price))); | ||
| const realized = isPositive(positionSize) ? multiply(closedQty, subtract(price, entryPrice)) : multiply(closedQty, subtract(entryPrice, price)); | ||
| gross = add(gross, realized); | ||
| realizations.push({ fillId: fill.id, gross: realized }); | ||
| } | ||
@@ -238,3 +240,3 @@ } | ||
| } | ||
| return { gross, undeterminedSize }; | ||
| return { gross, undeterminedSize, realizations }; | ||
| } | ||
@@ -241,0 +243,0 @@ function computeBasketWeightedRatioV1(basket, priceMap) { |
+2
-2
| { | ||
| "name": "@pear-protocol/utils", | ||
| "version": "0.3.0", | ||
| "version": "0.4.0", | ||
| "description": "Pear Protocol Utility functions", | ||
@@ -30,3 +30,3 @@ "private": false, | ||
| "@noble/hashes": "^1.3.2", | ||
| "@pear-protocol/types": "^1.14.1", | ||
| "@pear-protocol/types": "^1.15.0", | ||
| "bignumber.js": "9.3.1" | ||
@@ -33,0 +33,0 @@ }, |
98959
0.27%2589
0.27%Updated