@metamask-previews/perps-controller 0.0.0-preview-e4aa1532 → 0.0.0-preview-6dfa4aeba
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/CHANGELOG.md +1 -11
- package/dist/PerpsController.cjs +66 -2224
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +79 -933
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +79 -933
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +64 -2221
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/index.cjs +1 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -19
- package/dist/__mocks__/hyperliquidMock.cjs +0 -68
- package/dist/__mocks__/hyperliquidMock.cjs.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.cts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.cts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.mts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.mts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.mjs +0 -65
- package/dist/__mocks__/hyperliquidMock.mjs.map +0 -1
- package/dist/__mocks__/providerMocks.cjs +0 -144
- package/dist/__mocks__/providerMocks.cjs.map +0 -1
- package/dist/__mocks__/providerMocks.d.cts +0 -44
- package/dist/__mocks__/providerMocks.d.cts.map +0 -1
- package/dist/__mocks__/providerMocks.d.mts +0 -44
- package/dist/__mocks__/providerMocks.d.mts.map +0 -1
- package/dist/__mocks__/providerMocks.mjs +0 -136
- package/dist/__mocks__/providerMocks.mjs.map +0 -1
- package/dist/__mocks__/serviceMocks.cjs +0 -187
- package/dist/__mocks__/serviceMocks.cjs.map +0 -1
- package/dist/__mocks__/serviceMocks.d.cts +0 -58
- package/dist/__mocks__/serviceMocks.d.cts.map +0 -1
- package/dist/__mocks__/serviceMocks.d.mts +0 -58
- package/dist/__mocks__/serviceMocks.d.mts.map +0 -1
- package/dist/__mocks__/serviceMocks.mjs +0 -180
- package/dist/__mocks__/serviceMocks.mjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -459
- package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -455
- package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
- package/dist/aggregation/index.cjs +0 -9
- package/dist/aggregation/index.cjs.map +0 -1
- package/dist/aggregation/index.d.cts +0 -6
- package/dist/aggregation/index.d.cts.map +0 -1
- package/dist/aggregation/index.d.mts +0 -6
- package/dist/aggregation/index.d.mts.map +0 -1
- package/dist/aggregation/index.mjs +0 -5
- package/dist/aggregation/index.mjs.map +0 -1
- package/dist/constants/eventNames.cjs +0 -117
- package/dist/constants/eventNames.cjs.map +0 -1
- package/dist/constants/eventNames.d.cts +0 -106
- package/dist/constants/eventNames.d.cts.map +0 -1
- package/dist/constants/eventNames.d.mts +0 -106
- package/dist/constants/eventNames.d.mts.map +0 -1
- package/dist/constants/eventNames.mjs +0 -114
- package/dist/constants/eventNames.mjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.cjs +0 -366
- package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.cts +0 -276
- package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.mts +0 -276
- package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
- package/dist/constants/hyperLiquidConfig.mjs +0 -357
- package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
- package/dist/constants/index.cjs +0 -23
- package/dist/constants/index.cjs.map +0 -1
- package/dist/constants/index.d.cts +0 -7
- package/dist/constants/index.d.cts.map +0 -1
- package/dist/constants/index.d.mts +0 -7
- package/dist/constants/index.d.mts.map +0 -1
- package/dist/constants/index.mjs +0 -7
- package/dist/constants/index.mjs.map +0 -1
- package/dist/constants/orderTypes.cjs +0 -31
- package/dist/constants/orderTypes.cjs.map +0 -1
- package/dist/constants/orderTypes.d.cts +0 -19
- package/dist/constants/orderTypes.d.cts.map +0 -1
- package/dist/constants/orderTypes.d.mts +0 -19
- package/dist/constants/orderTypes.d.mts.map +0 -1
- package/dist/constants/orderTypes.mjs +0 -27
- package/dist/constants/orderTypes.mjs.map +0 -1
- package/dist/constants/performanceMetrics.cjs +0 -61
- package/dist/constants/performanceMetrics.cjs.map +0 -1
- package/dist/constants/performanceMetrics.d.cts +0 -44
- package/dist/constants/performanceMetrics.d.cts.map +0 -1
- package/dist/constants/performanceMetrics.d.mts +0 -44
- package/dist/constants/performanceMetrics.d.mts.map +0 -1
- package/dist/constants/performanceMetrics.mjs +0 -58
- package/dist/constants/performanceMetrics.mjs.map +0 -1
- package/dist/constants/perpsConfig.cjs +0 -461
- package/dist/constants/perpsConfig.cjs.map +0 -1
- package/dist/constants/perpsConfig.d.cts +0 -343
- package/dist/constants/perpsConfig.d.cts.map +0 -1
- package/dist/constants/perpsConfig.d.mts +0 -343
- package/dist/constants/perpsConfig.d.mts.map +0 -1
- package/dist/constants/perpsConfig.mjs +0 -458
- package/dist/constants/perpsConfig.mjs.map +0 -1
- package/dist/constants/perpsErrorCodes.cjs +0 -79
- package/dist/constants/perpsErrorCodes.cjs.map +0 -1
- package/dist/constants/perpsErrorCodes.d.cts +0 -64
- package/dist/constants/perpsErrorCodes.d.cts.map +0 -1
- package/dist/constants/perpsErrorCodes.d.mts +0 -64
- package/dist/constants/perpsErrorCodes.d.mts.map +0 -1
- package/dist/constants/perpsErrorCodes.mjs +0 -76
- package/dist/constants/perpsErrorCodes.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.cjs +0 -857
- package/dist/platform-services/HyperLiquidClientService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.cts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.mts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.mjs +0 -853
- package/dist/platform-services/HyperLiquidClientService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs +0 -2170
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs +0 -2166
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.cjs +0 -140
- package/dist/platform-services/HyperLiquidWalletService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.cts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.mts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.mjs +0 -136
- package/dist/platform-services/HyperLiquidWalletService.mjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +0 -777
- package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +0 -773
- package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.cjs +0 -5172
- package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.cts +0 -881
- package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.mts +0 -881
- package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
- package/dist/providers/HyperLiquidProvider.mjs +0 -5168
- package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
- package/dist/providers/index.cjs +0 -11
- package/dist/providers/index.cjs.map +0 -1
- package/dist/providers/index.d.cts +0 -6
- package/dist/providers/index.d.cts.map +0 -1
- package/dist/providers/index.d.mts +0 -6
- package/dist/providers/index.d.mts.map +0 -1
- package/dist/providers/index.mjs +0 -6
- package/dist/providers/index.mjs.map +0 -1
- package/dist/routing/ProviderRouter.cjs +0 -148
- package/dist/routing/ProviderRouter.cjs.map +0 -1
- package/dist/routing/ProviderRouter.d.cts +0 -124
- package/dist/routing/ProviderRouter.d.cts.map +0 -1
- package/dist/routing/ProviderRouter.d.mts +0 -124
- package/dist/routing/ProviderRouter.d.mts.map +0 -1
- package/dist/routing/ProviderRouter.mjs +0 -144
- package/dist/routing/ProviderRouter.mjs.map +0 -1
- package/dist/routing/index.cjs +0 -9
- package/dist/routing/index.cjs.map +0 -1
- package/dist/routing/index.d.cts +0 -6
- package/dist/routing/index.d.cts.map +0 -1
- package/dist/routing/index.d.mts +0 -6
- package/dist/routing/index.d.mts.map +0 -1
- package/dist/routing/index.mjs +0 -5
- package/dist/routing/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -161
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -345
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -345
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs +0 -153
- package/dist/selectors.mjs.map +0 -1
- package/dist/services/AccountService.cjs +0 -313
- package/dist/services/AccountService.cjs.map +0 -1
- package/dist/services/AccountService.d.cts +0 -53
- package/dist/services/AccountService.d.cts.map +0 -1
- package/dist/services/AccountService.d.mts +0 -53
- package/dist/services/AccountService.d.mts.map +0 -1
- package/dist/services/AccountService.mjs +0 -309
- package/dist/services/AccountService.mjs.map +0 -1
- package/dist/services/DataLakeService.cjs +0 -219
- package/dist/services/DataLakeService.cjs.map +0 -1
- package/dist/services/DataLakeService.d.cts +0 -49
- package/dist/services/DataLakeService.d.cts.map +0 -1
- package/dist/services/DataLakeService.d.mts +0 -49
- package/dist/services/DataLakeService.d.mts.map +0 -1
- package/dist/services/DataLakeService.mjs +0 -215
- package/dist/services/DataLakeService.mjs.map +0 -1
- package/dist/services/DepositService.cjs +0 -96
- package/dist/services/DepositService.cjs.map +0 -1
- package/dist/services/DepositService.d.cts +0 -37
- package/dist/services/DepositService.d.cts.map +0 -1
- package/dist/services/DepositService.d.mts +0 -37
- package/dist/services/DepositService.d.mts.map +0 -1
- package/dist/services/DepositService.mjs +0 -92
- package/dist/services/DepositService.mjs.map +0 -1
- package/dist/services/EligibilityService.cjs +0 -156
- package/dist/services/EligibilityService.cjs.map +0 -1
- package/dist/services/EligibilityService.d.cts +0 -48
- package/dist/services/EligibilityService.d.cts.map +0 -1
- package/dist/services/EligibilityService.d.mts +0 -48
- package/dist/services/EligibilityService.d.mts.map +0 -1
- package/dist/services/EligibilityService.mjs +0 -152
- package/dist/services/EligibilityService.mjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.cjs +0 -258
- package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.cts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.mts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.mjs +0 -254
- package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
- package/dist/services/MarketDataService.cjs +0 -875
- package/dist/services/MarketDataService.cjs.map +0 -1
- package/dist/services/MarketDataService.d.cts +0 -289
- package/dist/services/MarketDataService.d.cts.map +0 -1
- package/dist/services/MarketDataService.d.mts +0 -289
- package/dist/services/MarketDataService.d.mts.map +0 -1
- package/dist/services/MarketDataService.mjs +0 -871
- package/dist/services/MarketDataService.mjs.map +0 -1
- package/dist/services/RewardsIntegrationService.cjs +0 -94
- package/dist/services/RewardsIntegrationService.cjs.map +0 -1
- package/dist/services/RewardsIntegrationService.d.cts +0 -30
- package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
- package/dist/services/RewardsIntegrationService.d.mts +0 -30
- package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
- package/dist/services/RewardsIntegrationService.mjs +0 -90
- package/dist/services/RewardsIntegrationService.mjs.map +0 -1
- package/dist/services/ServiceContext.cjs +0 -3
- package/dist/services/ServiceContext.cjs.map +0 -1
- package/dist/services/ServiceContext.d.cts +0 -110
- package/dist/services/ServiceContext.d.cts.map +0 -1
- package/dist/services/ServiceContext.d.mts +0 -110
- package/dist/services/ServiceContext.d.mts.map +0 -1
- package/dist/services/ServiceContext.mjs +0 -2
- package/dist/services/ServiceContext.mjs.map +0 -1
- package/dist/services/TradingService.cjs +0 -1481
- package/dist/services/TradingService.cjs.map +0 -1
- package/dist/services/TradingService.d.cts +0 -308
- package/dist/services/TradingService.d.cts.map +0 -1
- package/dist/services/TradingService.d.mts +0 -308
- package/dist/services/TradingService.d.mts.map +0 -1
- package/dist/services/TradingService.mjs +0 -1477
- package/dist/services/TradingService.mjs.map +0 -1
- package/dist/services/index.cjs +0 -26
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.d.cts +0 -11
- package/dist/services/index.d.cts.map +0 -1
- package/dist/services/index.d.mts +0 -11
- package/dist/services/index.d.mts.map +0 -1
- package/dist/services/index.mjs +0 -10
- package/dist/services/index.mjs.map +0 -1
- package/dist/services/utils.cjs +0 -16
- package/dist/services/utils.cjs.map +0 -1
- package/dist/services/utils.d.cts +0 -8
- package/dist/services/utils.d.cts.map +0 -1
- package/dist/services/utils.d.mts +0 -8
- package/dist/services/utils.d.mts.map +0 -1
- package/dist/services/utils.mjs +0 -12
- package/dist/services/utils.mjs.map +0 -1
- package/dist/types/chart.cjs +0 -42
- package/dist/types/chart.cjs.map +0 -1
- package/dist/types/chart.d.cts +0 -62
- package/dist/types/chart.d.cts.map +0 -1
- package/dist/types/chart.d.mts +0 -62
- package/dist/types/chart.d.mts.map +0 -1
- package/dist/types/chart.mjs +0 -39
- package/dist/types/chart.mjs.map +0 -1
- package/dist/types/hyperliquid-types.cjs +0 -3
- package/dist/types/hyperliquid-types.cjs.map +0 -1
- package/dist/types/hyperliquid-types.d.cts +0 -52
- package/dist/types/hyperliquid-types.d.cts.map +0 -1
- package/dist/types/hyperliquid-types.d.mts +0 -52
- package/dist/types/hyperliquid-types.d.mts.map +0 -1
- package/dist/types/hyperliquid-types.mjs +0 -2
- package/dist/types/hyperliquid-types.mjs.map +0 -1
- package/dist/types/index.cjs +0 -96
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -1153
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -1153
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -79
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/transactionTypes.cjs +0 -28
- package/dist/types/transactionTypes.cjs.map +0 -1
- package/dist/types/transactionTypes.d.cts +0 -64
- package/dist/types/transactionTypes.d.cts.map +0 -1
- package/dist/types/transactionTypes.d.mts +0 -64
- package/dist/types/transactionTypes.d.mts.map +0 -1
- package/dist/types/transactionTypes.mjs +0 -23
- package/dist/types/transactionTypes.mjs.map +0 -1
- package/dist/utils/accountUtils.cjs +0 -65
- package/dist/utils/accountUtils.cjs.map +0 -1
- package/dist/utils/accountUtils.d.cts +0 -26
- package/dist/utils/accountUtils.d.cts.map +0 -1
- package/dist/utils/accountUtils.d.mts +0 -26
- package/dist/utils/accountUtils.d.mts.map +0 -1
- package/dist/utils/accountUtils.mjs +0 -61
- package/dist/utils/accountUtils.mjs.map +0 -1
- package/dist/utils/amountConversion.cjs +0 -61
- package/dist/utils/amountConversion.cjs.map +0 -1
- package/dist/utils/amountConversion.d.cts +0 -16
- package/dist/utils/amountConversion.d.cts.map +0 -1
- package/dist/utils/amountConversion.d.mts +0 -16
- package/dist/utils/amountConversion.d.mts.map +0 -1
- package/dist/utils/amountConversion.mjs +0 -54
- package/dist/utils/amountConversion.mjs.map +0 -1
- package/dist/utils/chartUtils.cjs +0 -98
- package/dist/utils/chartUtils.cjs.map +0 -1
- package/dist/utils/chartUtils.d.cts +0 -14
- package/dist/utils/chartUtils.d.cts.map +0 -1
- package/dist/utils/chartUtils.d.mts +0 -14
- package/dist/utils/chartUtils.d.mts.map +0 -1
- package/dist/utils/chartUtils.mjs +0 -94
- package/dist/utils/chartUtils.mjs.map +0 -1
- package/dist/utils/errorUtils.cjs +0 -22
- package/dist/utils/errorUtils.cjs.map +0 -1
- package/dist/utils/errorUtils.d.cts +0 -13
- package/dist/utils/errorUtils.d.cts.map +0 -1
- package/dist/utils/errorUtils.d.mts +0 -13
- package/dist/utils/errorUtils.d.mts.map +0 -1
- package/dist/utils/errorUtils.mjs +0 -18
- package/dist/utils/errorUtils.mjs.map +0 -1
- package/dist/utils/formatUtils.cjs +0 -987
- package/dist/utils/formatUtils.cjs.map +0 -1
- package/dist/utils/formatUtils.d.cts +0 -387
- package/dist/utils/formatUtils.d.cts.map +0 -1
- package/dist/utils/formatUtils.d.mts +0 -387
- package/dist/utils/formatUtils.d.mts.map +0 -1
- package/dist/utils/formatUtils.mjs +0 -966
- package/dist/utils/formatUtils.mjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.cjs +0 -454
- package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.cts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.mjs +0 -439
- package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -89
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -84
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.cjs +0 -426
- package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.cts +0 -143
- package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.mts +0 -143
- package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
- package/dist/utils/hyperLiquidValidation.mjs +0 -413
- package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
- package/dist/utils/idUtils.cjs +0 -50
- package/dist/utils/idUtils.cjs.map +0 -1
- package/dist/utils/idUtils.d.cts +0 -38
- package/dist/utils/idUtils.d.cts.map +0 -1
- package/dist/utils/idUtils.d.mts +0 -38
- package/dist/utils/idUtils.d.mts.map +0 -1
- package/dist/utils/idUtils.mjs +0 -42
- package/dist/utils/idUtils.mjs.map +0 -1
- package/dist/utils/marginUtils.cjs +0 -137
- package/dist/utils/marginUtils.cjs.map +0 -1
- package/dist/utils/marginUtils.d.cts +0 -64
- package/dist/utils/marginUtils.d.cts.map +0 -1
- package/dist/utils/marginUtils.d.mts +0 -64
- package/dist/utils/marginUtils.d.mts.map +0 -1
- package/dist/utils/marginUtils.mjs +0 -131
- package/dist/utils/marginUtils.mjs.map +0 -1
- package/dist/utils/marketDataTransform.cjs +0 -227
- package/dist/utils/marketDataTransform.cjs.map +0 -1
- package/dist/utils/marketDataTransform.d.cts +0 -45
- package/dist/utils/marketDataTransform.d.cts.map +0 -1
- package/dist/utils/marketDataTransform.d.mts +0 -45
- package/dist/utils/marketDataTransform.d.mts.map +0 -1
- package/dist/utils/marketDataTransform.mjs +0 -220
- package/dist/utils/marketDataTransform.mjs.map +0 -1
- package/dist/utils/marketUtils.cjs +0 -420
- package/dist/utils/marketUtils.cjs.map +0 -1
- package/dist/utils/marketUtils.d.cts +0 -227
- package/dist/utils/marketUtils.d.cts.map +0 -1
- package/dist/utils/marketUtils.d.mts +0 -227
- package/dist/utils/marketUtils.d.mts.map +0 -1
- package/dist/utils/marketUtils.mjs +0 -404
- package/dist/utils/marketUtils.mjs.map +0 -1
- package/dist/utils/orderBookGrouping.cjs +0 -151
- package/dist/utils/orderBookGrouping.cjs.map +0 -1
- package/dist/utils/orderBookGrouping.d.cts +0 -76
- package/dist/utils/orderBookGrouping.d.cts.map +0 -1
- package/dist/utils/orderBookGrouping.d.mts +0 -76
- package/dist/utils/orderBookGrouping.d.mts.map +0 -1
- package/dist/utils/orderBookGrouping.mjs +0 -143
- package/dist/utils/orderBookGrouping.mjs.map +0 -1
- package/dist/utils/orderCalculations.cjs +0 -283
- package/dist/utils/orderCalculations.cjs.map +0 -1
- package/dist/utils/orderCalculations.d.cts +0 -107
- package/dist/utils/orderCalculations.d.cts.map +0 -1
- package/dist/utils/orderCalculations.d.mts +0 -107
- package/dist/utils/orderCalculations.d.mts.map +0 -1
- package/dist/utils/orderCalculations.mjs +0 -274
- package/dist/utils/orderCalculations.mjs.map +0 -1
- package/dist/utils/orderUtils.cjs +0 -159
- package/dist/utils/orderUtils.cjs.map +0 -1
- package/dist/utils/orderUtils.d.cts +0 -66
- package/dist/utils/orderUtils.d.cts.map +0 -1
- package/dist/utils/orderUtils.d.mts +0 -66
- package/dist/utils/orderUtils.d.mts.map +0 -1
- package/dist/utils/orderUtils.mjs +0 -151
- package/dist/utils/orderUtils.mjs.map +0 -1
- package/dist/utils/pnlCalculations.cjs +0 -107
- package/dist/utils/pnlCalculations.cjs.map +0 -1
- package/dist/utils/pnlCalculations.d.cts +0 -79
- package/dist/utils/pnlCalculations.d.cts.map +0 -1
- package/dist/utils/pnlCalculations.d.mts +0 -79
- package/dist/utils/pnlCalculations.d.mts.map +0 -1
- package/dist/utils/pnlCalculations.mjs +0 -97
- package/dist/utils/pnlCalculations.mjs.map +0 -1
- package/dist/utils/positionCalculations.cjs +0 -176
- package/dist/utils/positionCalculations.cjs.map +0 -1
- package/dist/utils/positionCalculations.d.cts +0 -85
- package/dist/utils/positionCalculations.d.cts.map +0 -1
- package/dist/utils/positionCalculations.d.mts +0 -85
- package/dist/utils/positionCalculations.d.mts.map +0 -1
- package/dist/utils/positionCalculations.mjs +0 -165
- package/dist/utils/positionCalculations.mjs.map +0 -1
- package/dist/utils/sortMarkets.cjs +0 -88
- package/dist/utils/sortMarkets.cjs.map +0 -1
- package/dist/utils/sortMarkets.d.cts +0 -21
- package/dist/utils/sortMarkets.d.cts.map +0 -1
- package/dist/utils/sortMarkets.d.mts +0 -21
- package/dist/utils/sortMarkets.d.mts.map +0 -1
- package/dist/utils/sortMarkets.mjs +0 -84
- package/dist/utils/sortMarkets.mjs.map +0 -1
- package/dist/utils/standaloneInfoClient.cjs +0 -34
- package/dist/utils/standaloneInfoClient.cjs.map +0 -1
- package/dist/utils/standaloneInfoClient.d.cts +0 -31
- package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
- package/dist/utils/standaloneInfoClient.d.mts +0 -31
- package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
- package/dist/utils/standaloneInfoClient.mjs +0 -30
- package/dist/utils/standaloneInfoClient.mjs.map +0 -1
- package/dist/utils/stringParseUtils.cjs +0 -49
- package/dist/utils/stringParseUtils.cjs.map +0 -1
- package/dist/utils/stringParseUtils.d.cts +0 -35
- package/dist/utils/stringParseUtils.d.cts.map +0 -1
- package/dist/utils/stringParseUtils.d.mts +0 -35
- package/dist/utils/stringParseUtils.d.mts.map +0 -1
- package/dist/utils/stringParseUtils.mjs +0 -44
- package/dist/utils/stringParseUtils.mjs.map +0 -1
- package/dist/utils/time.cjs +0 -37
- package/dist/utils/time.cjs.map +0 -1
- package/dist/utils/time.d.cts +0 -17
- package/dist/utils/time.d.cts.map +0 -1
- package/dist/utils/time.d.mts +0 -17
- package/dist/utils/time.d.mts.map +0 -1
- package/dist/utils/time.mjs +0 -33
- package/dist/utils/time.mjs.map +0 -1
- package/dist/utils/tpslValidation.cjs +0 -505
- package/dist/utils/tpslValidation.cjs.map +0 -1
- package/dist/utils/tpslValidation.d.cts +0 -182
- package/dist/utils/tpslValidation.d.cts.map +0 -1
- package/dist/utils/tpslValidation.d.mts +0 -182
- package/dist/utils/tpslValidation.d.mts.map +0 -1
- package/dist/utils/tpslValidation.mjs +0 -482
- package/dist/utils/tpslValidation.mjs.map +0 -1
- package/dist/utils/transactionUtils.cjs +0 -36
- package/dist/utils/transactionUtils.cjs.map +0 -1
- package/dist/utils/transactionUtils.d.cts +0 -17
- package/dist/utils/transactionUtils.d.cts.map +0 -1
- package/dist/utils/transactionUtils.d.mts +0 -17
- package/dist/utils/transactionUtils.d.mts.map +0 -1
- package/dist/utils/transactionUtils.mjs +0 -32
- package/dist/utils/transactionUtils.mjs.map +0 -1
- package/dist/utils/wait.cjs +0 -12
- package/dist/utils/wait.cjs.map +0 -1
- package/dist/utils/wait.d.cts +0 -8
- package/dist/utils/wait.d.cts.map +0 -1
- package/dist/utils/wait.d.mts +0 -8
- package/dist/utils/wait.d.mts.map +0 -1
- package/dist/utils/wait.mjs +0 -8
- package/dist/utils/wait.mjs.map +0 -1
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.determineMakerStatus = exports.getOrderLabelDirection = exports.formatOrderLabel = exports.willFlipPosition = exports.getOrderDirection = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Capitalize the first letter of a string.
|
|
6
|
-
*
|
|
7
|
-
* @param str - String to capitalize.
|
|
8
|
-
* @returns Capitalized string.
|
|
9
|
-
*/
|
|
10
|
-
function capitalize(str) {
|
|
11
|
-
if (!str) {
|
|
12
|
-
return '';
|
|
13
|
-
}
|
|
14
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Get the order direction based on the side and position size
|
|
18
|
-
*
|
|
19
|
-
* @param side - The side of the order
|
|
20
|
-
* @param positionSize - The size of the position
|
|
21
|
-
* @returns The order direction ('long' or 'short') - raw string, translate in UI layer
|
|
22
|
-
*/
|
|
23
|
-
const getOrderDirection = (side, positionSize) => {
|
|
24
|
-
const hasPosition = Boolean(positionSize);
|
|
25
|
-
// No existing position → direction depends only on side
|
|
26
|
-
if (!hasPosition) {
|
|
27
|
-
return side === 'buy' ? 'long' : 'short';
|
|
28
|
-
}
|
|
29
|
-
// Existing position → infer direction based on position size
|
|
30
|
-
if (positionSize && parseFloat(positionSize) > 0) {
|
|
31
|
-
return 'long';
|
|
32
|
-
}
|
|
33
|
-
return 'short';
|
|
34
|
-
};
|
|
35
|
-
exports.getOrderDirection = getOrderDirection;
|
|
36
|
-
const willFlipPosition = (currentPosition, orderParams) => {
|
|
37
|
-
const currentPositionSize = parseFloat(currentPosition.size);
|
|
38
|
-
const positionDirection = currentPositionSize > 0 ? 'long' : 'short';
|
|
39
|
-
const orderDirection = orderParams.isBuy ? 'long' : 'short';
|
|
40
|
-
const orderSize = parseFloat(orderParams.size);
|
|
41
|
-
if (orderParams.reduceOnly === true) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
if (orderParams.orderType !== 'market') {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
if (positionDirection === orderDirection) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
if (orderSize > Math.abs(currentPositionSize)) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
};
|
|
55
|
-
exports.willFlipPosition = willFlipPosition;
|
|
56
|
-
/**
|
|
57
|
-
* Format an order label following the pattern: [Type] [Close?] [Direction]
|
|
58
|
-
*
|
|
59
|
-
* Examples:
|
|
60
|
-
* - Market Long
|
|
61
|
-
* - Market Close Long
|
|
62
|
-
* - Limit Short
|
|
63
|
-
* - Limit Close Short
|
|
64
|
-
* - Stop Market Close Long
|
|
65
|
-
* - Take Profit Limit Close Short
|
|
66
|
-
*
|
|
67
|
-
* @param order - The order object
|
|
68
|
-
* @returns Formatted order label string
|
|
69
|
-
*/
|
|
70
|
-
const formatOrderLabel = (order) => {
|
|
71
|
-
const { side, detailedOrderType, orderType, reduceOnly, isTrigger } = order;
|
|
72
|
-
// Determine if this is a closing order
|
|
73
|
-
const isClosing = Boolean(reduceOnly ?? isTrigger);
|
|
74
|
-
// Determine direction based on whether it's closing or not
|
|
75
|
-
let direction;
|
|
76
|
-
if (isClosing) {
|
|
77
|
-
// For closing orders: sell closes long, buy closes short
|
|
78
|
-
direction = side === 'sell' ? 'long' : 'short';
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// For opening orders: buy is long, sell is short
|
|
82
|
-
direction = side === 'buy' ? 'long' : 'short';
|
|
83
|
-
}
|
|
84
|
-
// Get the order type string
|
|
85
|
-
// Use detailedOrderType if available (e.g., "Stop Market", "Take Profit Limit")
|
|
86
|
-
// Otherwise fall back to basic orderType
|
|
87
|
-
const typeString = detailedOrderType ?? (orderType === 'limit' ? 'Limit' : 'Market');
|
|
88
|
-
// Build the label: [Type] [Close?] [Direction]
|
|
89
|
-
if (isClosing) {
|
|
90
|
-
return capitalize(`${typeString} close ${direction}`);
|
|
91
|
-
}
|
|
92
|
-
return capitalize(`${typeString} ${direction}`);
|
|
93
|
-
};
|
|
94
|
-
exports.formatOrderLabel = formatOrderLabel;
|
|
95
|
-
/**
|
|
96
|
-
* Get just the direction portion of an order label
|
|
97
|
-
* Used for compatibility with existing code that expects just "long" or "short"
|
|
98
|
-
*
|
|
99
|
-
* @param order - The order object
|
|
100
|
-
* @returns Direction string ("long" or "short" for opening, "Close Long" or "Close Short" for closing)
|
|
101
|
-
*/
|
|
102
|
-
const getOrderLabelDirection = (order) => {
|
|
103
|
-
const { side, reduceOnly, isTrigger } = order;
|
|
104
|
-
// Determine if this is a closing order
|
|
105
|
-
const isClosing = Boolean(reduceOnly ?? isTrigger);
|
|
106
|
-
if (isClosing) {
|
|
107
|
-
// For closing orders: sell closes long, buy closes short
|
|
108
|
-
return side === 'sell' ? 'Close Long' : 'Close Short';
|
|
109
|
-
}
|
|
110
|
-
// For opening orders: buy is long, sell is short
|
|
111
|
-
return side === 'buy' ? 'long' : 'short';
|
|
112
|
-
};
|
|
113
|
-
exports.getOrderLabelDirection = getOrderLabelDirection;
|
|
114
|
-
/**
|
|
115
|
-
* Determines if a limit order will likely be a maker or taker.
|
|
116
|
-
*
|
|
117
|
-
* Logic:
|
|
118
|
-
* 1. Validates price data freshness and market state
|
|
119
|
-
* 2. Market orders are always taker
|
|
120
|
-
* 3. Limit orders that would execute immediately are taker
|
|
121
|
-
* 4. Limit orders that go into order book are maker
|
|
122
|
-
*
|
|
123
|
-
* @param params - Order parameters
|
|
124
|
-
* @param params.orderType - The order type (market or limit)
|
|
125
|
-
* @param params.limitPrice - The limit price for limit orders
|
|
126
|
-
* @param params.direction - The order direction (long or short)
|
|
127
|
-
* @param params.bestAsk - The best ask price from order book
|
|
128
|
-
* @param params.bestBid - The best bid price from order book
|
|
129
|
-
* @param params.symbol - The trading symbol for logging
|
|
130
|
-
* @param debugLogger - Optional debug logger for detailed logging
|
|
131
|
-
* @returns True if maker order, false if taker order
|
|
132
|
-
*/
|
|
133
|
-
function determineMakerStatus(params, debugLogger) {
|
|
134
|
-
const { orderType, limitPrice, direction, bestAsk, bestBid, symbol } = params;
|
|
135
|
-
// Market orders are always taker
|
|
136
|
-
if (orderType === 'market') {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
// Default to taker when limit price is not specified
|
|
140
|
-
if (!limitPrice || limitPrice === '') {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
const limitPriceNum = Number.parseFloat(limitPrice);
|
|
144
|
-
if (Number.isNaN(limitPriceNum) || limitPriceNum <= 0) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
if (bestBid !== undefined && bestAsk !== undefined) {
|
|
148
|
-
if (direction === 'long') {
|
|
149
|
-
return limitPriceNum < bestAsk;
|
|
150
|
-
}
|
|
151
|
-
// Short direction
|
|
152
|
-
return limitPriceNum > bestBid;
|
|
153
|
-
}
|
|
154
|
-
// Default to taker when no bid/ask data is available
|
|
155
|
-
debugLogger?.log('Fee Calculation: No bid/ask data available, using conservative taker fee', { symbol });
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
exports.determineMakerStatus = determineMakerStatus;
|
|
159
|
-
//# sourceMappingURL=orderUtils.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orderUtils.cjs","sourceRoot":"","sources":["../../src/utils/orderUtils.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAQD;;;;;;GAMG;AACI,MAAM,iBAAiB,G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ent":["import type { OrderParams, Order, PerpsDebugLogger, Position } from '../types';\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param str - String to capitalize.\n * @returns Capitalized string.\n */\nfunction capitalize(str: string): string {\n if (!str) {\n return '';\n }\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Optional debug logger for order utility functions.\n * When provided, enables detailed logging for debugging.\n */\nexport type OrderUtilsDebugLogger = PerpsDebugLogger | undefined;\n\n/**\n * Get the order direction based on the side and position size\n *\n * @param side - The side of the order\n * @param positionSize - The size of the position\n * @returns The order direction ('long' or 'short') - raw string, translate in UI layer\n */\nexport const getOrderDirection = (\n side: 'buy' | 'sell',\n positionSize: string | undefined,\n): 'long' | 'short' => {\n const hasPosition = Boolean(positionSize);\n\n // No existing position → direction depends only on side\n if (!hasPosition) {\n return side === 'buy' ? 'long' : 'short';\n }\n\n // Existing position → infer direction based on position size\n if (positionSize && parseFloat(positionSize) > 0) {\n return 'long';\n }\n\n return 'short';\n};\n\nexport const willFlipPosition = (\n currentPosition: Position,\n orderParams: OrderParams,\n): boolean => {\n const currentPositionSize = parseFloat(currentPosition.size);\n const positionDirection = currentPositionSize > 0 ? 'long' : 'short';\n const orderDirection = orderParams.isBuy ? 'long' : 'short';\n const orderSize = parseFloat(orderParams.size);\n\n if (orderParams.reduceOnly === true) {\n return false;\n }\n\n if (orderParams.orderType !== 'market') {\n return false;\n }\n\n if (positionDirection === orderDirection) {\n return false;\n }\n\n if (orderSize > Math.abs(currentPositionSize)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Format an order label following the pattern: [Type] [Close?] [Direction]\n *\n * Examples:\n * - Market Long\n * - Market Close Long\n * - Limit Short\n * - Limit Close Short\n * - Stop Market Close Long\n * - Take Profit Limit Close Short\n *\n * @param order - The order object\n * @returns Formatted order label string\n */\nexport const formatOrderLabel = (order: Order): string => {\n const { side, detailedOrderType, orderType, reduceOnly, isTrigger } = order;\n\n // Determine if this is a closing order\n const isClosing = Boolean(reduceOnly ?? isTrigger);\n\n // Determine direction based on whether it's closing or not\n let direction: string;\n if (isClosing) {\n // For closing orders: sell closes long, buy closes short\n direction = side === 'sell' ? 'long' : 'short';\n } else {\n // For opening orders: buy is long, sell is short\n direction = side === 'buy' ? 'long' : 'short';\n }\n\n // Get the order type string\n // Use detailedOrderType if available (e.g., \"Stop Market\", \"Take Profit Limit\")\n // Otherwise fall back to basic orderType\n const typeString =\n detailedOrderType ?? (orderType === 'limit' ? 'Limit' : 'Market');\n\n // Build the label: [Type] [Close?] [Direction]\n if (isClosing) {\n return capitalize(`${typeString} close ${direction}`);\n }\n\n return capitalize(`${typeString} ${direction}`);\n};\n\n/**\n * Get just the direction portion of an order label\n * Used for compatibility with existing code that expects just \"long\" or \"short\"\n *\n * @param order - The order object\n * @returns Direction string (\"long\" or \"short\" for opening, \"Close Long\" or \"Close Short\" for closing)\n */\nexport const getOrderLabelDirection = (order: Order): string => {\n const { side, reduceOnly, isTrigger } = order;\n\n // Determine if this is a closing order\n const isClosing = Boolean(reduceOnly ?? isTrigger);\n\n if (isClosing) {\n // For closing orders: sell closes long, buy closes short\n return side === 'sell' ? 'Close Long' : 'Close Short';\n }\n\n // For opening orders: buy is long, sell is short\n return side === 'buy' ? 'long' : 'short';\n};\n\n/**\n * Determines if a limit order will likely be a maker or taker.\n *\n * Logic:\n * 1. Validates price data freshness and market state\n * 2. Market orders are always taker\n * 3. Limit orders that would execute immediately are taker\n * 4. Limit orders that go into order book are maker\n *\n * @param params - Order parameters\n * @param params.orderType - The order type (market or limit)\n * @param params.limitPrice - The limit price for limit orders\n * @param params.direction - The order direction (long or short)\n * @param params.bestAsk - The best ask price from order book\n * @param params.bestBid - The best bid price from order book\n * @param params.symbol - The trading symbol for logging\n * @param debugLogger - Optional debug logger for detailed logging\n * @returns True if maker order, false if taker order\n */\nexport function determineMakerStatus(\n params: {\n orderType: 'market' | 'limit';\n limitPrice?: string;\n direction: 'long' | 'short';\n bestAsk?: number;\n bestBid?: number;\n symbol?: string;\n },\n debugLogger?: OrderUtilsDebugLogger,\n): boolean {\n const { orderType, limitPrice, direction, bestAsk, bestBid, symbol } = params;\n // Market orders are always taker\n if (orderType === 'market') {\n return false;\n }\n\n // Default to taker when limit price is not specified\n if (!limitPrice || limitPrice === '') {\n return false;\n }\n\n const limitPriceNum = Number.parseFloat(limitPrice);\n\n if (Number.isNaN(limitPriceNum) || limitPriceNum <= 0) {\n return false;\n }\n\n if (bestBid !== undefined && bestAsk !== undefined) {\n if (direction === 'long') {\n return limitPriceNum < bestAsk;\n }\n\n // Short direction\n return limitPriceNum > bestBid;\n }\n\n // Default to taker when no bid/ask data is available\n debugLogger?.log(\n 'Fee Calculation: No bid/ask data available, using conservative taker fee',\n { symbol },\n );\n return false;\n}\n"]}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { OrderParams, Order, PerpsDebugLogger, Position } from "../types/index.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* Optional debug logger for order utility functions.
|
|
4
|
-
* When provided, enables detailed logging for debugging.
|
|
5
|
-
*/
|
|
6
|
-
export type OrderUtilsDebugLogger = PerpsDebugLogger | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Get the order direction based on the side and position size
|
|
9
|
-
*
|
|
10
|
-
* @param side - The side of the order
|
|
11
|
-
* @param positionSize - The size of the position
|
|
12
|
-
* @returns The order direction ('long' or 'short') - raw string, translate in UI layer
|
|
13
|
-
*/
|
|
14
|
-
export declare const getOrderDirection: (side: 'buy' | 'sell', positionSize: string | undefined) => 'long' | 'short';
|
|
15
|
-
export declare const willFlipPosition: (currentPosition: Position, orderParams: OrderParams) => boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Format an order label following the pattern: [Type] [Close?] [Direction]
|
|
18
|
-
*
|
|
19
|
-
* Examples:
|
|
20
|
-
* - Market Long
|
|
21
|
-
* - Market Close Long
|
|
22
|
-
* - Limit Short
|
|
23
|
-
* - Limit Close Short
|
|
24
|
-
* - Stop Market Close Long
|
|
25
|
-
* - Take Profit Limit Close Short
|
|
26
|
-
*
|
|
27
|
-
* @param order - The order object
|
|
28
|
-
* @returns Formatted order label string
|
|
29
|
-
*/
|
|
30
|
-
export declare const formatOrderLabel: (order: Order) => string;
|
|
31
|
-
/**
|
|
32
|
-
* Get just the direction portion of an order label
|
|
33
|
-
* Used for compatibility with existing code that expects just "long" or "short"
|
|
34
|
-
*
|
|
35
|
-
* @param order - The order object
|
|
36
|
-
* @returns Direction string ("long" or "short" for opening, "Close Long" or "Close Short" for closing)
|
|
37
|
-
*/
|
|
38
|
-
export declare const getOrderLabelDirection: (order: Order) => string;
|
|
39
|
-
/**
|
|
40
|
-
* Determines if a limit order will likely be a maker or taker.
|
|
41
|
-
*
|
|
42
|
-
* Logic:
|
|
43
|
-
* 1. Validates price data freshness and market state
|
|
44
|
-
* 2. Market orders are always taker
|
|
45
|
-
* 3. Limit orders that would execute immediately are taker
|
|
46
|
-
* 4. Limit orders that go into order book are maker
|
|
47
|
-
*
|
|
48
|
-
* @param params - Order parameters
|
|
49
|
-
* @param params.orderType - The order type (market or limit)
|
|
50
|
-
* @param params.limitPrice - The limit price for limit orders
|
|
51
|
-
* @param params.direction - The order direction (long or short)
|
|
52
|
-
* @param params.bestAsk - The best ask price from order book
|
|
53
|
-
* @param params.bestBid - The best bid price from order book
|
|
54
|
-
* @param params.symbol - The trading symbol for logging
|
|
55
|
-
* @param debugLogger - Optional debug logger for detailed logging
|
|
56
|
-
* @returns True if maker order, false if taker order
|
|
57
|
-
*/
|
|
58
|
-
export declare function determineMakerStatus(params: {
|
|
59
|
-
orderType: 'market' | 'limit';
|
|
60
|
-
limitPrice?: string;
|
|
61
|
-
direction: 'long' | 'short';
|
|
62
|
-
bestAsk?: number;
|
|
63
|
-
bestBid?: number;
|
|
64
|
-
symbol?: string;
|
|
65
|
-
}, debugLogger?: OrderUtilsDebugLogger): boolean;
|
|
66
|
-
//# sourceMappingURL=orderUtils.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orderUtils.d.cts","sourceRoot":"","sources":["../../src/utils/orderUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,2BAAiB;AAe/E;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,SACtB,KAAK,GAAG,MAAM,gBACN,MAAM,GAAG,SAAS,KAC/B,MAAM,GAAG,OAcX,CAAC;AAEF,eAAO,MAAM,gBAAgB,oBACV,QAAQ,eACZ,WAAW,KACvB,OAuBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,UAAW,KAAK,KAAG,MA4B/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,UAAW,KAAK,KAAG,MAarD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE;IACN,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,EACD,WAAW,CAAC,EAAE,qBAAqB,GAClC,OAAO,CAiCT"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { OrderParams, Order, PerpsDebugLogger, Position } from "../types/index.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* Optional debug logger for order utility functions.
|
|
4
|
-
* When provided, enables detailed logging for debugging.
|
|
5
|
-
*/
|
|
6
|
-
export type OrderUtilsDebugLogger = PerpsDebugLogger | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Get the order direction based on the side and position size
|
|
9
|
-
*
|
|
10
|
-
* @param side - The side of the order
|
|
11
|
-
* @param positionSize - The size of the position
|
|
12
|
-
* @returns The order direction ('long' or 'short') - raw string, translate in UI layer
|
|
13
|
-
*/
|
|
14
|
-
export declare const getOrderDirection: (side: 'buy' | 'sell', positionSize: string | undefined) => 'long' | 'short';
|
|
15
|
-
export declare const willFlipPosition: (currentPosition: Position, orderParams: OrderParams) => boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Format an order label following the pattern: [Type] [Close?] [Direction]
|
|
18
|
-
*
|
|
19
|
-
* Examples:
|
|
20
|
-
* - Market Long
|
|
21
|
-
* - Market Close Long
|
|
22
|
-
* - Limit Short
|
|
23
|
-
* - Limit Close Short
|
|
24
|
-
* - Stop Market Close Long
|
|
25
|
-
* - Take Profit Limit Close Short
|
|
26
|
-
*
|
|
27
|
-
* @param order - The order object
|
|
28
|
-
* @returns Formatted order label string
|
|
29
|
-
*/
|
|
30
|
-
export declare const formatOrderLabel: (order: Order) => string;
|
|
31
|
-
/**
|
|
32
|
-
* Get just the direction portion of an order label
|
|
33
|
-
* Used for compatibility with existing code that expects just "long" or "short"
|
|
34
|
-
*
|
|
35
|
-
* @param order - The order object
|
|
36
|
-
* @returns Direction string ("long" or "short" for opening, "Close Long" or "Close Short" for closing)
|
|
37
|
-
*/
|
|
38
|
-
export declare const getOrderLabelDirection: (order: Order) => string;
|
|
39
|
-
/**
|
|
40
|
-
* Determines if a limit order will likely be a maker or taker.
|
|
41
|
-
*
|
|
42
|
-
* Logic:
|
|
43
|
-
* 1. Validates price data freshness and market state
|
|
44
|
-
* 2. Market orders are always taker
|
|
45
|
-
* 3. Limit orders that would execute immediately are taker
|
|
46
|
-
* 4. Limit orders that go into order book are maker
|
|
47
|
-
*
|
|
48
|
-
* @param params - Order parameters
|
|
49
|
-
* @param params.orderType - The order type (market or limit)
|
|
50
|
-
* @param params.limitPrice - The limit price for limit orders
|
|
51
|
-
* @param params.direction - The order direction (long or short)
|
|
52
|
-
* @param params.bestAsk - The best ask price from order book
|
|
53
|
-
* @param params.bestBid - The best bid price from order book
|
|
54
|
-
* @param params.symbol - The trading symbol for logging
|
|
55
|
-
* @param debugLogger - Optional debug logger for detailed logging
|
|
56
|
-
* @returns True if maker order, false if taker order
|
|
57
|
-
*/
|
|
58
|
-
export declare function determineMakerStatus(params: {
|
|
59
|
-
orderType: 'market' | 'limit';
|
|
60
|
-
limitPrice?: string;
|
|
61
|
-
direction: 'long' | 'short';
|
|
62
|
-
bestAsk?: number;
|
|
63
|
-
bestBid?: number;
|
|
64
|
-
symbol?: string;
|
|
65
|
-
}, debugLogger?: OrderUtilsDebugLogger): boolean;
|
|
66
|
-
//# sourceMappingURL=orderUtils.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orderUtils.d.mts","sourceRoot":"","sources":["../../src/utils/orderUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,2BAAiB;AAe/E;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,SACtB,KAAK,GAAG,MAAM,gBACN,MAAM,GAAG,SAAS,KAC/B,MAAM,GAAG,OAcX,CAAC;AAEF,eAAO,MAAM,gBAAgB,oBACV,QAAQ,eACZ,WAAW,KACvB,OAuBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,UAAW,KAAK,KAAG,MA4B/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,UAAW,KAAK,KAAG,MAarD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE;IACN,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,EACD,WAAW,CAAC,EAAE,qBAAqB,GAClC,OAAO,CAiCT"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capitalize the first letter of a string.
|
|
3
|
-
*
|
|
4
|
-
* @param str - String to capitalize.
|
|
5
|
-
* @returns Capitalized string.
|
|
6
|
-
*/
|
|
7
|
-
function capitalize(str) {
|
|
8
|
-
if (!str) {
|
|
9
|
-
return '';
|
|
10
|
-
}
|
|
11
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Get the order direction based on the side and position size
|
|
15
|
-
*
|
|
16
|
-
* @param side - The side of the order
|
|
17
|
-
* @param positionSize - The size of the position
|
|
18
|
-
* @returns The order direction ('long' or 'short') - raw string, translate in UI layer
|
|
19
|
-
*/
|
|
20
|
-
export const getOrderDirection = (side, positionSize) => {
|
|
21
|
-
const hasPosition = Boolean(positionSize);
|
|
22
|
-
// No existing position → direction depends only on side
|
|
23
|
-
if (!hasPosition) {
|
|
24
|
-
return side === 'buy' ? 'long' : 'short';
|
|
25
|
-
}
|
|
26
|
-
// Existing position → infer direction based on position size
|
|
27
|
-
if (positionSize && parseFloat(positionSize) > 0) {
|
|
28
|
-
return 'long';
|
|
29
|
-
}
|
|
30
|
-
return 'short';
|
|
31
|
-
};
|
|
32
|
-
export const willFlipPosition = (currentPosition, orderParams) => {
|
|
33
|
-
const currentPositionSize = parseFloat(currentPosition.size);
|
|
34
|
-
const positionDirection = currentPositionSize > 0 ? 'long' : 'short';
|
|
35
|
-
const orderDirection = orderParams.isBuy ? 'long' : 'short';
|
|
36
|
-
const orderSize = parseFloat(orderParams.size);
|
|
37
|
-
if (orderParams.reduceOnly === true) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
if (orderParams.orderType !== 'market') {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (positionDirection === orderDirection) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (orderSize > Math.abs(currentPositionSize)) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Format an order label following the pattern: [Type] [Close?] [Direction]
|
|
53
|
-
*
|
|
54
|
-
* Examples:
|
|
55
|
-
* - Market Long
|
|
56
|
-
* - Market Close Long
|
|
57
|
-
* - Limit Short
|
|
58
|
-
* - Limit Close Short
|
|
59
|
-
* - Stop Market Close Long
|
|
60
|
-
* - Take Profit Limit Close Short
|
|
61
|
-
*
|
|
62
|
-
* @param order - The order object
|
|
63
|
-
* @returns Formatted order label string
|
|
64
|
-
*/
|
|
65
|
-
export const formatOrderLabel = (order) => {
|
|
66
|
-
const { side, detailedOrderType, orderType, reduceOnly, isTrigger } = order;
|
|
67
|
-
// Determine if this is a closing order
|
|
68
|
-
const isClosing = Boolean(reduceOnly ?? isTrigger);
|
|
69
|
-
// Determine direction based on whether it's closing or not
|
|
70
|
-
let direction;
|
|
71
|
-
if (isClosing) {
|
|
72
|
-
// For closing orders: sell closes long, buy closes short
|
|
73
|
-
direction = side === 'sell' ? 'long' : 'short';
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// For opening orders: buy is long, sell is short
|
|
77
|
-
direction = side === 'buy' ? 'long' : 'short';
|
|
78
|
-
}
|
|
79
|
-
// Get the order type string
|
|
80
|
-
// Use detailedOrderType if available (e.g., "Stop Market", "Take Profit Limit")
|
|
81
|
-
// Otherwise fall back to basic orderType
|
|
82
|
-
const typeString = detailedOrderType ?? (orderType === 'limit' ? 'Limit' : 'Market');
|
|
83
|
-
// Build the label: [Type] [Close?] [Direction]
|
|
84
|
-
if (isClosing) {
|
|
85
|
-
return capitalize(`${typeString} close ${direction}`);
|
|
86
|
-
}
|
|
87
|
-
return capitalize(`${typeString} ${direction}`);
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Get just the direction portion of an order label
|
|
91
|
-
* Used for compatibility with existing code that expects just "long" or "short"
|
|
92
|
-
*
|
|
93
|
-
* @param order - The order object
|
|
94
|
-
* @returns Direction string ("long" or "short" for opening, "Close Long" or "Close Short" for closing)
|
|
95
|
-
*/
|
|
96
|
-
export const getOrderLabelDirection = (order) => {
|
|
97
|
-
const { side, reduceOnly, isTrigger } = order;
|
|
98
|
-
// Determine if this is a closing order
|
|
99
|
-
const isClosing = Boolean(reduceOnly ?? isTrigger);
|
|
100
|
-
if (isClosing) {
|
|
101
|
-
// For closing orders: sell closes long, buy closes short
|
|
102
|
-
return side === 'sell' ? 'Close Long' : 'Close Short';
|
|
103
|
-
}
|
|
104
|
-
// For opening orders: buy is long, sell is short
|
|
105
|
-
return side === 'buy' ? 'long' : 'short';
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Determines if a limit order will likely be a maker or taker.
|
|
109
|
-
*
|
|
110
|
-
* Logic:
|
|
111
|
-
* 1. Validates price data freshness and market state
|
|
112
|
-
* 2. Market orders are always taker
|
|
113
|
-
* 3. Limit orders that would execute immediately are taker
|
|
114
|
-
* 4. Limit orders that go into order book are maker
|
|
115
|
-
*
|
|
116
|
-
* @param params - Order parameters
|
|
117
|
-
* @param params.orderType - The order type (market or limit)
|
|
118
|
-
* @param params.limitPrice - The limit price for limit orders
|
|
119
|
-
* @param params.direction - The order direction (long or short)
|
|
120
|
-
* @param params.bestAsk - The best ask price from order book
|
|
121
|
-
* @param params.bestBid - The best bid price from order book
|
|
122
|
-
* @param params.symbol - The trading symbol for logging
|
|
123
|
-
* @param debugLogger - Optional debug logger for detailed logging
|
|
124
|
-
* @returns True if maker order, false if taker order
|
|
125
|
-
*/
|
|
126
|
-
export function determineMakerStatus(params, debugLogger) {
|
|
127
|
-
const { orderType, limitPrice, direction, bestAsk, bestBid, symbol } = params;
|
|
128
|
-
// Market orders are always taker
|
|
129
|
-
if (orderType === 'market') {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
// Default to taker when limit price is not specified
|
|
133
|
-
if (!limitPrice || limitPrice === '') {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
const limitPriceNum = Number.parseFloat(limitPrice);
|
|
137
|
-
if (Number.isNaN(limitPriceNum) || limitPriceNum <= 0) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
if (bestBid !== undefined && bestAsk !== undefined) {
|
|
141
|
-
if (direction === 'long') {
|
|
142
|
-
return limitPriceNum < bestAsk;
|
|
143
|
-
}
|
|
144
|
-
// Short direction
|
|
145
|
-
return limitPriceNum > bestBid;
|
|
146
|
-
}
|
|
147
|
-
// Default to taker when no bid/ask data is available
|
|
148
|
-
debugLogger?.log('Fee Calculation: No bid/ask data available, using conservative taker fee', { symbol });
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
//# sourceMappingURL=orderUtils.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orderUtils.mjs","sourceRoot":"","sources":["../../src/utils/orderUtils.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAQD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,IAAoB,EACpB,YAAgC,EACd,EAAE;IACpB,MAAM,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAE1C,wDAAwD;IACxD,IAAI,CAAC,WAAW,EAAE,CAAC;Q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CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;AAC3C,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAOC,EACD,WAAmC;IAEnC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC9E,iCAAiC;IACjC,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qDAAqD;IACrD,IAAI,CAAC,UAAU,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAEpD,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACnD,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;YACzB,OAAO,aAAa,GAAG,OAAO,CAAC;QACjC,CAAC;QAED,kBAAkB;QAClB,OAAO,aAAa,GAAG,OAAO,CAAC;IACjC,CAAC;IAED,qDAAqD;IACrD,WAAW,EAAE,GAAG,CACd,0EAA0E,EAC1E,EAAE,MAAM,EAAE,CACX,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { OrderParams, Order, PerpsDebugLogger, Position } from '../types';\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param str - String to capitalize.\n * @returns Capitalized string.\n */\nfunction capitalize(str: string): string {\n if (!str) {\n return '';\n }\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Optional debug logger for order utility functions.\n * When provided, enables detailed logging for debugging.\n */\nexport type OrderUtilsDebugLogger = PerpsDebugLogger | undefined;\n\n/**\n * Get the order direction based on the side and position size\n *\n * @param side - The side of the order\n * @param positionSize - The size of the position\n * @returns The order direction ('long' or 'short') - raw string, translate in UI layer\n */\nexport const getOrderDirection = (\n side: 'buy' | 'sell',\n positionSize: string | undefined,\n): 'long' | 'short' => {\n const hasPosition = Boolean(positionSize);\n\n // No existing position → direction depends only on side\n if (!hasPosition) {\n return side === 'buy' ? 'long' : 'short';\n }\n\n // Existing position → infer direction based on position size\n if (positionSize && parseFloat(positionSize) > 0) {\n return 'long';\n }\n\n return 'short';\n};\n\nexport const willFlipPosition = (\n currentPosition: Position,\n orderParams: OrderParams,\n): boolean => {\n const currentPositionSize = parseFloat(currentPosition.size);\n const positionDirection = currentPositionSize > 0 ? 'long' : 'short';\n const orderDirection = orderParams.isBuy ? 'long' : 'short';\n const orderSize = parseFloat(orderParams.size);\n\n if (orderParams.reduceOnly === true) {\n return false;\n }\n\n if (orderParams.orderType !== 'market') {\n return false;\n }\n\n if (positionDirection === orderDirection) {\n return false;\n }\n\n if (orderSize > Math.abs(currentPositionSize)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Format an order label following the pattern: [Type] [Close?] [Direction]\n *\n * Examples:\n * - Market Long\n * - Market Close Long\n * - Limit Short\n * - Limit Close Short\n * - Stop Market Close Long\n * - Take Profit Limit Close Short\n *\n * @param order - The order object\n * @returns Formatted order label string\n */\nexport const formatOrderLabel = (order: Order): string => {\n const { side, detailedOrderType, orderType, reduceOnly, isTrigger } = order;\n\n // Determine if this is a closing order\n const isClosing = Boolean(reduceOnly ?? isTrigger);\n\n // Determine direction based on whether it's closing or not\n let direction: string;\n if (isClosing) {\n // For closing orders: sell closes long, buy closes short\n direction = side === 'sell' ? 'long' : 'short';\n } else {\n // For opening orders: buy is long, sell is short\n direction = side === 'buy' ? 'long' : 'short';\n }\n\n // Get the order type string\n // Use detailedOrderType if available (e.g., \"Stop Market\", \"Take Profit Limit\")\n // Otherwise fall back to basic orderType\n const typeString =\n detailedOrderType ?? (orderType === 'limit' ? 'Limit' : 'Market');\n\n // Build the label: [Type] [Close?] [Direction]\n if (isClosing) {\n return capitalize(`${typeString} close ${direction}`);\n }\n\n return capitalize(`${typeString} ${direction}`);\n};\n\n/**\n * Get just the direction portion of an order label\n * Used for compatibility with existing code that expects just \"long\" or \"short\"\n *\n * @param order - The order object\n * @returns Direction string (\"long\" or \"short\" for opening, \"Close Long\" or \"Close Short\" for closing)\n */\nexport const getOrderLabelDirection = (order: Order): string => {\n const { side, reduceOnly, isTrigger } = order;\n\n // Determine if this is a closing order\n const isClosing = Boolean(reduceOnly ?? isTrigger);\n\n if (isClosing) {\n // For closing orders: sell closes long, buy closes short\n return side === 'sell' ? 'Close Long' : 'Close Short';\n }\n\n // For opening orders: buy is long, sell is short\n return side === 'buy' ? 'long' : 'short';\n};\n\n/**\n * Determines if a limit order will likely be a maker or taker.\n *\n * Logic:\n * 1. Validates price data freshness and market state\n * 2. Market orders are always taker\n * 3. Limit orders that would execute immediately are taker\n * 4. Limit orders that go into order book are maker\n *\n * @param params - Order parameters\n * @param params.orderType - The order type (market or limit)\n * @param params.limitPrice - The limit price for limit orders\n * @param params.direction - The order direction (long or short)\n * @param params.bestAsk - The best ask price from order book\n * @param params.bestBid - The best bid price from order book\n * @param params.symbol - The trading symbol for logging\n * @param debugLogger - Optional debug logger for detailed logging\n * @returns True if maker order, false if taker order\n */\nexport function determineMakerStatus(\n params: {\n orderType: 'market' | 'limit';\n limitPrice?: string;\n direction: 'long' | 'short';\n bestAsk?: number;\n bestBid?: number;\n symbol?: string;\n },\n debugLogger?: OrderUtilsDebugLogger,\n): boolean {\n const { orderType, limitPrice, direction, bestAsk, bestBid, symbol } = params;\n // Market orders are always taker\n if (orderType === 'market') {\n return false;\n }\n\n // Default to taker when limit price is not specified\n if (!limitPrice || limitPrice === '') {\n return false;\n }\n\n const limitPriceNum = Number.parseFloat(limitPrice);\n\n if (Number.isNaN(limitPriceNum) || limitPriceNum <= 0) {\n return false;\n }\n\n if (bestBid !== undefined && bestAsk !== undefined) {\n if (direction === 'long') {\n return limitPriceNum < bestAsk;\n }\n\n // Short direction\n return limitPriceNum > bestBid;\n }\n\n // Default to taker when no bid/ask data is available\n debugLogger?.log(\n 'Fee Calculation: No bid/ask data available, using conservative taker fee',\n { symbol },\n );\n return false;\n}\n"]}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* P&L calculation utilities for Perps trading
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calculateTotalPnLPercentage = exports.calculateTotalPnL = exports.calculatePnLPercentageFromUnrealized = exports.calculatePnLWithPercentage = exports.calculatePnLPercentage = exports.calculateExpectedPnL = exports.calculatePnL = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Calculate P&L for a position.
|
|
9
|
-
*
|
|
10
|
-
* @param params - P&L calculation parameters
|
|
11
|
-
* @returns The calculated profit or loss value
|
|
12
|
-
*/
|
|
13
|
-
function calculatePnL(params) {
|
|
14
|
-
const { entryPrice, currentPrice, size } = params;
|
|
15
|
-
return (currentPrice - entryPrice) * size;
|
|
16
|
-
}
|
|
17
|
-
exports.calculatePnL = calculatePnL;
|
|
18
|
-
/**
|
|
19
|
-
* Calculate expected profit/loss for TP/SL trigger, accounting for closing fees.
|
|
20
|
-
* Reuses calculatePnL for gross P&L, then subtracts fees.
|
|
21
|
-
*
|
|
22
|
-
* @param params - Expected P&L calculation parameters
|
|
23
|
-
* @returns The expected net profit or loss after fees
|
|
24
|
-
*/
|
|
25
|
-
function calculateExpectedPnL(params) {
|
|
26
|
-
const { triggerPrice, entryPrice, size, closingFee } = params;
|
|
27
|
-
const grossPnL = calculatePnL({
|
|
28
|
-
entryPrice,
|
|
29
|
-
currentPrice: triggerPrice,
|
|
30
|
-
size,
|
|
31
|
-
});
|
|
32
|
-
return grossPnL - closingFee;
|
|
33
|
-
}
|
|
34
|
-
exports.calculateExpectedPnL = calculateExpectedPnL;
|
|
35
|
-
/**
|
|
36
|
-
* Calculate P&L percentage for a position.
|
|
37
|
-
*
|
|
38
|
-
* @param params - P&L calculation parameters
|
|
39
|
-
* @returns The P&L as a percentage value
|
|
40
|
-
*/
|
|
41
|
-
function calculatePnLPercentage(params) {
|
|
42
|
-
const { entryPrice, currentPrice, size } = params;
|
|
43
|
-
return ((currentPrice - entryPrice) / entryPrice) * 100 * Math.sign(size);
|
|
44
|
-
}
|
|
45
|
-
exports.calculatePnLPercentage = calculatePnLPercentage;
|
|
46
|
-
/**
|
|
47
|
-
* Calculate both P&L and P&L percentage.
|
|
48
|
-
*
|
|
49
|
-
* @param params - P&L calculation parameters
|
|
50
|
-
* @returns Object containing both P&L value and percentage
|
|
51
|
-
*/
|
|
52
|
-
function calculatePnLWithPercentage(params) {
|
|
53
|
-
return {
|
|
54
|
-
pnl: calculatePnL(params),
|
|
55
|
-
pnlPercentage: calculatePnLPercentage(params),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
exports.calculatePnLWithPercentage = calculatePnLWithPercentage;
|
|
59
|
-
/**
|
|
60
|
-
* Calculate P&L percentage based on unrealized P&L and position value.
|
|
61
|
-
* This is used when current price is not available.
|
|
62
|
-
*
|
|
63
|
-
* @param params - Parameters including unrealized P&L, entry price, and size
|
|
64
|
-
* @returns The P&L as a percentage value
|
|
65
|
-
*/
|
|
66
|
-
function calculatePnLPercentageFromUnrealized(params) {
|
|
67
|
-
const { unrealizedPnl, entryPrice, size } = params;
|
|
68
|
-
const entryValue = entryPrice * Math.abs(size);
|
|
69
|
-
if (entryValue === 0) {
|
|
70
|
-
return 0;
|
|
71
|
-
}
|
|
72
|
-
return (unrealizedPnl / entryValue) * 100;
|
|
73
|
-
}
|
|
74
|
-
exports.calculatePnLPercentageFromUnrealized = calculatePnLPercentageFromUnrealized;
|
|
75
|
-
/**
|
|
76
|
-
* Calculate total P&L for multiple positions.
|
|
77
|
-
*
|
|
78
|
-
* @param params - Parameters containing array of positions
|
|
79
|
-
* @returns The sum of unrealized P&L across all positions
|
|
80
|
-
*/
|
|
81
|
-
function calculateTotalPnL(params) {
|
|
82
|
-
const { positions } = params;
|
|
83
|
-
return positions.reduce((sum, position) => sum + parseFloat(position.unrealizedPnl || '0'), 0);
|
|
84
|
-
}
|
|
85
|
-
exports.calculateTotalPnL = calculateTotalPnL;
|
|
86
|
-
/**
|
|
87
|
-
* Calculate total P&L percentage for multiple positions.
|
|
88
|
-
*
|
|
89
|
-
* @param params - Parameters containing array of positions
|
|
90
|
-
* @returns The weighted average P&L percentage across all positions
|
|
91
|
-
*/
|
|
92
|
-
function calculateTotalPnLPercentage(params) {
|
|
93
|
-
const { positions } = params;
|
|
94
|
-
let totalPnl = 0;
|
|
95
|
-
let totalEntryValue = 0;
|
|
96
|
-
positions.forEach((position) => {
|
|
97
|
-
const pnl = parseFloat(position.unrealizedPnl || '0');
|
|
98
|
-
const entryPrice = parseFloat(position.entryPrice || '0');
|
|
99
|
-
const size = Math.abs(parseFloat(position.size || '0'));
|
|
100
|
-
const entryValue = entryPrice * size;
|
|
101
|
-
totalPnl += pnl;
|
|
102
|
-
totalEntryValue += entryValue;
|
|
103
|
-
});
|
|
104
|
-
return totalEntryValue === 0 ? 0 : (totalPnl / totalEntryValue) * 100;
|
|
105
|
-
}
|
|
106
|
-
exports.calculateTotalPnLPercentage = calculateTotalPnLPercentage;
|
|
107
|
-
//# sourceMappingURL=pnlCalculations.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pnlCalculations.cjs","sourceRoot":"","sources":["../../src/utils/pnlCalculations.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAgCH;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,MAA4B;IACvD,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAClD,OAAO,CAAC,YAAY,GAAG,UAAU,CAAC,GAAG,IAA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S,EAAE,GAAG,MAAM,CAAC;IAC7B,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,aAAa,IAAI,GAAG,CAAC,EAClE,CAAC,CACF,CAAC;AACJ,CAAC;AAND,8CAMC;AAED;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,MAAsB;IAChE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,eAAe,GAAG,CAAC,CAAC;IAExB,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC7B,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,aAAa,IAAI,GAAG,CAAC,CAAC;QACtD,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC;QACxD,MAAM,UAAU,GAAG,UAAU,GAAG,IAAI,CAAC;QAErC,QAAQ,IAAI,GAAG,CAAC;QAChB,eAAe,IAAI,UAAU,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,eAAe,CAAC,GAAG,GAAG,CAAC;AACxE,CAAC;AAhBD,kEAgBC","sourcesContent":["/**\n * P&L calculation utilities for Perps trading\n */\n\nimport type { Position } from '../types';\n\nexport type PnLCalculationParams = {\n entryPrice: number;\n currentPrice: number;\n size: number;\n};\n\nexport type PnLResult = {\n pnl: number;\n pnlPercentage: number;\n};\n\nexport type PnLFromUnrealizedParams = {\n unrealizedPnl: number;\n entryPrice: number;\n size: number;\n};\n\nexport type TotalPnLParams = {\n positions: Position[];\n};\n\nexport type ExpectedPnLParams = {\n triggerPrice: number;\n entryPrice: number;\n size: number;\n closingFee: number;\n};\n\n/**\n * Calculate P&L for a position.\n *\n * @param params - P&L calculation parameters\n * @returns The calculated profit or loss value\n */\nexport function calculatePnL(params: PnLCalculationParams): number {\n const { entryPrice, currentPrice, size } = params;\n return (currentPrice - entryPrice) * size;\n}\n\n/**\n * Calculate expected profit/loss for TP/SL trigger, accounting for closing fees.\n * Reuses calculatePnL for gross P&L, then subtracts fees.\n *\n * @param params - Expected P&L calculation parameters\n * @returns The expected net profit or loss after fees\n */\nexport function calculateExpectedPnL(params: ExpectedPnLParams): number {\n const { triggerPrice, entryPrice, size, closingFee } = params;\n const grossPnL = calculatePnL({\n entryPrice,\n currentPrice: triggerPrice,\n size,\n });\n return grossPnL - closingFee;\n}\n\n/**\n * Calculate P&L percentage for a position.\n *\n * @param params - P&L calculation parameters\n * @returns The P&L as a percentage value\n */\nexport function calculatePnLPercentage(params: PnLCalculationParams): number {\n const { entryPrice, currentPrice, size } = params;\n return ((currentPrice - entryPrice) / entryPrice) * 100 * Math.sign(size);\n}\n\n/**\n * Calculate both P&L and P&L percentage.\n *\n * @param params - P&L calculation parameters\n * @returns Object containing both P&L value and percentage\n */\nexport function calculatePnLWithPercentage(\n params: PnLCalculationParams,\n): PnLResult {\n return {\n pnl: calculatePnL(params),\n pnlPercentage: calculatePnLPercentage(params),\n };\n}\n\n/**\n * Calculate P&L percentage based on unrealized P&L and position value.\n * This is used when current price is not available.\n *\n * @param params - Parameters including unrealized P&L, entry price, and size\n * @returns The P&L as a percentage value\n */\nexport function calculatePnLPercentageFromUnrealized(\n params: PnLFromUnrealizedParams,\n): number {\n const { unrealizedPnl, entryPrice, size } = params;\n const entryValue = entryPrice * Math.abs(size);\n if (entryValue === 0) {\n return 0;\n }\n return (unrealizedPnl / entryValue) * 100;\n}\n\n/**\n * Calculate total P&L for multiple positions.\n *\n * @param params - Parameters containing array of positions\n * @returns The sum of unrealized P&L across all positions\n */\nexport function calculateTotalPnL(params: TotalPnLParams): number {\n const { positions } = params;\n return positions.reduce(\n (sum, position) => sum + parseFloat(position.unrealizedPnl || '0'),\n 0,\n );\n}\n\n/**\n * Calculate total P&L percentage for multiple positions.\n *\n * @param params - Parameters containing array of positions\n * @returns The weighted average P&L percentage across all positions\n */\nexport function calculateTotalPnLPercentage(params: TotalPnLParams): number {\n const { positions } = params;\n let totalPnl = 0;\n let totalEntryValue = 0;\n\n positions.forEach((position) => {\n const pnl = parseFloat(position.unrealizedPnl || '0');\n const entryPrice = parseFloat(position.entryPrice || '0');\n const size = Math.abs(parseFloat(position.size || '0'));\n const entryValue = entryPrice * size;\n\n totalPnl += pnl;\n totalEntryValue += entryValue;\n });\n\n return totalEntryValue === 0 ? 0 : (totalPnl / totalEntryValue) * 100;\n}\n"]}
|