@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
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DecimalString,
|
|
3
|
+
isDecimalString,
|
|
4
|
+
type Market,
|
|
5
|
+
PerpsErrorCode,
|
|
6
|
+
} from '@lifi/perps-types'
|
|
7
|
+
import Big from 'big.js'
|
|
8
|
+
import { TruncBig } from '../decimal/big.js'
|
|
9
|
+
import { PerpsError } from '../errors/PerpsError.js'
|
|
10
|
+
import type { PerpsSDKClient } from '../types/provider.js'
|
|
11
|
+
import { snapOrderSize } from './snap.js'
|
|
12
|
+
|
|
13
|
+
/** @public */
|
|
14
|
+
export interface OrderAmountsInput {
|
|
15
|
+
sdk: PerpsSDKClient
|
|
16
|
+
market: Market
|
|
17
|
+
/** The field the user typed; the other two are calculated from it. */
|
|
18
|
+
held: 'margin' | 'size' | 'notional'
|
|
19
|
+
amount: DecimalString
|
|
20
|
+
leverage: number
|
|
21
|
+
price: DecimalString
|
|
22
|
+
/** Decimals for the quote-asset amounts (margin, notional). Default 2. */
|
|
23
|
+
quoteDecimals?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
export interface OrderAmounts {
|
|
28
|
+
/**
|
|
29
|
+
* On the `quoteDecimals` grid: rounded up when derived, so it funds `size`
|
|
30
|
+
* at the requested leverage, and truncated when the user holds it.
|
|
31
|
+
*/
|
|
32
|
+
margin: DecimalString
|
|
33
|
+
/** Snapped onto the venue lot grid. */
|
|
34
|
+
size: DecimalString
|
|
35
|
+
/** Truncated to `quoteDecimals`. */
|
|
36
|
+
notional: DecimalString
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const DEFAULT_QUOTE_DECIMALS = 2
|
|
40
|
+
const TEN = new Big(10)
|
|
41
|
+
|
|
42
|
+
/** Round a quote amount down onto its decimal grid, with no trailing zeros. */
|
|
43
|
+
function quoteAmount(value: Big, decimals: number): DecimalString {
|
|
44
|
+
const truncated = value.round(decimals, Big.roundDown)
|
|
45
|
+
return truncated.eq(0) ? '0' : truncated.toFixed()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The smallest margin on the `decimals` grid that funds `notional` at
|
|
50
|
+
* `leverage`, so `margin × leverage ≥ notional` holds. The one derived amount
|
|
51
|
+
* that rounds up: a margin rounded down under-funds the size it backs.
|
|
52
|
+
*
|
|
53
|
+
* The ceiling is exact: the remainder decides the carry, so the result never
|
|
54
|
+
* leans on a fixed decimal-place limit the way `div` then `round` would.
|
|
55
|
+
*/
|
|
56
|
+
function coveringMargin(
|
|
57
|
+
notional: Big,
|
|
58
|
+
leverage: Big,
|
|
59
|
+
decimals: number
|
|
60
|
+
): DecimalString {
|
|
61
|
+
const scale = TEN.pow(decimals)
|
|
62
|
+
const scaled = notional.times(scale)
|
|
63
|
+
const remainder = scaled.mod(leverage)
|
|
64
|
+
const whole = scaled.minus(remainder).div(leverage)
|
|
65
|
+
const covering = remainder.eq(0) ? whole : whole.plus(1)
|
|
66
|
+
return covering.eq(0) ? '0' : covering.div(scale).toFixed()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* An order needs three positive amounts. A grid that snaps any of them to
|
|
71
|
+
* zero — a sub-lot size, a sub-cent quote amount — describes no order a venue
|
|
72
|
+
* can take, so the caller gets `null` instead of a result it has to re-check.
|
|
73
|
+
*/
|
|
74
|
+
function executable(amounts: OrderAmounts): OrderAmounts | null {
|
|
75
|
+
const positive =
|
|
76
|
+
new Big(amounts.size).gt(0) &&
|
|
77
|
+
new Big(amounts.margin).gt(0) &&
|
|
78
|
+
new Big(amounts.notional).gt(0)
|
|
79
|
+
return positive ? amounts : null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function positiveDecimal(value: DecimalString): Big | null {
|
|
83
|
+
if (!isDecimalString(value)) {
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
const parsed = new TruncBig(value)
|
|
87
|
+
return parsed.gt(0) ? parsed : null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The three order-entry amounts, derived from whichever one the user typed.
|
|
92
|
+
*
|
|
93
|
+
* The held field is normalised first — truncated to `quoteDecimals` for a
|
|
94
|
+
* margin or notional, snapped onto the venue lot grid for a size — and the
|
|
95
|
+
* other two are then derived from that normalised value, so the three agree
|
|
96
|
+
* with each other rather than with an input the user cannot see.
|
|
97
|
+
*
|
|
98
|
+
* Rounding is directional, so the result always funds itself:
|
|
99
|
+
* `size × price ≤ margin × leverage`. A derived size truncates onto the lot
|
|
100
|
+
* grid and a derived notional truncates onto the quote grid, but a derived
|
|
101
|
+
* margin rounds **up** onto the quote grid, because it is the one amount that
|
|
102
|
+
* has to cover the others rather than cap them.
|
|
103
|
+
*
|
|
104
|
+
* Formulas: `size = margin × leverage ÷ price`,
|
|
105
|
+
* `margin = size × price ÷ leverage`, `notional = size × price`
|
|
106
|
+
* (or `margin × leverage` when the margin is held).
|
|
107
|
+
*
|
|
108
|
+
* @returns `null` when `amount` or `price` is not a positive decimal string,
|
|
109
|
+
* when `leverage` is not a positive finite number, or when the venue and
|
|
110
|
+
* quote grids snap the result to a non-positive amount — a sub-lot size or
|
|
111
|
+
* a sub-cent quote amount describes no order a venue can take.
|
|
112
|
+
* @throws {PerpsError} `ValidationError` when `quoteDecimals` is not a
|
|
113
|
+
* non-negative integer, or `SDKError` when `market.providerId` names no
|
|
114
|
+
* registered provider plugin.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export function calculateOrderAmounts(
|
|
118
|
+
input: OrderAmountsInput
|
|
119
|
+
): OrderAmounts | null {
|
|
120
|
+
const {
|
|
121
|
+
sdk,
|
|
122
|
+
market,
|
|
123
|
+
held,
|
|
124
|
+
leverage,
|
|
125
|
+
quoteDecimals = DEFAULT_QUOTE_DECIMALS,
|
|
126
|
+
} = input
|
|
127
|
+
if (!Number.isInteger(quoteDecimals) || quoteDecimals < 0) {
|
|
128
|
+
throw new PerpsError(
|
|
129
|
+
PerpsErrorCode.ValidationError,
|
|
130
|
+
`Invalid quoteDecimals for order amounts: ${quoteDecimals}`
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
const amount = positiveDecimal(input.amount)
|
|
134
|
+
const price = positiveDecimal(input.price)
|
|
135
|
+
if (
|
|
136
|
+
amount === null ||
|
|
137
|
+
price === null ||
|
|
138
|
+
!Number.isFinite(leverage) ||
|
|
139
|
+
leverage <= 0
|
|
140
|
+
) {
|
|
141
|
+
return null
|
|
142
|
+
}
|
|
143
|
+
const leverageFactor = new TruncBig(leverage)
|
|
144
|
+
|
|
145
|
+
if (held === 'size') {
|
|
146
|
+
const size = snapOrderSize(sdk, market, amount.toFixed())
|
|
147
|
+
const notional = new TruncBig(size).times(price)
|
|
148
|
+
return executable({
|
|
149
|
+
margin: coveringMargin(notional, leverageFactor, quoteDecimals),
|
|
150
|
+
size,
|
|
151
|
+
notional: quoteAmount(notional, quoteDecimals),
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (held === 'notional') {
|
|
156
|
+
const notional = quoteAmount(amount, quoteDecimals)
|
|
157
|
+
const exact = new TruncBig(notional)
|
|
158
|
+
return executable({
|
|
159
|
+
margin: coveringMargin(exact, leverageFactor, quoteDecimals),
|
|
160
|
+
size: snapOrderSize(sdk, market, exact.div(price).toFixed()),
|
|
161
|
+
notional,
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const margin = quoteAmount(amount, quoteDecimals)
|
|
166
|
+
const notional = new TruncBig(margin).times(leverage)
|
|
167
|
+
return executable({
|
|
168
|
+
margin,
|
|
169
|
+
size: snapOrderSize(sdk, market, notional.div(price).toFixed()),
|
|
170
|
+
notional: quoteAmount(notional, quoteDecimals),
|
|
171
|
+
})
|
|
172
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type DecimalString, PerpsErrorCode } from '@lifi/perps-types'
|
|
2
|
+
import { DivBig } from '../decimal/big.js'
|
|
3
|
+
import { PerpsError } from '../errors/PerpsError.js'
|
|
4
|
+
import { requireDecimal } from './requireDecimal.js'
|
|
5
|
+
|
|
6
|
+
/** @public */
|
|
7
|
+
export interface RefuelAmountInput {
|
|
8
|
+
/** USD value of the gas the route recommends. */
|
|
9
|
+
gasUsd: DecimalString
|
|
10
|
+
/** USD price of one whole source token. */
|
|
11
|
+
priceUsd: DecimalString
|
|
12
|
+
/** Decimals of the source token, which the result is spelled to exactly. */
|
|
13
|
+
decimals: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Source-token amount whose USD value covers `gasUsd`, rounded **up** onto
|
|
18
|
+
* the token's decimal grid so a refuel never lands short of the
|
|
19
|
+
* recommendation. The result keeps trailing zeros to `decimals`, so it seeds
|
|
20
|
+
* an amount input at the token's own precision.
|
|
21
|
+
*
|
|
22
|
+
* The quotient does not terminate for most prices, which is why this is a
|
|
23
|
+
* big.js primitive: an 18-decimal token needs a ceiling at 10^-18, far past
|
|
24
|
+
* what a `number` can carry.
|
|
25
|
+
*
|
|
26
|
+
* @returns `undefined` when `gasUsd` or `priceUsd` is not greater than zero,
|
|
27
|
+
* which is a route with nothing to refuel rather than a failure.
|
|
28
|
+
* @throws {PerpsError} `ValidationError` when `gasUsd` or `priceUsd` is not a
|
|
29
|
+
* {@link DecimalString}, or when `decimals` is not a non-negative integer.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export function calculateRefuelAmount(
|
|
33
|
+
input: RefuelAmountInput
|
|
34
|
+
): DecimalString | undefined {
|
|
35
|
+
const { decimals } = input
|
|
36
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
37
|
+
throw new PerpsError(
|
|
38
|
+
PerpsErrorCode.ValidationError,
|
|
39
|
+
`Invalid \`decimals\` for a refuel amount: ${decimals}`
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
const gasUsd = requireDecimal(input.gasUsd, 'gasUsd')
|
|
43
|
+
const priceUsd = requireDecimal(input.priceUsd, 'priceUsd')
|
|
44
|
+
if (!gasUsd.gt(0) || !priceUsd.gt(0)) {
|
|
45
|
+
return undefined
|
|
46
|
+
}
|
|
47
|
+
return new DivBig(gasUsd)
|
|
48
|
+
.div(priceUsd)
|
|
49
|
+
.round(decimals, DivBig.roundUp)
|
|
50
|
+
.toFixed(decimals)
|
|
51
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DecimalString,
|
|
3
|
+
isDecimalString,
|
|
4
|
+
PerpsErrorCode,
|
|
5
|
+
} from '@lifi/perps-types'
|
|
6
|
+
import Big from 'big.js'
|
|
7
|
+
import { PerpsError } from '../errors/PerpsError.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parse a wire-tier decimal input, naming the field it came from when the
|
|
11
|
+
* value breaks the {@link DecimalString} contract, so a malformed amount
|
|
12
|
+
* fails at the SDK boundary instead of inside big.js.
|
|
13
|
+
*
|
|
14
|
+
* @throws {PerpsError} `ValidationError` naming `field`.
|
|
15
|
+
*/
|
|
16
|
+
export function requireDecimal(value: DecimalString, field: string): Big {
|
|
17
|
+
if (!isDecimalString(value)) {
|
|
18
|
+
throw new PerpsError(
|
|
19
|
+
PerpsErrorCode.ValidationError,
|
|
20
|
+
`Invalid \`${field}\`: '${value}' is not a decimal string.`
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
return new Big(value)
|
|
24
|
+
}
|
package/src/wire/snap.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DecimalString, Market } from '@lifi/perps-types'
|
|
2
|
+
import { requireProvider } from '../client/requireProvider.js'
|
|
3
|
+
import type { PerpsSDKClient } from '../types/provider.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Snap `size` onto the lot grid of `market`'s venue, truncating toward zero,
|
|
7
|
+
* through the market's own provider. Takes and gives a {@link DecimalString},
|
|
8
|
+
* so a caller never converts an order size to a `number`.
|
|
9
|
+
*
|
|
10
|
+
* @throws {PerpsError} `SDKError` when `market.providerId` names no registered
|
|
11
|
+
* provider plugin.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function snapOrderSize(
|
|
15
|
+
sdk: PerpsSDKClient,
|
|
16
|
+
market: Market,
|
|
17
|
+
size: DecimalString
|
|
18
|
+
): DecimalString {
|
|
19
|
+
return requireProvider(sdk, market.providerId).snapOrderSize(market, size)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Snap `price` onto the tick grid of `market`'s venue, rounding half-up,
|
|
24
|
+
* through the market's own provider. Takes and gives a {@link DecimalString},
|
|
25
|
+
* so a caller never converts an order price to a `number`.
|
|
26
|
+
*
|
|
27
|
+
* @throws {PerpsError} `SDKError` when `market.providerId` names no registered
|
|
28
|
+
* provider plugin, or `ValidationError` when the market lacks the tick
|
|
29
|
+
* metadata the venue's rules need.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export function snapOrderPrice(
|
|
33
|
+
sdk: PerpsSDKClient,
|
|
34
|
+
market: Market,
|
|
35
|
+
price: DecimalString
|
|
36
|
+
): DecimalString {
|
|
37
|
+
return requireProvider(sdk, market.providerId).snapOrderPrice(market, price)
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DecimalString } from '@lifi/perps-types'
|
|
2
|
+
import { requireDecimal } from './requireDecimal.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The part of `units` that a venue-wide free figure releases: never below
|
|
6
|
+
* zero, never above the units held. `Balance.transferable` on every provider
|
|
7
|
+
* is this clamp over the venue's own free-margin or unlocked-balance figure.
|
|
8
|
+
*
|
|
9
|
+
* @param venueFigure - The venue's free figure for the category, which can
|
|
10
|
+
* exceed `units` or fall below zero.
|
|
11
|
+
* @param units - Units held in the category, the upper bound of the clamp.
|
|
12
|
+
* @throws {PerpsError} `ValidationError` when either input is not a
|
|
13
|
+
* {@link DecimalString}, naming the field.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export function calculateTransferable(
|
|
17
|
+
venueFigure: DecimalString,
|
|
18
|
+
units: DecimalString
|
|
19
|
+
): DecimalString {
|
|
20
|
+
const figure = requireDecimal(venueFigure, 'venueFigure')
|
|
21
|
+
const held = requireDecimal(units, 'units')
|
|
22
|
+
if (figure.lt(0)) {
|
|
23
|
+
return '0'
|
|
24
|
+
}
|
|
25
|
+
return (figure.gt(held) ? held : figure).toFixed()
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DecimalString } from '@lifi/perps-types'
|
|
2
|
+
import type { WithdrawableBalance } from '../types/withdrawal.js'
|
|
3
|
+
import { requireDecimal } from './requireDecimal.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Largest `amount` a withdrawable row can fund: `available` when the venue
|
|
7
|
+
* deducts the fee from the amount or publishes no fee, and
|
|
8
|
+
* `available − withdrawalFee` floored at zero when the venue charges the fee
|
|
9
|
+
* on top (`isFeeDeducted === false`).
|
|
10
|
+
*
|
|
11
|
+
* @throws {PerpsError} `ValidationError` when `available` or `withdrawalFee`
|
|
12
|
+
* is not a {@link DecimalString}, naming the field.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export function calculateWithdrawMax(
|
|
16
|
+
row: Pick<
|
|
17
|
+
WithdrawableBalance,
|
|
18
|
+
'available' | 'withdrawalFee' | 'isFeeDeducted'
|
|
19
|
+
>
|
|
20
|
+
): DecimalString {
|
|
21
|
+
const available = requireDecimal(row.available, 'available')
|
|
22
|
+
if (row.isFeeDeducted !== false || row.withdrawalFee === undefined) {
|
|
23
|
+
return available.toFixed()
|
|
24
|
+
}
|
|
25
|
+
const funded = available.minus(
|
|
26
|
+
requireDecimal(row.withdrawalFee, 'withdrawalFee')
|
|
27
|
+
)
|
|
28
|
+
return funded.gt(0) ? funded.toFixed() : '0'
|
|
29
|
+
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type FeeTier, type Market, type MarketContext, type OrderbookLevel, type Quote, type QuoteSide, type TradeType } from '@lifi/perps-types';
|
|
2
|
-
export declare function calculatePositionSize(marginUsd: number, leverage: number, price: number): number;
|
|
3
|
-
export declare function calculateNotionalValue(size: number, price: number): number;
|
|
4
|
-
export declare function calculateUnrealizedPnl(entryPrice: number, currentPrice: number, size: number): number;
|
|
5
|
-
export declare function calculateRoe(pnl: number, margin: number): number;
|
|
6
|
-
export declare function calculateRequiredMargin(notionalValue: number, leverage: number): number;
|
|
7
|
-
export declare function estimateFees(sizeUsd: number, feeRate: number): number;
|
|
8
|
-
export declare function applySlippage(price: number, slippagePercent: number, isBuy: boolean): number;
|
|
9
|
-
export declare function liquidationDistancePercent(params: {
|
|
10
|
-
liquidationPrice: number;
|
|
11
|
-
currentPrice: number;
|
|
12
|
-
}): number;
|
|
13
|
-
export declare function effectiveLeverage(params: {
|
|
14
|
-
positionValueUsd: number;
|
|
15
|
-
marginUsd: number;
|
|
16
|
-
}): number;
|
|
17
|
-
export interface ExpectedPnl {
|
|
18
|
-
amount: number;
|
|
19
|
-
percent: number;
|
|
20
|
-
}
|
|
21
|
-
export declare function calculateExpectedPnl(triggerPrice: number, entryPrice: number, leverage: number, isLong: boolean, margin: number): ExpectedPnl | null;
|
|
22
|
-
export declare function priceFromPercent(percent: number, entryPrice: number, leverage: number, isLong: boolean): number;
|
|
23
|
-
export declare function percentFromPrice(price: number, entryPrice: number, leverage: number, isLong: boolean): number;
|
|
24
|
-
export declare function calculateRealizedPnlPercent(realizedPnl: number, size: number, price: number): number;
|
|
25
|
-
interface BookWalk {
|
|
26
|
-
baseSize: number;
|
|
27
|
-
filledNotional: number;
|
|
28
|
-
vwap: number;
|
|
29
|
-
insufficientLiquidity: boolean;
|
|
30
|
-
}
|
|
31
|
-
export declare function walkOrderbook(levels: OrderbookLevel[], sizeUsd: number): BookWalk;
|
|
32
|
-
interface BuildQuoteInput {
|
|
33
|
-
provider: string;
|
|
34
|
-
symbol: string;
|
|
35
|
-
type: TradeType;
|
|
36
|
-
side: QuoteSide;
|
|
37
|
-
sizeUsd: number;
|
|
38
|
-
market: Market;
|
|
39
|
-
price: MarketContext;
|
|
40
|
-
bids: OrderbookLevel[];
|
|
41
|
-
asks: OrderbookLevel[];
|
|
42
|
-
feeTier: FeeTier;
|
|
43
|
-
timestamp: number;
|
|
44
|
-
}
|
|
45
|
-
export declare function buildQuote(input: BuildQuoteInput): Quote;
|
|
46
|
-
export {};
|
|
47
|
-
//# sourceMappingURL=calculations.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../../src/utils/calculations.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,cAAc,EAEnB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAA;AAkB1B,wBAAgB,qBAAqB,CACnC,SAAS,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EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd,MAAM,CAYR;AAWD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd,MAAM,CAWR;AAWD,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,MAAM,CASR;AAGD,UAAU,QAAQ;IAEhB,QAAQ,EAAE,MAAM,CAAA;IAEhB,cAAc,EAAE,MAAM,CAAA;IAEtB,IAAI,EAAE,MAAM,CAAA;IAEZ,qBAAqB,EAAE,OAAO,CAAA;CAC/B;AAeD,wBAAgB,aAAa,CAC3B,MAAM,EAAE,cAAc,EAAE,EACxB,OAAO,EAAE,MAAM,GACd,QAAQ,CAgCV;AAcD,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,aAAa,CAAA;IACpB,IAAI,EAAE,cAAc,EAAE,CAAA;IACtB,IAAI,EAAE,cAAc,EAAE,CAAA;IAEtB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB;AAaD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CA+BxD"}
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculatePositionSize = calculatePositionSize;
|
|
4
|
-
exports.calculateNotionalValue = calculateNotionalValue;
|
|
5
|
-
exports.calculateUnrealizedPnl = calculateUnrealizedPnl;
|
|
6
|
-
exports.calculateRoe = calculateRoe;
|
|
7
|
-
exports.calculateRequiredMargin = calculateRequiredMargin;
|
|
8
|
-
exports.estimateFees = estimateFees;
|
|
9
|
-
exports.applySlippage = applySlippage;
|
|
10
|
-
exports.liquidationDistancePercent = liquidationDistancePercent;
|
|
11
|
-
exports.effectiveLeverage = effectiveLeverage;
|
|
12
|
-
exports.calculateExpectedPnl = calculateExpectedPnl;
|
|
13
|
-
exports.priceFromPercent = priceFromPercent;
|
|
14
|
-
exports.percentFromPrice = percentFromPrice;
|
|
15
|
-
exports.calculateRealizedPnlPercent = calculateRealizedPnlPercent;
|
|
16
|
-
exports.walkOrderbook = walkOrderbook;
|
|
17
|
-
exports.buildQuote = buildQuote;
|
|
18
|
-
const perps_types_1 = require("@lifi/perps-types");
|
|
19
|
-
const PerpsError_js_1 = require("../errors/PerpsError.js");
|
|
20
|
-
const decimal_js_1 = require("./decimal.js");
|
|
21
|
-
function calculatePositionSize(marginUsd, leverage, price) {
|
|
22
|
-
if (price === 0) {
|
|
23
|
-
return (marginUsd * leverage) / price;
|
|
24
|
-
}
|
|
25
|
-
if (!(0, decimal_js_1.areFinite)(marginUsd, leverage, price)) {
|
|
26
|
-
return Number.NaN;
|
|
27
|
-
}
|
|
28
|
-
return new decimal_js_1.DivBig(marginUsd).times(leverage).div(price).toNumber();
|
|
29
|
-
}
|
|
30
|
-
function calculateNotionalValue(size, price) {
|
|
31
|
-
if (!(0, decimal_js_1.areFinite)(size, price)) {
|
|
32
|
-
return Number.NaN;
|
|
33
|
-
}
|
|
34
|
-
return new decimal_js_1.DivBig(size).abs().times(price).toNumber();
|
|
35
|
-
}
|
|
36
|
-
function calculateUnrealizedPnl(entryPrice, currentPrice, size) {
|
|
37
|
-
if (!(0, decimal_js_1.areFinite)(entryPrice, currentPrice, size)) {
|
|
38
|
-
return Number.NaN;
|
|
39
|
-
}
|
|
40
|
-
return new decimal_js_1.DivBig(currentPrice).minus(entryPrice).times(size).toNumber();
|
|
41
|
-
}
|
|
42
|
-
function calculateRoe(pnl, margin) {
|
|
43
|
-
if (margin === 0) {
|
|
44
|
-
return 0;
|
|
45
|
-
}
|
|
46
|
-
if (!(0, decimal_js_1.areFinite)(pnl, margin)) {
|
|
47
|
-
return Number.NaN;
|
|
48
|
-
}
|
|
49
|
-
return new decimal_js_1.DivBig(pnl).div(margin).times(100).toNumber();
|
|
50
|
-
}
|
|
51
|
-
function calculateRequiredMargin(notionalValue, leverage) {
|
|
52
|
-
if (leverage === 0) {
|
|
53
|
-
return notionalValue / leverage;
|
|
54
|
-
}
|
|
55
|
-
if (!(0, decimal_js_1.areFinite)(notionalValue, leverage)) {
|
|
56
|
-
return Number.NaN;
|
|
57
|
-
}
|
|
58
|
-
return new decimal_js_1.DivBig(notionalValue).div(leverage).toNumber();
|
|
59
|
-
}
|
|
60
|
-
function estimateFees(sizeUsd, feeRate) {
|
|
61
|
-
if (!(0, decimal_js_1.areFinite)(sizeUsd, feeRate)) {
|
|
62
|
-
return Number.NaN;
|
|
63
|
-
}
|
|
64
|
-
return new decimal_js_1.DivBig(sizeUsd).times(feeRate).toNumber();
|
|
65
|
-
}
|
|
66
|
-
function applySlippage(price, slippagePercent, isBuy) {
|
|
67
|
-
if (!(0, decimal_js_1.areFinite)(price, slippagePercent)) {
|
|
68
|
-
return Number.NaN;
|
|
69
|
-
}
|
|
70
|
-
const multiplier = new decimal_js_1.DivBig(slippagePercent).div(100).plus(1);
|
|
71
|
-
if (isBuy) {
|
|
72
|
-
return new decimal_js_1.DivBig(price).times(multiplier).toNumber();
|
|
73
|
-
}
|
|
74
|
-
if (multiplier.eq(0)) {
|
|
75
|
-
return price / multiplier.toNumber();
|
|
76
|
-
}
|
|
77
|
-
return new decimal_js_1.DivBig(price).div(multiplier).toNumber();
|
|
78
|
-
}
|
|
79
|
-
function liquidationDistancePercent(params) {
|
|
80
|
-
const { liquidationPrice, currentPrice } = params;
|
|
81
|
-
if (currentPrice === 0) {
|
|
82
|
-
return 0;
|
|
83
|
-
}
|
|
84
|
-
return Math.abs((liquidationPrice - currentPrice) / currentPrice) * 100;
|
|
85
|
-
}
|
|
86
|
-
function effectiveLeverage(params) {
|
|
87
|
-
const { positionValueUsd, marginUsd } = params;
|
|
88
|
-
if (marginUsd === 0) {
|
|
89
|
-
return 0;
|
|
90
|
-
}
|
|
91
|
-
if (!(0, decimal_js_1.areFinite)(positionValueUsd, marginUsd)) {
|
|
92
|
-
return Number.NaN;
|
|
93
|
-
}
|
|
94
|
-
return new decimal_js_1.DivBig(positionValueUsd).div(marginUsd).toNumber();
|
|
95
|
-
}
|
|
96
|
-
function calculateExpectedPnl(triggerPrice, entryPrice, leverage, isLong, margin) {
|
|
97
|
-
if (!triggerPrice || entryPrice === 0 || margin === 0) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
if (!(0, decimal_js_1.areFinite)(triggerPrice, entryPrice, leverage, margin)) {
|
|
101
|
-
return { amount: Number.NaN, percent: Number.NaN };
|
|
102
|
-
}
|
|
103
|
-
const priceDiff = isLong
|
|
104
|
-
? new decimal_js_1.DivBig(triggerPrice).minus(entryPrice)
|
|
105
|
-
: new decimal_js_1.DivBig(entryPrice).minus(triggerPrice);
|
|
106
|
-
const percent = priceDiff.div(entryPrice).times(leverage).times(100);
|
|
107
|
-
const amount = percent.times(margin).div(100);
|
|
108
|
-
return { amount: amount.toNumber(), percent: percent.toNumber() };
|
|
109
|
-
}
|
|
110
|
-
function priceFromPercent(percent, entryPrice, leverage, isLong) {
|
|
111
|
-
if (entryPrice === 0 || leverage === 0) {
|
|
112
|
-
return 0;
|
|
113
|
-
}
|
|
114
|
-
if (!(0, decimal_js_1.areFinite)(percent, entryPrice, leverage)) {
|
|
115
|
-
return Number.NaN;
|
|
116
|
-
}
|
|
117
|
-
const priceDelta = new decimal_js_1.DivBig(percent)
|
|
118
|
-
.times(entryPrice)
|
|
119
|
-
.div(new decimal_js_1.DivBig(leverage).times(100));
|
|
120
|
-
const entry = new decimal_js_1.DivBig(entryPrice);
|
|
121
|
-
return (isLong ? entry.plus(priceDelta) : entry.minus(priceDelta)).toNumber();
|
|
122
|
-
}
|
|
123
|
-
function percentFromPrice(price, entryPrice, leverage, isLong) {
|
|
124
|
-
if (entryPrice === 0 || leverage === 0) {
|
|
125
|
-
return 0;
|
|
126
|
-
}
|
|
127
|
-
if (!(0, decimal_js_1.areFinite)(price, entryPrice, leverage)) {
|
|
128
|
-
return Number.NaN;
|
|
129
|
-
}
|
|
130
|
-
const priceDiff = isLong
|
|
131
|
-
? new decimal_js_1.DivBig(price).minus(entryPrice)
|
|
132
|
-
: new decimal_js_1.DivBig(entryPrice).minus(price);
|
|
133
|
-
return priceDiff.div(entryPrice).times(leverage).times(100).toNumber();
|
|
134
|
-
}
|
|
135
|
-
function calculateRealizedPnlPercent(realizedPnl, size, price) {
|
|
136
|
-
if (!(0, decimal_js_1.areFinite)(realizedPnl, size, price)) {
|
|
137
|
-
return Number.NaN;
|
|
138
|
-
}
|
|
139
|
-
const positionValue = new decimal_js_1.DivBig(size).abs().times(price);
|
|
140
|
-
if (positionValue.eq(0)) {
|
|
141
|
-
return 0;
|
|
142
|
-
}
|
|
143
|
-
return new decimal_js_1.DivBig(realizedPnl).div(positionValue).times(100).toNumber();
|
|
144
|
-
}
|
|
145
|
-
function walkOrderbook(levels, sizeUsd) {
|
|
146
|
-
if (!Number.isFinite(sizeUsd)) {
|
|
147
|
-
return {
|
|
148
|
-
baseSize: Number.NaN,
|
|
149
|
-
filledNotional: Number.NaN,
|
|
150
|
-
vwap: Number.NaN,
|
|
151
|
-
insufficientLiquidity: true,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
let remaining = new decimal_js_1.DivBig(sizeUsd);
|
|
155
|
-
let baseSize = new decimal_js_1.DivBig(0);
|
|
156
|
-
let filledNotional = new decimal_js_1.DivBig(0);
|
|
157
|
-
for (const level of levels) {
|
|
158
|
-
if (remaining.lte(0)) {
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
const { price, size } = parseLevel(level);
|
|
162
|
-
const levelNotional = size.times(price);
|
|
163
|
-
const take = remaining.lt(levelNotional) ? remaining : levelNotional;
|
|
164
|
-
if (take.eq(0)) {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
filledNotional = filledNotional.plus(take);
|
|
168
|
-
baseSize = baseSize.plus(take.div(price));
|
|
169
|
-
remaining = remaining.minus(take);
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
baseSize: baseSize.toNumber(),
|
|
173
|
-
filledNotional: filledNotional.toNumber(),
|
|
174
|
-
vwap: baseSize.eq(0) ? 0 : filledNotional.div(baseSize).toNumber(),
|
|
175
|
-
insufficientLiquidity: remaining.gt(0),
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
function parseLevel(level) {
|
|
179
|
-
try {
|
|
180
|
-
return { price: new decimal_js_1.DivBig(level.price), size: new decimal_js_1.DivBig(level.size) };
|
|
181
|
-
}
|
|
182
|
-
catch {
|
|
183
|
-
throw new PerpsError_js_1.PerpsError(perps_types_1.PerpsErrorCode.ValidationError, `Malformed orderbook level: price='${level.price}', size='${level.size}'`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function buildQuote(input) {
|
|
187
|
-
const { market, price, side, sizeUsd, feeTier } = input;
|
|
188
|
-
const markPrice = Number.parseFloat(price.markPrice);
|
|
189
|
-
const levels = side === 'buy' ? input.asks : input.bids;
|
|
190
|
-
const walk = walkOrderbook(levels, sizeUsd);
|
|
191
|
-
const priceImpactBps = markPrice === 0 || walk.vwap === 0
|
|
192
|
-
? 0
|
|
193
|
-
: Math.abs((walk.vwap - markPrice) / markPrice) * 10_000;
|
|
194
|
-
const feeUsd = estimateFees(walk.filledNotional, Number.parseFloat(feeTier.taker));
|
|
195
|
-
return {
|
|
196
|
-
provider: input.provider,
|
|
197
|
-
symbol: input.symbol,
|
|
198
|
-
marketId: market.id,
|
|
199
|
-
type: input.type,
|
|
200
|
-
side,
|
|
201
|
-
sizeUsd: sizeUsd.toString(),
|
|
202
|
-
baseSize: walk.baseSize.toString(),
|
|
203
|
-
markPrice: price.markPrice,
|
|
204
|
-
expectedFillPrice: walk.vwap.toString(),
|
|
205
|
-
priceImpactBps: priceImpactBps.toString(),
|
|
206
|
-
feeTier,
|
|
207
|
-
isDefaultFeeTier: true,
|
|
208
|
-
feeUsd: feeUsd.toString(),
|
|
209
|
-
funding: price.funding ?? null,
|
|
210
|
-
insufficientLiquidity: walk.insufficientLiquidity,
|
|
211
|
-
timestamp: input.timestamp,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
//# sourceMappingURL=calculations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.js","sourceRoot":"","sources":["../../../src/utils/calculations.ts"],"names":[],"mappings":";;AAmCA,sDAYC;AAUD,wDAKC;AAWD,wDASC;AAUD,oCAQC;AAUD,0DAWC;AAUD,oCAKC;AAWD,sCAgBC;AAWD,gEASC;AAYD,8CAYC;AAyBD,oDAmBC;AAWD,4CAiBC;AAWD,4CAgBC;AAWD,kEAaC;AA2BD,sCAmCC;AAwCD,gCA+BC;AAvcD,mDAS0B;AAE1B,2DAAoD;AACpD,6CAAgD;AAehD,SAAgB,qBAAqB,CACnC,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,IAAA,sBAAS,EAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC;QAC3C,OAAO,MAAM,CAAC,GAAG,CAAA;IACnB,CAAC;IACD,OAAO,IAAI,mBAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAA;AACpE,CAAC;AAUD,SAAgB,sBAAsB,CAA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IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI;QACJ,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;QAClC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;QACvC,cAAc,EAAE,cAAc,CAAC,QAAQ,EAAE;QACzC,OAAO;QACP,gBAAgB,EAAE,IAAI;QACtB,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;QACzB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI;QAC9B,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;QACjD,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAA;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/utils/decimal.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AAMxB,eAAO,MAAM,MAAM,oBAAQ,CAAA;AAO3B,eAAO,MAAM,QAAQ,oBAAQ,CAAA;AAK7B,wBAAgB,SAAS,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAEtD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decimal.js","sourceRoot":"","sources":["../../../src/utils/decimal.ts"],"names":[],"mappings":";;;;;;AAkBA,8BAEC;AApBD,oDAAwB;AAMX,QAAA,MAAM,GAAG,IAAA,gBAAG,GAAE,CAAA;AAC3B,cAAM,CAAC,EAAE,GAAG,EAAE,CAAA;AAMD,QAAA,QAAQ,GAAG,IAAA,gBAAG,GAAE,CAAA;AAC7B,gBAAQ,CAAC,EAAE,GAAG,EAAE,CAAA;AAChB,gBAAQ,CAAC,EAAE,GAAG,gBAAG,CAAC,SAAS,CAAA;AAG3B,SAAgB,SAAS,CAAC,GAAG,MAAgB;IAC3C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fillClassification.d.ts","sourceRoot":"","sources":["../../../src/utils/fillClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAYtD,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,kBAAkB,CAkCpB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fillClassification.js","sourceRoot":"","sources":["../../../src/utils/fillClassification.ts"],"names":[],"mappings":";;AAYA,4DAsCC;AAlDD,mDAAsD;AAYtD,SAAgB,wBAAwB,CACtC,aAAqB,EACrB,IAAY,EACZ,EAAU;IAEV,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IACvC,MAAM,KAAK,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAC7D,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,CAAA;IAEzB,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,GAAG,GAAG,CAAC;YACZ,CAAC,CAAC,gCAAkB,CAAC,WAAW;YAChC,CAAC,CAAC,gCAAkB,CAAC,YAAY,CAAA;IACrC,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACd,OAAO,gCAAkB,CAAC,WAAW,CAAA;QACvC,CAAC;QACD,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,OAAO,gCAAkB,CAAC,cAAc,CAAA;QAC1C,CAAC;QACD,IAAI,GAAG,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