@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
|
@@ -23,7 +23,7 @@ import { isValidCapabilitySymbol } from '../utils/capabilitySymbols.js';
|
|
|
23
23
|
import { PERPS_ERROR_ACTION, PERPS_ERROR_COMPONENT, PERPS_ERROR_OPERATION, createPerpsErrorContext, } from '../utils/errorContext.js';
|
|
24
24
|
import { ensureError, isHyperLiquidMultiSigRequiredError, isHyperLiquidUserNotFoundError, isKeyringLockedError, } from '../utils/errorUtils.js';
|
|
25
25
|
import { shouldDeferUnifiedAccountSetup } from '../utils/hyperLiquidAbstraction.js';
|
|
26
|
-
import { adaptAccountStateFromSDK, adaptHyperLiquidLedgerUpdateToUserHistoryItem, adaptMarketFromSDK, adaptOrderFromSDK, adaptPositionFromSDK, adaptPositionTriggerOrderFromSDK, adaptTpslLinkageToGrouping, buildAssetMapping, buildHyperLiquidFillId, formatHyperLiquidPrice, formatHyperLiquidSize, HYPERLIQUID_SCALE_CLOID_MARKER, parseAssetName, readScaleGroupId, } from '../utils/hyperLiquidAdapter.js';
|
|
26
|
+
import { adaptAccountStateFromSDK, adaptHyperLiquidLedgerUpdateToUserHistoryItem, adaptMarketFromSDK, adaptOrderFromSDK, adaptPositionFromSDK, adaptPositionTriggerOrderFromSDK, adaptPublicTradesFromHyperLiquid, adaptTpslLinkageToGrouping, buildAssetMapping, buildHyperLiquidFillId, formatHyperLiquidPrice, formatHyperLiquidSize, HYPERLIQUID_SCALE_CLOID_MARKER, parseAssetName, readScaleGroupId, } from '../utils/hyperLiquidAdapter.js';
|
|
27
27
|
import { previewHyperLiquidIsolatedPositionModify, resolveHyperLiquidMarginTiers, } from '../utils/hyperLiquidPositionPreview.js';
|
|
28
28
|
import { createErrorResult, getMaxOrderValue, getSupportedPaths, validateAssetSupport, validateBalance, validateCoinExists, validateDepositParams, validateOrderParams, validateWithdrawalParams, } from '../utils/hyperLiquidValidation.js';
|
|
29
29
|
import { generatePerpsId } from '../utils/idUtils.js';
|
|
@@ -380,8 +380,11 @@ const classifyCancelStatus = (status) => {
|
|
|
380
380
|
* placed for: an order netted at its original size subtracts more than it
|
|
381
381
|
* occupies, which can hide external liquidity sharing the level.
|
|
382
382
|
*
|
|
383
|
+
* Prices are matched by value, not text: an order submitted at "74676" sits on
|
|
384
|
+
* the level the book prints as "74676.0".
|
|
385
|
+
*
|
|
383
386
|
* @param levels - One side of the book, best-first.
|
|
384
|
-
* @param ownByPrice - This provider's own resting size at each price.
|
|
387
|
+
* @param ownByPrice - This provider's own resting size at each numeric price.
|
|
385
388
|
* @returns The best price other participants are showing, or null.
|
|
386
389
|
*/
|
|
387
390
|
const readBestExternalPrice = (levels, ownByPrice) => {
|
|
@@ -390,7 +393,7 @@ const readBestExternalPrice = (levels, ownByPrice) => {
|
|
|
390
393
|
if (!Number.isFinite(price) || price <= 0) {
|
|
391
394
|
continue;
|
|
392
395
|
}
|
|
393
|
-
const size = parseFloat(level.sz) - (ownByPrice.get(
|
|
396
|
+
const size = parseFloat(level.sz) - (ownByPrice.get(price) ?? 0);
|
|
394
397
|
if (size > 0) {
|
|
395
398
|
return price;
|
|
396
399
|
}
|
|
@@ -5700,6 +5703,7 @@ export class HyperLiquidProvider {
|
|
|
5700
5703
|
reduceOnly: params.reduceOnly ?? false,
|
|
5701
5704
|
orderId,
|
|
5702
5705
|
replacingOrderId: null,
|
|
5706
|
+
retryingOrderId: null,
|
|
5703
5707
|
pendingReplacement: null,
|
|
5704
5708
|
restingPrice: quotePrice,
|
|
5705
5709
|
arrivalPrice: quotePrice,
|
|
@@ -5714,6 +5718,8 @@ export class HyperLiquidProvider {
|
|
|
5714
5718
|
: Date.now() + params.chaseMaxDurationMs,
|
|
5715
5719
|
maxRepricings: params.chaseMaxRepricings ?? Number.POSITIVE_INFINITY,
|
|
5716
5720
|
repricings: 0,
|
|
5721
|
+
replacementRefusals: 0,
|
|
5722
|
+
replacementRetryDue: false,
|
|
5717
5723
|
timer: null,
|
|
5718
5724
|
active: true,
|
|
5719
5725
|
status: CHASE_ORDER_STATUS.Active,
|
|
@@ -5932,6 +5938,10 @@ export class HyperLiquidProvider {
|
|
|
5932
5938
|
* report a live chase with no timer, and every later cancel would try to
|
|
5933
5939
|
* cancel the dead order and keep the handle forever.
|
|
5934
5940
|
*
|
|
5941
|
+
* A session waiting to retry a refused replacement also owns no order, but
|
|
5942
|
+
* its tick failed before placing anything, so it keeps going like the first
|
|
5943
|
+
* case.
|
|
5944
|
+
*
|
|
5935
5945
|
* @param sessionId - Session whose tick failed.
|
|
5936
5946
|
*/
|
|
5937
5947
|
#recoverFailedChaseTick(sessionId) {
|
|
@@ -5939,7 +5949,7 @@ export class HyperLiquidProvider {
|
|
|
5939
5949
|
if (!session?.active) {
|
|
5940
5950
|
return;
|
|
5941
5951
|
}
|
|
5942
|
-
if (session.orderId === null) {
|
|
5952
|
+
if (session.orderId === null && !session.replacementRetryDue) {
|
|
5943
5953
|
session.active = false;
|
|
5944
5954
|
session.status = CHASE_ORDER_STATUS.Failed;
|
|
5945
5955
|
this.#deps.debugLogger.log('Chase ended with nothing resting', {
|
|
@@ -5980,9 +5990,13 @@ export class HyperLiquidProvider {
|
|
|
5980
5990
|
if (Date.now() >= session.deadline) {
|
|
5981
5991
|
// The window closed. The last order stays resting as an ordinary limit
|
|
5982
5992
|
// order and the session stays registered, so cancelling by its handle
|
|
5983
|
-
// still reaches that order.
|
|
5993
|
+
// still reaches that order. A refused replacement left nothing resting,
|
|
5994
|
+
// so that chase ends as the refusal would have.
|
|
5984
5995
|
session.active = false;
|
|
5985
|
-
session.status =
|
|
5996
|
+
session.status =
|
|
5997
|
+
session.orderId === null
|
|
5998
|
+
? CHASE_ORDER_STATUS.Failed
|
|
5999
|
+
: CHASE_ORDER_STATUS.DurationReached;
|
|
5986
6000
|
this.#deps.debugLogger.log('Chase session window closed', { sessionId });
|
|
5987
6001
|
await this.#rebalanceChaseSession(session);
|
|
5988
6002
|
return;
|
|
@@ -6068,7 +6082,14 @@ export class HyperLiquidProvider {
|
|
|
6068
6082
|
if (!session.active) {
|
|
6069
6083
|
return;
|
|
6070
6084
|
}
|
|
6071
|
-
if (
|
|
6085
|
+
if (session.orderId === null) {
|
|
6086
|
+
// The venue refused the last replacement, so nothing rests and there is
|
|
6087
|
+
// nothing to cancel. Rest the remainder at the touch just read.
|
|
6088
|
+
if (!(await this.#restChaseReplacement(sessionId, session, quotePrice, session.size))) {
|
|
6089
|
+
return;
|
|
6090
|
+
}
|
|
6091
|
+
}
|
|
6092
|
+
else if (quotePrice !== session.restingPrice) {
|
|
6072
6093
|
const outcome = await this.#cancelChaseChild(session);
|
|
6073
6094
|
// The cancel is a second round trip, and this is the window where a
|
|
6074
6095
|
// caller's `cancelOrder` does the most damage: it would cancel the order
|
|
@@ -6175,59 +6196,7 @@ export class HyperLiquidProvider {
|
|
|
6175
6196
|
await this.#rebalanceChaseSession(session);
|
|
6176
6197
|
return;
|
|
6177
6198
|
}
|
|
6178
|
-
|
|
6179
|
-
// Published *before* the placement starts, not from the promise it
|
|
6180
|
-
// returns: the window opens the moment `#restChaseOrder` is entered, so
|
|
6181
|
-
// deriving the marker from its return value would leave the synchronous
|
|
6182
|
-
// prefix of that call unguarded. A cancel arriving anywhere inside the
|
|
6183
|
-
// round trip now waits for the replacement to land instead of reading
|
|
6184
|
-
// the null `orderId` as "nothing rests", reporting success, and dropping
|
|
6185
|
-
// the handle while this call is still putting an order on the book.
|
|
6186
|
-
let settleReplacement;
|
|
6187
|
-
session.pendingReplacement = new Promise((resolve) => {
|
|
6188
|
-
settleReplacement = resolve;
|
|
6189
|
-
});
|
|
6190
|
-
try {
|
|
6191
|
-
session.orderId = await this.#restChaseOrder({
|
|
6192
|
-
assetId: session.assetId,
|
|
6193
|
-
isBuy: session.isBuy,
|
|
6194
|
-
price: quotePrice,
|
|
6195
|
-
size: remaining,
|
|
6196
|
-
reduceOnly: session.reduceOnly,
|
|
6197
|
-
builder: session.builder,
|
|
6198
|
-
marksSubscriptionCloid: session.marksSubscriptionCloid,
|
|
6199
|
-
accountContext: session.accountContext,
|
|
6200
|
-
exchangeClient: this.#clientService.getExchangeClient(),
|
|
6201
|
-
});
|
|
6202
|
-
session.size = remaining;
|
|
6203
|
-
}
|
|
6204
|
-
finally {
|
|
6205
|
-
// Cleared before the waiters wake, so they see the settled session.
|
|
6206
|
-
session.replacingOrderId = null;
|
|
6207
|
-
session.pendingReplacement = null;
|
|
6208
|
-
settleReplacement?.();
|
|
6209
|
-
}
|
|
6210
|
-
session.restingPrice = quotePrice;
|
|
6211
|
-
session.repricings += 1;
|
|
6212
|
-
this.#deps.debugLogger.log('Chase re-priced', {
|
|
6213
|
-
sessionId,
|
|
6214
|
-
orderId: session.orderId,
|
|
6215
|
-
restingPrice: quotePrice,
|
|
6216
|
-
size: session.size,
|
|
6217
|
-
repricings: session.repricings,
|
|
6218
|
-
});
|
|
6219
|
-
// A cancel that arrived during the round trip is now waiting on this
|
|
6220
|
-
// session; it cancels the order just recorded above. A `disconnect`
|
|
6221
|
-
// deregisters the session instead, and deliberately leaves resting
|
|
6222
|
-
// orders alone — logged with its ID so it stays traceable.
|
|
6223
|
-
if (!this.#chaseSessions.has(sessionId)) {
|
|
6224
|
-
this.#deps.debugLogger.log('Chase replacement outlived its session', {
|
|
6225
|
-
sessionId,
|
|
6226
|
-
orderId: session.orderId,
|
|
6227
|
-
});
|
|
6228
|
-
return;
|
|
6229
|
-
}
|
|
6230
|
-
if (!session.active) {
|
|
6199
|
+
if (!(await this.#restChaseReplacement(sessionId, session, quotePrice, remainder.remainingSize))) {
|
|
6231
6200
|
return;
|
|
6232
6201
|
}
|
|
6233
6202
|
}
|
|
@@ -6262,6 +6231,129 @@ export class HyperLiquidProvider {
|
|
|
6262
6231
|
}
|
|
6263
6232
|
this.#scheduleChaseTick(sessionId);
|
|
6264
6233
|
}
|
|
6234
|
+
/**
|
|
6235
|
+
* Rest a chase's remainder at a new price once its previous child is off the
|
|
6236
|
+
* book.
|
|
6237
|
+
*
|
|
6238
|
+
* Two venue outcomes no longer end the chase as failed:
|
|
6239
|
+
*
|
|
6240
|
+
* - A remainder worth less than the venue's per-order minimum cannot be placed
|
|
6241
|
+
* at all — a partial fill can leave one size step under it. The chase ends
|
|
6242
|
+
* filled, reporting the unfilled remainder, and nothing is submitted. A
|
|
6243
|
+
* chase that has not filled at all ends failed instead, as it did when the
|
|
6244
|
+
* venue refused the submission.
|
|
6245
|
+
* - A refusal the first placement would retry, such as a post-only order that
|
|
6246
|
+
* would have matched because the touch moved during the round trip, leaves
|
|
6247
|
+
* nothing resting. The session stays active and the next tick rests the
|
|
6248
|
+
* remainder at the touch it reads then, up to
|
|
6249
|
+
* `CHASE_ORDER_CONFIG.InitialPlacementAttempts` refusals in a row.
|
|
6250
|
+
*
|
|
6251
|
+
* Any other refusal, or one past that limit, still throws, and tick recovery
|
|
6252
|
+
* ends the session.
|
|
6253
|
+
*
|
|
6254
|
+
* @param sessionId - Session being re-priced.
|
|
6255
|
+
* @param session - The session itself.
|
|
6256
|
+
* @param price - Formatted price to rest at.
|
|
6257
|
+
* @param size - Formatted size still to chase.
|
|
6258
|
+
* @returns Whether the tick should go on to its stop checks: false when the
|
|
6259
|
+
* chase ended, was stopped or replaced during the round trip, or is waiting
|
|
6260
|
+
* for the next tick.
|
|
6261
|
+
*/
|
|
6262
|
+
async #restChaseReplacement(sessionId, session, price, size) {
|
|
6263
|
+
if (parseFloat(size) * parseFloat(price) < this.#getMinimumOrderSize()) {
|
|
6264
|
+
session.replacingOrderId = null;
|
|
6265
|
+
session.active = false;
|
|
6266
|
+
session.size = size;
|
|
6267
|
+
session.status =
|
|
6268
|
+
parseFloat(size) < parseFloat(session.originalSize)
|
|
6269
|
+
? CHASE_ORDER_STATUS.Filled
|
|
6270
|
+
: CHASE_ORDER_STATUS.Failed;
|
|
6271
|
+
this.#deps.debugLogger.log('Chase remainder below venue minimum', {
|
|
6272
|
+
sessionId,
|
|
6273
|
+
remainingSize: size,
|
|
6274
|
+
price,
|
|
6275
|
+
status: session.status,
|
|
6276
|
+
});
|
|
6277
|
+
await this.#rebalanceChaseSession(session);
|
|
6278
|
+
return false;
|
|
6279
|
+
}
|
|
6280
|
+
// Published *before* the placement starts, not from the promise it
|
|
6281
|
+
// returns: the window opens the moment `#restChaseOrder` is entered, so
|
|
6282
|
+
// deriving the marker from its return value would leave the synchronous
|
|
6283
|
+
// prefix of that call unguarded. A cancel arriving anywhere inside the
|
|
6284
|
+
// round trip now waits for the replacement to land instead of reading
|
|
6285
|
+
// the null `orderId` as "nothing rests", reporting success, and dropping
|
|
6286
|
+
// the handle while this call is still putting an order on the book.
|
|
6287
|
+
let settleReplacement;
|
|
6288
|
+
session.pendingReplacement = new Promise((resolve) => {
|
|
6289
|
+
settleReplacement = resolve;
|
|
6290
|
+
});
|
|
6291
|
+
try {
|
|
6292
|
+
// Cleared first, so a refusal that ends the chase leaves no retry due.
|
|
6293
|
+
session.replacementRetryDue = false;
|
|
6294
|
+
session.orderId = await this.#restChaseOrder({
|
|
6295
|
+
assetId: session.assetId,
|
|
6296
|
+
isBuy: session.isBuy,
|
|
6297
|
+
price,
|
|
6298
|
+
size,
|
|
6299
|
+
reduceOnly: session.reduceOnly,
|
|
6300
|
+
builder: session.builder,
|
|
6301
|
+
marksSubscriptionCloid: session.marksSubscriptionCloid,
|
|
6302
|
+
accountContext: session.accountContext,
|
|
6303
|
+
exchangeClient: this.#clientService.getExchangeClient(),
|
|
6304
|
+
});
|
|
6305
|
+
session.size = size;
|
|
6306
|
+
session.replacementRefusals = 0;
|
|
6307
|
+
session.retryingOrderId = null;
|
|
6308
|
+
}
|
|
6309
|
+
catch (error) {
|
|
6310
|
+
// Recorded so the next tick, or the failed session, reports what is
|
|
6311
|
+
// actually left to chase.
|
|
6312
|
+
session.size = size;
|
|
6313
|
+
session.replacementRefusals += 1;
|
|
6314
|
+
if (!isRetryableChasePlacementError(error) ||
|
|
6315
|
+
session.replacementRefusals >=
|
|
6316
|
+
CHASE_ORDER_CONFIG.InitialPlacementAttempts) {
|
|
6317
|
+
throw error;
|
|
6318
|
+
}
|
|
6319
|
+
session.replacementRetryDue = true;
|
|
6320
|
+
session.retryingOrderId ??= session.replacingOrderId;
|
|
6321
|
+
this.#deps.debugLogger.log('Chase replacement refused, retrying', {
|
|
6322
|
+
sessionId,
|
|
6323
|
+
error: ensureError(error, 'HyperLiquidProvider.restChaseReplacement')
|
|
6324
|
+
.message,
|
|
6325
|
+
});
|
|
6326
|
+
this.#scheduleChaseTick(sessionId);
|
|
6327
|
+
return false;
|
|
6328
|
+
}
|
|
6329
|
+
finally {
|
|
6330
|
+
// Cleared before the waiters wake, so they see the settled session.
|
|
6331
|
+
session.replacingOrderId = null;
|
|
6332
|
+
session.pendingReplacement = null;
|
|
6333
|
+
settleReplacement?.();
|
|
6334
|
+
}
|
|
6335
|
+
session.restingPrice = price;
|
|
6336
|
+
session.repricings += 1;
|
|
6337
|
+
this.#deps.debugLogger.log('Chase re-priced', {
|
|
6338
|
+
sessionId,
|
|
6339
|
+
orderId: session.orderId,
|
|
6340
|
+
restingPrice: price,
|
|
6341
|
+
size: session.size,
|
|
6342
|
+
repricings: session.repricings,
|
|
6343
|
+
});
|
|
6344
|
+
// A cancel that arrived during the round trip is now waiting on this
|
|
6345
|
+
// session; it cancels the order just recorded above. A `disconnect`
|
|
6346
|
+
// deregisters the session instead, and deliberately leaves resting
|
|
6347
|
+
// orders alone — logged with its ID so it stays traceable.
|
|
6348
|
+
if (!this.#chaseSessions.has(sessionId)) {
|
|
6349
|
+
this.#deps.debugLogger.log('Chase replacement outlived its session', {
|
|
6350
|
+
sessionId,
|
|
6351
|
+
orderId: session.orderId,
|
|
6352
|
+
});
|
|
6353
|
+
return false;
|
|
6354
|
+
}
|
|
6355
|
+
return session.active;
|
|
6356
|
+
}
|
|
6265
6357
|
/**
|
|
6266
6358
|
* Resolve how much of the chase's own order is really sitting on its level.
|
|
6267
6359
|
*
|
|
@@ -6280,8 +6372,8 @@ export class HyperLiquidProvider {
|
|
|
6280
6372
|
* @param params.isBuy - Side being quoted.
|
|
6281
6373
|
* @param params.callerOrderId - The asking session's order, if it has one.
|
|
6282
6374
|
* @param params.ownSide - The side of the book those orders rest on.
|
|
6283
|
-
* @returns Our resting size at each price, the asking child's
|
|
6284
|
-
* result, or the unavailable sentinel.
|
|
6375
|
+
* @returns Our resting size at each numeric price, the asking child's
|
|
6376
|
+
* terminal result, or the unavailable sentinel.
|
|
6285
6377
|
*/
|
|
6286
6378
|
async #resolveOwnRestingSizes(params) {
|
|
6287
6379
|
const { symbol, isBuy, callerOrderId, ownSide } = params;
|
|
@@ -6293,7 +6385,7 @@ export class HyperLiquidProvider {
|
|
|
6293
6385
|
session.isBuy === isBuy) {
|
|
6294
6386
|
ourOrders.push({
|
|
6295
6387
|
orderId: session.orderId,
|
|
6296
|
-
price: session.restingPrice,
|
|
6388
|
+
price: parseFloat(session.restingPrice),
|
|
6297
6389
|
size: session.size,
|
|
6298
6390
|
});
|
|
6299
6391
|
}
|
|
@@ -6311,7 +6403,7 @@ export class HyperLiquidProvider {
|
|
|
6311
6403
|
// resting — an order partially fills without the loop seeing it — and only
|
|
6312
6404
|
// then is a lookup worth a round trip.
|
|
6313
6405
|
const ambiguous = ourOrders.filter((order) => {
|
|
6314
|
-
const level = ownSide?.find((entry) => entry.px === order.price);
|
|
6406
|
+
const level = ownSide?.find((entry) => parseFloat(entry.px) === order.price);
|
|
6315
6407
|
return !level || parseFloat(level.sz) <= (recorded.get(order.price) ?? 0);
|
|
6316
6408
|
});
|
|
6317
6409
|
let callerTerminalResult = null;
|
|
@@ -6856,7 +6948,12 @@ export class HyperLiquidProvider {
|
|
|
6856
6948
|
continue;
|
|
6857
6949
|
}
|
|
6858
6950
|
this.#stopChaseSession(sessionId);
|
|
6859
|
-
|
|
6951
|
+
// A refused replacement left nothing resting, and its retry will not
|
|
6952
|
+
// run while backgrounded, so it ends as the refusal would have.
|
|
6953
|
+
session.status =
|
|
6954
|
+
session.orderId === null
|
|
6955
|
+
? CHASE_ORDER_STATUS.Failed
|
|
6956
|
+
: CHASE_ORDER_STATUS.Backgrounded;
|
|
6860
6957
|
}
|
|
6861
6958
|
return await this.getChaseOrders();
|
|
6862
6959
|
}
|
|
@@ -7905,7 +8002,8 @@ export class HyperLiquidProvider {
|
|
|
7905
8002
|
// session handle stops the loop, joins any replacement, and removes the
|
|
7906
8003
|
// current child instead of leaving a replacement chasing behind the user.
|
|
7907
8004
|
const owningChase = [...this.#chaseSessions.entries()].find(([, session]) => session.orderId === params.orderId ||
|
|
7908
|
-
session.replacingOrderId === params.orderId
|
|
8005
|
+
session.replacingOrderId === params.orderId ||
|
|
8006
|
+
session.retryingOrderId === params.orderId);
|
|
7909
8007
|
let accountContext;
|
|
7910
8008
|
try {
|
|
7911
8009
|
if (owningChase) {
|
|
@@ -8012,7 +8110,8 @@ export class HyperLiquidProvider {
|
|
|
8012
8110
|
const chaseSessions = [...this.#chaseSessions.entries()];
|
|
8013
8111
|
const chaseRoutes = params.flatMap((order, index) => {
|
|
8014
8112
|
const owner = chaseSessions.find(([, session]) => session.orderId === order.orderId ||
|
|
8015
|
-
session.replacingOrderId === order.orderId
|
|
8113
|
+
session.replacingOrderId === order.orderId ||
|
|
8114
|
+
session.retryingOrderId === order.orderId);
|
|
8016
8115
|
return owner ? [{ handle: owner[0], index, order }] : [];
|
|
8017
8116
|
});
|
|
8018
8117
|
const chaseIndexes = new Set(chaseRoutes.map(({ index }) => index));
|
|
@@ -12118,6 +12217,67 @@ export class HyperLiquidProvider {
|
|
|
12118
12217
|
subscribeToCandles(params) {
|
|
12119
12218
|
return this.#clientService.subscribeToCandles(params);
|
|
12120
12219
|
}
|
|
12220
|
+
/**
|
|
12221
|
+
* A coin's most recent public trades, newest first. The venue returns its
|
|
12222
|
+
* last 10 trades, so `limit` only caps that count.
|
|
12223
|
+
*
|
|
12224
|
+
* @param params - Coin and optional limit.
|
|
12225
|
+
* @returns The trades, newest first.
|
|
12226
|
+
*/
|
|
12227
|
+
async getPublicTrades(params) {
|
|
12228
|
+
await this.#ensureClientsInitialized();
|
|
12229
|
+
const trades = await this.#clientService.fetchRecentTrades(params.symbol);
|
|
12230
|
+
const adapted = adaptPublicTradesFromHyperLiquid(trades, params.symbol);
|
|
12231
|
+
return params.limit === undefined
|
|
12232
|
+
? adapted
|
|
12233
|
+
: adapted.slice(0, params.limit);
|
|
12234
|
+
}
|
|
12235
|
+
/**
|
|
12236
|
+
* Stream a coin's public trades from the `trades` WebSocket channel. The
|
|
12237
|
+
* SDK shares one subscription per coin, so only the listener that opens it
|
|
12238
|
+
* may first receive the venue's recent trades. Like `subscribeToCandles`,
|
|
12239
|
+
* the stream is not restored after the client service reconnects its
|
|
12240
|
+
* WebSocket and `onError` is not called; resubscribe after a reconnect.
|
|
12241
|
+
*
|
|
12242
|
+
* @param params - Coin, callback and error handler.
|
|
12243
|
+
* @returns A cleanup function; safe to call before the stream opens.
|
|
12244
|
+
*/
|
|
12245
|
+
subscribeToPublicTrades(params) {
|
|
12246
|
+
const { symbol, callback, onError } = params;
|
|
12247
|
+
let released = false;
|
|
12248
|
+
let release = null;
|
|
12249
|
+
const open = async () => {
|
|
12250
|
+
try {
|
|
12251
|
+
await this.#ensureClientsInitialized();
|
|
12252
|
+
if (released) {
|
|
12253
|
+
return;
|
|
12254
|
+
}
|
|
12255
|
+
release = this.#clientService.subscribeToTrades({
|
|
12256
|
+
symbol,
|
|
12257
|
+
callback: (trades) => {
|
|
12258
|
+
const adapted = adaptPublicTradesFromHyperLiquid(trades, symbol);
|
|
12259
|
+
if (adapted.length > 0) {
|
|
12260
|
+
callback(adapted);
|
|
12261
|
+
}
|
|
12262
|
+
},
|
|
12263
|
+
onError,
|
|
12264
|
+
});
|
|
12265
|
+
}
|
|
12266
|
+
catch (error) {
|
|
12267
|
+
if (!released) {
|
|
12268
|
+
onError?.(ensureError(error, 'HyperLiquidProvider.subscribeToPublicTrades'));
|
|
12269
|
+
}
|
|
12270
|
+
}
|
|
12271
|
+
};
|
|
12272
|
+
open().catch(() => {
|
|
12273
|
+
// Failures are reported to onError inside open().
|
|
12274
|
+
});
|
|
12275
|
+
return () => {
|
|
12276
|
+
released = true;
|
|
12277
|
+
release?.();
|
|
12278
|
+
release = null;
|
|
12279
|
+
};
|
|
12280
|
+
}
|
|
12121
12281
|
/**
|
|
12122
12282
|
* Configure live data settings
|
|
12123
12283
|
*
|