@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,459 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable no-restricted-syntax, @typescript-eslint/prefer-nullish-coalescing */
|
|
3
|
-
// TODO: Fix ESLint errors in this file - tracked for Phase 6 cleanup
|
|
4
|
-
/**
|
|
5
|
-
* SubscriptionMultiplexer - Manages WebSocket subscriptions across multiple providers
|
|
6
|
-
*
|
|
7
|
-
* Responsibilities:
|
|
8
|
-
* - Manage subscriptions to multiple providers simultaneously
|
|
9
|
-
* - Tag all updates with providerId so UI can differentiate sources
|
|
10
|
-
* - Support aggregation modes: 'merge' (all prices) or 'best_price' (best price per symbol)
|
|
11
|
-
* - Cache latest updates per provider per symbol for aggregation
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.SubscriptionMultiplexer = void 0;
|
|
15
|
-
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
16
|
-
/**
|
|
17
|
-
* SubscriptionMultiplexer manages real-time data subscriptions across
|
|
18
|
-
* multiple perps providers.
|
|
19
|
-
*
|
|
20
|
-
* Key features:
|
|
21
|
-
* - Subscribes to all providers simultaneously
|
|
22
|
-
* - Tags all updates with source providerId
|
|
23
|
-
* - Caches latest values for aggregation
|
|
24
|
-
* - Supports different aggregation modes for prices
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const mux = new SubscriptionMultiplexer();
|
|
29
|
-
*
|
|
30
|
-
* const unsubscribe = mux.subscribeToPrices({
|
|
31
|
-
* symbols: ['BTC', 'ETH'],
|
|
32
|
-
* providers: [
|
|
33
|
-
* ['hyperliquid', hlProvider],
|
|
34
|
-
* ['myx', myxProvider],
|
|
35
|
-
* ],
|
|
36
|
-
* callback: (prices) => {
|
|
37
|
-
* // prices have providerId injected
|
|
38
|
-
* prices.forEach(p => console.log(`${p.providerId}: ${p.symbol} = ${p.price}`));
|
|
39
|
-
* },
|
|
40
|
-
* aggregationMode: 'merge',
|
|
41
|
-
* });
|
|
42
|
-
*
|
|
43
|
-
* // Later: clean up
|
|
44
|
-
* unsubscribe();
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
class SubscriptionMultiplexer {
|
|
48
|
-
/**
|
|
49
|
-
* Create a new SubscriptionMultiplexer.
|
|
50
|
-
*
|
|
51
|
-
* @param options - Optional configuration including logger for error reporting
|
|
52
|
-
*/
|
|
53
|
-
constructor(options) {
|
|
54
|
-
/**
|
|
55
|
-
* Cache of latest prices per symbol per provider
|
|
56
|
-
* Map<symbol, Map<providerId, PriceUpdate>>
|
|
57
|
-
*/
|
|
58
|
-
this.priceCache = new Map();
|
|
59
|
-
/**
|
|
60
|
-
* Cache of latest positions per provider
|
|
61
|
-
* Map<providerId, Position[]>
|
|
62
|
-
*/
|
|
63
|
-
this.positionCache = new Map();
|
|
64
|
-
/**
|
|
65
|
-
* Cache of latest orders per provider
|
|
66
|
-
* Map<providerId, Order[]>
|
|
67
|
-
*/
|
|
68
|
-
this.orderCache = new Map();
|
|
69
|
-
/**
|
|
70
|
-
* Cache of latest account state per provider
|
|
71
|
-
* Map<providerId, AccountState>
|
|
72
|
-
*/
|
|
73
|
-
this.accountCache = new Map();
|
|
74
|
-
this.logger = options?.logger;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Subscribe to price updates from multiple providers.
|
|
78
|
-
*
|
|
79
|
-
* @param params - Subscription parameters
|
|
80
|
-
* @returns Unsubscribe function
|
|
81
|
-
*/
|
|
82
|
-
subscribeToPrices(params) {
|
|
83
|
-
const { symbols, providers, callback, aggregationMode = 'merge', throttleMs, includeOrderBook, includeMarketData, } = params;
|
|
84
|
-
const unsubscribers = [];
|
|
85
|
-
// Subscribe to each provider with defensive error handling
|
|
86
|
-
for (const [providerId, provider] of providers) {
|
|
87
|
-
try {
|
|
88
|
-
const subscribeParams = {
|
|
89
|
-
symbols,
|
|
90
|
-
callback: (updates) => {
|
|
91
|
-
// Tag and cache each update
|
|
92
|
-
updates.forEach((update) => {
|
|
93
|
-
const taggedUpdate = { ...update, providerId };
|
|
94
|
-
// Initialize symbol cache if needed
|
|
95
|
-
if (!this.priceCache.has(update.symbol)) {
|
|
96
|
-
this.priceCache.set(update.symbol, new Map());
|
|
97
|
-
}
|
|
98
|
-
const symbolCache = this.priceCache.get(update.symbol);
|
|
99
|
-
if (symbolCache) {
|
|
100
|
-
symbolCache.set(providerId, taggedUpdate);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
// Aggregate and emit based on mode
|
|
104
|
-
const aggregated = this.aggregatePrices(symbols, aggregationMode);
|
|
105
|
-
callback(aggregated);
|
|
106
|
-
},
|
|
107
|
-
throttleMs,
|
|
108
|
-
includeOrderBook,
|
|
109
|
-
includeMarketData,
|
|
110
|
-
};
|
|
111
|
-
const unsub = provider.subscribeToPrices(subscribeParams);
|
|
112
|
-
unsubscribers.push(unsub);
|
|
113
|
-
}
|
|
114
|
-
catch (caughtError) {
|
|
115
|
-
// Log to Sentry before cleanup
|
|
116
|
-
const errorObj = caughtError instanceof Error
|
|
117
|
-
? caughtError
|
|
118
|
-
: new Error(String(caughtError));
|
|
119
|
-
this.logger?.error(errorObj, {
|
|
120
|
-
tags: {
|
|
121
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
122
|
-
provider: providerId,
|
|
123
|
-
method: 'subscribeToPrices',
|
|
124
|
-
},
|
|
125
|
-
context: {
|
|
126
|
-
name: 'SubscriptionMultiplexer',
|
|
127
|
-
data: { subscribedCount: unsubscribers.length },
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
// Clean up any subscriptions created before the failure
|
|
131
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
132
|
-
throw caughtError;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// Return combined unsubscribe function
|
|
136
|
-
return () => {
|
|
137
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
138
|
-
// Optionally clear cache for these symbols
|
|
139
|
-
symbols.forEach((symbol) => {
|
|
140
|
-
this.priceCache.delete(symbol);
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Subscribe to position updates from multiple providers.
|
|
146
|
-
*
|
|
147
|
-
* @param params - Subscription parameters
|
|
148
|
-
* @returns Unsubscribe function
|
|
149
|
-
*/
|
|
150
|
-
subscribeToPositions(params) {
|
|
151
|
-
const { providers, callback } = params;
|
|
152
|
-
const unsubscribers = [];
|
|
153
|
-
for (const [providerId, provider] of providers) {
|
|
154
|
-
try {
|
|
155
|
-
const subscribeParams = {
|
|
156
|
-
callback: (positions) => {
|
|
157
|
-
// Tag positions with providerId and cache
|
|
158
|
-
const taggedPositions = positions.map((pos) => ({
|
|
159
|
-
...pos,
|
|
160
|
-
providerId,
|
|
161
|
-
}));
|
|
162
|
-
this.positionCache.set(providerId, taggedPositions);
|
|
163
|
-
// Emit aggregated positions from all providers
|
|
164
|
-
const allPositions = this.aggregatePositions();
|
|
165
|
-
callback(allPositions);
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
const unsub = provider.subscribeToPositions(subscribeParams);
|
|
169
|
-
unsubscribers.push(unsub);
|
|
170
|
-
}
|
|
171
|
-
catch (caughtError) {
|
|
172
|
-
const errorObj = caughtError instanceof Error
|
|
173
|
-
? caughtError
|
|
174
|
-
: new Error(String(caughtError));
|
|
175
|
-
this.logger?.error(errorObj, {
|
|
176
|
-
tags: {
|
|
177
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
178
|
-
provider: providerId,
|
|
179
|
-
method: 'subscribeToPositions',
|
|
180
|
-
},
|
|
181
|
-
context: {
|
|
182
|
-
name: 'SubscriptionMultiplexer',
|
|
183
|
-
data: { subscribedCount: unsubscribers.length },
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
187
|
-
throw caughtError;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return () => {
|
|
191
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
192
|
-
// Clear position cache for these providers
|
|
193
|
-
providers.forEach(([providerId]) => {
|
|
194
|
-
this.positionCache.delete(providerId);
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Subscribe to order fill updates from multiple providers.
|
|
200
|
-
*
|
|
201
|
-
* @param params - Subscription parameters
|
|
202
|
-
* @returns Unsubscribe function
|
|
203
|
-
*/
|
|
204
|
-
subscribeToOrderFills(params) {
|
|
205
|
-
const { providers, callback } = params;
|
|
206
|
-
const unsubscribers = [];
|
|
207
|
-
for (const [providerId, provider] of providers) {
|
|
208
|
-
try {
|
|
209
|
-
const subscribeParams = {
|
|
210
|
-
callback: (fills, isSnapshot) => {
|
|
211
|
-
// Tag fills with providerId
|
|
212
|
-
const taggedFills = fills.map((fill) => ({
|
|
213
|
-
...fill,
|
|
214
|
-
providerId,
|
|
215
|
-
}));
|
|
216
|
-
// For fills, we don't aggregate - emit immediately with tags
|
|
217
|
-
callback(taggedFills, isSnapshot);
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
const unsub = provider.subscribeToOrderFills(subscribeParams);
|
|
221
|
-
unsubscribers.push(unsub);
|
|
222
|
-
}
|
|
223
|
-
catch (caughtError) {
|
|
224
|
-
const errorObj = caughtError instanceof Error
|
|
225
|
-
? caughtError
|
|
226
|
-
: new Error(String(caughtError));
|
|
227
|
-
this.logger?.error(errorObj, {
|
|
228
|
-
tags: {
|
|
229
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
230
|
-
provider: providerId,
|
|
231
|
-
method: 'subscribeToOrderFills',
|
|
232
|
-
},
|
|
233
|
-
context: {
|
|
234
|
-
name: 'SubscriptionMultiplexer',
|
|
235
|
-
data: { subscribedCount: unsubscribers.length },
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
239
|
-
throw caughtError;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return () => {
|
|
243
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Subscribe to order updates from multiple providers.
|
|
248
|
-
*
|
|
249
|
-
* @param params - Subscription parameters
|
|
250
|
-
* @returns Unsubscribe function
|
|
251
|
-
*/
|
|
252
|
-
subscribeToOrders(params) {
|
|
253
|
-
const { providers, callback } = params;
|
|
254
|
-
const unsubscribers = [];
|
|
255
|
-
for (const [providerId, provider] of providers) {
|
|
256
|
-
try {
|
|
257
|
-
const subscribeParams = {
|
|
258
|
-
callback: (orders) => {
|
|
259
|
-
// Tag orders with providerId and cache
|
|
260
|
-
const taggedOrders = orders.map((order) => ({
|
|
261
|
-
...order,
|
|
262
|
-
providerId,
|
|
263
|
-
}));
|
|
264
|
-
this.orderCache.set(providerId, taggedOrders);
|
|
265
|
-
// Emit aggregated orders from all providers
|
|
266
|
-
const allOrders = this.aggregateOrders();
|
|
267
|
-
callback(allOrders);
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
const unsub = provider.subscribeToOrders(subscribeParams);
|
|
271
|
-
unsubscribers.push(unsub);
|
|
272
|
-
}
|
|
273
|
-
catch (caughtError) {
|
|
274
|
-
const errorObj = caughtError instanceof Error
|
|
275
|
-
? caughtError
|
|
276
|
-
: new Error(String(caughtError));
|
|
277
|
-
this.logger?.error(errorObj, {
|
|
278
|
-
tags: {
|
|
279
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
280
|
-
provider: providerId,
|
|
281
|
-
method: 'subscribeToOrders',
|
|
282
|
-
},
|
|
283
|
-
context: {
|
|
284
|
-
name: 'SubscriptionMultiplexer',
|
|
285
|
-
data: { subscribedCount: unsubscribers.length },
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
289
|
-
throw caughtError;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return () => {
|
|
293
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
294
|
-
providers.forEach(([providerId]) => {
|
|
295
|
-
this.orderCache.delete(providerId);
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Subscribe to account updates from multiple providers.
|
|
301
|
-
*
|
|
302
|
-
* @param params - Subscription parameters
|
|
303
|
-
* @returns Unsubscribe function
|
|
304
|
-
*/
|
|
305
|
-
subscribeToAccount(params) {
|
|
306
|
-
const { providers, callback } = params;
|
|
307
|
-
const unsubscribers = [];
|
|
308
|
-
for (const [providerId, provider] of providers) {
|
|
309
|
-
try {
|
|
310
|
-
const subscribeParams = {
|
|
311
|
-
callback: (account) => {
|
|
312
|
-
// Tag account with providerId and cache
|
|
313
|
-
const taggedAccount = { ...account, providerId };
|
|
314
|
-
this.accountCache.set(providerId, taggedAccount);
|
|
315
|
-
// Emit all cached account states
|
|
316
|
-
const allAccounts = Array.from(this.accountCache.values());
|
|
317
|
-
callback(allAccounts);
|
|
318
|
-
},
|
|
319
|
-
};
|
|
320
|
-
const unsub = provider.subscribeToAccount(subscribeParams);
|
|
321
|
-
unsubscribers.push(unsub);
|
|
322
|
-
}
|
|
323
|
-
catch (caughtError) {
|
|
324
|
-
const errorObj = caughtError instanceof Error
|
|
325
|
-
? caughtError
|
|
326
|
-
: new Error(String(caughtError));
|
|
327
|
-
this.logger?.error(errorObj, {
|
|
328
|
-
tags: {
|
|
329
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
330
|
-
provider: providerId,
|
|
331
|
-
method: 'subscribeToAccount',
|
|
332
|
-
},
|
|
333
|
-
context: {
|
|
334
|
-
name: 'SubscriptionMultiplexer',
|
|
335
|
-
data: { subscribedCount: unsubscribers.length },
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
339
|
-
throw caughtError;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return () => {
|
|
343
|
-
unsubscribers.forEach((unsub) => unsub());
|
|
344
|
-
providers.forEach(([providerId]) => {
|
|
345
|
-
this.accountCache.delete(providerId);
|
|
346
|
-
});
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Aggregate cached prices based on mode.
|
|
351
|
-
*
|
|
352
|
-
* @param symbols - Symbols to include in result
|
|
353
|
-
* @param mode - Aggregation mode
|
|
354
|
-
* @returns Aggregated price updates
|
|
355
|
-
*/
|
|
356
|
-
aggregatePrices(symbols, mode) {
|
|
357
|
-
const result = [];
|
|
358
|
-
symbols.forEach((symbol) => {
|
|
359
|
-
const providerPrices = this.priceCache.get(symbol);
|
|
360
|
-
if (!providerPrices || providerPrices.size === 0) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
if (mode === 'merge') {
|
|
364
|
-
// Return all prices (one per provider)
|
|
365
|
-
providerPrices.forEach((price) => {
|
|
366
|
-
result.push(price);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
// 'best_price': Return the best price across providers
|
|
371
|
-
const best = this.findBestPrice(providerPrices);
|
|
372
|
-
if (best) {
|
|
373
|
-
result.push(best);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
return result;
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Find the best price from multiple provider prices.
|
|
381
|
-
* "Best" is defined as the price with the smallest spread.
|
|
382
|
-
*
|
|
383
|
-
* @param providerPrices - Map of provider prices for a symbol
|
|
384
|
-
* @returns Best price update or undefined
|
|
385
|
-
*/
|
|
386
|
-
findBestPrice(providerPrices) {
|
|
387
|
-
let bestPrice;
|
|
388
|
-
let smallestSpread = Infinity;
|
|
389
|
-
providerPrices.forEach((price) => {
|
|
390
|
-
// If spread is available, use it to determine best
|
|
391
|
-
if (price.spread !== undefined) {
|
|
392
|
-
const spreadValue = parseFloat(price.spread);
|
|
393
|
-
if (!isNaN(spreadValue) && spreadValue < smallestSpread) {
|
|
394
|
-
smallestSpread = spreadValue;
|
|
395
|
-
bestPrice = price;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
else if (!bestPrice) {
|
|
399
|
-
// No spread info - just use the first one
|
|
400
|
-
bestPrice = price;
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
return bestPrice;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Aggregate positions from all providers.
|
|
407
|
-
*
|
|
408
|
-
* @returns All cached positions
|
|
409
|
-
*/
|
|
410
|
-
aggregatePositions() {
|
|
411
|
-
const allPositions = [];
|
|
412
|
-
this.positionCache.forEach((positions) => {
|
|
413
|
-
allPositions.push(...positions);
|
|
414
|
-
});
|
|
415
|
-
return allPositions;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Aggregate orders from all providers.
|
|
419
|
-
*
|
|
420
|
-
* @returns All cached orders
|
|
421
|
-
*/
|
|
422
|
-
aggregateOrders() {
|
|
423
|
-
const allOrders = [];
|
|
424
|
-
this.orderCache.forEach((orders) => {
|
|
425
|
-
allOrders.push(...orders);
|
|
426
|
-
});
|
|
427
|
-
return allOrders;
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Clear all cached data.
|
|
431
|
-
*/
|
|
432
|
-
clearCache() {
|
|
433
|
-
this.priceCache.clear();
|
|
434
|
-
this.positionCache.clear();
|
|
435
|
-
this.orderCache.clear();
|
|
436
|
-
this.accountCache.clear();
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Get cached price for a symbol from a specific provider.
|
|
440
|
-
*
|
|
441
|
-
* @param symbol - Market symbol
|
|
442
|
-
* @param providerId - Provider ID
|
|
443
|
-
* @returns Cached price update or undefined
|
|
444
|
-
*/
|
|
445
|
-
getCachedPrice(symbol, providerId) {
|
|
446
|
-
return this.priceCache.get(symbol)?.get(providerId);
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Get all cached prices for a symbol.
|
|
450
|
-
*
|
|
451
|
-
* @param symbol - Market symbol
|
|
452
|
-
* @returns Map of provider ID to price update
|
|
453
|
-
*/
|
|
454
|
-
getAllCachedPricesForSymbol(symbol) {
|
|
455
|
-
return this.priceCache.get(symbol);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
exports.SubscriptionMultiplexer = SubscriptionMultiplexer;
|
|
459
|
-
//# sourceMappingURL=SubscriptionMultiplexer.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionMultiplexer.cjs","sourceRoot":"","sources":["../../src/aggregation/SubscriptionMultiplexer.ts"],"names":[],"mappings":";AAAA,uFAAuF;AACvF,qEAAqE;AACrE;;;;;;;;GAQG;;;AAEH,8DAA2D;AA0F3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,uBAAuB;IAmClC;;;;OAIG;IACH,YAAY,OAAwC;QAlCpD;;;WAGG;QACc,eAAU,GAGvB,IAAI,GAAG,EAAE,CAAC;QAEd;;;WAGG;QACc,kBAAa,GAC5B,IAAI,GAAG,EAAE,CAAC;QAEZ;;;WAGG;QACc,eAAU,GAAoC,IAAI,GAAG,EAAE,CAAC;QAEzE;;;WAGG;QACc,iBAAY,GAC3B,IAAI,GAAG,EAAE,CAAC;QAQV,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACH,iBAAiB,CAAC,MAA+B;QAC/C,MAAM,EACJ,OAAO,EACP,SAAS,EACT,QAAQ,EACR,eAAe,GAAG,OAAO,EACzB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,GAClB,GAAG,MAAM,CAAC;QAEX,MAAM,aAAa,GAAmB,EAAE,CAAC;QAEzC,2DAA2D;QAC3D,KAAK,MAAM,CAAC,UA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TODO: Fix ESLint errors in this file - tracked for Phase 6 cleanup\n/**\n * SubscriptionMultiplexer - Manages WebSocket subscriptions across multiple providers\n *\n * Responsibilities:\n * - Manage subscriptions to multiple providers simultaneously\n * - Tag all updates with providerId so UI can differentiate sources\n * - Support aggregation modes: 'merge' (all prices) or 'best_price' (best price per symbol)\n * - Cache latest updates per provider per symbol for aggregation\n */\n\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport type {\n PerpsProviderType,\n PerpsProvider,\n PerpsLogger,\n PriceUpdate,\n Position,\n OrderFill,\n Order,\n AccountState,\n SubscribePricesParams,\n SubscribePositionsParams,\n SubscribeOrderFillsParams,\n SubscribeOrdersParams,\n SubscribeAccountParams,\n} from '../types';\n\n/**\n * Options for constructing SubscriptionMultiplexer.\n */\nexport type SubscriptionMultiplexerOptions = {\n /** Optional logger for error reporting (e.g., Sentry) */\n logger?: PerpsLogger;\n};\n\n/**\n * Aggregation mode for price subscriptions.\n */\nexport type PriceAggregationMode = 'merge' | 'best_price';\n\n/**\n * Parameters for multiplexed price subscriptions.\n */\nexport type MultiplexedPricesParams = {\n /** Symbols to subscribe to */\n symbols: string[];\n /** Provider instances to subscribe through */\n providers: [PerpsProviderType, PerpsProvider][];\n /** Callback to receive aggregated price updates */\n callback: (prices: PriceUpdate[]) => void;\n /** Aggregation mode: 'merge' returns all prices, 'best_price' returns best per symbol */\n aggregationMode?: PriceAggregationMode;\n /** Optional throttle in milliseconds */\n throttleMs?: number;\n /** Include order book data */\n includeOrderBook?: boolean;\n /** Include market data (funding, OI, volume) */\n includeMarketData?: boolean;\n};\n\n/**\n * Parameters for multiplexed position subscriptions.\n */\nexport type MultiplexedPositionsParams = {\n /** Provider instances to subscribe through */\n providers: [PerpsProviderType, PerpsProvider][];\n /** Callback to receive aggregated position updates */\n callback: (positions: Position[]) => void;\n};\n\n/**\n * Parameters for multiplexed order fill subscriptions.\n */\nexport type MultiplexedOrderFillsParams = {\n /** Provider instances to subscribe through */\n providers: [PerpsProviderType, PerpsProvider][];\n /** Callback to receive aggregated order fill updates */\n callback: (fills: OrderFill[], isSnapshot?: boolean) => void;\n};\n\n/**\n * Parameters for multiplexed order subscriptions.\n */\nexport type MultiplexedOrdersParams = {\n /** Provider instances to subscribe through */\n providers: [PerpsProviderType, PerpsProvider][];\n /** Callback to receive aggregated order updates */\n callback: (orders: Order[]) => void;\n};\n\n/**\n * Parameters for multiplexed account subscriptions.\n */\nexport type MultiplexedAccountParams = {\n /** Provider instances to subscribe through */\n providers: [PerpsProviderType, PerpsProvider][];\n /** Callback to receive account updates (one per provider) */\n callback: (accounts: AccountState[]) => void;\n};\n\n/**\n * SubscriptionMultiplexer manages real-time data subscriptions across\n * multiple perps providers.\n *\n * Key features:\n * - Subscribes to all providers simultaneously\n * - Tags all updates with source providerId\n * - Caches latest values for aggregation\n * - Supports different aggregation modes for prices\n *\n * @example\n * ```typescript\n * const mux = new SubscriptionMultiplexer();\n *\n * const unsubscribe = mux.subscribeToPrices({\n * symbols: ['BTC', 'ETH'],\n * providers: [\n * ['hyperliquid', hlProvider],\n * ['myx', myxProvider],\n * ],\n * callback: (prices) => {\n * // prices have providerId injected\n * prices.forEach(p => console.log(`${p.providerId}: ${p.symbol} = ${p.price}`));\n * },\n * aggregationMode: 'merge',\n * });\n *\n * // Later: clean up\n * unsubscribe();\n * ```\n */\nexport class SubscriptionMultiplexer {\n /**\n * Optional logger for error reporting\n */\n private readonly logger?: PerpsLogger;\n\n /**\n * Cache of latest prices per symbol per provider\n * Map<symbol, Map<providerId, PriceUpdate>>\n */\n private readonly priceCache: Map<\n string,\n Map<PerpsProviderType, PriceUpdate>\n > = new Map();\n\n /**\n * Cache of latest positions per provider\n * Map<providerId, Position[]>\n */\n private readonly positionCache: Map<PerpsProviderType, Position[]> =\n new Map();\n\n /**\n * Cache of latest orders per provider\n * Map<providerId, Order[]>\n */\n private readonly orderCache: Map<PerpsProviderType, Order[]> = new Map();\n\n /**\n * Cache of latest account state per provider\n * Map<providerId, AccountState>\n */\n private readonly accountCache: Map<PerpsProviderType, AccountState> =\n new Map();\n\n /**\n * Create a new SubscriptionMultiplexer.\n *\n * @param options - Optional configuration including logger for error reporting\n */\n constructor(options?: SubscriptionMultiplexerOptions) {\n this.logger = options?.logger;\n }\n\n /**\n * Subscribe to price updates from multiple providers.\n *\n * @param params - Subscription parameters\n * @returns Unsubscribe function\n */\n subscribeToPrices(params: MultiplexedPricesParams): () => void {\n const {\n symbols,\n providers,\n callback,\n aggregationMode = 'merge',\n throttleMs,\n includeOrderBook,\n includeMarketData,\n } = params;\n\n const unsubscribers: (() => void)[] = [];\n\n // Subscribe to each provider with defensive error handling\n for (const [providerId, provider] of providers) {\n try {\n const subscribeParams: SubscribePricesParams = {\n symbols,\n callback: (updates) => {\n // Tag and cache each update\n updates.forEach((update) => {\n const taggedUpdate: PriceUpdate = { ...update, providerId };\n\n // Initialize symbol cache if needed\n if (!this.priceCache.has(update.symbol)) {\n this.priceCache.set(update.symbol, new Map());\n }\n const symbolCache = this.priceCache.get(update.symbol);\n if (symbolCache) {\n symbolCache.set(providerId, taggedUpdate);\n }\n });\n\n // Aggregate and emit based on mode\n const aggregated = this.aggregatePrices(symbols, aggregationMode);\n callback(aggregated);\n },\n throttleMs,\n includeOrderBook,\n includeMarketData,\n };\n\n const unsub = provider.subscribeToPrices(subscribeParams);\n unsubscribers.push(unsub);\n } catch (caughtError) {\n // Log to Sentry before cleanup\n const errorObj =\n caughtError instanceof Error\n ? caughtError\n : new Error(String(caughtError));\n this.logger?.error(errorObj, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n provider: providerId,\n method: 'subscribeToPrices',\n },\n context: {\n name: 'SubscriptionMultiplexer',\n data: { subscribedCount: unsubscribers.length },\n },\n });\n\n // Clean up any subscriptions created before the failure\n unsubscribers.forEach((unsub) => unsub());\n throw caughtError;\n }\n }\n\n // Return combined unsubscribe function\n return () => {\n unsubscribers.forEach((unsub) => unsub());\n // Optionally clear cache for these symbols\n symbols.forEach((symbol) => {\n this.priceCache.delete(symbol);\n });\n };\n }\n\n /**\n * Subscribe to position updates from multiple providers.\n *\n * @param params - Subscription parameters\n * @returns Unsubscribe function\n */\n subscribeToPositions(params: MultiplexedPositionsParams): () => void {\n const { providers, callback } = params;\n const unsubscribers: (() => void)[] = [];\n\n for (const [providerId, provider] of providers) {\n try {\n const subscribeParams: SubscribePositionsParams = {\n callback: (positions) => {\n // Tag positions with providerId and cache\n const taggedPositions = positions.map((pos) => ({\n ...pos,\n providerId,\n }));\n this.positionCache.set(providerId, taggedPositions);\n\n // Emit aggregated positions from all providers\n const allPositions = this.aggregatePositions();\n callback(allPositions);\n },\n };\n\n const unsub = provider.subscribeToPositions(subscribeParams);\n unsubscribers.push(unsub);\n } catch (caughtError) {\n const errorObj =\n caughtError instanceof Error\n ? caughtError\n : new Error(String(caughtError));\n this.logger?.error(errorObj, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n provider: providerId,\n method: 'subscribeToPositions',\n },\n context: {\n name: 'SubscriptionMultiplexer',\n data: { subscribedCount: unsubscribers.length },\n },\n });\n unsubscribers.forEach((unsub) => unsub());\n throw caughtError;\n }\n }\n\n return () => {\n unsubscribers.forEach((unsub) => unsub());\n // Clear position cache for these providers\n providers.forEach(([providerId]) => {\n this.positionCache.delete(providerId);\n });\n };\n }\n\n /**\n * Subscribe to order fill updates from multiple providers.\n *\n * @param params - Subscription parameters\n * @returns Unsubscribe function\n */\n subscribeToOrderFills(params: MultiplexedOrderFillsParams): () => void {\n const { providers, callback } = params;\n const unsubscribers: (() => void)[] = [];\n\n for (const [providerId, provider] of providers) {\n try {\n const subscribeParams: SubscribeOrderFillsParams = {\n callback: (fills, isSnapshot) => {\n // Tag fills with providerId\n const taggedFills = fills.map((fill) => ({\n ...fill,\n providerId,\n }));\n\n // For fills, we don't aggregate - emit immediately with tags\n callback(taggedFills, isSnapshot);\n },\n };\n\n const unsub = provider.subscribeToOrderFills(subscribeParams);\n unsubscribers.push(unsub);\n } catch (caughtError) {\n const errorObj =\n caughtError instanceof Error\n ? caughtError\n : new Error(String(caughtError));\n this.logger?.error(errorObj, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n provider: providerId,\n method: 'subscribeToOrderFills',\n },\n context: {\n name: 'SubscriptionMultiplexer',\n data: { subscribedCount: unsubscribers.length },\n },\n });\n unsubscribers.forEach((unsub) => unsub());\n throw caughtError;\n }\n }\n\n return () => {\n unsubscribers.forEach((unsub) => unsub());\n };\n }\n\n /**\n * Subscribe to order updates from multiple providers.\n *\n * @param params - Subscription parameters\n * @returns Unsubscribe function\n */\n subscribeToOrders(params: MultiplexedOrdersParams): () => void {\n const { providers, callback } = params;\n const unsubscribers: (() => void)[] = [];\n\n for (const [providerId, provider] of providers) {\n try {\n const subscribeParams: SubscribeOrdersParams = {\n callback: (orders) => {\n // Tag orders with providerId and cache\n const taggedOrders = orders.map((order) => ({\n ...order,\n providerId,\n }));\n this.orderCache.set(providerId, taggedOrders);\n\n // Emit aggregated orders from all providers\n const allOrders = this.aggregateOrders();\n callback(allOrders);\n },\n };\n\n const unsub = provider.subscribeToOrders(subscribeParams);\n unsubscribers.push(unsub);\n } catch (caughtError) {\n const errorObj =\n caughtError instanceof Error\n ? caughtError\n : new Error(String(caughtError));\n this.logger?.error(errorObj, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n provider: providerId,\n method: 'subscribeToOrders',\n },\n context: {\n name: 'SubscriptionMultiplexer',\n data: { subscribedCount: unsubscribers.length },\n },\n });\n unsubscribers.forEach((unsub) => unsub());\n throw caughtError;\n }\n }\n\n return () => {\n unsubscribers.forEach((unsub) => unsub());\n providers.forEach(([providerId]) => {\n this.orderCache.delete(providerId);\n });\n };\n }\n\n /**\n * Subscribe to account updates from multiple providers.\n *\n * @param params - Subscription parameters\n * @returns Unsubscribe function\n */\n subscribeToAccount(params: MultiplexedAccountParams): () => void {\n const { providers, callback } = params;\n const unsubscribers: (() => void)[] = [];\n\n for (const [providerId, provider] of providers) {\n try {\n const subscribeParams: SubscribeAccountParams = {\n callback: (account) => {\n // Tag account with providerId and cache\n const taggedAccount: AccountState = { ...account, providerId };\n this.accountCache.set(providerId, taggedAccount);\n\n // Emit all cached account states\n const allAccounts = Array.from(this.accountCache.values());\n callback(allAccounts);\n },\n };\n\n const unsub = provider.subscribeToAccount(subscribeParams);\n unsubscribers.push(unsub);\n } catch (caughtError) {\n const errorObj =\n caughtError instanceof Error\n ? caughtError\n : new Error(String(caughtError));\n this.logger?.error(errorObj, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n provider: providerId,\n method: 'subscribeToAccount',\n },\n context: {\n name: 'SubscriptionMultiplexer',\n data: { subscribedCount: unsubscribers.length },\n },\n });\n unsubscribers.forEach((unsub) => unsub());\n throw caughtError;\n }\n }\n\n return () => {\n unsubscribers.forEach((unsub) => unsub());\n providers.forEach(([providerId]) => {\n this.accountCache.delete(providerId);\n });\n };\n }\n\n /**\n * Aggregate cached prices based on mode.\n *\n * @param symbols - Symbols to include in result\n * @param mode - Aggregation mode\n * @returns Aggregated price updates\n */\n private aggregatePrices(\n symbols: string[],\n mode: PriceAggregationMode,\n ): PriceUpdate[] {\n const result: PriceUpdate[] = [];\n\n symbols.forEach((symbol) => {\n const providerPrices = this.priceCache.get(symbol);\n if (!providerPrices || providerPrices.size === 0) {\n return;\n }\n\n if (mode === 'merge') {\n // Return all prices (one per provider)\n providerPrices.forEach((price) => {\n result.push(price);\n });\n } else {\n // 'best_price': Return the best price across providers\n const best = this.findBestPrice(providerPrices);\n if (best) {\n result.push(best);\n }\n }\n });\n\n return result;\n }\n\n /**\n * Find the best price from multiple provider prices.\n * \"Best\" is defined as the price with the smallest spread.\n *\n * @param providerPrices - Map of provider prices for a symbol\n * @returns Best price update or undefined\n */\n private findBestPrice(\n providerPrices: Map<PerpsProviderType, PriceUpdate>,\n ): PriceUpdate | undefined {\n let bestPrice: PriceUpdate | undefined;\n let smallestSpread = Infinity;\n\n providerPrices.forEach((price) => {\n // If spread is available, use it to determine best\n if (price.spread !== undefined) {\n const spreadValue = parseFloat(price.spread);\n if (!isNaN(spreadValue) && spreadValue < smallestSpread) {\n smallestSpread = spreadValue;\n bestPrice = price;\n }\n } else if (!bestPrice) {\n // No spread info - just use the first one\n bestPrice = price;\n }\n });\n\n return bestPrice;\n }\n\n /**\n * Aggregate positions from all providers.\n *\n * @returns All cached positions\n */\n private aggregatePositions(): Position[] {\n const allPositions: Position[] = [];\n this.positionCache.forEach((positions) => {\n allPositions.push(...positions);\n });\n return allPositions;\n }\n\n /**\n * Aggregate orders from all providers.\n *\n * @returns All cached orders\n */\n private aggregateOrders(): Order[] {\n const allOrders: Order[] = [];\n this.orderCache.forEach((orders) => {\n allOrders.push(...orders);\n });\n return allOrders;\n }\n\n /**\n * Clear all cached data.\n */\n clearCache(): void {\n this.priceCache.clear();\n this.positionCache.clear();\n this.orderCache.clear();\n this.accountCache.clear();\n }\n\n /**\n * Get cached price for a symbol from a specific provider.\n *\n * @param symbol - Market symbol\n * @param providerId - Provider ID\n * @returns Cached price update or undefined\n */\n getCachedPrice(\n symbol: string,\n providerId: PerpsProviderType,\n ): PriceUpdate | undefined {\n return this.priceCache.get(symbol)?.get(providerId);\n }\n\n /**\n * Get all cached prices for a symbol.\n *\n * @param symbol - Market symbol\n * @returns Map of provider ID to price update\n */\n getAllCachedPricesForSymbol(\n symbol: string,\n ): Map<PerpsProviderType, PriceUpdate> | undefined {\n return this.priceCache.get(symbol);\n }\n}\n"]}
|