@lifi/perps-sdk 20.1.1 → 21.1.0
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/README.md +81 -6
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +4 -1
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
- package/dist/cjs/decimal/big.d.ts.map +1 -0
- package/dist/cjs/{utils/decimal.js → decimal/big.js} +1 -1
- package/dist/cjs/decimal/big.js.map +1 -0
- package/dist/cjs/decimal/convert.d.ts +11 -0
- package/dist/cjs/decimal/convert.d.ts.map +1 -0
- package/dist/cjs/decimal/convert.js +70 -0
- package/dist/cjs/decimal/convert.js.map +1 -0
- package/dist/cjs/decimal/format.d.ts.map +1 -0
- package/dist/cjs/decimal/format.js.map +1 -0
- package/dist/cjs/decimal/parse.d.ts +6 -0
- package/dist/cjs/decimal/parse.d.ts.map +1 -0
- package/dist/cjs/{utils → decimal}/parse.js +5 -4
- package/dist/cjs/decimal/parse.js.map +1 -0
- package/dist/cjs/index.d.ts +17 -15
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +75 -61
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math/fills.d.ts +5 -0
- package/dist/cjs/math/fills.d.ts.map +1 -0
- package/dist/cjs/{utils/fillClassification.js → math/fills.js} +16 -1
- package/dist/cjs/math/fills.js.map +1 -0
- package/dist/cjs/math/order.d.ts +45 -0
- package/dist/cjs/math/order.d.ts.map +1 -0
- package/dist/cjs/math/order.js +256 -0
- package/dist/cjs/math/order.js.map +1 -0
- package/dist/cjs/math/position.d.ts +56 -0
- package/dist/cjs/math/position.d.ts.map +1 -0
- package/dist/cjs/math/position.js +160 -0
- package/dist/cjs/math/position.js.map +1 -0
- package/dist/cjs/services/getActivity.d.ts.map +1 -1
- package/dist/cjs/services/getActivity.js.map +1 -1
- package/dist/cjs/services/getFills.d.ts.map +1 -1
- package/dist/cjs/services/getFills.js.map +1 -1
- package/dist/cjs/services/getOrder.d.ts.map +1 -1
- package/dist/cjs/services/getOrder.js.map +1 -1
- package/dist/cjs/services/getOrders.d.ts.map +1 -1
- package/dist/cjs/services/getOrders.js.map +1 -1
- package/dist/cjs/services/getPositions.d.ts.map +1 -1
- package/dist/cjs/services/getPositions.js.map +1 -1
- package/dist/cjs/services/resolveQuote.d.ts.map +1 -1
- package/dist/cjs/services/resolveQuote.js +2 -2
- package/dist/cjs/services/resolveQuote.js.map +1 -1
- package/dist/cjs/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/cjs/services/resolveSubscribeQuote.js +2 -2
- package/dist/cjs/services/resolveSubscribeQuote.js.map +1 -1
- package/dist/cjs/types/provider.d.ts +3 -3
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts +2 -0
- package/dist/cjs/types/withdrawal.d.ts.map +1 -1
- package/dist/cjs/utils/orderClassification.d.ts +1 -3
- package/dist/cjs/utils/orderClassification.d.ts.map +1 -1
- package/dist/cjs/utils/orderClassification.js +1 -15
- package/dist/cjs/utils/orderClassification.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wire/orderAmounts.d.ts +18 -0
- package/dist/cjs/wire/orderAmounts.d.ts.map +1 -0
- package/dist/cjs/wire/orderAmounts.js +79 -0
- package/dist/cjs/wire/orderAmounts.js.map +1 -0
- package/dist/cjs/wire/refuel.d.ts +8 -0
- package/dist/cjs/wire/refuel.d.ts.map +1 -0
- package/dist/cjs/wire/refuel.js +23 -0
- package/dist/cjs/wire/refuel.js.map +1 -0
- package/dist/cjs/wire/requireDecimal.d.ts +4 -0
- package/dist/cjs/wire/requireDecimal.d.ts.map +1 -0
- package/dist/cjs/wire/requireDecimal.js +16 -0
- package/dist/cjs/wire/requireDecimal.js.map +1 -0
- package/dist/cjs/wire/snap.d.ts +5 -0
- package/dist/cjs/wire/snap.d.ts.map +1 -0
- package/dist/cjs/wire/snap.js +12 -0
- package/dist/cjs/wire/snap.js.map +1 -0
- package/dist/cjs/wire/transferable.d.ts +3 -0
- package/dist/cjs/wire/transferable.d.ts.map +1 -0
- package/dist/cjs/wire/transferable.js +13 -0
- package/dist/cjs/wire/transferable.js.map +1 -0
- package/dist/cjs/wire/withdraw.d.ts +4 -0
- package/dist/cjs/wire/withdraw.d.ts.map +1 -0
- package/dist/cjs/wire/withdraw.js +13 -0
- package/dist/cjs/wire/withdraw.js.map +1 -0
- package/dist/esm/client/PerpsClient.d.ts +37 -5
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +41 -6
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
- package/dist/esm/decimal/big.d.ts.map +1 -0
- package/dist/esm/{utils/decimal.js → decimal/big.js} +1 -1
- package/dist/esm/decimal/big.js.map +1 -0
- package/dist/esm/decimal/convert.d.ts +80 -0
- package/dist/esm/decimal/convert.d.ts.map +1 -0
- package/dist/esm/decimal/convert.js +118 -0
- package/dist/esm/decimal/convert.js.map +1 -0
- package/dist/esm/decimal/format.d.ts.map +1 -0
- package/dist/esm/decimal/format.js.map +1 -0
- package/dist/esm/decimal/parse.d.ts +29 -0
- package/dist/esm/decimal/parse.d.ts.map +1 -0
- package/dist/esm/{utils → decimal}/parse.js +9 -10
- package/dist/esm/decimal/parse.js.map +1 -0
- package/dist/esm/index.d.ts +17 -15
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +12 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math/fills.d.ts +26 -0
- package/dist/esm/math/fills.d.ts.map +1 -0
- package/dist/esm/{utils/fillClassification.js → math/fills.js} +26 -2
- package/dist/esm/math/fills.js.map +1 -0
- package/dist/esm/{utils/calculations.d.ts → math/order.d.ts} +70 -75
- package/dist/esm/math/order.d.ts.map +1 -0
- package/dist/esm/{utils/calculations.js → math/order.js} +155 -111
- package/dist/esm/math/order.js.map +1 -0
- package/dist/esm/math/position.d.ts +211 -0
- package/dist/esm/math/position.d.ts.map +1 -0
- package/dist/esm/math/position.js +299 -0
- package/dist/esm/math/position.js.map +1 -0
- package/dist/esm/services/getActivity.d.ts +4 -0
- package/dist/esm/services/getActivity.d.ts.map +1 -1
- package/dist/esm/services/getActivity.js +4 -0
- package/dist/esm/services/getActivity.js.map +1 -1
- package/dist/esm/services/getFills.d.ts +4 -0
- package/dist/esm/services/getFills.d.ts.map +1 -1
- package/dist/esm/services/getFills.js +4 -0
- package/dist/esm/services/getFills.js.map +1 -1
- package/dist/esm/services/getOrder.d.ts +4 -0
- package/dist/esm/services/getOrder.d.ts.map +1 -1
- package/dist/esm/services/getOrder.js +4 -0
- package/dist/esm/services/getOrder.js.map +1 -1
- package/dist/esm/services/getOrders.d.ts +10 -1
- package/dist/esm/services/getOrders.d.ts.map +1 -1
- package/dist/esm/services/getOrders.js +10 -1
- package/dist/esm/services/getOrders.js.map +1 -1
- package/dist/esm/services/getPositions.d.ts +4 -0
- package/dist/esm/services/getPositions.d.ts.map +1 -1
- package/dist/esm/services/getPositions.js +4 -0
- package/dist/esm/services/getPositions.js.map +1 -1
- package/dist/esm/services/resolveQuote.d.ts.map +1 -1
- package/dist/esm/services/resolveQuote.js +1 -1
- package/dist/esm/services/resolveQuote.js.map +1 -1
- package/dist/esm/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/esm/services/resolveSubscribeQuote.js +1 -1
- package/dist/esm/services/resolveSubscribeQuote.js.map +1 -1
- package/dist/esm/types/provider.d.ts +23 -11
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +12 -0
- package/dist/esm/types/withdrawal.d.ts.map +1 -1
- package/dist/esm/utils/orderClassification.d.ts +1 -14
- package/dist/esm/utils/orderClassification.d.ts.map +1 -1
- package/dist/esm/utils/orderClassification.js +1 -25
- package/dist/esm/utils/orderClassification.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wire/orderAmounts.d.ts +55 -0
- package/dist/esm/wire/orderAmounts.d.ts.map +1 -0
- package/dist/esm/wire/orderAmounts.js +114 -0
- package/dist/esm/wire/orderAmounts.js.map +1 -0
- package/dist/esm/wire/refuel.d.ts +28 -0
- package/dist/esm/wire/refuel.d.ts.map +1 -0
- package/dist/esm/wire/refuel.js +36 -0
- package/dist/esm/wire/refuel.js.map +1 -0
- package/dist/esm/wire/requireDecimal.d.ts +11 -0
- package/dist/esm/wire/requireDecimal.d.ts.map +1 -0
- package/dist/esm/wire/requireDecimal.js +17 -0
- package/dist/esm/wire/requireDecimal.js.map +1 -0
- package/dist/esm/wire/snap.d.ts +24 -0
- package/dist/esm/wire/snap.d.ts.map +1 -0
- package/dist/esm/wire/snap.js +27 -0
- package/dist/esm/wire/snap.js.map +1 -0
- package/dist/esm/wire/transferable.d.ts +15 -0
- package/dist/esm/wire/transferable.d.ts.map +1 -0
- package/dist/esm/wire/transferable.js +22 -0
- package/dist/esm/wire/transferable.js.map +1 -0
- package/dist/esm/wire/withdraw.d.ts +14 -0
- package/dist/esm/wire/withdraw.d.ts.map +1 -0
- package/dist/esm/wire/withdraw.js +20 -0
- package/dist/esm/wire/withdraw.js.map +1 -0
- package/dist/types/client/PerpsClient.d.ts +37 -5
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
- package/dist/types/decimal/big.d.ts.map +1 -0
- package/dist/types/decimal/convert.d.ts +80 -0
- package/dist/types/decimal/convert.d.ts.map +1 -0
- package/dist/types/decimal/format.d.ts.map +1 -0
- package/dist/types/decimal/parse.d.ts +29 -0
- package/dist/types/decimal/parse.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -15
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/math/fills.d.ts +26 -0
- package/dist/types/math/fills.d.ts.map +1 -0
- package/dist/types/{utils/calculations.d.ts → math/order.d.ts} +70 -75
- package/dist/types/math/order.d.ts.map +1 -0
- package/dist/types/math/position.d.ts +211 -0
- package/dist/types/math/position.d.ts.map +1 -0
- package/dist/types/services/getActivity.d.ts +4 -0
- package/dist/types/services/getActivity.d.ts.map +1 -1
- package/dist/types/services/getFills.d.ts +4 -0
- package/dist/types/services/getFills.d.ts.map +1 -1
- package/dist/types/services/getOrder.d.ts +4 -0
- package/dist/types/services/getOrder.d.ts.map +1 -1
- package/dist/types/services/getOrders.d.ts +10 -1
- package/dist/types/services/getOrders.d.ts.map +1 -1
- package/dist/types/services/getPositions.d.ts +4 -0
- package/dist/types/services/getPositions.d.ts.map +1 -1
- package/dist/types/services/resolveQuote.d.ts.map +1 -1
- package/dist/types/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +23 -11
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +12 -0
- package/dist/types/types/withdrawal.d.ts.map +1 -1
- package/dist/types/utils/orderClassification.d.ts +1 -14
- package/dist/types/utils/orderClassification.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wire/orderAmounts.d.ts +55 -0
- package/dist/types/wire/orderAmounts.d.ts.map +1 -0
- package/dist/types/wire/refuel.d.ts +28 -0
- package/dist/types/wire/refuel.d.ts.map +1 -0
- package/dist/types/wire/requireDecimal.d.ts +11 -0
- package/dist/types/wire/requireDecimal.d.ts.map +1 -0
- package/dist/types/wire/snap.d.ts +24 -0
- package/dist/types/wire/snap.d.ts.map +1 -0
- package/dist/types/wire/transferable.d.ts +15 -0
- package/dist/types/wire/transferable.d.ts.map +1 -0
- package/dist/types/wire/withdraw.d.ts +14 -0
- package/dist/types/wire/withdraw.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +41 -6
- package/src/decimal/convert.ts +164 -0
- package/src/{utils → decimal}/parse.ts +13 -11
- package/src/index.ts +80 -57
- package/src/{utils/fillClassification.ts → math/fills.ts} +30 -1
- package/src/{utils/calculations.ts → math/order.ts} +205 -127
- package/src/{utils/positionMath.ts → math/position.ts} +173 -21
- package/src/services/getActivity.ts +4 -0
- package/src/services/getFills.ts +4 -0
- package/src/services/getOrder.ts +4 -0
- package/src/services/getOrders.ts +10 -1
- package/src/services/getPositions.ts +4 -0
- package/src/services/resolveQuote.ts +1 -1
- package/src/services/resolveSubscribeQuote.ts +1 -1
- package/src/types/provider.ts +23 -10
- package/src/types/withdrawal.ts +12 -0
- package/src/utils/orderClassification.ts +0 -30
- package/src/version.ts +1 -1
- package/src/wire/orderAmounts.ts +172 -0
- package/src/wire/refuel.ts +51 -0
- package/src/wire/requireDecimal.ts +24 -0
- package/src/wire/snap.ts +38 -0
- package/src/wire/transferable.ts +26 -0
- package/src/wire/withdraw.ts +29 -0
- package/dist/cjs/utils/calculations.d.ts +0 -47
- package/dist/cjs/utils/calculations.d.ts.map +0 -1
- package/dist/cjs/utils/calculations.js +0 -214
- package/dist/cjs/utils/calculations.js.map +0 -1
- package/dist/cjs/utils/decimal.d.ts.map +0 -1
- package/dist/cjs/utils/decimal.js.map +0 -1
- package/dist/cjs/utils/fillClassification.d.ts +0 -3
- package/dist/cjs/utils/fillClassification.d.ts.map +0 -1
- package/dist/cjs/utils/fillClassification.js.map +0 -1
- package/dist/cjs/utils/format.d.ts.map +0 -1
- package/dist/cjs/utils/format.js.map +0 -1
- package/dist/cjs/utils/math.d.ts +0 -4
- package/dist/cjs/utils/math.d.ts.map +0 -1
- package/dist/cjs/utils/math.js +0 -8
- package/dist/cjs/utils/math.js.map +0 -1
- package/dist/cjs/utils/orderEntry.d.ts +0 -6
- package/dist/cjs/utils/orderEntry.d.ts.map +0 -1
- package/dist/cjs/utils/orderEntry.js +0 -20
- package/dist/cjs/utils/orderEntry.js.map +0 -1
- package/dist/cjs/utils/orderMath.d.ts +0 -6
- package/dist/cjs/utils/orderMath.d.ts.map +0 -1
- package/dist/cjs/utils/orderMath.js +0 -85
- package/dist/cjs/utils/orderMath.js.map +0 -1
- package/dist/cjs/utils/parse.d.ts +0 -3
- package/dist/cjs/utils/parse.d.ts.map +0 -1
- package/dist/cjs/utils/parse.js.map +0 -1
- package/dist/cjs/utils/positionMath.d.ts +0 -37
- package/dist/cjs/utils/positionMath.d.ts.map +0 -1
- package/dist/cjs/utils/positionMath.js +0 -99
- package/dist/cjs/utils/positionMath.js.map +0 -1
- package/dist/cjs/utils/scaleToInteger.d.ts +0 -3
- package/dist/cjs/utils/scaleToInteger.d.ts.map +0 -1
- package/dist/cjs/utils/scaleToInteger.js +0 -30
- package/dist/cjs/utils/scaleToInteger.js.map +0 -1
- package/dist/cjs/utils/units.d.ts +0 -3
- package/dist/cjs/utils/units.d.ts.map +0 -1
- package/dist/cjs/utils/units.js +0 -18
- package/dist/cjs/utils/units.js.map +0 -1
- package/dist/cjs/utils/validation.d.ts +0 -2
- package/dist/cjs/utils/validation.d.ts.map +0 -1
- package/dist/cjs/utils/validation.js +0 -16
- package/dist/cjs/utils/validation.js.map +0 -1
- package/dist/esm/utils/calculations.d.ts.map +0 -1
- package/dist/esm/utils/calculations.js.map +0 -1
- package/dist/esm/utils/decimal.d.ts.map +0 -1
- package/dist/esm/utils/decimal.js.map +0 -1
- package/dist/esm/utils/fillClassification.d.ts +0 -13
- package/dist/esm/utils/fillClassification.d.ts.map +0 -1
- package/dist/esm/utils/fillClassification.js.map +0 -1
- package/dist/esm/utils/format.d.ts.map +0 -1
- package/dist/esm/utils/format.js.map +0 -1
- package/dist/esm/utils/math.d.ts +0 -6
- package/dist/esm/utils/math.d.ts.map +0 -1
- package/dist/esm/utils/math.js +0 -5
- package/dist/esm/utils/math.js.map +0 -1
- package/dist/esm/utils/orderEntry.d.ts +0 -26
- package/dist/esm/utils/orderEntry.d.ts.map +0 -1
- package/dist/esm/utils/orderEntry.js +0 -34
- package/dist/esm/utils/orderEntry.js.map +0 -1
- package/dist/esm/utils/orderMath.d.ts +0 -37
- package/dist/esm/utils/orderMath.d.ts.map +0 -1
- package/dist/esm/utils/orderMath.js +0 -113
- package/dist/esm/utils/orderMath.js.map +0 -1
- package/dist/esm/utils/parse.d.ts +0 -28
- package/dist/esm/utils/parse.d.ts.map +0 -1
- package/dist/esm/utils/parse.js.map +0 -1
- package/dist/esm/utils/positionMath.d.ts +0 -120
- package/dist/esm/utils/positionMath.d.ts.map +0 -1
- package/dist/esm/utils/positionMath.js +0 -173
- package/dist/esm/utils/positionMath.js.map +0 -1
- package/dist/esm/utils/scaleToInteger.d.ts +0 -22
- package/dist/esm/utils/scaleToInteger.d.ts.map +0 -1
- package/dist/esm/utils/scaleToInteger.js +0 -34
- package/dist/esm/utils/scaleToInteger.js.map +0 -1
- package/dist/esm/utils/units.d.ts +0 -27
- package/dist/esm/utils/units.d.ts.map +0 -1
- package/dist/esm/utils/units.js +0 -38
- package/dist/esm/utils/units.js.map +0 -1
- package/dist/esm/utils/validation.d.ts +0 -18
- package/dist/esm/utils/validation.d.ts.map +0 -1
- package/dist/esm/utils/validation.js +0 -29
- package/dist/esm/utils/validation.js.map +0 -1
- package/dist/types/utils/calculations.d.ts.map +0 -1
- package/dist/types/utils/decimal.d.ts.map +0 -1
- package/dist/types/utils/fillClassification.d.ts +0 -13
- package/dist/types/utils/fillClassification.d.ts.map +0 -1
- package/dist/types/utils/format.d.ts.map +0 -1
- package/dist/types/utils/math.d.ts +0 -6
- package/dist/types/utils/math.d.ts.map +0 -1
- package/dist/types/utils/orderEntry.d.ts +0 -26
- package/dist/types/utils/orderEntry.d.ts.map +0 -1
- package/dist/types/utils/orderMath.d.ts +0 -37
- package/dist/types/utils/orderMath.d.ts.map +0 -1
- package/dist/types/utils/parse.d.ts +0 -28
- package/dist/types/utils/parse.d.ts.map +0 -1
- package/dist/types/utils/positionMath.d.ts +0 -120
- package/dist/types/utils/positionMath.d.ts.map +0 -1
- package/dist/types/utils/scaleToInteger.d.ts +0 -22
- package/dist/types/utils/scaleToInteger.d.ts.map +0 -1
- package/dist/types/utils/units.d.ts +0 -27
- package/dist/types/utils/units.d.ts.map +0 -1
- package/dist/types/utils/validation.d.ts +0 -18
- package/dist/types/utils/validation.d.ts.map +0 -1
- package/src/utils/math.ts +0 -7
- package/src/utils/orderEntry.ts +0 -38
- package/src/utils/orderMath.ts +0 -152
- package/src/utils/scaleToInteger.ts +0 -56
- package/src/utils/units.ts +0 -39
- package/src/utils/validation.ts +0 -38
- /package/dist/cjs/{utils → decimal}/format.d.ts +0 -0
- /package/dist/cjs/{utils → decimal}/format.js +0 -0
- /package/dist/esm/{utils → decimal}/format.d.ts +0 -0
- /package/dist/esm/{utils → decimal}/format.js +0 -0
- /package/dist/types/{utils → decimal}/format.d.ts +0 -0
- /package/src/{utils/decimal.ts → decimal/big.ts} +0 -0
- /package/src/{utils → decimal}/format.ts +0 -0
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Pure functions for computing position-related values that any consumer
|
|
5
|
-
* of the perps SDK would need. All parameters are required — no default
|
|
6
|
-
* values for critical financial parameters.
|
|
2
|
+
* Display-tier order formulas. Every function takes and gives `number`;
|
|
3
|
+
* exact decimal arithmetic happens internally with `DivBig`.
|
|
7
4
|
*/
|
|
8
|
-
import { type FeeTier, type Market, type MarketContext, type OrderbookLevel, type Quote, type QuoteSide, type TradeType } from '@lifi/perps-types';
|
|
5
|
+
import { type FeeTier, type Market, type MarketContext, type Order, type OrderbookLevel, type Position, type Quote, type QuoteSide, type RegularOrder, type TradeType, type TriggerOrder } from '@lifi/perps-types';
|
|
9
6
|
/**
|
|
10
7
|
* Calculate position size in asset units from margin.
|
|
11
8
|
*
|
|
@@ -15,48 +12,15 @@ import { type FeeTier, type Market, type MarketContext, type OrderbookLevel, typ
|
|
|
15
12
|
* @returns Position size in asset units
|
|
16
13
|
* @example
|
|
17
14
|
* ```ts
|
|
18
|
-
*
|
|
15
|
+
* calculateSize(100, 10, 2000) // 0.5 (ETH at $2000)
|
|
19
16
|
* ```
|
|
20
17
|
* @public
|
|
21
18
|
*/
|
|
22
|
-
export declare function
|
|
19
|
+
export declare function calculateSize(marginUsd: number, leverage: number, price: number): number;
|
|
23
20
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @param size - Position size in asset units
|
|
27
|
-
* @param price - Current asset price
|
|
28
|
-
* @returns Notional value in USD
|
|
29
|
-
* @public
|
|
30
|
-
*/
|
|
31
|
-
export declare function calculateNotionalValue(size: number, price: number): number;
|
|
32
|
-
/**
|
|
33
|
-
* Calculate unrealized PnL.
|
|
34
|
-
*
|
|
35
|
-
* @param entryPrice - Position entry price
|
|
36
|
-
* @param currentPrice - Current market price
|
|
37
|
-
* @param size - Position size (positive for long, negative for short)
|
|
38
|
-
* @returns Unrealized PnL in USD
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
export declare function calculateUnrealizedPnl(entryPrice: number, currentPrice: number, size: number): number;
|
|
42
|
-
/**
|
|
43
|
-
* Calculate return on equity (ROE) percentage.
|
|
44
|
-
*
|
|
45
|
-
* @param pnl - Profit/loss in USD
|
|
46
|
-
* @param margin - Initial margin in USD
|
|
47
|
-
* @returns ROE as percentage (e.g., 10 for 10%)
|
|
48
|
-
* @public
|
|
21
|
+
* @deprecated Use `calculateSize`. Removed in the next major.
|
|
49
22
|
*/
|
|
50
|
-
export declare
|
|
51
|
-
/**
|
|
52
|
-
* Calculate required margin for a position.
|
|
53
|
-
*
|
|
54
|
-
* @param notionalValue - Position notional value in USD
|
|
55
|
-
* @param leverage - Position leverage
|
|
56
|
-
* @returns Required margin in USD
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
export declare function calculateRequiredMargin(notionalValue: number, leverage: number): number;
|
|
23
|
+
export declare const calculatePositionSize: typeof calculateSize;
|
|
60
24
|
/**
|
|
61
25
|
* Estimate trading fees.
|
|
62
26
|
*
|
|
@@ -76,33 +40,6 @@ export declare function estimateFees(sizeUsd: number, feeRate: number): number;
|
|
|
76
40
|
* @public
|
|
77
41
|
*/
|
|
78
42
|
export declare function applySlippage(price: number, slippagePercent: number, isBuy: boolean): number;
|
|
79
|
-
/**
|
|
80
|
-
* Distance from the current price to the liquidation price, as a percentage of
|
|
81
|
-
* the current price.
|
|
82
|
-
*
|
|
83
|
-
* @param liquidationPrice - The position's liquidation price
|
|
84
|
-
* @param currentPrice - Current market price
|
|
85
|
-
* @returns Absolute distance as a percentage, or 0 when current price is zero
|
|
86
|
-
* @public
|
|
87
|
-
*/
|
|
88
|
-
export declare function liquidationDistancePercent(params: {
|
|
89
|
-
liquidationPrice: number;
|
|
90
|
-
currentPrice: number;
|
|
91
|
-
}): number;
|
|
92
|
-
/**
|
|
93
|
-
* Effective leverage of an open position.
|
|
94
|
-
*
|
|
95
|
-
* leverage = positionValueUsd / marginUsd
|
|
96
|
-
*
|
|
97
|
-
* @param positionValueUsd - Position notional value in USD
|
|
98
|
-
* @param marginUsd - Margin backing the position in USD
|
|
99
|
-
* @returns Effective leverage, or 0 when margin is zero
|
|
100
|
-
* @public
|
|
101
|
-
*/
|
|
102
|
-
export declare function effectiveLeverage(params: {
|
|
103
|
-
positionValueUsd: number;
|
|
104
|
-
marginUsd: number;
|
|
105
|
-
}): number;
|
|
106
43
|
/**
|
|
107
44
|
* Signed expected PnL for a trigger price — see {@link calculateExpectedPnl}.
|
|
108
45
|
*
|
|
@@ -127,7 +64,7 @@ export interface ExpectedPnl {
|
|
|
127
64
|
*/
|
|
128
65
|
export declare function calculateExpectedPnl(triggerPrice: number, entryPrice: number, leverage: number, isLong: boolean, margin: number): ExpectedPnl | null;
|
|
129
66
|
/**
|
|
130
|
-
*
|
|
67
|
+
* Calculate the trigger price that realises a percentage gain/loss.
|
|
131
68
|
*
|
|
132
69
|
* @param percent - Target gain/loss percentage (positive = profitable direction)
|
|
133
70
|
* @param entryPrice - Position entry price
|
|
@@ -135,9 +72,13 @@ export declare function calculateExpectedPnl(triggerPrice: number, entryPrice: n
|
|
|
135
72
|
* @param isLong - True for long positions, false for short
|
|
136
73
|
* @public
|
|
137
74
|
*/
|
|
138
|
-
export declare function
|
|
75
|
+
export declare function calculateTriggerPrice(percent: number, entryPrice: number, leverage: number, isLong: boolean): number;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Use `calculateTriggerPrice`. Removed in the next major.
|
|
78
|
+
*/
|
|
79
|
+
export declare const priceFromPercent: typeof calculateTriggerPrice;
|
|
139
80
|
/**
|
|
140
|
-
*
|
|
81
|
+
* Calculate the percentage gain/loss a trigger price realises.
|
|
141
82
|
*
|
|
142
83
|
* @param price - Target price
|
|
143
84
|
* @param entryPrice - Position entry price
|
|
@@ -145,7 +86,11 @@ export declare function priceFromPercent(percent: number, entryPrice: number, le
|
|
|
145
86
|
* @param isLong - True for long positions, false for short
|
|
146
87
|
* @public
|
|
147
88
|
*/
|
|
148
|
-
export declare function
|
|
89
|
+
export declare function calculateTriggerPercent(price: number, entryPrice: number, leverage: number, isLong: boolean): number;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Use `calculateTriggerPercent`. Removed in the next major.
|
|
92
|
+
*/
|
|
93
|
+
export declare const percentFromPrice: typeof calculateTriggerPercent;
|
|
149
94
|
/**
|
|
150
95
|
* Calculate realized PnL as a percentage of position value at close.
|
|
151
96
|
*
|
|
@@ -208,5 +153,55 @@ interface BuildQuoteInput {
|
|
|
208
153
|
* @public
|
|
209
154
|
*/
|
|
210
155
|
export declare function buildQuote(input: BuildQuoteInput): Quote;
|
|
156
|
+
/**
|
|
157
|
+
* Pick the matching open position for an order's market, if any.
|
|
158
|
+
*
|
|
159
|
+
* @param marketId - The order's `market.id`.
|
|
160
|
+
* @param positions - Open positions list (any market).
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
export declare function findMatchingPosition(marketId: string, positions: readonly Position[]): Position | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Resolve the close-size against a position, applying the spec's cap rules:
|
|
166
|
+
* - `orderSize === 0` is the Hyperliquid convention for "close entire
|
|
167
|
+
* position" → close the full position size.
|
|
168
|
+
* - Otherwise cap at the absolute position size; an order larger than the
|
|
169
|
+
* position can only close what's open.
|
|
170
|
+
*
|
|
171
|
+
* Inputs are non-negative magnitudes.
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
export declare function resolveCloseSize(orderSize: number, positionSize: number): number;
|
|
175
|
+
/**
|
|
176
|
+
* Expected rPnL for a resting limit order against a matching position.
|
|
177
|
+
*
|
|
178
|
+
* Reducing requires opposite sides (long position + SELL, short position +
|
|
179
|
+
* BUY). Same-side orders add to the position and have no rPnL → `null`.
|
|
180
|
+
* Projects `remainingSize`, because an already-filled quantity has realised
|
|
181
|
+
* its PnL at the fill price rather than at this order's limit price. A
|
|
182
|
+
* `remainingSize` of zero leaves nothing to project.
|
|
183
|
+
*/
|
|
184
|
+
declare function regularOrderRealizedPnl(order: RegularOrder, position: Position | undefined): number | null;
|
|
185
|
+
/** Project the unfilled closing quantity of an active trigger at its trigger price. */
|
|
186
|
+
declare function triggerOrderRealizedPnl(order: TriggerOrder, position: Position | undefined): number | null;
|
|
187
|
+
/**
|
|
188
|
+
* Expected rPnL an unfilled order would realise against a matching position:
|
|
189
|
+
* a resting limit order prices off its limit, an armed trigger off its trigger
|
|
190
|
+
* price. A TWAP parent carries no single execution price, so it projects
|
|
191
|
+
* nothing.
|
|
192
|
+
*
|
|
193
|
+
* @returns Realised PnL if the order would reduce the position, otherwise
|
|
194
|
+
* `null`.
|
|
195
|
+
* @public
|
|
196
|
+
*/
|
|
197
|
+
export declare function estimateRealizedPnl(order: Order, position: Position | undefined): number | null;
|
|
198
|
+
/**
|
|
199
|
+
* @deprecated Use `estimateRealizedPnl`. Removed in the next major.
|
|
200
|
+
*/
|
|
201
|
+
export declare const expectedRealizedPnlForOpenOrder: typeof regularOrderRealizedPnl;
|
|
202
|
+
/**
|
|
203
|
+
* @deprecated Use `estimateRealizedPnl`. Removed in the next major.
|
|
204
|
+
*/
|
|
205
|
+
export declare const expectedRealizedPnlForTriggerOrder: typeof triggerOrderRealizedPnl;
|
|
211
206
|
export {};
|
|
212
|
-
//# sourceMappingURL=
|
|
207
|
+
//# sourceMappingURL=order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../../src/math/order.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,KAAK,EACV,KAAK,cAAc,EAInB,KAAK,QAAQ,EAEb,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAA;AAW1B;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,MAAM,CAQR;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,sBAAgB,CAAA;AAElD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,OAAO,GACb,MAAM,CAYR;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAA;IACd,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAA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,cAAc,EAAE,CAAA;IACtB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CA+BxD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,SAAS,QAAQ,EAAE,GAC7B,QAAQ,GAAG,SAAS,CAEtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,MAAM,CAKR;AAED;;;;;;;;GAQG;AACH,iBAAS,uBAAuB,CAC9B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,MAAM,GAAG,IAAI,CAyCf;AAED,uFAAuF;AACvF,iBAAS,uBAAuB,CAC9B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,MAAM,GAAG,IAAI,CA2Cf;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,MAAM,GAAG,IAAI,CAQf;AAED;;GAEG;AACH,eAAO,MAAM,+BAA+B,gCAA0B,CAAA;AAEtE;;GAEG;AACH,eAAO,MAAM,kCAAkC,gCAA0B,CAAA"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Pure functions for computing position-related values that any consumer
|
|
5
|
-
* of the perps SDK would need. All parameters are required — no default
|
|
6
|
-
* values for critical financial parameters.
|
|
2
|
+
* Display-tier order formulas. Every function takes and gives `number`;
|
|
3
|
+
* exact decimal arithmetic happens internally with `DivBig`.
|
|
7
4
|
*/
|
|
8
|
-
import { PerpsErrorCode, } from '@lifi/perps-types';
|
|
5
|
+
import { OrderSide, OrderStatus, PerpsErrorCode, PositionSide, } from '@lifi/perps-types';
|
|
6
|
+
import { areFinite, DivBig } from '../decimal/big.js';
|
|
9
7
|
import { PerpsError } from '../errors/PerpsError.js';
|
|
10
|
-
import {
|
|
8
|
+
import { isActiveOrderStatus, isRegularOrder, isTriggerOrder, } from '../utils/orderClassification.js';
|
|
9
|
+
import { calculateRealizedPnl } from './position.js';
|
|
11
10
|
/**
|
|
12
11
|
* Calculate position size in asset units from margin.
|
|
13
12
|
*
|
|
@@ -17,11 +16,11 @@ import { areFinite, DivBig } from './decimal.js';
|
|
|
17
16
|
* @returns Position size in asset units
|
|
18
17
|
* @example
|
|
19
18
|
* ```ts
|
|
20
|
-
*
|
|
19
|
+
* calculateSize(100, 10, 2000) // 0.5 (ETH at $2000)
|
|
21
20
|
* ```
|
|
22
21
|
* @public
|
|
23
22
|
*/
|
|
24
|
-
export function
|
|
23
|
+
export function calculateSize(marginUsd, leverage, price) {
|
|
25
24
|
if (price === 0) {
|
|
26
25
|
return (marginUsd * leverage) / price;
|
|
27
26
|
}
|
|
@@ -31,68 +30,9 @@ export function calculatePositionSize(marginUsd, leverage, price) {
|
|
|
31
30
|
return new DivBig(marginUsd).times(leverage).div(price).toNumber();
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @param size - Position size in asset units
|
|
37
|
-
* @param price - Current asset price
|
|
38
|
-
* @returns Notional value in USD
|
|
39
|
-
* @public
|
|
33
|
+
* @deprecated Use `calculateSize`. Removed in the next major.
|
|
40
34
|
*/
|
|
41
|
-
export
|
|
42
|
-
if (!areFinite(size, price)) {
|
|
43
|
-
return Number.NaN;
|
|
44
|
-
}
|
|
45
|
-
return new DivBig(size).abs().times(price).toNumber();
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Calculate unrealized PnL.
|
|
49
|
-
*
|
|
50
|
-
* @param entryPrice - Position entry price
|
|
51
|
-
* @param currentPrice - Current market price
|
|
52
|
-
* @param size - Position size (positive for long, negative for short)
|
|
53
|
-
* @returns Unrealized PnL in USD
|
|
54
|
-
* @public
|
|
55
|
-
*/
|
|
56
|
-
export function calculateUnrealizedPnl(entryPrice, currentPrice, size) {
|
|
57
|
-
if (!areFinite(entryPrice, currentPrice, size)) {
|
|
58
|
-
return Number.NaN;
|
|
59
|
-
}
|
|
60
|
-
return new DivBig(currentPrice).minus(entryPrice).times(size).toNumber();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Calculate return on equity (ROE) percentage.
|
|
64
|
-
*
|
|
65
|
-
* @param pnl - Profit/loss in USD
|
|
66
|
-
* @param margin - Initial margin in USD
|
|
67
|
-
* @returns ROE as percentage (e.g., 10 for 10%)
|
|
68
|
-
* @public
|
|
69
|
-
*/
|
|
70
|
-
export function calculateRoe(pnl, margin) {
|
|
71
|
-
if (margin === 0) {
|
|
72
|
-
return 0;
|
|
73
|
-
}
|
|
74
|
-
if (!areFinite(pnl, margin)) {
|
|
75
|
-
return Number.NaN;
|
|
76
|
-
}
|
|
77
|
-
return new DivBig(pnl).div(margin).times(100).toNumber();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Calculate required margin for a position.
|
|
81
|
-
*
|
|
82
|
-
* @param notionalValue - Position notional value in USD
|
|
83
|
-
* @param leverage - Position leverage
|
|
84
|
-
* @returns Required margin in USD
|
|
85
|
-
* @public
|
|
86
|
-
*/
|
|
87
|
-
export function calculateRequiredMargin(notionalValue, leverage) {
|
|
88
|
-
if (leverage === 0) {
|
|
89
|
-
return notionalValue / leverage;
|
|
90
|
-
}
|
|
91
|
-
if (!areFinite(notionalValue, leverage)) {
|
|
92
|
-
return Number.NaN;
|
|
93
|
-
}
|
|
94
|
-
return new DivBig(notionalValue).div(leverage).toNumber();
|
|
95
|
-
}
|
|
35
|
+
export const calculatePositionSize = calculateSize;
|
|
96
36
|
/**
|
|
97
37
|
* Estimate trading fees.
|
|
98
38
|
*
|
|
@@ -129,42 +69,6 @@ export function applySlippage(price, slippagePercent, isBuy) {
|
|
|
129
69
|
}
|
|
130
70
|
return new DivBig(price).div(multiplier).toNumber();
|
|
131
71
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Distance from the current price to the liquidation price, as a percentage of
|
|
134
|
-
* the current price.
|
|
135
|
-
*
|
|
136
|
-
* @param liquidationPrice - The position's liquidation price
|
|
137
|
-
* @param currentPrice - Current market price
|
|
138
|
-
* @returns Absolute distance as a percentage, or 0 when current price is zero
|
|
139
|
-
* @public
|
|
140
|
-
*/
|
|
141
|
-
export function liquidationDistancePercent(params) {
|
|
142
|
-
const { liquidationPrice, currentPrice } = params;
|
|
143
|
-
if (currentPrice === 0) {
|
|
144
|
-
return 0;
|
|
145
|
-
}
|
|
146
|
-
return Math.abs((liquidationPrice - currentPrice) / currentPrice) * 100;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Effective leverage of an open position.
|
|
150
|
-
*
|
|
151
|
-
* leverage = positionValueUsd / marginUsd
|
|
152
|
-
*
|
|
153
|
-
* @param positionValueUsd - Position notional value in USD
|
|
154
|
-
* @param marginUsd - Margin backing the position in USD
|
|
155
|
-
* @returns Effective leverage, or 0 when margin is zero
|
|
156
|
-
* @public
|
|
157
|
-
*/
|
|
158
|
-
export function effectiveLeverage(params) {
|
|
159
|
-
const { positionValueUsd, marginUsd } = params;
|
|
160
|
-
if (marginUsd === 0) {
|
|
161
|
-
return 0;
|
|
162
|
-
}
|
|
163
|
-
if (!areFinite(positionValueUsd, marginUsd)) {
|
|
164
|
-
return Number.NaN;
|
|
165
|
-
}
|
|
166
|
-
return new DivBig(positionValueUsd).div(marginUsd).toNumber();
|
|
167
|
-
}
|
|
168
72
|
/**
|
|
169
73
|
* Calculate expected gain/loss for a TP or SL trigger price.
|
|
170
74
|
* Returns signed values — positive means profit, negative means loss.
|
|
@@ -191,7 +95,7 @@ export function calculateExpectedPnl(triggerPrice, entryPrice, leverage, isLong,
|
|
|
191
95
|
return { amount: amount.toNumber(), percent: percent.toNumber() };
|
|
192
96
|
}
|
|
193
97
|
/**
|
|
194
|
-
*
|
|
98
|
+
* Calculate the trigger price that realises a percentage gain/loss.
|
|
195
99
|
*
|
|
196
100
|
* @param percent - Target gain/loss percentage (positive = profitable direction)
|
|
197
101
|
* @param entryPrice - Position entry price
|
|
@@ -199,7 +103,7 @@ export function calculateExpectedPnl(triggerPrice, entryPrice, leverage, isLong,
|
|
|
199
103
|
* @param isLong - True for long positions, false for short
|
|
200
104
|
* @public
|
|
201
105
|
*/
|
|
202
|
-
export function
|
|
106
|
+
export function calculateTriggerPrice(percent, entryPrice, leverage, isLong) {
|
|
203
107
|
if (entryPrice === 0 || leverage === 0) {
|
|
204
108
|
return 0;
|
|
205
109
|
}
|
|
@@ -213,7 +117,11 @@ export function priceFromPercent(percent, entryPrice, leverage, isLong) {
|
|
|
213
117
|
return (isLong ? entry.plus(priceDelta) : entry.minus(priceDelta)).toNumber();
|
|
214
118
|
}
|
|
215
119
|
/**
|
|
216
|
-
*
|
|
120
|
+
* @deprecated Use `calculateTriggerPrice`. Removed in the next major.
|
|
121
|
+
*/
|
|
122
|
+
export const priceFromPercent = calculateTriggerPrice;
|
|
123
|
+
/**
|
|
124
|
+
* Calculate the percentage gain/loss a trigger price realises.
|
|
217
125
|
*
|
|
218
126
|
* @param price - Target price
|
|
219
127
|
* @param entryPrice - Position entry price
|
|
@@ -221,7 +129,7 @@ export function priceFromPercent(percent, entryPrice, leverage, isLong) {
|
|
|
221
129
|
* @param isLong - True for long positions, false for short
|
|
222
130
|
* @public
|
|
223
131
|
*/
|
|
224
|
-
export function
|
|
132
|
+
export function calculateTriggerPercent(price, entryPrice, leverage, isLong) {
|
|
225
133
|
if (entryPrice === 0 || leverage === 0) {
|
|
226
134
|
return 0;
|
|
227
135
|
}
|
|
@@ -233,6 +141,10 @@ export function percentFromPrice(price, entryPrice, leverage, isLong) {
|
|
|
233
141
|
: new DivBig(entryPrice).minus(price);
|
|
234
142
|
return priceDiff.div(entryPrice).times(leverage).times(100).toNumber();
|
|
235
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* @deprecated Use `calculateTriggerPercent`. Removed in the next major.
|
|
146
|
+
*/
|
|
147
|
+
export const percentFromPrice = calculateTriggerPercent;
|
|
236
148
|
/**
|
|
237
149
|
* Calculate realized PnL as a percentage of position value at close.
|
|
238
150
|
*
|
|
@@ -345,4 +257,136 @@ export function buildQuote(input) {
|
|
|
345
257
|
timestamp: input.timestamp,
|
|
346
258
|
};
|
|
347
259
|
}
|
|
348
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Pick the matching open position for an order's market, if any.
|
|
262
|
+
*
|
|
263
|
+
* @param marketId - The order's `market.id`.
|
|
264
|
+
* @param positions - Open positions list (any market).
|
|
265
|
+
* @public
|
|
266
|
+
*/
|
|
267
|
+
export function findMatchingPosition(marketId, positions) {
|
|
268
|
+
return positions.find((p) => p.market.id === marketId);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Resolve the close-size against a position, applying the spec's cap rules:
|
|
272
|
+
* - `orderSize === 0` is the Hyperliquid convention for "close entire
|
|
273
|
+
* position" → close the full position size.
|
|
274
|
+
* - Otherwise cap at the absolute position size; an order larger than the
|
|
275
|
+
* position can only close what's open.
|
|
276
|
+
*
|
|
277
|
+
* Inputs are non-negative magnitudes.
|
|
278
|
+
* @public
|
|
279
|
+
*/
|
|
280
|
+
export function resolveCloseSize(orderSize, positionSize) {
|
|
281
|
+
if (orderSize === 0) {
|
|
282
|
+
return positionSize;
|
|
283
|
+
}
|
|
284
|
+
return Math.min(orderSize, positionSize);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Expected rPnL for a resting limit order against a matching position.
|
|
288
|
+
*
|
|
289
|
+
* Reducing requires opposite sides (long position + SELL, short position +
|
|
290
|
+
* BUY). Same-side orders add to the position and have no rPnL → `null`.
|
|
291
|
+
* Projects `remainingSize`, because an already-filled quantity has realised
|
|
292
|
+
* its PnL at the fill price rather than at this order's limit price. A
|
|
293
|
+
* `remainingSize` of zero leaves nothing to project.
|
|
294
|
+
*/
|
|
295
|
+
function regularOrderRealizedPnl(order, position) {
|
|
296
|
+
if (!position || !isActiveOrderStatus(order.status)) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
const isLong = position.side === PositionSide.LONG;
|
|
300
|
+
const reducesPosition = (isLong && order.side === OrderSide.SELL) ||
|
|
301
|
+
(!isLong && order.side === OrderSide.BUY);
|
|
302
|
+
if (!reducesPosition) {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
const limitPrice = Number.parseFloat(order.price ?? '');
|
|
306
|
+
const entryPrice = Number.parseFloat(position.entryPrice);
|
|
307
|
+
const orderSize = Math.abs(Number.parseFloat(order.remainingSize));
|
|
308
|
+
const positionSize = Math.abs(Number.parseFloat(position.size));
|
|
309
|
+
if (!Number.isFinite(limitPrice) ||
|
|
310
|
+
!Number.isFinite(entryPrice) ||
|
|
311
|
+
!Number.isFinite(orderSize) ||
|
|
312
|
+
!Number.isFinite(positionSize) ||
|
|
313
|
+
positionSize <= 0) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
// `resolveCloseSize` reads a zero size as "close the whole position", a
|
|
317
|
+
// convention that belongs to an order's submitted size. `remainingSize` is
|
|
318
|
+
// the unfilled quantity, so zero means nothing is left to fill.
|
|
319
|
+
if (orderSize === 0) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
const closeSize = resolveCloseSize(orderSize, positionSize);
|
|
323
|
+
return calculateRealizedPnl({
|
|
324
|
+
entryPrice,
|
|
325
|
+
closePrice: limitPrice,
|
|
326
|
+
closeSize,
|
|
327
|
+
isLong,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/** Project the unfilled closing quantity of an active trigger at its trigger price. */
|
|
331
|
+
function triggerOrderRealizedPnl(order, position) {
|
|
332
|
+
if (!position ||
|
|
333
|
+
!isActiveOrderStatus(order.status) ||
|
|
334
|
+
order.status === OrderStatus.PENDING) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
const isLong = position.side === PositionSide.LONG;
|
|
338
|
+
if ((isLong && order.side !== OrderSide.SELL) ||
|
|
339
|
+
(!isLong && order.side !== OrderSide.BUY)) {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
const triggerPrice = Number.parseFloat(order.triggerPrice);
|
|
343
|
+
const entryPrice = Number.parseFloat(position.entryPrice);
|
|
344
|
+
const orderSize = Math.abs(Number.parseFloat(order.remainingSize));
|
|
345
|
+
const positionSize = Math.abs(Number.parseFloat(position.size));
|
|
346
|
+
if (!Number.isFinite(triggerPrice) ||
|
|
347
|
+
!Number.isFinite(entryPrice) ||
|
|
348
|
+
!Number.isFinite(orderSize) ||
|
|
349
|
+
!Number.isFinite(positionSize) ||
|
|
350
|
+
positionSize <= 0) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
if (orderSize === 0 &&
|
|
354
|
+
(Number.parseFloat(order.originalSize) !== 0 || !order.reduceOnly)) {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
const closeSize = resolveCloseSize(orderSize, positionSize);
|
|
358
|
+
return calculateRealizedPnl({
|
|
359
|
+
entryPrice,
|
|
360
|
+
closePrice: triggerPrice,
|
|
361
|
+
closeSize,
|
|
362
|
+
isLong,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Expected rPnL an unfilled order would realise against a matching position:
|
|
367
|
+
* a resting limit order prices off its limit, an armed trigger off its trigger
|
|
368
|
+
* price. A TWAP parent carries no single execution price, so it projects
|
|
369
|
+
* nothing.
|
|
370
|
+
*
|
|
371
|
+
* @returns Realised PnL if the order would reduce the position, otherwise
|
|
372
|
+
* `null`.
|
|
373
|
+
* @public
|
|
374
|
+
*/
|
|
375
|
+
export function estimateRealizedPnl(order, position) {
|
|
376
|
+
if (isTriggerOrder(order)) {
|
|
377
|
+
return triggerOrderRealizedPnl(order, position);
|
|
378
|
+
}
|
|
379
|
+
if (isRegularOrder(order)) {
|
|
380
|
+
return regularOrderRealizedPnl(order, position);
|
|
381
|
+
}
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* @deprecated Use `estimateRealizedPnl`. Removed in the next major.
|
|
386
|
+
*/
|
|
387
|
+
export const expectedRealizedPnlForOpenOrder = regularOrderRealizedPnl;
|
|
388
|
+
/**
|
|
389
|
+
* @deprecated Use `estimateRealizedPnl`. Removed in the next major.
|
|
390
|
+
*/
|
|
391
|
+
export const expectedRealizedPnlForTriggerOrder = triggerOrderRealizedPnl;
|
|
392
|
+
//# sourceMappingURL=order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/math/order.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAML,SAAS,EACT,WAAW,EACX,cAAc,EAEd,YAAY,GAMb,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,cAAc,GACf,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAEpD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,SAAiB,EACjB,QAAgB,EAChB,KAAa;IAEb,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,KAAK,CAAA;IACvC,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC;QAC3C,OAAO,MAAM,CAAC,GA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