@metamask-previews/perps-controller 10.0.0-preview-a42e8d0d2 → 10.0.0-preview-5a03e1b92
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 +77 -0
- package/dist/constants/eventNames.cjs +6 -0
- package/dist/constants/eventNames.cjs.map +1 -1
- package/dist/constants/eventNames.d.cts +4 -0
- package/dist/constants/eventNames.d.cts.map +1 -1
- package/dist/constants/eventNames.d.mts +4 -0
- package/dist/constants/eventNames.d.mts.map +1 -1
- package/dist/constants/eventNames.mjs +6 -0
- package/dist/constants/eventNames.mjs.map +1 -1
- package/dist/index.cjs +86 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/perpsErrorCodes.cjs +16 -0
- package/dist/perpsErrorCodes.cjs.map +1 -1
- package/dist/perpsErrorCodes.d.cts +12 -0
- package/dist/perpsErrorCodes.d.cts.map +1 -1
- package/dist/perpsErrorCodes.d.mts +12 -0
- package/dist/perpsErrorCodes.d.mts.map +1 -1
- package/dist/perpsErrorCodes.mjs +16 -0
- package/dist/perpsErrorCodes.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +674 -77
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts +13 -0
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts +13 -0
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +676 -79
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +17 -17
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +17 -17
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +121 -11
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts +21 -0
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts +21 -0
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs +121 -11
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/TradingService.cjs +6 -2
- package/dist/services/TradingService.cjs.map +1 -1
- package/dist/services/TradingService.d.cts.map +1 -1
- package/dist/services/TradingService.d.mts.map +1 -1
- package/dist/services/TradingService.mjs +6 -2
- package/dist/services/TradingService.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +69 -4
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +69 -4
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/perps-types.cjs.map +1 -1
- package/dist/types/perps-types.d.cts +35 -1
- package/dist/types/perps-types.d.cts.map +1 -1
- package/dist/types/perps-types.d.mts +35 -1
- package/dist/types/perps-types.d.mts.map +1 -1
- package/dist/types/perps-types.mjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.cjs +168 -10
- package/dist/utils/hyperLiquidAdapter.cjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.cts +35 -1
- package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +35 -1
- package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.mjs +166 -11
- package/dist/utils/hyperLiquidAdapter.mjs.map +1 -1
- package/dist/utils/hyperLiquidValidation.cjs +160 -5
- package/dist/utils/hyperLiquidValidation.cjs.map +1 -1
- package/dist/utils/hyperLiquidValidation.d.cts +23 -4
- package/dist/utils/hyperLiquidValidation.d.cts.map +1 -1
- package/dist/utils/hyperLiquidValidation.d.mts +23 -4
- package/dist/utils/hyperLiquidValidation.d.mts.map +1 -1
- package/dist/utils/hyperLiquidValidation.mjs +160 -5
- package/dist/utils/hyperLiquidValidation.mjs.map +1 -1
- package/dist/utils/index.cjs +5 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +2 -1
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +2 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/orderCalculations.cjs +363 -37
- package/dist/utils/orderCalculations.cjs.map +1 -1
- package/dist/utils/orderCalculations.d.cts +87 -2
- package/dist/utils/orderCalculations.d.cts.map +1 -1
- package/dist/utils/orderCalculations.d.mts +87 -2
- package/dist/utils/orderCalculations.d.mts.map +1 -1
- package/dist/utils/orderCalculations.mjs +359 -36
- package/dist/utils/orderCalculations.mjs.map +1 -1
- package/dist/utils/orderTypes.cjs +222 -0
- package/dist/utils/orderTypes.cjs.map +1 -0
- package/dist/utils/orderTypes.d.cts +114 -0
- package/dist/utils/orderTypes.d.cts.map +1 -0
- package/dist/utils/orderTypes.d.mts +114 -0
- package/dist/utils/orderTypes.d.mts.map +1 -0
- package/dist/utils/orderTypes.mjs +210 -0
- package/dist/utils/orderTypes.mjs.map +1 -0
- package/package.json +7 -6
|
@@ -129,6 +129,27 @@ export declare class HyperLiquidSubscriptionService {
|
|
|
129
129
|
* @returns true if WebSocket has sent at least one update, false otherwise
|
|
130
130
|
*/
|
|
131
131
|
isPositionsCacheInitialized(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Get the cached positions for one DEX, or null when that DEX has published
|
|
134
|
+
* none this session.
|
|
135
|
+
*
|
|
136
|
+
* A DEX only enters this map once its `clearinghouseState` subscription has
|
|
137
|
+
* published, so `null` means the absence of a symbol proves nothing about
|
|
138
|
+
* whether a position exists there.
|
|
139
|
+
*
|
|
140
|
+
* Prefer this over `getCachedPositions()` when a decision depends on whether a
|
|
141
|
+
* specific symbol is absent. The aggregate is only rebuilt once *every*
|
|
142
|
+
* expected DEX has published (`#aggregateAndNotifySubscribers`), so after a
|
|
143
|
+
* reconnect — which resets `#initializedDexs` without clearing these caches —
|
|
144
|
+
* the aggregate can sit frozen at its pre-reconnect contents while this map
|
|
145
|
+
* keeps receiving per-DEX updates. Deciding "covered" from this map and then
|
|
146
|
+
* reading the symbol from the aggregate would mix a fresh answer with stale
|
|
147
|
+
* data.
|
|
148
|
+
*
|
|
149
|
+
* @param dexName - DEX identifier, or '' for the main DEX.
|
|
150
|
+
* @returns That DEX's cached positions, or null if it has not published.
|
|
151
|
+
*/
|
|
152
|
+
getCachedPositionsForDex(dexName: string): Position[] | null;
|
|
132
153
|
/**
|
|
133
154
|
* Get cached positions from WebSocket subscription
|
|
134
155
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidSubscriptionService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EASV,gBAAgB,EAMjB,4BAA4B;AAQ7B,OAAO,KAAK,EAEV,0BAA0B,EAE3B,uCAAsC;AAGvC,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"HyperLiquidSubscriptionService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EASV,gBAAgB,EAMjB,4BAA4B;AAQ7B,OAAO,KAAK,EAEV,0BAA0B,EAE3B,uCAAsC;AA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AA0B,IAAI,SAAS,EAAE,GAAG,IAAI;IAslCvD;;;;;;;OAOG;IACI,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,IAAI;IAuPzE;;;;;;OAMG;IACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IA8MlD;;OAEG;IACI,QAAQ,IAAI,IAAI;CA+MxB"}
|
|
@@ -129,6 +129,27 @@ export declare class HyperLiquidSubscriptionService {
|
|
|
129
129
|
* @returns true if WebSocket has sent at least one update, false otherwise
|
|
130
130
|
*/
|
|
131
131
|
isPositionsCacheInitialized(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Get the cached positions for one DEX, or null when that DEX has published
|
|
134
|
+
* none this session.
|
|
135
|
+
*
|
|
136
|
+
* A DEX only enters this map once its `clearinghouseState` subscription has
|
|
137
|
+
* published, so `null` means the absence of a symbol proves nothing about
|
|
138
|
+
* whether a position exists there.
|
|
139
|
+
*
|
|
140
|
+
* Prefer this over `getCachedPositions()` when a decision depends on whether a
|
|
141
|
+
* specific symbol is absent. The aggregate is only rebuilt once *every*
|
|
142
|
+
* expected DEX has published (`#aggregateAndNotifySubscribers`), so after a
|
|
143
|
+
* reconnect — which resets `#initializedDexs` without clearing these caches —
|
|
144
|
+
* the aggregate can sit frozen at its pre-reconnect contents while this map
|
|
145
|
+
* keeps receiving per-DEX updates. Deciding "covered" from this map and then
|
|
146
|
+
* reading the symbol from the aggregate would mix a fresh answer with stale
|
|
147
|
+
* data.
|
|
148
|
+
*
|
|
149
|
+
* @param dexName - DEX identifier, or '' for the main DEX.
|
|
150
|
+
* @returns That DEX's cached positions, or null if it has not published.
|
|
151
|
+
*/
|
|
152
|
+
getCachedPositionsForDex(dexName: string): Position[] | null;
|
|
132
153
|
/**
|
|
133
154
|
* Get cached positions from WebSocket subscription
|
|
134
155
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidSubscriptionService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EASV,gBAAgB,EAMjB,4BAA4B;AAQ7B,OAAO,KAAK,EAEV,0BAA0B,EAE3B,uCAAsC;AAGvC,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"HyperLiquidSubscriptionService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EASV,gBAAgB,EAMjB,4BAA4B;AAQ7B,OAAO,KAAK,EAEV,0BAA0B,EAE3B,uCAAsC;AAGvC,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAG1B,2BAA0B;AAsB3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAsC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAsC;AAa9E;;;GAGG;AACH,qBAAa,8BAA8B;;gBAiSvC,aAAa,EAAE,wBAAwB,EACvC,aAAa,EAAE,wBAAwB,EACvC,oBAAoB,EAAE,yBAAyB,EAC/C,WAAW,CAAC,EAAE,OAAO,EACrB,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,mBAAmB,CAAC,EAAE,MAAM;IA+K9B;;;;;;;;OAQG;IACI,eAAe,CACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC;YACb,UAAU,EAA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I,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE,GAAG,IAAI;IAInE;;;;OAIG;IACI,kBAAkB,IAAI,QAAQ,EAAE,GAAG,IAAI;IAI9C;;;;OAIG;IACI,eAAe,IAAI,KAAK,EAAE,GAAG,IAAI;IAIxC;;;;;OAKG;IACI,2BAA2B,IAAI,KAAK,EAAE,GAAG,IAAI;IAOpD;;;;;;OAMG;IACI,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIlD,sBAAsB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAS1E;;;;;OAKG;IACI,cAAc,IAAI,SAAS,EAAE,GAAG,IAAI;IAI3C;;;;;;;;OAQG;IACI,0BAA0B,IAAI,SAAS,EAAE,GAAG,IAAI;IAslCvD;;;;;;;OAOG;IACI,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,IAAI;IAuPzE;;;;;;OAMG;IACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IA8MlD;;OAEG;IACI,QAAQ,IAAI,IAAI;CA+MxB"}
|
|
@@ -20,6 +20,7 @@ import { ensureError } from "../utils/errorUtils.mjs";
|
|
|
20
20
|
import { adaptPositionFromSDK, adaptOrderFromSDK, adaptAccountStateFromSDK, parseAssetName } from "../utils/hyperLiquidAdapter.mjs";
|
|
21
21
|
import { processBboData } from "../utils/hyperLiquidOrderBookProcessor.mjs";
|
|
22
22
|
import { calculateOpenInterestUSD, isMarketTradable } from "../utils/marketDataTransform.mjs";
|
|
23
|
+
import { buildPositionTriggerOrderFromOrder, hashTriggerOrders } from "../utils/orderTypes.mjs";
|
|
23
24
|
/**
|
|
24
25
|
* Service for managing HyperLiquid WebSocket subscriptions
|
|
25
26
|
* Implements singleton subscription architecture with reference counting
|
|
@@ -601,6 +602,29 @@ export class HyperLiquidSubscriptionService {
|
|
|
601
602
|
isPositionsCacheInitialized() {
|
|
602
603
|
return __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_positionsCacheInitialized, "f");
|
|
603
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* Get the cached positions for one DEX, or null when that DEX has published
|
|
607
|
+
* none this session.
|
|
608
|
+
*
|
|
609
|
+
* A DEX only enters this map once its `clearinghouseState` subscription has
|
|
610
|
+
* published, so `null` means the absence of a symbol proves nothing about
|
|
611
|
+
* whether a position exists there.
|
|
612
|
+
*
|
|
613
|
+
* Prefer this over `getCachedPositions()` when a decision depends on whether a
|
|
614
|
+
* specific symbol is absent. The aggregate is only rebuilt once *every*
|
|
615
|
+
* expected DEX has published (`#aggregateAndNotifySubscribers`), so after a
|
|
616
|
+
* reconnect — which resets `#initializedDexs` without clearing these caches —
|
|
617
|
+
* the aggregate can sit frozen at its pre-reconnect contents while this map
|
|
618
|
+
* keeps receiving per-DEX updates. Deciding "covered" from this map and then
|
|
619
|
+
* reading the symbol from the aggregate would mix a fresh answer with stale
|
|
620
|
+
* data.
|
|
621
|
+
*
|
|
622
|
+
* @param dexName - DEX identifier, or '' for the main DEX.
|
|
623
|
+
* @returns That DEX's cached positions, or null if it has not published.
|
|
624
|
+
*/
|
|
625
|
+
getCachedPositionsForDex(dexName) {
|
|
626
|
+
return __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexPositionsCache, "f").get(dexName) ?? null;
|
|
627
|
+
}
|
|
604
628
|
/**
|
|
605
629
|
* Get cached positions from WebSocket subscription
|
|
606
630
|
*
|
|
@@ -1165,7 +1189,11 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1165
1189
|
return '0';
|
|
1166
1190
|
}
|
|
1167
1191
|
return positions
|
|
1168
|
-
.map((pos) => `${pos.symbol}:${pos.size}:${pos.entryPrice}:${pos.leverage.value}:${pos.takeProfitPrice ?? ''}:${pos.stopLossPrice ?? ''}:${pos.takeProfitCount}:${pos.stopLossCount}:${pos.unrealizedPnl}:${pos.returnOnEquity}:${pos.liquidationPrice ?? ''}:${pos.marginUsed || ''}
|
|
1192
|
+
.map((pos) => `${pos.symbol}:${pos.size}:${pos.entryPrice}:${pos.leverage.value}:${pos.takeProfitPrice ?? ''}:${pos.stopLossPrice ?? ''}:${pos.takeProfitCount}:${pos.stopLossCount}:${pos.unrealizedPnl}:${pos.returnOnEquity}:${pos.liquidationPrice ?? ''}:${pos.marginUsed || ''}:${
|
|
1193
|
+
// Trigger arrays are part of the emitted shape, so a standalone or
|
|
1194
|
+
// partial trigger appearing/disappearing has to change the hash —
|
|
1195
|
+
// otherwise subscribers never receive the updated arrays.
|
|
1196
|
+
hashTriggerOrders(pos.takeProfitOrders)}:${hashTriggerOrders(pos.stopLossOrders)}`)
|
|
1169
1197
|
.join('|');
|
|
1170
1198
|
}, _HyperLiquidSubscriptionService_hashOrders = function _HyperLiquidSubscriptionService_hashOrders(orders) {
|
|
1171
1199
|
if (!orders || orders.length === 0) {
|
|
@@ -1179,12 +1207,44 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1179
1207
|
}, _HyperLiquidSubscriptionService_extractTPSLFromOrders = function _HyperLiquidSubscriptionService_extractTPSLFromOrders(orders, positions, cachedProcessedOrders) {
|
|
1180
1208
|
const tpslMap = new Map();
|
|
1181
1209
|
const tpslCountMap = new Map();
|
|
1210
|
+
// Complete per-symbol trigger order view, including quantity-scoped (partial)
|
|
1211
|
+
// TP/SL orders that the scalar tpslMap prices cannot represent.
|
|
1212
|
+
const triggerOrderMap = new Map();
|
|
1213
|
+
const addTriggerOrder = (symbol, triggerOrder) => {
|
|
1214
|
+
if (!triggerOrder) {
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const existing = triggerOrderMap.get(symbol) ?? {
|
|
1218
|
+
takeProfitOrders: [],
|
|
1219
|
+
stopLossOrders: [],
|
|
1220
|
+
};
|
|
1221
|
+
if (triggerOrder.direction === 'take_profit') {
|
|
1222
|
+
existing.takeProfitOrders.push(triggerOrder);
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
existing.stopLossOrders.push(triggerOrder);
|
|
1226
|
+
}
|
|
1227
|
+
triggerOrderMap.set(symbol, existing);
|
|
1228
|
+
};
|
|
1182
1229
|
// If cached processed orders provided, extract TP/SL from them directly
|
|
1183
1230
|
if (cachedProcessedOrders) {
|
|
1231
|
+
// Hoisted out of the per-order loop: this runs on every order-update tick.
|
|
1232
|
+
const positionsBySymbol = new Map(positions.map((position) => [position.symbol, position]));
|
|
1184
1233
|
cachedProcessedOrders.forEach((order) => {
|
|
1185
1234
|
// Use triggerPrice for TP/SL (trigger condition price), falling back to price
|
|
1186
1235
|
// This ensures consistency with raw SDK order processing which uses triggerPx
|
|
1187
1236
|
const tpslPrice = order.triggerPrice ?? order.price;
|
|
1237
|
+
// Collected before the position-bound filter below: partial TP/SL orders
|
|
1238
|
+
// are standalone (not position-bound) and still belong to this view.
|
|
1239
|
+
// A trigger that is another order's child does not — same rule as the
|
|
1240
|
+
// REST path in HyperLiquidProvider.getPositions.
|
|
1241
|
+
if (order.isTrigger && order.reduceOnly && !order.parentOrderId) {
|
|
1242
|
+
addTriggerOrder(order.symbol, buildPositionTriggerOrderFromOrder({
|
|
1243
|
+
order,
|
|
1244
|
+
positionSize: positionsBySymbol.get(order.symbol)?.size ?? '0',
|
|
1245
|
+
entryPrice: positionsBySymbol.get(order.symbol)?.entryPrice,
|
|
1246
|
+
}));
|
|
1247
|
+
}
|
|
1188
1248
|
if (order.isTrigger && tpslPrice) {
|
|
1189
1249
|
// When UsePositionBoundTpsl is enabled, only position-bound TP/SL orders
|
|
1190
1250
|
// should be shown on positions — skip normalTpsl children of limit orders
|
|
@@ -1242,10 +1302,25 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1242
1302
|
}
|
|
1243
1303
|
}
|
|
1244
1304
|
});
|
|
1245
|
-
return {
|
|
1305
|
+
return {
|
|
1306
|
+
tpslMap,
|
|
1307
|
+
tpslCountMap,
|
|
1308
|
+
triggerOrderMap,
|
|
1309
|
+
processedOrders: cachedProcessedOrders,
|
|
1310
|
+
};
|
|
1246
1311
|
}
|
|
1247
1312
|
// Process raw SDK orders
|
|
1248
1313
|
const processedOrders = [];
|
|
1314
|
+
// TP/SL children of a pending parent order are listed both nested under the
|
|
1315
|
+
// parent and as top-level entries. Map each child back to its parent so the
|
|
1316
|
+
// converted order carries the link and the position trigger view can exclude
|
|
1317
|
+
// them: they protect that order, not a position.
|
|
1318
|
+
const parentIdByChildId = new Map();
|
|
1319
|
+
orders.forEach((order) => {
|
|
1320
|
+
order.children?.forEach((child) => {
|
|
1321
|
+
parentIdByChildId.set(child.oid, order.oid);
|
|
1322
|
+
});
|
|
1323
|
+
});
|
|
1249
1324
|
orders.forEach((order) => {
|
|
1250
1325
|
let position;
|
|
1251
1326
|
let positionForCoin;
|
|
@@ -1316,19 +1391,48 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1316
1391
|
}
|
|
1317
1392
|
// Convert ALL open orders to Order format
|
|
1318
1393
|
const convertedOrder = adaptOrderFromSDK(order, position ?? positionForCoin);
|
|
1394
|
+
const parentOrderId = parentIdByChildId.get(order.oid);
|
|
1395
|
+
if (parentOrderId !== undefined) {
|
|
1396
|
+
convertedOrder.parentOrderId = parentOrderId.toString();
|
|
1397
|
+
}
|
|
1319
1398
|
processedOrders.push(convertedOrder);
|
|
1399
|
+
if (convertedOrder.isTrigger &&
|
|
1400
|
+
convertedOrder.reduceOnly &&
|
|
1401
|
+
!convertedOrder.parentOrderId) {
|
|
1402
|
+
addTriggerOrder(convertedOrder.symbol, buildPositionTriggerOrderFromOrder({
|
|
1403
|
+
order: convertedOrder,
|
|
1404
|
+
positionSize: (position ?? positionForCoin)?.size ?? '0',
|
|
1405
|
+
entryPrice: (position ?? positionForCoin)?.entryPrice,
|
|
1406
|
+
}));
|
|
1407
|
+
}
|
|
1320
1408
|
});
|
|
1321
|
-
return { tpslMap, tpslCountMap, processedOrders };
|
|
1322
|
-
}, _HyperLiquidSubscriptionService_mergeTPSLIntoPositions = function _HyperLiquidSubscriptionService_mergeTPSLIntoPositions(positions, tpslMap, tpslCountMap) {
|
|
1409
|
+
return { tpslMap, tpslCountMap, triggerOrderMap, processedOrders };
|
|
1410
|
+
}, _HyperLiquidSubscriptionService_mergeTPSLIntoPositions = function _HyperLiquidSubscriptionService_mergeTPSLIntoPositions(positions, tpslMap, tpslCountMap, triggerOrderMap) {
|
|
1323
1411
|
return positions.map((position) => {
|
|
1324
1412
|
const tpsl = tpslMap.get(position.symbol) ?? {};
|
|
1325
1413
|
const tpslCount = tpslCountMap.get(position.symbol) ?? {};
|
|
1414
|
+
const triggerOrders = triggerOrderMap?.get(position.symbol);
|
|
1415
|
+
const takeProfitOrders = triggerOrders?.takeProfitOrders ?? [];
|
|
1416
|
+
const stopLossOrders = triggerOrders?.stopLossOrders ?? [];
|
|
1326
1417
|
return {
|
|
1327
1418
|
...position,
|
|
1328
1419
|
takeProfitPrice: tpsl.takeProfitPrice ?? undefined,
|
|
1329
1420
|
stopLossPrice: tpsl.stopLossPrice ?? undefined,
|
|
1330
|
-
|
|
1331
|
-
|
|
1421
|
+
// Counts come from the same arrays as the REST path, so both transports
|
|
1422
|
+
// report one definition. Orders whose placement type the exchange did
|
|
1423
|
+
// not name (HyperLiquid's ambiguous 'Trigger') are absent from both,
|
|
1424
|
+
// where the legacy count included them.
|
|
1425
|
+
// Keyed on the map, not on this symbol's entry: a symbol with no
|
|
1426
|
+
// entry has no triggers, and falling back to the legacy count there
|
|
1427
|
+
// would report a count beside an empty array.
|
|
1428
|
+
takeProfitCount: triggerOrderMap
|
|
1429
|
+
? takeProfitOrders.length
|
|
1430
|
+
: (tpslCount.takeProfitCount ?? 0),
|
|
1431
|
+
stopLossCount: triggerOrderMap
|
|
1432
|
+
? stopLossOrders.length
|
|
1433
|
+
: (tpslCount.stopLossCount ?? 0),
|
|
1434
|
+
takeProfitOrders,
|
|
1435
|
+
stopLossOrders,
|
|
1332
1436
|
};
|
|
1333
1437
|
});
|
|
1334
1438
|
}, _HyperLiquidSubscriptionService_aggregateAccountStates = function _HyperLiquidSubscriptionService_aggregateAccountStates() {
|
|
@@ -1865,10 +1969,16 @@ async function _HyperLiquidSubscriptionService_createClearinghouseSubscription(u
|
|
|
1865
1969
|
const cachedOrders = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexOrdersCache, "f").get(cacheKey) ?? [];
|
|
1866
1970
|
// Re-extract TP/SL from cached orders for the new positions
|
|
1867
1971
|
// This ensures TP/SL data persists across clearinghouseState updates
|
|
1868
|
-
|
|
1972
|
+
// Default the trigger arrays so "no triggers" and "not streamed yet"
|
|
1973
|
+
// look the same to consumers as they do on the REST path.
|
|
1974
|
+
let positionsWithTPSL = positions.map((position) => ({
|
|
1975
|
+
...position,
|
|
1976
|
+
takeProfitOrders: position.takeProfitOrders ?? [],
|
|
1977
|
+
stopLossOrders: position.stopLossOrders ?? [],
|
|
1978
|
+
}));
|
|
1869
1979
|
if (cachedOrders.length > 0) {
|
|
1870
|
-
const { tpslMap, tpslCountMap } = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_extractTPSLFromOrders).call(this, [], positions, cachedOrders);
|
|
1871
|
-
positionsWithTPSL = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_mergeTPSLIntoPositions).call(this, positions, tpslMap, tpslCountMap);
|
|
1980
|
+
const { tpslMap, tpslCountMap, triggerOrderMap } = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_extractTPSLFromOrders).call(this, [], positions, cachedOrders);
|
|
1981
|
+
positionsWithTPSL = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_mergeTPSLIntoPositions).call(this, positions, tpslMap, tpslCountMap, triggerOrderMap);
|
|
1872
1982
|
}
|
|
1873
1983
|
// Update account state
|
|
1874
1984
|
const accountState = adaptAccountStateFromSDK(data.clearinghouseState);
|
|
@@ -1949,12 +2059,12 @@ async function _HyperLiquidSubscriptionService_createOpenOrdersSubscription(user
|
|
|
1949
2059
|
// Get cached positions for TP/SL processing
|
|
1950
2060
|
const cachedPositions = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexPositionsCache, "f").get(cacheKey) ?? [];
|
|
1951
2061
|
// Extract TP/SL and process orders
|
|
1952
|
-
const { tpslMap, tpslCountMap, processedOrders: orders, } = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_extractTPSLFromOrders).call(this, data.orders, cachedPositions);
|
|
2062
|
+
const { tpslMap, tpslCountMap, triggerOrderMap, processedOrders: orders, } = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_extractTPSLFromOrders).call(this, data.orders, cachedPositions);
|
|
1953
2063
|
// Update orders cache with processed orders
|
|
1954
2064
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexOrdersCache, "f").set(cacheKey, orders);
|
|
1955
2065
|
// Update positions with TP/SL if we have positions
|
|
1956
2066
|
if (cachedPositions.length > 0) {
|
|
1957
|
-
const positionsWithTPSL = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_mergeTPSLIntoPositions).call(this, cachedPositions, tpslMap, tpslCountMap);
|
|
2067
|
+
const positionsWithTPSL = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_mergeTPSLIntoPositions).call(this, cachedPositions, tpslMap, tpslCountMap, triggerOrderMap);
|
|
1958
2068
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexPositionsCache, "f").set(cacheKey, positionsWithTPSL);
|
|
1959
2069
|
}
|
|
1960
2070
|
// Mark this DEX as initialized (has sent first data)
|