@metamask-previews/perps-controller 23.1.0-preview-d0ecc4dd6 → 23.1.0-preview-fe3c580ff
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 +58 -0
- package/README.md +35 -0
- package/dist/PerpsController-method-action-types.d.ts +96 -7
- package/dist/PerpsController-method-action-types.d.ts.map +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -1
- package/dist/PerpsController.d.ts +131 -52
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +854 -54
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/lighterConfig.d.ts +4 -0
- package/dist/constants/lighterConfig.d.ts.map +1 -1
- package/dist/constants/lighterConfig.js +4 -0
- package/dist/constants/lighterConfig.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/perpsErrorCodes.d.ts +1 -0
- package/dist/perpsErrorCodes.d.ts.map +1 -1
- package/dist/perpsErrorCodes.js +2 -0
- package/dist/perpsErrorCodes.js.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts +31 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.js +250 -38
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts +20 -1
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +227 -67
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/providers/LighterProvider.d.ts +3 -1
- package/dist/providers/LighterProvider.d.ts.map +1 -1
- package/dist/providers/LighterProvider.js +100 -2
- package/dist/providers/LighterProvider.js.map +1 -1
- package/dist/routing/isPerpsProviderType.d.ts +10 -0
- package/dist/routing/isPerpsProviderType.d.ts.map +1 -0
- package/dist/routing/isPerpsProviderType.js +11 -0
- package/dist/routing/isPerpsProviderType.js.map +1 -0
- package/dist/routing/resolveTradeConfigProviderKey.d.ts +22 -0
- package/dist/routing/resolveTradeConfigProviderKey.d.ts.map +1 -0
- package/dist/routing/resolveTradeConfigProviderKey.js +25 -0
- package/dist/routing/resolveTradeConfigProviderKey.js.map +1 -0
- package/dist/selectors.d.ts +35 -233
- package/dist/selectors.d.ts.map +1 -1
- package/dist/selectors.js +36 -13
- package/dist/selectors.js.map +1 -1
- package/dist/services/HyperLiquidClientService.d.ts +26 -0
- package/dist/services/HyperLiquidClientService.d.ts.map +1 -1
- package/dist/services/HyperLiquidClientService.js +73 -0
- package/dist/services/HyperLiquidClientService.js.map +1 -1
- package/dist/services/LighterClientService.d.ts +9 -1
- package/dist/services/LighterClientService.d.ts.map +1 -1
- package/dist/services/LighterClientService.js +32 -1
- package/dist/services/LighterClientService.js.map +1 -1
- package/dist/services/MarketDataService.d.ts.map +1 -1
- package/dist/services/MarketDataService.js +12 -6
- package/dist/services/MarketDataService.js.map +1 -1
- package/dist/services/ServiceContext.d.ts +15 -3
- package/dist/services/ServiceContext.d.ts.map +1 -1
- package/dist/services/ServiceContext.js.map +1 -1
- package/dist/services/TradingService.d.ts +3 -1
- package/dist/services/TradingService.d.ts.map +1 -1
- package/dist/services/TradingService.js +9 -4
- package/dist/services/TradingService.js.map +1 -1
- package/dist/types/hyperliquid-types.d.ts +2 -1
- package/dist/types/hyperliquid-types.d.ts.map +1 -1
- package/dist/types/hyperliquid-types.js.map +1 -1
- package/dist/types/index.d.ts +125 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/lighter-types.d.ts +31 -0
- package/dist/types/lighter-types.d.ts.map +1 -1
- package/dist/types/lighter-types.js.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.ts +14 -2
- package/dist/utils/hyperLiquidAdapter.d.ts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.js +41 -0
- package/dist/utils/hyperLiquidAdapter.js.map +1 -1
- package/dist/utils/lighterAdapter.d.ts +13 -1
- package/dist/utils/lighterAdapter.d.ts.map +1 -1
- package/dist/utils/lighterAdapter.js +47 -0
- package/dist/utils/lighterAdapter.js.map +1 -1
- package/dist/utils/publicTrades.d.ts +30 -0
- package/dist/utils/publicTrades.d.ts.map +1 -0
- package/dist/utils/publicTrades.js +45 -0
- package/dist/utils/publicTrades.js.map +1 -0
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import type { CaipAccountId } from '@metamask/utils';
|
|
17
17
|
import { ProviderRouter } from '../routing/ProviderRouter.js';
|
|
18
18
|
import { WebSocketConnectionState } from '../types/index.js';
|
|
19
|
-
import type { AccountState, AggregatedProviderConfig, AssetRoute, BatchCancelOrdersParams, CancelOrderParams, CancelOrderResult, CancelOrdersResult, ChaseOrder, GetChaseOrderOwnershipParams, ReconcileChaseOrderCancellationParams, ReconcileChaseOrderCancellationResult, PerpsChaseOrderOwnership, ClosePositionParams, ClosePositionsParams, ClosePositionsResult, DepositParams, DisconnectResult, EditOrderParams, FeeCalculationParams, FeeCalculationResult, Funding, GetAccountStateParams, GetAccountSupportParams, GetAvailableDexsParams, GetFundingParams, GetHistoricalPortfolioParams, GetMarketsParams, GetOrderCapabilitiesParams, GetMarginModeLockParams, GetScalePriceLadderParams, GetOrderFillsParams, GetOrdersParams, GetOrFetchFillsParams, GetPositionsParams, GetSupportedPathsParams, HistoricalPortfolioResult, InitializeResult, PerpsProvider, LiquidationPriceParams, LiveDataConfig, MaintenanceMarginParams, PositionModifyPreviewParams, PositionModifyPreviewResult, MarginResult, MarketInfo, Order, OrderFill, OrderParams, OrderResult, PerpsMarketData, PerpsAccountSupport, PerpsOrderCapabilities, PerpsMarginModeLock, PerpsScalePriceLadder, PerpsPendingManualRecovery, PerpsRecoveredDispatch, AttachedOrderGroup, PerpsRecoveryVenueReview, ScaleOrderGroup, ResolveRecoveryProtectionParams, PerpsRecoveryProtectionResult, PerpsProviderType, Position, ReadyToTradeResult, SubscribeAccountParams, SubscribeCandlesParams, SubscribeOICapsParams, SubscribeAvailableToTradeParams, SubscribeOrderBookParams, SubscribeOrderFillsParams, SubscribeOrdersParams, SubscribeTwapOrdersParams, SubscribePositionsParams, SubscribePricesParams, ToggleTestnetResult, TwapOrder, UpdateMarginParams, UpdatePositionTPSLParams, ReplacePositionTPSLLegParams, UserHistoryItem, WithdrawParams, WithdrawResult, RawLedgerUpdate, PerpsReadOptions, PerpsFeeResolution } from '../types/index.js';
|
|
19
|
+
import type { AccountState, AggregatedProviderConfig, AssetRoute, BatchCancelOrdersParams, CancelOrderParams, CancelOrderResult, CancelOrdersResult, ChaseOrder, GetChaseOrderOwnershipParams, ReconcileChaseOrderCancellationParams, ReconcileChaseOrderCancellationResult, PerpsChaseOrderOwnership, ClosePositionParams, ClosePositionsParams, ClosePositionsResult, DepositParams, DisconnectResult, EditOrderParams, FeeCalculationParams, FeeCalculationResult, Funding, GetAccountStateParams, GetAccountSupportParams, GetAvailableDexsParams, GetFundingParams, GetHistoricalPortfolioParams, GetMarketsParams, GetOrderCapabilitiesParams, GetMarginModeLockParams, GetScalePriceLadderParams, GetOrderFillsParams, GetPublicTradesParams, GetOrdersParams, GetOrFetchFillsParams, GetPositionsParams, GetSupportedPathsParams, HistoricalPortfolioResult, InitializeResult, PerpsProvider, LiquidationPriceParams, LiveDataConfig, MaintenanceMarginParams, PositionModifyPreviewParams, PositionModifyPreviewResult, MarginResult, MarketInfo, Order, OrderFill, PublicTrade, OrderParams, OrderResult, PerpsMarketData, PerpsAccountSupport, PerpsOrderCapabilities, PerpsMarginModeLock, PerpsScalePriceLadder, PerpsPendingManualRecovery, PerpsRecoveredDispatch, AttachedOrderGroup, PerpsRecoveryVenueReview, ScaleOrderGroup, ResolveRecoveryProtectionParams, PerpsRecoveryProtectionResult, PerpsProviderType, Position, ReadyToTradeResult, SubscribeAccountParams, SubscribeCandlesParams, SubscribeOICapsParams, SubscribeAvailableToTradeParams, SubscribeOrderBookParams, SubscribeOrderFillsParams, SubscribeOrdersParams, SubscribeTwapOrdersParams, SubscribePositionsParams, SubscribePricesParams, SubscribePublicTradesParams, ToggleTestnetResult, TwapOrder, UpdateMarginParams, UpdatePositionTPSLParams, ReplacePositionTPSLLegParams, UserHistoryItem, WithdrawParams, WithdrawResult, RawLedgerUpdate, PerpsReadOptions, PerpsFeeResolution } from '../types/index.js';
|
|
20
20
|
/** Error returned when only some providers suspend their Chase orders. */
|
|
21
21
|
export declare class ChaseOrderSuspensionError extends Error {
|
|
22
22
|
readonly suspendedOrders: ChaseOrder[];
|
|
@@ -77,6 +77,16 @@ export declare class AggregatedPerpsProvider implements PerpsProvider {
|
|
|
77
77
|
* @returns The provider id the write will be submitted through.
|
|
78
78
|
*/
|
|
79
79
|
getWriteProviderId(providerId?: PerpsProviderType): PerpsProviderType;
|
|
80
|
+
/**
|
|
81
|
+
* Change the default provider used when an operation does not name a venue.
|
|
82
|
+
*
|
|
83
|
+
* Only the routing default changes: no provider is re-initialized and no
|
|
84
|
+
* stream is reconnected, so the call is synchronous.
|
|
85
|
+
*
|
|
86
|
+
* @param providerId - New default provider. Must be registered.
|
|
87
|
+
* @throws If the provider is not registered.
|
|
88
|
+
*/
|
|
89
|
+
setDefaultProvider(providerId: PerpsProviderType): void;
|
|
80
90
|
getDepositRoutes(params?: GetSupportedPathsParams): AssetRoute[];
|
|
81
91
|
getWithdrawalRoutes(params?: GetSupportedPathsParams): AssetRoute[];
|
|
82
92
|
/**
|
|
@@ -320,6 +330,26 @@ export declare class AggregatedPerpsProvider implements PerpsProvider {
|
|
|
320
330
|
subscribeToOICaps(params: SubscribeOICapsParams): () => void;
|
|
321
331
|
subscribeToCandles(params: SubscribeCandlesParams): () => void;
|
|
322
332
|
subscribeToOrderBook(params: SubscribeOrderBookParams): () => void;
|
|
333
|
+
/**
|
|
334
|
+
* Read public trades from the explicit route, else the default provider.
|
|
335
|
+
* An unrouted read resolves to an empty list if the default changes before
|
|
336
|
+
* the venue answers.
|
|
337
|
+
*
|
|
338
|
+
* @param params - Market, optional limit and route.
|
|
339
|
+
* @returns The route's trades, newest first.
|
|
340
|
+
* @throws If the route is not registered or has no public trade feed.
|
|
341
|
+
*/
|
|
342
|
+
getPublicTrades(params: GetPublicTradesParams): Promise<PublicTrade[]>;
|
|
343
|
+
/**
|
|
344
|
+
* Stream public trades from the explicit route, else the default provider.
|
|
345
|
+
* An unrouted stream follows the default and moves with it. A missing
|
|
346
|
+
* route or one without a public trade feed returns a no-op cleanup and
|
|
347
|
+
* never calls back.
|
|
348
|
+
*
|
|
349
|
+
* @param params - Market, optional route, callback and error handler.
|
|
350
|
+
* @returns A cleanup function to unsubscribe.
|
|
351
|
+
*/
|
|
352
|
+
subscribeToPublicTrades(params: SubscribePublicTradesParams): () => void;
|
|
323
353
|
/**
|
|
324
354
|
* Stream available to trade from the explicit route, else the default
|
|
325
355
|
* provider, as order placement routes. A route without support returns a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AggregatedPerpsProvider.d.ts","sourceRoot":"","sources":["../../src/providers/AggregatedPerpsProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMrD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EAExB,UAAU,EACV,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,4BAA4B,EAC5B,qCAAqC,EACrC,qCAAqC,EACrC,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,OAAO,EACP,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,EACh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ACF;
|
|
1
|
+
{"version":3,"file":"AggregatedPerpsProvider.d.ts","sourceRoot":"","sources":["../../src/providers/AggregatedPerpsProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMrD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EAExB,UAAU,EACV,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,4BAA4B,EAC5B,qCAAqC,EACrC,qCAAqC,EACrC,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,OAAO,EACP,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,gBAAgB,EAChB,0BAA0B,EAC1B,uBAAuB,EACvB,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,gBAAgB,EAEhB,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,YAAY,EACZ,UAAU,EACV,KAAK,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,+BAA+B,EAC/B,6BAA6B,EAC7B,iBAAiB,EACjB,QAAQ,EACR,kBAAkB,EAClB,sBAAsB,EAC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AI,OAAO,CAAC,kBAAkB,CAAC,CAElD;IAED;;;;;;;OAOG;IACG,oBAAoB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAqCxD;IAEK,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAiB5C;IAEK,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5C;IAED,2BAA2B,IAAI,wBAAwB,CAMtD;IAED,0BAA0B,CACxB,QAAQ,EAAE,CACR,KAAK,EAAE,wBAAwB,EAC/B,mBAAmB,EAAE,MAAM,KACxB,IAAI,GACR,MAAM,IAAI,CAcZ;IAEK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAK/B;IAMD,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;IAMK,gBAAgB,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAMzE;IAMD;;;;;OAKG;IACH,WAAW,CAAC,UAAU,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAKxE;IAED;;;;;OAKG;IACH,cAAc,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAQrD;IAED;;;;OAIG;IACH,cAAc,IAAI,iBAAiB,EAAE,CAEpC;IAED;;;;;OAKG;IACH,WAAW,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAElD;IAED;;;;OAIG;IACH,SAAS,IAAI,cAAc,CAE1B;CACF"}
|
|
@@ -67,12 +67,15 @@ export class AggregatedPerpsProvider {
|
|
|
67
67
|
protocolId = 'aggregated';
|
|
68
68
|
routesOrdersByProviderId = true;
|
|
69
69
|
#providers;
|
|
70
|
+
/** Default provider used when an operation does not name a venue. */
|
|
70
71
|
#defaultProvider;
|
|
71
72
|
#aggregationMode;
|
|
72
73
|
#deps;
|
|
73
74
|
#isTestnet;
|
|
74
75
|
#router;
|
|
75
76
|
#subscriptionMux;
|
|
77
|
+
/** Streams that follow the routing default and must move with it. */
|
|
78
|
+
#defaultRoutedSubscriptions = new Set();
|
|
76
79
|
constructor(config) {
|
|
77
80
|
this.#providers = config.providers;
|
|
78
81
|
this.#defaultProvider = config.defaultProvider;
|
|
@@ -132,6 +135,135 @@ export class AggregatedPerpsProvider {
|
|
|
132
135
|
getWriteProviderId(providerId) {
|
|
133
136
|
return providerId ?? this.#defaultProvider;
|
|
134
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Change the default provider used when an operation does not name a venue.
|
|
140
|
+
*
|
|
141
|
+
* Only the routing default changes: no provider is re-initialized and no
|
|
142
|
+
* stream is reconnected, so the call is synchronous.
|
|
143
|
+
*
|
|
144
|
+
* @param providerId - New default provider. Must be registered.
|
|
145
|
+
* @throws If the provider is not registered.
|
|
146
|
+
*/
|
|
147
|
+
setDefaultProvider(providerId) {
|
|
148
|
+
if (!this.#providers.has(providerId)) {
|
|
149
|
+
throw new Error(`[AggregatedPerpsProvider] Default provider '${providerId}' not available`);
|
|
150
|
+
}
|
|
151
|
+
const changed = providerId !== this.#defaultProvider;
|
|
152
|
+
if (changed) {
|
|
153
|
+
this.#defaultProvider = providerId;
|
|
154
|
+
this.#router.setDefaultProvider(providerId);
|
|
155
|
+
}
|
|
156
|
+
// Runs even when the default is unchanged so a stream that failed to
|
|
157
|
+
// re-open earlier is retried instead of staying detached.
|
|
158
|
+
this.#rerouteDefaultSubscriptions();
|
|
159
|
+
if (changed) {
|
|
160
|
+
this.#deps.debugLogger.log('[AggregatedPerpsProvider] Default provider changed', { defaultProvider: providerId });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Register a stream that follows the routing default.
|
|
165
|
+
*
|
|
166
|
+
* The returned cleanup detaches the stream from whichever venue it is
|
|
167
|
+
* currently open on, so it stays valid across a default change.
|
|
168
|
+
*
|
|
169
|
+
* @param options - Stream options.
|
|
170
|
+
* @param options.open - Opens the stream on a given provider.
|
|
171
|
+
* @param options.onInvalidate - Invalidates a consumer's cached value before
|
|
172
|
+
* the stream moves (for example, emits an unavailable account snapshot).
|
|
173
|
+
* @returns A cleanup function that closes the stream.
|
|
174
|
+
*/
|
|
175
|
+
#trackDefaultRoutedSubscription(options) {
|
|
176
|
+
const subscription = {
|
|
177
|
+
open: options.open,
|
|
178
|
+
onInvalidate: options.onInvalidate,
|
|
179
|
+
unsubscribe: () => undefined,
|
|
180
|
+
providerId: this.#defaultProvider,
|
|
181
|
+
failed: false,
|
|
182
|
+
};
|
|
183
|
+
// Initial open failures propagate to the caller, matching the previous
|
|
184
|
+
// contract for these subscribe methods.
|
|
185
|
+
subscription.unsubscribe = options.open(this.#getDefaultProvider());
|
|
186
|
+
this.#defaultRoutedSubscriptions.add(subscription);
|
|
187
|
+
return () => {
|
|
188
|
+
if (!this.#defaultRoutedSubscriptions.delete(subscription)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
subscription.unsubscribe();
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Move every default-routed stream to the current default venue.
|
|
196
|
+
*
|
|
197
|
+
* Only the stream's subscription is torn down and re-opened; the venue
|
|
198
|
+
* transports stay connected. The caller's cleanup function keeps working.
|
|
199
|
+
*/
|
|
200
|
+
#rerouteDefaultSubscriptions() {
|
|
201
|
+
if (this.#defaultRoutedSubscriptions.size === 0) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const target = this.#defaultProvider;
|
|
205
|
+
for (const subscription of this.#defaultRoutedSubscriptions) {
|
|
206
|
+
if (!subscription.failed && subscription.providerId === target) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
this.#rerouteSubscription(subscription);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Re-open one stream on the current default, isolating its failure from the
|
|
214
|
+
* other subscriptions. A stream that throws is marked failed and retried on
|
|
215
|
+
* the next `setDefaultProvider` call.
|
|
216
|
+
*
|
|
217
|
+
* @param subscription - The stream to move.
|
|
218
|
+
*/
|
|
219
|
+
#rerouteSubscription(subscription) {
|
|
220
|
+
const providerId = this.#defaultProvider;
|
|
221
|
+
const { unsubscribe } = subscription;
|
|
222
|
+
subscription.unsubscribe = () => undefined;
|
|
223
|
+
try {
|
|
224
|
+
unsubscribe();
|
|
225
|
+
}
|
|
226
|
+
catch (caughtError) {
|
|
227
|
+
this.#logSubscriptionRerouteError(caughtError, 'unsubscribe', providerId);
|
|
228
|
+
}
|
|
229
|
+
subscription.providerId = undefined;
|
|
230
|
+
if (subscription.onInvalidate) {
|
|
231
|
+
try {
|
|
232
|
+
subscription.onInvalidate();
|
|
233
|
+
}
|
|
234
|
+
catch (caughtError) {
|
|
235
|
+
this.#logSubscriptionRerouteError(caughtError, 'onInvalidate', providerId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
subscription.unsubscribe = subscription.open(this.#getDefaultProvider());
|
|
240
|
+
subscription.providerId = providerId;
|
|
241
|
+
subscription.failed = false;
|
|
242
|
+
}
|
|
243
|
+
catch (caughtError) {
|
|
244
|
+
subscription.failed = true;
|
|
245
|
+
this.#logSubscriptionRerouteError(caughtError, 'open', providerId);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Report a default-routed subscription that could not be moved.
|
|
250
|
+
*
|
|
251
|
+
* @param caughtError - The thrown error.
|
|
252
|
+
* @param method - Which step failed.
|
|
253
|
+
* @param providerId - The venue the stream was moving to.
|
|
254
|
+
*/
|
|
255
|
+
#logSubscriptionRerouteError(caughtError, method, providerId) {
|
|
256
|
+
this.#deps.logger.error(ensureError(caughtError, 'AggregatedPerpsProvider.rerouteSubscription'), {
|
|
257
|
+
tags: {
|
|
258
|
+
feature: PERPS_CONSTANTS.FeatureName,
|
|
259
|
+
provider: providerId,
|
|
260
|
+
},
|
|
261
|
+
context: {
|
|
262
|
+
name: 'AggregatedPerpsProvider',
|
|
263
|
+
data: { method: `subscription.${method}`, providerId },
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
}
|
|
135
267
|
/**
|
|
136
268
|
* Get the explicit provider, or the default when no route was supplied.
|
|
137
269
|
*
|
|
@@ -326,10 +458,13 @@ export class AggregatedPerpsProvider {
|
|
|
326
458
|
return this.#extractSuccessfulResults(results, 'getPositions').flat();
|
|
327
459
|
}
|
|
328
460
|
async getAccountState(params) {
|
|
329
|
-
//
|
|
461
|
+
// Capture the route before awaiting: `setDefaultProvider` can run while
|
|
462
|
+
// the venue request is in flight, and the response must stay attributed to
|
|
463
|
+
// the provider that served it (the user-data preloader buckets by this id).
|
|
464
|
+
const providerId = this.#defaultProvider;
|
|
330
465
|
const provider = this.#getDefaultProvider();
|
|
331
466
|
const state = await provider.getAccountState(params);
|
|
332
|
-
return { ...state, providerId
|
|
467
|
+
return { ...state, providerId };
|
|
333
468
|
}
|
|
334
469
|
async getMarkets(params) {
|
|
335
470
|
const results = await Promise.allSettled(this.#getActiveProviders().map(async ([id, provider]) => {
|
|
@@ -882,42 +1017,103 @@ export class AggregatedPerpsProvider {
|
|
|
882
1017
|
* native TWAP push channel.
|
|
883
1018
|
*/
|
|
884
1019
|
subscribeToTwapOrders(params) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1020
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1021
|
+
// A full empty snapshot replaces the previous venue's cached schedules,
|
|
1022
|
+
// including when the new venue exposes no native TWAP stream.
|
|
1023
|
+
onInvalidate: () => params.callback([], true),
|
|
1024
|
+
open: (provider) => {
|
|
1025
|
+
if (!provider.subscribeToTwapOrders) {
|
|
1026
|
+
return () => {
|
|
1027
|
+
// No-op: default provider exposes no native TWAP push channel
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
// Capture each stream's route so late batches from the old venue keep
|
|
1031
|
+
// their source identity during teardown or after a default change.
|
|
1032
|
+
const providerId = this.#defaultProvider;
|
|
1033
|
+
return provider.subscribeToTwapOrders({
|
|
1034
|
+
...params,
|
|
1035
|
+
// Stamp the same way getTwapOrders does, so swapping a poll for this
|
|
1036
|
+
// subscription does not silently drop providerId from every schedule.
|
|
1037
|
+
callback: (twapOrders, isSnapshot) => params.callback(twapOrders.map((order) => ({
|
|
1038
|
+
...order,
|
|
1039
|
+
providerId,
|
|
1040
|
+
})), isSnapshot),
|
|
1041
|
+
});
|
|
1042
|
+
},
|
|
902
1043
|
});
|
|
903
1044
|
}
|
|
904
1045
|
subscribeToAccount(params) {
|
|
905
|
-
//
|
|
906
|
-
//
|
|
907
|
-
|
|
908
|
-
|
|
1046
|
+
// Account, candles, order book and OI caps have no per-venue route of
|
|
1047
|
+
// their own, so they follow the routing default and move with it.
|
|
1048
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1049
|
+
open: (provider) => provider.subscribeToAccount(params),
|
|
1050
|
+
// Emit an unavailable snapshot so a consumer that caches the balance
|
|
1051
|
+
// (for example Mobile's account stream channel) does not keep showing
|
|
1052
|
+
// the previous venue's value while the new venue's first update pends.
|
|
1053
|
+
onInvalidate: () => params.callback(null),
|
|
1054
|
+
});
|
|
909
1055
|
}
|
|
910
1056
|
subscribeToOICaps(params) {
|
|
911
|
-
|
|
912
|
-
|
|
1057
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1058
|
+
open: (provider) => provider.subscribeToOICaps(params),
|
|
1059
|
+
});
|
|
913
1060
|
}
|
|
914
1061
|
subscribeToCandles(params) {
|
|
915
|
-
|
|
916
|
-
|
|
1062
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1063
|
+
open: (provider) => provider.subscribeToCandles(params),
|
|
1064
|
+
});
|
|
917
1065
|
}
|
|
918
1066
|
subscribeToOrderBook(params) {
|
|
919
|
-
|
|
920
|
-
|
|
1067
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1068
|
+
open: (provider) => provider.subscribeToOrderBook(params),
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Read public trades from the explicit route, else the default provider.
|
|
1073
|
+
* An unrouted read resolves to an empty list if the default changes before
|
|
1074
|
+
* the venue answers.
|
|
1075
|
+
*
|
|
1076
|
+
* @param params - Market, optional limit and route.
|
|
1077
|
+
* @returns The route's trades, newest first.
|
|
1078
|
+
* @throws If the route is not registered or has no public trade feed.
|
|
1079
|
+
*/
|
|
1080
|
+
async getPublicTrades(params) {
|
|
1081
|
+
const [providerId, provider] = this.#getProviderOrDefault(params.providerId);
|
|
1082
|
+
if (!provider.getPublicTrades) {
|
|
1083
|
+
throw new Error(`Public trades not supported by provider ${providerId}`);
|
|
1084
|
+
}
|
|
1085
|
+
const trades = await provider.getPublicTrades({ ...params, providerId });
|
|
1086
|
+
if (params.providerId === undefined &&
|
|
1087
|
+
providerId !== this.#defaultProvider) {
|
|
1088
|
+
return [];
|
|
1089
|
+
}
|
|
1090
|
+
return trades;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Stream public trades from the explicit route, else the default provider.
|
|
1094
|
+
* An unrouted stream follows the default and moves with it. A missing
|
|
1095
|
+
* route or one without a public trade feed returns a no-op cleanup and
|
|
1096
|
+
* never calls back.
|
|
1097
|
+
*
|
|
1098
|
+
* @param params - Market, optional route, callback and error handler.
|
|
1099
|
+
* @returns A cleanup function to unsubscribe.
|
|
1100
|
+
*/
|
|
1101
|
+
subscribeToPublicTrades(params) {
|
|
1102
|
+
if (params.providerId === undefined) {
|
|
1103
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1104
|
+
open: (defaultProvider) => defaultProvider.subscribeToPublicTrades?.({
|
|
1105
|
+
...params,
|
|
1106
|
+
providerId: this.#defaultProvider,
|
|
1107
|
+
}) ?? (() => undefined),
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
const provider = this.#providers.get(params.providerId);
|
|
1111
|
+
if (!provider?.subscribeToPublicTrades) {
|
|
1112
|
+
return () => {
|
|
1113
|
+
// No-op: route missing or without a public trade feed
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
return provider.subscribeToPublicTrades(params);
|
|
921
1117
|
}
|
|
922
1118
|
/**
|
|
923
1119
|
* Stream available to trade from the explicit route, else the default
|
|
@@ -928,7 +1124,18 @@ export class AggregatedPerpsProvider {
|
|
|
928
1124
|
* @returns A cleanup function to unsubscribe.
|
|
929
1125
|
*/
|
|
930
1126
|
subscribeToAvailableToTrade(params) {
|
|
931
|
-
|
|
1127
|
+
if (params.providerId === undefined) {
|
|
1128
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1129
|
+
open: (provider) => provider.subscribeToAvailableToTrade?.({
|
|
1130
|
+
...params,
|
|
1131
|
+
providerId: this.#defaultProvider,
|
|
1132
|
+
}) ?? (() => undefined),
|
|
1133
|
+
// As with a stopped stream, the old venue's value is now unknown.
|
|
1134
|
+
// Notify before opening the new stream, which may emit immediately.
|
|
1135
|
+
onInvalidate: () => params.onError?.(new Error('Available-to-trade provider changed; value is unknown')),
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
const { providerId } = params;
|
|
932
1139
|
// Read the map directly: #getProviderOrDefault throws when the route is
|
|
933
1140
|
// unavailable, and this method's contract is a no-op cleanup.
|
|
934
1141
|
const provider = this.#providers.get(providerId);
|
|
@@ -1058,14 +1265,19 @@ export class AggregatedPerpsProvider {
|
|
|
1058
1265
|
return WebSocketConnectionState.Disconnected;
|
|
1059
1266
|
}
|
|
1060
1267
|
subscribeToConnectionState(listener) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1268
|
+
return this.#trackDefaultRoutedSubscription({
|
|
1269
|
+
open: (provider) => {
|
|
1270
|
+
if (provider.subscribeToConnectionState) {
|
|
1271
|
+
// Providers deliver their current state immediately on subscribe, so
|
|
1272
|
+
// a re-route notifies the listener of the new venue's state.
|
|
1273
|
+
return provider.subscribeToConnectionState(listener);
|
|
1274
|
+
}
|
|
1275
|
+
listener(WebSocketConnectionState.Disconnected, 0);
|
|
1276
|
+
return () => {
|
|
1277
|
+
/* noop */
|
|
1278
|
+
};
|
|
1279
|
+
},
|
|
1280
|
+
});
|
|
1069
1281
|
}
|
|
1070
1282
|
async reconnect() {
|
|
1071
1283
|
const provider = this.#getDefaultProvider();
|