@katanaperps/katana-perps-sdk 0.0.0-placeholder
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/.nvmrc +1 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/abis/ERC20.json +288 -0
- package/dist/abis/EarningsEscrow.json +468 -0
- package/dist/abis/Exchange_v1.json +3644 -0
- package/dist/abis/IOFT.json +447 -0
- package/dist/bridge/config.d.ts +262 -0
- package/dist/bridge/config.d.ts.map +1 -0
- package/dist/bridge/config.js +221 -0
- package/dist/bridge/deposit.d.ts +107 -0
- package/dist/bridge/deposit.d.ts.map +1 -0
- package/dist/bridge/deposit.js +284 -0
- package/dist/bridge/index.d.ts +5 -0
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/index.js +7 -0
- package/dist/bridge/utils.d.ts +140 -0
- package/dist/bridge/utils.d.ts.map +1 -0
- package/dist/bridge/utils.js +66 -0
- package/dist/bridge/withdraw.d.ts +42 -0
- package/dist/bridge/withdraw.d.ts.map +1 -0
- package/dist/bridge/withdraw.js +86 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +6 -0
- package/dist/client/orderBook/index.d.ts +2 -0
- package/dist/client/orderBook/index.d.ts.map +1 -0
- package/dist/client/orderBook/index.js +4 -0
- package/dist/client/orderBook/realTime.d.ts +180 -0
- package/dist/client/orderBook/realTime.d.ts.map +1 -0
- package/dist/client/orderBook/realTime.js +344 -0
- package/dist/client/orderBook/utils.d.ts +15 -0
- package/dist/client/orderBook/utils.d.ts.map +1 -0
- package/dist/client/orderBook/utils.js +77 -0
- package/dist/client/rest/authenticated.d.ts +1199 -0
- package/dist/client/rest/authenticated.d.ts.map +1 -0
- package/dist/client/rest/authenticated.js +1311 -0
- package/dist/client/rest/index.d.ts +3 -0
- package/dist/client/rest/index.d.ts.map +1 -0
- package/dist/client/rest/index.js +5 -0
- package/dist/client/rest/public.d.ts +436 -0
- package/dist/client/rest/public.d.ts.map +1 -0
- package/dist/client/rest/public.js +502 -0
- package/dist/client/webSocket/guards.d.ts +15 -0
- package/dist/client/webSocket/guards.d.ts.map +1 -0
- package/dist/client/webSocket/guards.js +37 -0
- package/dist/client/webSocket/index.d.ts +632 -0
- package/dist/client/webSocket/index.d.ts.map +1 -0
- package/dist/client/webSocket/index.js +1048 -0
- package/dist/client/webSocket/transform.d.ts +3 -0
- package/dist/client/webSocket/transform.d.ts.map +1 -0
- package/dist/client/webSocket/transform.js +244 -0
- package/dist/constants.d.ts +34 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +38 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/orderbook/apiConversions.d.ts +8 -0
- package/dist/orderbook/apiConversions.d.ts.map +1 -0
- package/dist/orderbook/apiConversions.js +100 -0
- package/dist/orderbook/demo.d.ts +2 -0
- package/dist/orderbook/demo.d.ts.map +1 -0
- package/dist/orderbook/demo.js +68 -0
- package/dist/orderbook/index.d.ts +3 -0
- package/dist/orderbook/index.d.ts.map +1 -0
- package/dist/orderbook/index.js +5 -0
- package/dist/orderbook/quantities.d.ts +112 -0
- package/dist/orderbook/quantities.d.ts.map +1 -0
- package/dist/orderbook/quantities.js +257 -0
- package/dist/orderbook/utils.d.ts +8 -0
- package/dist/orderbook/utils.d.ts.map +1 -0
- package/dist/orderbook/utils.js +28 -0
- package/dist/pipmath.d.ts +21 -0
- package/dist/pipmath.d.ts.map +1 -0
- package/dist/pipmath.js +110 -0
- package/dist/signatures.d.ts +37 -0
- package/dist/signatures.d.ts.map +1 -0
- package/dist/signatures.js +450 -0
- package/dist/tests/orderbook/quantities/calculateInitialMarginFractionWithOverride.test.d.ts +2 -0
- package/dist/tests/orderbook/quantities/calculateInitialMarginFractionWithOverride.test.d.ts.map +1 -0
- package/dist/tests/orderbook/quantities/calculateInitialMarginFractionWithOverride.test.js +49 -0
- package/dist/tests/orderbook/quantities/calculateMaximumInitialMarginFractionOverride.test.d.ts +2 -0
- package/dist/tests/orderbook/quantities/calculateMaximumInitialMarginFractionOverride.test.d.ts.map +1 -0
- package/dist/tests/orderbook/quantities/calculateMaximumInitialMarginFractionOverride.test.js +122 -0
- package/dist/tests/orderbook/quantities/determineMaximumReduceOnlyQuantityAvailableAtPriceLevel.test.d.ts +2 -0
- package/dist/tests/orderbook/quantities/determineMaximumReduceOnlyQuantityAvailableAtPriceLevel.test.d.ts.map +1 -0
- package/dist/tests/orderbook/quantities/determineMaximumReduceOnlyQuantityAvailableAtPriceLevel.test.js +138 -0
- package/dist/tests/orderbook/quantities.test.d.ts +2 -0
- package/dist/tests/orderbook/quantities.test.d.ts.map +1 -0
- package/dist/tests/orderbook/quantities.test.js +310 -0
- package/dist/tests/testHelpers.d.ts +2 -0
- package/dist/tests/testHelpers.d.ts.map +1 -0
- package/dist/tests/testHelpers.js +16 -0
- package/dist/tests/utils/deriveBaseURL.test.d.ts +2 -0
- package/dist/tests/utils/deriveBaseURL.test.d.ts.map +1 -0
- package/dist/tests/utils/deriveBaseURL.test.js +46 -0
- package/dist/typechain-types/ERC20.d.ts +170 -0
- package/dist/typechain-types/ERC20.d.ts.map +1 -0
- package/dist/typechain-types/ERC20.js +2 -0
- package/dist/typechain-types/EarningsEscrow.d.ts +210 -0
- package/dist/typechain-types/EarningsEscrow.d.ts.map +1 -0
- package/dist/typechain-types/EarningsEscrow.js +2 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter.d.ts +253 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter.d.ts.map +1 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter.js +2 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter_v2.d.ts +338 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter_v2.d.ts.map +1 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter_v2.js +2 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter_v3.d.ts +413 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter_v3.d.ts.map +1 -0
- package/dist/typechain-types/ExchangeLayerZeroAdapter_v3.js +2 -0
- package/dist/typechain-types/Exchange_v1.d.ts +2172 -0
- package/dist/typechain-types/Exchange_v1.d.ts.map +1 -0
- package/dist/typechain-types/Exchange_v1.js +2 -0
- package/dist/typechain-types/Exchange_v2.d.ts +2148 -0
- package/dist/typechain-types/Exchange_v2.d.ts.map +1 -0
- package/dist/typechain-types/Exchange_v2.js +2 -0
- package/dist/typechain-types/FixedIncomeVaultProviderStateAggregator_v1.d.ts +148 -0
- package/dist/typechain-types/FixedIncomeVaultProviderStateAggregator_v1.d.ts.map +1 -0
- package/dist/typechain-types/FixedIncomeVaultProviderStateAggregator_v1.js +2 -0
- package/dist/typechain-types/FixedIncomeVaultProvider_v1.d.ts +1204 -0
- package/dist/typechain-types/FixedIncomeVaultProvider_v1.d.ts.map +1 -0
- package/dist/typechain-types/FixedIncomeVaultProvider_v1.js +2 -0
- package/dist/typechain-types/IOFT.d.ts +247 -0
- package/dist/typechain-types/IOFT.d.ts.map +1 -0
- package/dist/typechain-types/IOFT.js +2 -0
- package/dist/typechain-types/IRewardVault.d.ts +649 -0
- package/dist/typechain-types/IRewardVault.d.ts.map +1 -0
- package/dist/typechain-types/IRewardVault.js +2 -0
- package/dist/typechain-types/KumaOFTAdapterUSDC.d.ts +638 -0
- package/dist/typechain-types/KumaOFTAdapterUSDC.d.ts.map +1 -0
- package/dist/typechain-types/KumaOFTAdapterUSDC.js +2 -0
- package/dist/typechain-types/KumaOFTUSDC.d.ts +756 -0
- package/dist/typechain-types/KumaOFTUSDC.d.ts.map +1 -0
- package/dist/typechain-types/KumaOFTUSDC.js +2 -0
- package/dist/typechain-types/KumaStargateForwarder_v1.d.ts +252 -0
- package/dist/typechain-types/KumaStargateForwarder_v1.d.ts.map +1 -0
- package/dist/typechain-types/KumaStargateForwarder_v1.js +2 -0
- package/dist/typechain-types/KumaStargateForwarder_v2.d.ts +252 -0
- package/dist/typechain-types/KumaStargateForwarder_v2.d.ts.map +1 -0
- package/dist/typechain-types/KumaStargateForwarder_v2.js +2 -0
- package/dist/typechain-types/ProfitShareVaultProvider_v1.d.ts +1095 -0
- package/dist/typechain-types/ProfitShareVaultProvider_v1.d.ts.map +1 -0
- package/dist/typechain-types/ProfitShareVaultProvider_v1.js +2 -0
- package/dist/typechain-types/StargatePoolUSDC.d.ts +956 -0
- package/dist/typechain-types/StargatePoolUSDC.d.ts.map +1 -0
- package/dist/typechain-types/StargatePoolUSDC.js +2 -0
- package/dist/typechain-types/common.d.ts +51 -0
- package/dist/typechain-types/common.d.ts.map +1 -0
- package/dist/typechain-types/common.js +2 -0
- package/dist/typechain-types/factories/ERC20__factory.d.ts +226 -0
- package/dist/typechain-types/factories/ERC20__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/ERC20__factory.js +305 -0
- package/dist/typechain-types/factories/EarningsEscrow__factory.d.ts +370 -0
- package/dist/typechain-types/factories/EarningsEscrow__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/EarningsEscrow__factory.js +485 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter__factory.d.ts +359 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter__factory.js +471 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter_v2__factory.d.ts +419 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter_v2__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter_v2__factory.js +545 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter_v3__factory.d.ts +546 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter_v3__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/ExchangeLayerZeroAdapter_v3__factory.js +710 -0
- package/dist/typechain-types/factories/Exchange_v1__factory.d.ts +2852 -0
- package/dist/typechain-types/factories/Exchange_v1__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/Exchange_v1__factory.js +3661 -0
- package/dist/typechain-types/factories/Exchange_v2__factory.d.ts +2832 -0
- package/dist/typechain-types/factories/Exchange_v2__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/Exchange_v2__factory.js +3636 -0
- package/dist/typechain-types/factories/FixedIncomeVaultProviderStateAggregator_v1__factory.d.ts +180 -0
- package/dist/typechain-types/factories/FixedIncomeVaultProviderStateAggregator_v1__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/FixedIncomeVaultProviderStateAggregator_v1__factory.js +246 -0
- package/dist/typechain-types/factories/FixedIncomeVaultProvider_v1__factory.d.ts +2092 -0
- package/dist/typechain-types/factories/FixedIncomeVaultProvider_v1__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/FixedIncomeVaultProvider_v1__factory.js +2702 -0
- package/dist/typechain-types/factories/IOFT__factory.d.ts +352 -0
- package/dist/typechain-types/factories/IOFT__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/IOFT__factory.js +464 -0
- package/dist/typechain-types/factories/IRewardVault__factory.d.ts +1019 -0
- package/dist/typechain-types/factories/IRewardVault__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/IRewardVault__factory.js +1311 -0
- package/dist/typechain-types/factories/KumaOFTAdapterUSDC__factory.d.ts +996 -0
- package/dist/typechain-types/factories/KumaOFTAdapterUSDC__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/KumaOFTAdapterUSDC__factory.js +1306 -0
- package/dist/typechain-types/factories/KumaOFTUSDC__factory.d.ts +1234 -0
- package/dist/typechain-types/factories/KumaOFTUSDC__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/KumaOFTUSDC__factory.js +1619 -0
- package/dist/typechain-types/factories/KumaStargateForwarder_v1__factory.d.ts +354 -0
- package/dist/typechain-types/factories/KumaStargateForwarder_v1__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/KumaStargateForwarder_v1__factory.js +464 -0
- package/dist/typechain-types/factories/KumaStargateForwarder_v2__factory.d.ts +370 -0
- package/dist/typechain-types/factories/KumaStargateForwarder_v2__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/KumaStargateForwarder_v2__factory.js +486 -0
- package/dist/typechain-types/factories/ProfitShareVaultProvider_v1__factory.d.ts +1914 -0
- package/dist/typechain-types/factories/ProfitShareVaultProvider_v1__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/ProfitShareVaultProvider_v1__factory.js +2475 -0
- package/dist/typechain-types/factories/StargatePoolUSDC__factory.d.ts +1557 -0
- package/dist/typechain-types/factories/StargatePoolUSDC__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/StargatePoolUSDC__factory.js +2019 -0
- package/dist/typechain-types/factories/index.d.ts +5 -0
- package/dist/typechain-types/factories/index.d.ts.map +1 -0
- package/dist/typechain-types/factories/index.js +13 -0
- package/dist/typechain-types/index.d.ts +10 -0
- package/dist/typechain-types/index.d.ts.map +1 -0
- package/dist/typechain-types/index.js +15 -0
- package/dist/types/delegatedKeys.d.ts +44 -0
- package/dist/types/delegatedKeys.d.ts.map +1 -0
- package/dist/types/delegatedKeys.js +2 -0
- package/dist/types/enums/index.d.ts +4 -0
- package/dist/types/enums/index.d.ts.map +1 -0
- package/dist/types/enums/index.js +6 -0
- package/dist/types/enums/request.d.ts +980 -0
- package/dist/types/enums/request.d.ts.map +1 -0
- package/dist/types/enums/request.js +906 -0
- package/dist/types/enums/response.d.ts +329 -0
- package/dist/types/enums/response.d.ts.map +1 -0
- package/dist/types/enums/response.js +296 -0
- package/dist/types/enums/signature.d.ts +118 -0
- package/dist/types/enums/signature.d.ts.map +1 -0
- package/dist/types/enums/signature.js +131 -0
- package/dist/types/errors.d.ts +5 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +2 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/orderBook.d.ts +72 -0
- package/dist/types/orderBook.d.ts.map +1 -0
- package/dist/types/orderBook.js +2 -0
- package/dist/types/rest/common/common.d.ts +118 -0
- package/dist/types/rest/common/common.d.ts.map +1 -0
- package/dist/types/rest/common/common.js +2 -0
- package/dist/types/rest/common/guards.d.ts +8 -0
- package/dist/types/rest/common/guards.d.ts.map +1 -0
- package/dist/types/rest/common/guards.js +14 -0
- package/dist/types/rest/endpoints/AssociateWallet.d.ts +40 -0
- package/dist/types/rest/endpoints/AssociateWallet.d.ts.map +1 -0
- package/dist/types/rest/endpoints/AssociateWallet.js +2 -0
- package/dist/types/rest/endpoints/CancelOrders.d.ts +134 -0
- package/dist/types/rest/endpoints/CancelOrders.d.ts.map +1 -0
- package/dist/types/rest/endpoints/CancelOrders.js +2 -0
- package/dist/types/rest/endpoints/CreateOrder.d.ts +401 -0
- package/dist/types/rest/endpoints/CreateOrder.d.ts.map +1 -0
- package/dist/types/rest/endpoints/CreateOrder.js +2 -0
- package/dist/types/rest/endpoints/GetAuthenticationToken.d.ts +39 -0
- package/dist/types/rest/endpoints/GetAuthenticationToken.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetAuthenticationToken.js +2 -0
- package/dist/types/rest/endpoints/GetCandles.d.ts +115 -0
- package/dist/types/rest/endpoints/GetCandles.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetCandles.js +2 -0
- package/dist/types/rest/endpoints/GetDeposits.d.ts +109 -0
- package/dist/types/rest/endpoints/GetDeposits.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetDeposits.js +2 -0
- package/dist/types/rest/endpoints/GetExchange.d.ts +78 -0
- package/dist/types/rest/endpoints/GetExchange.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetExchange.js +9 -0
- package/dist/types/rest/endpoints/GetFills.d.ts +178 -0
- package/dist/types/rest/endpoints/GetFills.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetFills.js +2 -0
- package/dist/types/rest/endpoints/GetFundingPayments.d.ts +52 -0
- package/dist/types/rest/endpoints/GetFundingPayments.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetFundingPayments.js +2 -0
- package/dist/types/rest/endpoints/GetFundingRates.d.ts +34 -0
- package/dist/types/rest/endpoints/GetFundingRates.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetFundingRates.js +2 -0
- package/dist/types/rest/endpoints/GetGasFees.d.ts +23 -0
- package/dist/types/rest/endpoints/GetGasFees.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetGasFees.js +2 -0
- package/dist/types/rest/endpoints/GetHistoricalPnL.d.ts +39 -0
- package/dist/types/rest/endpoints/GetHistoricalPnL.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetHistoricalPnL.js +2 -0
- package/dist/types/rest/endpoints/GetInitialMarginFractionOverride.d.ts +31 -0
- package/dist/types/rest/endpoints/GetInitialMarginFractionOverride.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetInitialMarginFractionOverride.js +2 -0
- package/dist/types/rest/endpoints/GetLiquidations.d.ts +52 -0
- package/dist/types/rest/endpoints/GetLiquidations.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetLiquidations.js +2 -0
- package/dist/types/rest/endpoints/GetMarketMakerRewardsEpochs.d.ts +534 -0
- package/dist/types/rest/endpoints/GetMarketMakerRewardsEpochs.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetMarketMakerRewardsEpochs.js +2 -0
- package/dist/types/rest/endpoints/GetMarkets.d.ts +161 -0
- package/dist/types/rest/endpoints/GetMarkets.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetMarkets.js +2 -0
- package/dist/types/rest/endpoints/GetOrderBook.d.ts +176 -0
- package/dist/types/rest/endpoints/GetOrderBook.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetOrderBook.js +2 -0
- package/dist/types/rest/endpoints/GetOrders.d.ts +188 -0
- package/dist/types/rest/endpoints/GetOrders.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetOrders.js +2 -0
- package/dist/types/rest/endpoints/GetPing.d.ts +8 -0
- package/dist/types/rest/endpoints/GetPing.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetPing.js +2 -0
- package/dist/types/rest/endpoints/GetPositions.d.ts +104 -0
- package/dist/types/rest/endpoints/GetPositions.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetPositions.js +2 -0
- package/dist/types/rest/endpoints/GetTickers.d.ts +129 -0
- package/dist/types/rest/endpoints/GetTickers.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetTickers.js +2 -0
- package/dist/types/rest/endpoints/GetTime.d.ts +14 -0
- package/dist/types/rest/endpoints/GetTime.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetTime.js +2 -0
- package/dist/types/rest/endpoints/GetTrades.d.ts +62 -0
- package/dist/types/rest/endpoints/GetTrades.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetTrades.js +2 -0
- package/dist/types/rest/endpoints/GetWallets.d.ts +121 -0
- package/dist/types/rest/endpoints/GetWallets.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetWallets.js +2 -0
- package/dist/types/rest/endpoints/GetWithdrawals.d.ts +98 -0
- package/dist/types/rest/endpoints/GetWithdrawals.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetWithdrawals.js +2 -0
- package/dist/types/rest/endpoints/GetWithdrawalsFromManagedAccount.d.ts +98 -0
- package/dist/types/rest/endpoints/GetWithdrawalsFromManagedAccount.d.ts.map +1 -0
- package/dist/types/rest/endpoints/GetWithdrawalsFromManagedAccount.js +2 -0
- package/dist/types/rest/endpoints/Payouts.d.ts +199 -0
- package/dist/types/rest/endpoints/Payouts.d.ts.map +1 -0
- package/dist/types/rest/endpoints/Payouts.js +2 -0
- package/dist/types/rest/endpoints/SetInitialMarginFractionOverride.d.ts +83 -0
- package/dist/types/rest/endpoints/SetInitialMarginFractionOverride.d.ts.map +1 -0
- package/dist/types/rest/endpoints/SetInitialMarginFractionOverride.js +2 -0
- package/dist/types/rest/endpoints/WithdrawFunds.d.ts +144 -0
- package/dist/types/rest/endpoints/WithdrawFunds.d.ts.map +1 -0
- package/dist/types/rest/endpoints/WithdrawFunds.js +2 -0
- package/dist/types/rest/endpoints/WithdrawFundsFromManagedAccountByQuantity.d.ts +161 -0
- package/dist/types/rest/endpoints/WithdrawFundsFromManagedAccountByQuantity.d.ts.map +1 -0
- package/dist/types/rest/endpoints/WithdrawFundsFromManagedAccountByQuantity.js +2 -0
- package/dist/types/rest/endpoints/WithdrawFundsFromManagedAccountByShares.d.ts +160 -0
- package/dist/types/rest/endpoints/WithdrawFundsFromManagedAccountByShares.d.ts.map +1 -0
- package/dist/types/rest/endpoints/WithdrawFundsFromManagedAccountByShares.js +2 -0
- package/dist/types/rest/endpoints/index.d.ts +33 -0
- package/dist/types/rest/endpoints/index.d.ts.map +1 -0
- package/dist/types/rest/endpoints/index.js +35 -0
- package/dist/types/rest/endpoints/internal.d.ts +329 -0
- package/dist/types/rest/endpoints/internal.d.ts.map +1 -0
- package/dist/types/rest/endpoints/internal.js +14 -0
- package/dist/types/rest/index.d.ts +4 -0
- package/dist/types/rest/index.d.ts.map +1 -0
- package/dist/types/rest/index.js +6 -0
- package/dist/types/swaps.d.ts +11 -0
- package/dist/types/swaps.d.ts.map +1 -0
- package/dist/types/swaps.js +2 -0
- package/dist/types/utils.d.ts +67 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +3 -0
- package/dist/types/webSocket/base.d.ts +83 -0
- package/dist/types/webSocket/base.d.ts.map +1 -0
- package/dist/types/webSocket/base.js +2 -0
- package/dist/types/webSocket/constants.d.ts +41 -0
- package/dist/types/webSocket/constants.d.ts.map +1 -0
- package/dist/types/webSocket/constants.js +54 -0
- package/dist/types/webSocket/index.d.ts +6 -0
- package/dist/types/webSocket/index.d.ts.map +1 -0
- package/dist/types/webSocket/index.js +8 -0
- package/dist/types/webSocket/options.d.ts +276 -0
- package/dist/types/webSocket/options.d.ts.map +1 -0
- package/dist/types/webSocket/options.js +2 -0
- package/dist/types/webSocket/request/index.d.ts +3 -0
- package/dist/types/webSocket/request/index.d.ts.map +1 -0
- package/dist/types/webSocket/request/index.js +5 -0
- package/dist/types/webSocket/request/request.d.ts +137 -0
- package/dist/types/webSocket/request/request.d.ts.map +1 -0
- package/dist/types/webSocket/request/request.js +2 -0
- package/dist/types/webSocket/request/subscriptions.d.ts +498 -0
- package/dist/types/webSocket/request/subscriptions.d.ts.map +1 -0
- package/dist/types/webSocket/request/subscriptions.js +2 -0
- package/dist/types/webSocket/response/candles.d.ts +138 -0
- package/dist/types/webSocket/response/candles.d.ts.map +1 -0
- package/dist/types/webSocket/response/candles.js +2 -0
- package/dist/types/webSocket/response/deposits.d.ts +80 -0
- package/dist/types/webSocket/response/deposits.d.ts.map +1 -0
- package/dist/types/webSocket/response/deposits.js +2 -0
- package/dist/types/webSocket/response/fundingPayments.d.ts +78 -0
- package/dist/types/webSocket/response/fundingPayments.d.ts.map +1 -0
- package/dist/types/webSocket/response/fundingPayments.js +2 -0
- package/dist/types/webSocket/response/index.d.ts +13 -0
- package/dist/types/webSocket/response/index.d.ts.map +1 -0
- package/dist/types/webSocket/response/index.js +15 -0
- package/dist/types/webSocket/response/liquidations.d.ts +78 -0
- package/dist/types/webSocket/response/liquidations.d.ts.map +1 -0
- package/dist/types/webSocket/response/liquidations.js +2 -0
- package/dist/types/webSocket/response/orderbook.d.ts +214 -0
- package/dist/types/webSocket/response/orderbook.d.ts.map +1 -0
- package/dist/types/webSocket/response/orderbook.js +2 -0
- package/dist/types/webSocket/response/orders.d.ts +355 -0
- package/dist/types/webSocket/response/orders.d.ts.map +1 -0
- package/dist/types/webSocket/response/orders.js +2 -0
- package/dist/types/webSocket/response/ordersFill.d.ts +138 -0
- package/dist/types/webSocket/response/ordersFill.d.ts.map +1 -0
- package/dist/types/webSocket/response/ordersFill.js +2 -0
- package/dist/types/webSocket/response/positions.d.ts +120 -0
- package/dist/types/webSocket/response/positions.d.ts.map +1 -0
- package/dist/types/webSocket/response/positions.js +2 -0
- package/dist/types/webSocket/response/tickers.d.ts +131 -0
- package/dist/types/webSocket/response/tickers.d.ts.map +1 -0
- package/dist/types/webSocket/response/tickers.js +2 -0
- package/dist/types/webSocket/response/trades.d.ts +90 -0
- package/dist/types/webSocket/response/trades.d.ts.map +1 -0
- package/dist/types/webSocket/response/trades.js +2 -0
- package/dist/types/webSocket/response/webclient/base.d.ts +24 -0
- package/dist/types/webSocket/response/webclient/base.d.ts.map +1 -0
- package/dist/types/webSocket/response/webclient/base.js +2 -0
- package/dist/types/webSocket/response/webclient/events/exchangeStatus.d.ts +31 -0
- package/dist/types/webSocket/response/webclient/events/exchangeStatus.d.ts.map +1 -0
- package/dist/types/webSocket/response/webclient/events/exchangeStatus.js +2 -0
- package/dist/types/webSocket/response/webclient/events/index.d.ts +4 -0
- package/dist/types/webSocket/response/webclient/events/index.d.ts.map +1 -0
- package/dist/types/webSocket/response/webclient/events/index.js +6 -0
- package/dist/types/webSocket/response/webclient/events/reloadBanners.d.ts +17 -0
- package/dist/types/webSocket/response/webclient/events/reloadBanners.d.ts.map +1 -0
- package/dist/types/webSocket/response/webclient/events/reloadBanners.js +2 -0
- package/dist/types/webSocket/response/webclient/events/transactionSettled.d.ts +76 -0
- package/dist/types/webSocket/response/webclient/events/transactionSettled.d.ts.map +1 -0
- package/dist/types/webSocket/response/webclient/events/transactionSettled.js +2 -0
- package/dist/types/webSocket/response/webclient/index.d.ts +3 -0
- package/dist/types/webSocket/response/webclient/index.d.ts.map +1 -0
- package/dist/types/webSocket/response/webclient/index.js +5 -0
- package/dist/types/webSocket/response/webclient/webclient.d.ts +13 -0
- package/dist/types/webSocket/response/webclient/webclient.d.ts.map +1 -0
- package/dist/types/webSocket/response/webclient/webclient.js +2 -0
- package/dist/types/webSocket/response/withdrawals.d.ts +83 -0
- package/dist/types/webSocket/response/withdrawals.d.ts.map +1 -0
- package/dist/types/webSocket/response/withdrawals.js +2 -0
- package/dist/utils.d.ts +63 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +136 -0
- package/package.json +200 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BigNumber } from 'bignumber.js';
|
|
2
|
+
import { OrderSide } from '#types/enums/request';
|
|
3
|
+
import type { L2OrderBook, OrderBookLevelL1, OrderBookLevelL2 } from '#types/orderBook';
|
|
4
|
+
import type { KatanaPerpsInitialMarginFractionOverride, KatanaPerpsMarket, KatanaPerpsOrder, KatanaPerpsPosition, KatanaPerpsWallet } from '#types/rest/endpoints/index';
|
|
5
|
+
export type LeverageParameters = Pick<KatanaPerpsMarket, 'maximumPositionSize' | 'initialMarginFraction' | 'maintenanceMarginFraction' | 'basePositionSize' | 'incrementalPositionSize' | 'incrementalInitialMarginFraction'>;
|
|
6
|
+
export type LeverageParametersBigInt = Record<keyof LeverageParameters, bigint>;
|
|
7
|
+
type Position = {
|
|
8
|
+
market: string;
|
|
9
|
+
quantity: bigint;
|
|
10
|
+
indexPrice: bigint;
|
|
11
|
+
marginRequirement: bigint;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Price and Size values form the {@link OrderBookLevelL1} type
|
|
15
|
+
*/
|
|
16
|
+
export type PriceAndSize = Pick<OrderBookLevelL1, 'price' | 'size'>;
|
|
17
|
+
/**
|
|
18
|
+
* Standing orders
|
|
19
|
+
*/
|
|
20
|
+
export type StandingOrder = Pick<KatanaPerpsOrder, 'market' | 'side' | 'originalQuantity' | 'executedQuantity' | 'price'>;
|
|
21
|
+
type ActiveStandingOrder = StandingOrder & {
|
|
22
|
+
price: string;
|
|
23
|
+
};
|
|
24
|
+
type ActiveStandingOrderBigInt = Pick<ActiveStandingOrder, 'side'> & {
|
|
25
|
+
openQuantity: bigint;
|
|
26
|
+
price: bigint;
|
|
27
|
+
};
|
|
28
|
+
export declare function isActiveStandingOrder(order: StandingOrder): order is ActiveStandingOrder;
|
|
29
|
+
export declare const asksTickRoundingMode: 0;
|
|
30
|
+
export declare const bidsTickRoundingMode: 1;
|
|
31
|
+
export declare const nullLevel: OrderBookLevelL2;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the initial margin fraction for a position or an order.
|
|
34
|
+
*
|
|
35
|
+
* Use {@link convertToLeverageParametersBigInt} to convert a {@link KatanaPerpsMarket}
|
|
36
|
+
* or {@link LeverageParameters} object to {@link LeverageParametersBigInt}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function calculateInitialMarginFractionWithOverride(args: {
|
|
39
|
+
/** Signed */
|
|
40
|
+
baseQuantity: bigint;
|
|
41
|
+
initialMarginFractionOverride: bigint | null;
|
|
42
|
+
leverageParameters: LeverageParametersBigInt;
|
|
43
|
+
}): bigint;
|
|
44
|
+
export declare function calculateMaximumInitialMarginFractionOverride(market: Pick<KatanaPerpsMarket, 'market' | 'initialMarginFraction'>, wallet: Pick<KatanaPerpsWallet, 'positions' | 'freeCollateral' | 'heldCollateral'>, walletInitialMarginFractionOverrides: KatanaPerpsInitialMarginFractionOverride[]): string;
|
|
45
|
+
export declare function convertToActiveStandingOrderBigInt(order: ActiveStandingOrder): ActiveStandingOrderBigInt;
|
|
46
|
+
export declare function convertToLeverageParametersBigInt(leverageParameters: LeverageParameters): LeverageParametersBigInt;
|
|
47
|
+
/**
|
|
48
|
+
* Converts a {@link KatanaPerpsPosition} object to one used by some functions in this
|
|
49
|
+
* file.
|
|
50
|
+
*/
|
|
51
|
+
export declare function convertToPositionBigInt(position: KatanaPerpsPosition): Position;
|
|
52
|
+
/**
|
|
53
|
+
* Determines the liquidity available in the given order book (asks or bids)
|
|
54
|
+
* for a given taker quantity (which may be expressed in base or quote asset)
|
|
55
|
+
* and price (optional).
|
|
56
|
+
* In other words, it performs very basic order matching to provide an estimate
|
|
57
|
+
* of the base and quote quantities with which a taker order of the given
|
|
58
|
+
* size (quantity) and limit price (optional) would be filled.
|
|
59
|
+
*
|
|
60
|
+
* The taker order may represent a limit or a market order: If a limit price is
|
|
61
|
+
* given, it is matched as a limit order (which necessitates specifying whether
|
|
62
|
+
* it's a buy or a sell). Otherwise it is matched as a market order.
|
|
63
|
+
*
|
|
64
|
+
* The provided list of orders or price levels (asks or bids) is expected to be
|
|
65
|
+
* sorted by best price (ascending for asks (lowest first), descending for bids
|
|
66
|
+
* (highest first)). Multiple orders per price level are supported.
|
|
67
|
+
*
|
|
68
|
+
* To support high-precision calculations in which pip-precision is
|
|
69
|
+
* insufficient, the result may optionally be returned in double-pip precision;
|
|
70
|
+
* the returned values then represent numbers with 16 decimals instead of 8.
|
|
71
|
+
*
|
|
72
|
+
* @param returnInDoublePipPrecision - Defaults to false
|
|
73
|
+
*/
|
|
74
|
+
export declare function calculateGrossFillQuantities(makerSideOrders: Iterable<PriceAndSize>, takerOrder: {
|
|
75
|
+
side: OrderSide;
|
|
76
|
+
quantity: bigint;
|
|
77
|
+
isQuantityInQuote: boolean;
|
|
78
|
+
limitPrice?: bigint;
|
|
79
|
+
}, returnInDoublePipPrecision?: boolean): {
|
|
80
|
+
baseQuantity: bigint;
|
|
81
|
+
quoteQuantity: bigint;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Reduce-only orders may only be on the books if their execution would in fact
|
|
85
|
+
* result in a reduction of an open position. That is, if any of the wallet's
|
|
86
|
+
* other standing orders would be matched and executed first and reduce the
|
|
87
|
+
* position, any reduce-only liquidity newly added to the books may not exceed
|
|
88
|
+
* the remaining size of the position.
|
|
89
|
+
*
|
|
90
|
+
* This function returns the size of the given open position minus the combined
|
|
91
|
+
* size of all the wallet's standing orders on the other side of the book that
|
|
92
|
+
* are priced better (higher for buys, lower for sells) or equal to the provided
|
|
93
|
+
* limit price.
|
|
94
|
+
*/
|
|
95
|
+
export declare function determineMaximumReduceOnlyQuantityAvailableAtPriceLevel(args: {
|
|
96
|
+
limitPrice: bigint;
|
|
97
|
+
position: KatanaPerpsPosition;
|
|
98
|
+
orderSide: OrderSide;
|
|
99
|
+
walletsStandingOrders: StandingOrder[];
|
|
100
|
+
}): bigint;
|
|
101
|
+
/**
|
|
102
|
+
* Helper function to re-aggregate L2 orderbook price levels at a larger (more zeroes) tick size
|
|
103
|
+
*/
|
|
104
|
+
export declare function aggregateL2OrderBookAtTickSize(inputBook: L2OrderBook, tickSize: bigint): L2OrderBook;
|
|
105
|
+
/**
|
|
106
|
+
* Adjusts prices in pips to account for tick size by discarding insignificant digits using
|
|
107
|
+
* specified rounding mode. Ex price 123456789 at tick size 1 is 123456789, at tick size 10
|
|
108
|
+
* 123456780, at 100 123456700, etc
|
|
109
|
+
*/
|
|
110
|
+
export declare function adjustPriceToTickSize(price: bigint, tickSize: bigint, roundingMode?: BigNumber.RoundingMode): bigint;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=quantities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quantities.d.ts","sourceRoot":"","sources":["../../src/orderbook/quantities.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adjustPriceToTickSize = exports.aggregateL2OrderBookAtTickSize = exports.determineMaximumReduceOnlyQuantityAvailableAtPriceLevel = exports.calculateGrossFillQuantities = exports.convertToPositionBigInt = exports.convertToLeverageParametersBigInt = exports.convertToActiveStandingOrderBigInt = exports.calculateMaximumInitialMarginFractionOverride = exports.calculateInitialMarginFractionWithOverride = exports.nullLevel = exports.bidsTickRoundingMode = exports.asksTickRoundingMode = exports.isActiveStandingOrder = void 0;
|
|
4
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
5
|
+
const _pipmath_1 = require("#pipmath");
|
|
6
|
+
const request_1 = require("#types/enums/request");
|
|
7
|
+
function isActiveStandingOrder(order) {
|
|
8
|
+
return typeof order.price !== 'undefined';
|
|
9
|
+
}
|
|
10
|
+
exports.isActiveStandingOrder = isActiveStandingOrder;
|
|
11
|
+
exports.asksTickRoundingMode = bignumber_js_1.BigNumber.ROUND_UP;
|
|
12
|
+
exports.bidsTickRoundingMode = bignumber_js_1.BigNumber.ROUND_DOWN;
|
|
13
|
+
exports.nullLevel = {
|
|
14
|
+
price: BigInt(0),
|
|
15
|
+
size: BigInt(0),
|
|
16
|
+
numOrders: 0,
|
|
17
|
+
type: 'limit',
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
function calculateInitialMarginFraction(leverageParameters, baseQuantity) {
|
|
23
|
+
const absPositionQty = (0, _pipmath_1.absBigInt)(baseQuantity);
|
|
24
|
+
if (absPositionQty <= leverageParameters.basePositionSize) {
|
|
25
|
+
return leverageParameters.initialMarginFraction;
|
|
26
|
+
}
|
|
27
|
+
return (leverageParameters.initialMarginFraction +
|
|
28
|
+
(0, _pipmath_1.divideBigInt)(absPositionQty - leverageParameters.basePositionSize, leverageParameters.incrementalPositionSize, _pipmath_1.ROUNDING.RoundUp) *
|
|
29
|
+
leverageParameters.incrementalInitialMarginFraction);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the initial margin fraction for a position or an order.
|
|
33
|
+
*
|
|
34
|
+
* Use {@link convertToLeverageParametersBigInt} to convert a {@link KatanaPerpsMarket}
|
|
35
|
+
* or {@link LeverageParameters} object to {@link LeverageParametersBigInt}.
|
|
36
|
+
*/
|
|
37
|
+
function calculateInitialMarginFractionWithOverride(args) {
|
|
38
|
+
const { initialMarginFractionOverride, leverageParameters, baseQuantity } = args;
|
|
39
|
+
return (0, _pipmath_1.maxBigInt)(calculateInitialMarginFraction(leverageParameters, baseQuantity), initialMarginFractionOverride ?? BigInt(0));
|
|
40
|
+
}
|
|
41
|
+
exports.calculateInitialMarginFractionWithOverride = calculateInitialMarginFractionWithOverride;
|
|
42
|
+
function calculateMaximumInitialMarginFractionOverride(market, wallet, walletInitialMarginFractionOverrides) {
|
|
43
|
+
const positionForMarket = wallet.positions &&
|
|
44
|
+
wallet.positions.find((p) => p.market === market.market);
|
|
45
|
+
let positionNotionalValue = 0n;
|
|
46
|
+
if (positionForMarket) {
|
|
47
|
+
const position = convertToPositionBigInt(positionForMarket);
|
|
48
|
+
positionNotionalValue = (0, _pipmath_1.multiplyPips)((0, _pipmath_1.absBigInt)(position.quantity), position.indexPrice);
|
|
49
|
+
}
|
|
50
|
+
const effectiveInitialMarginFraction = (0, _pipmath_1.decimalToPip)(walletInitialMarginFractionOverrides.find((imfo) => imfo.market === market.market)?.initialMarginFractionOverride || market.initialMarginFraction);
|
|
51
|
+
const initialMarginRequirement = (0, _pipmath_1.multiplyPips)(positionNotionalValue, effectiveInitialMarginFraction);
|
|
52
|
+
const potentialHeldOrderValue = (0, _pipmath_1.dividePips)((0, _pipmath_1.decimalToPip)(wallet.heldCollateral), effectiveInitialMarginFraction);
|
|
53
|
+
const potentialLeveragedValue = positionNotionalValue + potentialHeldOrderValue;
|
|
54
|
+
const availableCollateralForLeverage = initialMarginRequirement + (0, _pipmath_1.decimalToPip)(wallet.freeCollateral);
|
|
55
|
+
return (0, _pipmath_1.pipToDecimal)(potentialLeveragedValue === 0n ? _pipmath_1.oneInPips : ((0, _pipmath_1.minBigInt)(_pipmath_1.oneInPips, (0, _pipmath_1.dividePips)(availableCollateralForLeverage, potentialLeveragedValue))));
|
|
56
|
+
}
|
|
57
|
+
exports.calculateMaximumInitialMarginFractionOverride = calculateMaximumInitialMarginFractionOverride;
|
|
58
|
+
function convertToActiveStandingOrderBigInt(order) {
|
|
59
|
+
return {
|
|
60
|
+
...order,
|
|
61
|
+
openQuantity: (0, _pipmath_1.decimalToPip)(order.originalQuantity) -
|
|
62
|
+
(0, _pipmath_1.decimalToPip)(order.executedQuantity),
|
|
63
|
+
price: (0, _pipmath_1.decimalToPip)(order.price),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.convertToActiveStandingOrderBigInt = convertToActiveStandingOrderBigInt;
|
|
67
|
+
function convertToLeverageParametersBigInt(leverageParameters) {
|
|
68
|
+
return {
|
|
69
|
+
maximumPositionSize: (0, _pipmath_1.decimalToPip)(leverageParameters.maximumPositionSize),
|
|
70
|
+
initialMarginFraction: (0, _pipmath_1.decimalToPip)(leverageParameters.initialMarginFraction),
|
|
71
|
+
maintenanceMarginFraction: (0, _pipmath_1.decimalToPip)(leverageParameters.maintenanceMarginFraction),
|
|
72
|
+
basePositionSize: (0, _pipmath_1.decimalToPip)(leverageParameters.basePositionSize),
|
|
73
|
+
incrementalPositionSize: (0, _pipmath_1.decimalToPip)(leverageParameters.incrementalPositionSize),
|
|
74
|
+
incrementalInitialMarginFraction: (0, _pipmath_1.decimalToPip)(leverageParameters.incrementalInitialMarginFraction),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
exports.convertToLeverageParametersBigInt = convertToLeverageParametersBigInt;
|
|
78
|
+
/**
|
|
79
|
+
* Converts a {@link KatanaPerpsPosition} object to one used by some functions in this
|
|
80
|
+
* file.
|
|
81
|
+
*/
|
|
82
|
+
function convertToPositionBigInt(position) {
|
|
83
|
+
return {
|
|
84
|
+
market: position.market,
|
|
85
|
+
quantity: (0, _pipmath_1.decimalToPip)(position.quantity),
|
|
86
|
+
indexPrice: (0, _pipmath_1.decimalToPip)(position.indexPrice),
|
|
87
|
+
marginRequirement: (0, _pipmath_1.decimalToPip)(position.marginRequirement),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
exports.convertToPositionBigInt = convertToPositionBigInt;
|
|
91
|
+
/**
|
|
92
|
+
* Determines the liquidity available in the given order book (asks or bids)
|
|
93
|
+
* for a given taker quantity (which may be expressed in base or quote asset)
|
|
94
|
+
* and price (optional).
|
|
95
|
+
* In other words, it performs very basic order matching to provide an estimate
|
|
96
|
+
* of the base and quote quantities with which a taker order of the given
|
|
97
|
+
* size (quantity) and limit price (optional) would be filled.
|
|
98
|
+
*
|
|
99
|
+
* The taker order may represent a limit or a market order: If a limit price is
|
|
100
|
+
* given, it is matched as a limit order (which necessitates specifying whether
|
|
101
|
+
* it's a buy or a sell). Otherwise it is matched as a market order.
|
|
102
|
+
*
|
|
103
|
+
* The provided list of orders or price levels (asks or bids) is expected to be
|
|
104
|
+
* sorted by best price (ascending for asks (lowest first), descending for bids
|
|
105
|
+
* (highest first)). Multiple orders per price level are supported.
|
|
106
|
+
*
|
|
107
|
+
* To support high-precision calculations in which pip-precision is
|
|
108
|
+
* insufficient, the result may optionally be returned in double-pip precision;
|
|
109
|
+
* the returned values then represent numbers with 16 decimals instead of 8.
|
|
110
|
+
*
|
|
111
|
+
* @param returnInDoublePipPrecision - Defaults to false
|
|
112
|
+
*/
|
|
113
|
+
function calculateGrossFillQuantities(makerSideOrders, takerOrder, returnInDoublePipPrecision = false) {
|
|
114
|
+
const takerQuantity2p = takerOrder.quantity * _pipmath_1.oneInPips;
|
|
115
|
+
let filledBaseQty2p = BigInt(0);
|
|
116
|
+
let filledQuoteQty2p = BigInt(0);
|
|
117
|
+
const makeReturnValue = () => {
|
|
118
|
+
if (returnInDoublePipPrecision) {
|
|
119
|
+
return {
|
|
120
|
+
baseQuantity: filledBaseQty2p,
|
|
121
|
+
quoteQuantity: filledQuoteQty2p,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
baseQuantity: filledBaseQty2p / _pipmath_1.oneInPips,
|
|
126
|
+
quoteQuantity: filledQuoteQty2p / _pipmath_1.oneInPips,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
for (const makerOrder of makerSideOrders) {
|
|
130
|
+
if (!doOrdersMatch(makerOrder, takerOrder)) {
|
|
131
|
+
return makeReturnValue();
|
|
132
|
+
}
|
|
133
|
+
const maxTakerQuantity2p = takerOrder.isQuantityInQuote ?
|
|
134
|
+
takerQuantity2p - filledQuoteQty2p
|
|
135
|
+
: takerQuantity2p - filledBaseQty2p;
|
|
136
|
+
const tradeQuantities = determineTradeQuantities(makerOrder, maxTakerQuantity2p, takerOrder.isQuantityInQuote);
|
|
137
|
+
if (tradeQuantities.baseQuantity2p === BigInt(0) ||
|
|
138
|
+
tradeQuantities.quoteQuantity2p === BigInt(0)) {
|
|
139
|
+
return makeReturnValue();
|
|
140
|
+
}
|
|
141
|
+
filledBaseQty2p += tradeQuantities.baseQuantity2p;
|
|
142
|
+
filledQuoteQty2p += tradeQuantities.quoteQuantity2p;
|
|
143
|
+
}
|
|
144
|
+
return makeReturnValue();
|
|
145
|
+
}
|
|
146
|
+
exports.calculateGrossFillQuantities = calculateGrossFillQuantities;
|
|
147
|
+
/**
|
|
148
|
+
* Operates in double-pip precision ("2p") (16 decimals)
|
|
149
|
+
*
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
function determineTradeQuantities(makerOrder, maxTakerQuantity2p, isMaxTakerQuantityInQuote) {
|
|
153
|
+
const makerQuantity2p = makerOrder.size * _pipmath_1.oneInPips;
|
|
154
|
+
// Limit by base
|
|
155
|
+
const fillBaseQty2p = isMaxTakerQuantityInQuote ? makerQuantity2p : ((0, _pipmath_1.minBigInt)(maxTakerQuantity2p, makerQuantity2p));
|
|
156
|
+
const fillQuoteQty2p = (0, _pipmath_1.multiplyPips)(fillBaseQty2p, makerOrder.price);
|
|
157
|
+
// Limit by quote
|
|
158
|
+
if (isMaxTakerQuantityInQuote && maxTakerQuantity2p < fillQuoteQty2p) {
|
|
159
|
+
return {
|
|
160
|
+
// Reduce base proportionally to reduction of fillQuoteQty2p
|
|
161
|
+
baseQuantity2p: (fillBaseQty2p * maxTakerQuantity2p) / fillQuoteQty2p,
|
|
162
|
+
quoteQuantity2p: maxTakerQuantity2p,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
baseQuantity2p: fillBaseQty2p,
|
|
167
|
+
quoteQuantity2p: fillQuoteQty2p,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
173
|
+
function doOrdersMatch(makerOrder, takerOrder) {
|
|
174
|
+
if (!takerOrder.limitPrice) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
return ((takerOrder.side === request_1.OrderSide.buy &&
|
|
178
|
+
takerOrder.limitPrice >= makerOrder.price) ||
|
|
179
|
+
(takerOrder.side === request_1.OrderSide.sell &&
|
|
180
|
+
takerOrder.limitPrice <= makerOrder.price));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Reduce-only orders may only be on the books if their execution would in fact
|
|
184
|
+
* result in a reduction of an open position. That is, if any of the wallet's
|
|
185
|
+
* other standing orders would be matched and executed first and reduce the
|
|
186
|
+
* position, any reduce-only liquidity newly added to the books may not exceed
|
|
187
|
+
* the remaining size of the position.
|
|
188
|
+
*
|
|
189
|
+
* This function returns the size of the given open position minus the combined
|
|
190
|
+
* size of all the wallet's standing orders on the other side of the book that
|
|
191
|
+
* are priced better (higher for buys, lower for sells) or equal to the provided
|
|
192
|
+
* limit price.
|
|
193
|
+
*/
|
|
194
|
+
function determineMaximumReduceOnlyQuantityAvailableAtPriceLevel(args) {
|
|
195
|
+
const { limitPrice, position, orderSide, walletsStandingOrders } = args;
|
|
196
|
+
const positionQty = (0, _pipmath_1.decimalToPip)(position.quantity);
|
|
197
|
+
if (positionQty === BigInt(0)) {
|
|
198
|
+
return BigInt(0);
|
|
199
|
+
}
|
|
200
|
+
if ((orderSide === request_1.OrderSide.buy && positionQty > BigInt(0)) ||
|
|
201
|
+
(orderSide === request_1.OrderSide.sell && positionQty < BigInt(0))) {
|
|
202
|
+
// Order does not reduce position
|
|
203
|
+
return BigInt(0);
|
|
204
|
+
}
|
|
205
|
+
const activeStandingOrdersOnSameSide = walletsStandingOrders
|
|
206
|
+
.filter((order) => order.market === position.market && order.side === orderSide)
|
|
207
|
+
.filter(isActiveStandingOrder)
|
|
208
|
+
.map(convertToActiveStandingOrderBigInt);
|
|
209
|
+
let betterPricedActiveQtyOnTheBooks = BigInt(0);
|
|
210
|
+
for (const order of activeStandingOrdersOnSameSide) {
|
|
211
|
+
if ((order.side === request_1.OrderSide.buy && order.price >= limitPrice) ||
|
|
212
|
+
(order.side === request_1.OrderSide.sell && order.price <= limitPrice)) {
|
|
213
|
+
betterPricedActiveQtyOnTheBooks += order.openQuantity;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return (0, _pipmath_1.maxBigInt)((0, _pipmath_1.absBigInt)(positionQty) - betterPricedActiveQtyOnTheBooks, BigInt(0));
|
|
217
|
+
}
|
|
218
|
+
exports.determineMaximumReduceOnlyQuantityAvailableAtPriceLevel = determineMaximumReduceOnlyQuantityAvailableAtPriceLevel;
|
|
219
|
+
/**
|
|
220
|
+
* Helper function to re-aggregate L2 orderbook price levels at a larger (more zeroes) tick size
|
|
221
|
+
*/
|
|
222
|
+
function aggregateL2OrderBookAtTickSize(inputBook, tickSize) {
|
|
223
|
+
const askLevelsByPrice = new Map();
|
|
224
|
+
for (const askLevel of inputBook.asks) {
|
|
225
|
+
const price = adjustPriceToTickSize(askLevel.price, tickSize, exports.asksTickRoundingMode);
|
|
226
|
+
const level = askLevelsByPrice.get(price) || { ...exports.nullLevel, price };
|
|
227
|
+
level.numOrders += askLevel.numOrders;
|
|
228
|
+
level.size += askLevel.size;
|
|
229
|
+
askLevelsByPrice.set(price, level);
|
|
230
|
+
}
|
|
231
|
+
const bidLevelsByPrice = new Map();
|
|
232
|
+
for (const bidLevel of inputBook.bids) {
|
|
233
|
+
const price = adjustPriceToTickSize(bidLevel.price, tickSize, exports.bidsTickRoundingMode);
|
|
234
|
+
const level = bidLevelsByPrice.get(price) || { ...exports.nullLevel, price };
|
|
235
|
+
level.numOrders += bidLevel.numOrders;
|
|
236
|
+
level.size += bidLevel.size;
|
|
237
|
+
bidLevelsByPrice.set(price, level);
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
...inputBook,
|
|
241
|
+
asks: Array.from(askLevelsByPrice.values()),
|
|
242
|
+
bids: Array.from(bidLevelsByPrice.values()),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
exports.aggregateL2OrderBookAtTickSize = aggregateL2OrderBookAtTickSize;
|
|
246
|
+
/**
|
|
247
|
+
* Adjusts prices in pips to account for tick size by discarding insignificant digits using
|
|
248
|
+
* specified rounding mode. Ex price 123456789 at tick size 1 is 123456789, at tick size 10
|
|
249
|
+
* 123456780, at 100 123456700, etc
|
|
250
|
+
*/
|
|
251
|
+
function adjustPriceToTickSize(price, tickSize, roundingMode = bignumber_js_1.BigNumber.ROUND_HALF_UP) {
|
|
252
|
+
const significantDigits = new bignumber_js_1.BigNumber(price.toString())
|
|
253
|
+
.dividedBy(new bignumber_js_1.BigNumber(tickSize.toString()))
|
|
254
|
+
.toFixed(0, roundingMode);
|
|
255
|
+
return BigInt(significantDigits) * tickSize;
|
|
256
|
+
}
|
|
257
|
+
exports.adjustPriceToTickSize = adjustPriceToTickSize;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/orderbook/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,CAoB5D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.L2toL1OrderBook = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Derive the level 1 orderbook from a level 2 orderbook
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function L2toL1OrderBook(l2) {
|
|
10
|
+
return {
|
|
11
|
+
...l2,
|
|
12
|
+
asks: l2.asks.length ?
|
|
13
|
+
{
|
|
14
|
+
price: l2.asks[0].price,
|
|
15
|
+
size: l2.asks[0].size,
|
|
16
|
+
numOrders: l2.asks[0].numOrders,
|
|
17
|
+
}
|
|
18
|
+
: { price: BigInt(0), size: BigInt(0), numOrders: 0 },
|
|
19
|
+
bids: l2.bids.length ?
|
|
20
|
+
{
|
|
21
|
+
price: l2.bids[0].price,
|
|
22
|
+
size: l2.bids[0].size,
|
|
23
|
+
numOrders: l2.bids[0].numOrders,
|
|
24
|
+
}
|
|
25
|
+
: { price: BigInt(0), size: BigInt(0), numOrders: 0 },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.L2toL1OrderBook = L2toL1OrderBook;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const exchangeDecimals = 8;
|
|
2
|
+
export declare const oneInPips: bigint;
|
|
3
|
+
export declare const MAX_64_BIT_INT: bigint;
|
|
4
|
+
export declare function absBigInt(a: bigint): bigint;
|
|
5
|
+
export declare const assetUnitsToDecimal: (assetUnits: bigint, decimals: number) => string;
|
|
6
|
+
export declare const assetUnitsToPip: (assetUnits: bigint, assetUnitDecimals?: number) => bigint;
|
|
7
|
+
export declare const pipToAssetUnits: (pips: bigint, assetUnitDecimals?: number) => bigint;
|
|
8
|
+
export declare const decimalToPip: (decimal: string) => bigint;
|
|
9
|
+
export declare enum ROUNDING {
|
|
10
|
+
Truncate = 0,
|
|
11
|
+
RoundUp = 1,
|
|
12
|
+
RoundDown = 2
|
|
13
|
+
}
|
|
14
|
+
export declare function divideBigInt(dividend: bigint, divisor: bigint, rounding?: ROUNDING): bigint;
|
|
15
|
+
export declare const dividePips: (valueInPips: bigint, divisorInPips: bigint) => bigint;
|
|
16
|
+
export declare const maxBigInt: (a: bigint, b: bigint) => bigint;
|
|
17
|
+
export declare const minBigInt: (a: bigint, b: bigint) => bigint;
|
|
18
|
+
export declare const multiplyPips: (pipValue1: bigint, pipValue2: bigint, roundUp?: boolean) => bigint;
|
|
19
|
+
export declare const pipToDecimal: (pips: bigint) => string;
|
|
20
|
+
export declare function squareRootBigInt(value: bigint): bigint;
|
|
21
|
+
//# sourceMappingURL=pipmath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipmath.d.ts","sourceRoot":"","sources":["../src/pipmath.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,SAAS,QAAiC,CAAC;AACxD,eAAO,MAAM,cAAc,QAAiC,CAAC;AAE7D,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,eAAO,MAAM,mBAAmB,eAClB,MAAM,YACR,MAAM,KACf,MAGF,CAAC;AAEF,eAAO,MAAM,eAAe,eACd,MAAM,iCAEjB,MAGF,CAAC;AAEF,eAAO,MAAM,eAAe,SACpB,MAAM,iCAEX,MAGF,CAAC;AAEF,eAAO,MAAM,YAAY,YAAkC,MAAM,KAAG,MAQnE,CAAC;AAEF,oBAAY,QAAQ;IAClB,QAAQ,IAAI;IACZ,OAAO,IAAI;IACX,SAAS,IAAI;CACd;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,QAA4B,GACrC,MAAM,CAuBR;AAED,eAAO,MAAM,UAAU,gBACR,MAAM,iBACJ,MAAM,KACpB,MAKF,CAAC;AAEF,eAAO,MAAM,SAAS,MAAyB,MAAM,KAAK,MAAM,KAAG,MAKlE,CAAC;AAEF,eAAO,MAAM,SAAS,MAAyB,MAAM,KAAK,MAAM,KAAG,MAKlE,CAAC;AAEF,eAAO,MAAM,YAAY,cACZ,MAAM,aACN,MAAM,wBAEhB,MAMF,CAAC;AAEF,eAAO,MAAM,YAAY,SAA+B,MAAM,KAAG,MAEhE,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBtD"}
|
package/dist/pipmath.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.squareRootBigInt = exports.pipToDecimal = exports.multiplyPips = exports.minBigInt = exports.maxBigInt = exports.dividePips = exports.divideBigInt = exports.ROUNDING = exports.decimalToPip = exports.pipToAssetUnits = exports.assetUnitsToPip = exports.assetUnitsToDecimal = exports.absBigInt = exports.MAX_64_BIT_INT = exports.oneInPips = exports.exchangeDecimals = void 0;
|
|
4
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
5
|
+
exports.exchangeDecimals = 8;
|
|
6
|
+
exports.oneInPips = BigInt(10 ** exports.exchangeDecimals);
|
|
7
|
+
exports.MAX_64_BIT_INT = BigInt('18446744073709551615');
|
|
8
|
+
function absBigInt(a) {
|
|
9
|
+
return a < BigInt(0) ? -a : a;
|
|
10
|
+
}
|
|
11
|
+
exports.absBigInt = absBigInt;
|
|
12
|
+
const assetUnitsToDecimal = function assetUnitsToDecimal(assetUnits, decimals) {
|
|
13
|
+
const bn = new bignumber_js_1.BigNumber(assetUnits.toString());
|
|
14
|
+
return bn.shiftedBy(decimals * -1).toFixed(exports.exchangeDecimals);
|
|
15
|
+
};
|
|
16
|
+
exports.assetUnitsToDecimal = assetUnitsToDecimal;
|
|
17
|
+
const assetUnitsToPip = function assetUnitsToPip(assetUnits, assetUnitDecimals = 18) {
|
|
18
|
+
const bn = new bignumber_js_1.BigNumber(assetUnits.toString());
|
|
19
|
+
return BigInt(bn.shiftedBy(exports.exchangeDecimals - assetUnitDecimals).toFixed(0));
|
|
20
|
+
};
|
|
21
|
+
exports.assetUnitsToPip = assetUnitsToPip;
|
|
22
|
+
const pipToAssetUnits = function pipToAssetUnits(pips, assetUnitDecimals = 18) {
|
|
23
|
+
const bn = new bignumber_js_1.BigNumber(pips.toString());
|
|
24
|
+
return BigInt(bn.shiftedBy(assetUnitDecimals - exports.exchangeDecimals).toFixed(0));
|
|
25
|
+
};
|
|
26
|
+
exports.pipToAssetUnits = pipToAssetUnits;
|
|
27
|
+
const decimalToPip = function decimalToPip(decimal) {
|
|
28
|
+
const bn = new bignumber_js_1.BigNumber(decimal);
|
|
29
|
+
return BigInt(bn
|
|
30
|
+
.shiftedBy(exports.exchangeDecimals)
|
|
31
|
+
.integerValue(bignumber_js_1.BigNumber.ROUND_DOWN)
|
|
32
|
+
.toString());
|
|
33
|
+
};
|
|
34
|
+
exports.decimalToPip = decimalToPip;
|
|
35
|
+
var ROUNDING;
|
|
36
|
+
(function (ROUNDING) {
|
|
37
|
+
ROUNDING[ROUNDING["Truncate"] = 0] = "Truncate";
|
|
38
|
+
ROUNDING[ROUNDING["RoundUp"] = 1] = "RoundUp";
|
|
39
|
+
ROUNDING[ROUNDING["RoundDown"] = 2] = "RoundDown";
|
|
40
|
+
})(ROUNDING || (exports.ROUNDING = ROUNDING = {}));
|
|
41
|
+
function divideBigInt(dividend, divisor, rounding = ROUNDING.Truncate) {
|
|
42
|
+
if (divisor < BigInt(0)) {
|
|
43
|
+
throw new Error(`Division by negative numbers is not supported (got ${dividend.toString()}/${divisor.toString()})`);
|
|
44
|
+
}
|
|
45
|
+
const result = dividend / divisor;
|
|
46
|
+
if (rounding === ROUNDING.RoundUp &&
|
|
47
|
+
dividend > BigInt(0) && // Truncation is the same as rounding up in negative numbers
|
|
48
|
+
result * divisor !== dividend) {
|
|
49
|
+
return result + BigInt(1);
|
|
50
|
+
}
|
|
51
|
+
if (rounding === ROUNDING.RoundDown &&
|
|
52
|
+
dividend < BigInt(0) && // Truncation is the same as rounding down in positive numbers
|
|
53
|
+
result * divisor !== dividend) {
|
|
54
|
+
return result - BigInt(1);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
exports.divideBigInt = divideBigInt;
|
|
59
|
+
const dividePips = function dividePips(valueInPips, divisorInPips) {
|
|
60
|
+
if (divisorInPips <= BigInt(0)) {
|
|
61
|
+
return BigInt(0);
|
|
62
|
+
}
|
|
63
|
+
return (valueInPips * exports.oneInPips) / divisorInPips;
|
|
64
|
+
};
|
|
65
|
+
exports.dividePips = dividePips;
|
|
66
|
+
const maxBigInt = function maxBigInt(a, b) {
|
|
67
|
+
if (a >= b) {
|
|
68
|
+
return a;
|
|
69
|
+
}
|
|
70
|
+
return b;
|
|
71
|
+
};
|
|
72
|
+
exports.maxBigInt = maxBigInt;
|
|
73
|
+
const minBigInt = function minBigInt(a, b) {
|
|
74
|
+
if (a <= b) {
|
|
75
|
+
return a;
|
|
76
|
+
}
|
|
77
|
+
return b;
|
|
78
|
+
};
|
|
79
|
+
exports.minBigInt = minBigInt;
|
|
80
|
+
const multiplyPips = function multiplyPips(pipValue1, pipValue2, roundUp = false) {
|
|
81
|
+
const pipValuesProduct = pipValue1 * pipValue2;
|
|
82
|
+
if (roundUp && pipValuesProduct % exports.oneInPips > 0) {
|
|
83
|
+
return BigInt(1) + pipValuesProduct / exports.oneInPips;
|
|
84
|
+
}
|
|
85
|
+
return pipValuesProduct / exports.oneInPips;
|
|
86
|
+
};
|
|
87
|
+
exports.multiplyPips = multiplyPips;
|
|
88
|
+
const pipToDecimal = function pipToDecimal(pips) {
|
|
89
|
+
return (0, exports.assetUnitsToDecimal)(pips, exports.exchangeDecimals);
|
|
90
|
+
};
|
|
91
|
+
exports.pipToDecimal = pipToDecimal;
|
|
92
|
+
function squareRootBigInt(value) {
|
|
93
|
+
if (value < BigInt(0)) {
|
|
94
|
+
throw new Error('Square root of negative numbers is not supported');
|
|
95
|
+
}
|
|
96
|
+
if (value === BigInt(0)) {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
if (value <= BigInt(3)) {
|
|
100
|
+
return BigInt(1);
|
|
101
|
+
}
|
|
102
|
+
let z = value;
|
|
103
|
+
let x = value / BigInt(2) + BigInt(1);
|
|
104
|
+
while (x < z) {
|
|
105
|
+
z = x;
|
|
106
|
+
x = (value / x + x) / BigInt(2);
|
|
107
|
+
}
|
|
108
|
+
return z;
|
|
109
|
+
}
|
|
110
|
+
exports.squareRootBigInt = squareRootBigInt;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import type * as types from '#index';
|
|
3
|
+
import type { WithdrawalFromManagedAccountStruct } from './typechain-types/Exchange_v1';
|
|
4
|
+
export type SignTypedData = (domain: ethers.TypedDataDomain, typeData: Record<string, Array<ethers.TypedDataField>>, value: Record<string, any>) => Promise<string>;
|
|
5
|
+
export declare function createPrivateKeyTypedDataSigner(walletPrivateKey: string): SignTypedData;
|
|
6
|
+
export declare const getDomainSeparator: (contractAddress: string, chainId: number, sandbox: boolean) => {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
chainId: number;
|
|
10
|
+
verifyingContract: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const getWalletAssociationSignatureTypedData: (data: types.RestRequestAssociateWallet, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
13
|
+
export declare const getWalletUnlockSignatureTypedData: ({ nonce }: {
|
|
14
|
+
nonce: string;
|
|
15
|
+
}, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
16
|
+
export declare const getDelegatedKeyAuthorizationSignatureTypedData: ({ delegatedKey, nonce }: {
|
|
17
|
+
delegatedKey: string;
|
|
18
|
+
nonce: string;
|
|
19
|
+
}, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
20
|
+
export declare const getOrderSignatureTypedData: (data: types.RestRequestOrder, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
21
|
+
export declare const getOrderCancellationByOrderIdSignatureTypedData: (data: types.RestRequestCancelOrdersByOrderIds, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
22
|
+
export declare const getOrderCancellationByDelegatedKeySignatureTypedData: (data: types.RestRequestCancelOrdersByDelegatedKey, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
23
|
+
export declare const getOrderCancellationByMarketSymbolSignatureTypedData: (data: types.RestRequestCancelOrdersByMarket, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
24
|
+
export declare const getOrderCancellationByWalletSignatureTypedData: (data: types.RestRequestCancelOrders, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
25
|
+
export declare const getOrderCancellationSignatureTypedData: (data: types.RestRequestCancelOrders, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, typeData: Record<string, ethers.TypedDataField[]>, value: Record<string, any>];
|
|
26
|
+
export declare function getSetVaultDetailsSignatureTypedData(data: types.RestRequestSetVaultDetails, contractAddress: string, chainId: number, sandbox: boolean): Parameters<SignTypedData>;
|
|
27
|
+
export declare function getSetVaultXConnectionSignatureTypedData(data: types.RestRequestSetVaultXConnection, contractAddress: string, chainId: number, sandbox: boolean): Parameters<SignTypedData>;
|
|
28
|
+
export declare function getRemoveVaultXConnectionSignatureTypedData(data: types.RestRequestRemoveVaultXConnection, contractAddress: string, chainId: number, sandbox: boolean): Parameters<SignTypedData>;
|
|
29
|
+
export declare const getWithdrawalFromManagedAccountContractStructSignatureTypedData: (data: WithdrawalFromManagedAccountStruct, contractAddress: string, chainId: number, sandbox: boolean) => Promise<Parameters<ethers.JsonRpcSigner['signTypedData']>>;
|
|
30
|
+
export declare const getWithdrawalFromManagedAccountByQuantitySignatureTypedData: (data: types.RestRequestWithdrawFundsFromManagedAccountByQuantity, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, _value: Record<string, any>];
|
|
31
|
+
export declare const getWithdrawalFromManagedAccountBySharesSignatureTypedData: (data: types.RestRequestWithdrawFundsFromManagedAccountByShares, contractAddress: string, chainId: number, sandbox: boolean) => [domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, _value: Record<string, any>];
|
|
32
|
+
export declare function getWithdrawalSignatureTypedData(data: types.RestRequestWithdrawFunds, contractAddress: string, chainId: number, sandbox: boolean): Parameters<SignTypedData>;
|
|
33
|
+
export declare function getInitialMarginFractionOverrideSettingsSignatureTypedData(data: types.RestRequestSetInitialMarginFractionOverride, contractAddress: string, chainId: number, sandbox: boolean): Parameters<SignTypedData>;
|
|
34
|
+
export declare function uint128ToUuid(uint: ethers.BigNumberish): string;
|
|
35
|
+
export declare function uuidToHexString(uuid: string): string;
|
|
36
|
+
export declare function uuidToUint128(uuid: string): bigint;
|
|
37
|
+
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../src/signatures.ts"],"names":[],"mappings":"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"}
|