@metamask-previews/perps-controller 9.0.0-preview-e82188855 → 9.0.0-preview-ea5e7f6d0
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 +0 -34
- package/dist/PerpsController-method-action-types.cjs.map +1 -1
- package/dist/PerpsController-method-action-types.d.cts +1 -54
- package/dist/PerpsController-method-action-types.d.cts.map +1 -1
- package/dist/PerpsController-method-action-types.d.mts +1 -54
- package/dist/PerpsController-method-action-types.d.mts.map +1 -1
- package/dist/PerpsController-method-action-types.mjs.map +1 -1
- package/dist/PerpsController.cjs +8 -115
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +1 -59
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +1 -59
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +8 -115
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/constants/eventNames.cjs +0 -72
- package/dist/constants/eventNames.cjs.map +1 -1
- package/dist/constants/eventNames.d.cts +0 -54
- package/dist/constants/eventNames.d.cts.map +1 -1
- package/dist/constants/eventNames.d.mts +0 -54
- package/dist/constants/eventNames.d.mts.map +1 -1
- package/dist/constants/eventNames.mjs +0 -72
- package/dist/constants/eventNames.mjs.map +1 -1
- package/dist/constants/perpsConfig.cjs +0 -3
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +0 -2
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +0 -2
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +0 -3
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +2 -1
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +2 -1
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/selectors.cjs +1 -21
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +0 -11
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +0 -11
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +1 -20
- package/dist/selectors.mjs.map +1 -1
- package/dist/services/HyperLiquidClientService.cjs +8 -5
- package/dist/services/HyperLiquidClientService.cjs.map +1 -1
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -1
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -1
- package/dist/services/HyperLiquidClientService.mjs +7 -4
- package/dist/services/HyperLiquidClientService.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +33 -101
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs +33 -101
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/MarketDataService.cjs +0 -1
- package/dist/services/MarketDataService.cjs.map +1 -1
- package/dist/services/MarketDataService.d.cts.map +1 -1
- package/dist/services/MarketDataService.d.mts.map +1 -1
- package/dist/services/MarketDataService.mjs +0 -1
- package/dist/services/MarketDataService.mjs.map +1 -1
- package/dist/services/TerminalMarketService.cjs +0 -9
- package/dist/services/TerminalMarketService.cjs.map +1 -1
- package/dist/services/TerminalMarketService.d.cts.map +1 -1
- package/dist/services/TerminalMarketService.d.mts.map +1 -1
- package/dist/services/TerminalMarketService.mjs +1 -10
- package/dist/services/TerminalMarketService.mjs.map +1 -1
- package/dist/services/TradingService.cjs +7 -154
- package/dist/services/TradingService.cjs.map +1 -1
- package/dist/services/TradingService.d.cts +0 -4
- package/dist/services/TradingService.d.cts.map +1 -1
- package/dist/services/TradingService.d.mts +0 -4
- package/dist/services/TradingService.d.mts.map +1 -1
- package/dist/services/TradingService.mjs +7 -154
- package/dist/services/TradingService.mjs.map +1 -1
- package/dist/types/index.cjs +0 -7
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +1 -51
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +1 -51
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs +0 -7
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.cjs +4 -3
- package/dist/utils/hyperLiquidAdapter.cjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.mjs +4 -3
- package/dist/utils/hyperLiquidAdapter.mjs.map +1 -1
- package/dist/utils/standaloneInfoClient.cjs +1 -1
- package/dist/utils/standaloneInfoClient.cjs.map +1 -1
- package/package.json +2 -2
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _TradingService_instances, _TradingService_deps, _TradingService_controllerDeps, _TradingService_getErrorContext,
|
|
13
|
+
var _TradingService_instances, _TradingService_deps, _TradingService_controllerDeps, _TradingService_getErrorContext, _TradingService_trackOrderResult, _TradingService_handleOrderSuccess, _TradingService_withFeeDiscount, _TradingService_loadPositionData, _TradingService_calculateCloseMetrics, _TradingService_buildCloseEventProperties, _TradingService_trackPositionCloseResult, _TradingService_handleDataLakeReporting, _TradingService_calculateFeeDiscountWithMeasurement;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TradingService = void 0;
|
|
16
16
|
const uuid_1 = require("uuid");
|
|
@@ -124,16 +124,6 @@ class TradingService {
|
|
|
124
124
|
hasTP: Boolean(params.takeProfitPrice),
|
|
125
125
|
hasSL: Boolean(params.stopLossPrice),
|
|
126
126
|
});
|
|
127
|
-
// Emit submitted event before the provider round-trip (TAT-3134)
|
|
128
|
-
__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_trackSubmitted).call(this, types_1.PerpsAnalyticsEvent.TradeTransaction, {
|
|
129
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
130
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.DIRECTION]: params.isBuy
|
|
131
|
-
? eventNames_1.PERPS_EVENT_VALUE.DIRECTION.LONG
|
|
132
|
-
: eventNames_1.PERPS_EVENT_VALUE.DIRECTION.SHORT,
|
|
133
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ORDER_TYPE]: params.orderType,
|
|
134
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.LEVERAGE]: parseFloat(String(params.leverage ?? 1)),
|
|
135
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
136
|
-
});
|
|
137
127
|
// Observational threshold: when the provider round-trip exceeds
|
|
138
128
|
// PlaceOrderTimeoutMs we tag the trace and emit a breadcrumb, but we
|
|
139
129
|
// intentionally do NOT cancel the in-flight order. Cancelling client-side
|
|
@@ -392,21 +382,13 @@ class TradingService {
|
|
|
392
382
|
* @param options.provider - The perps provider instance.
|
|
393
383
|
* @param options.params - The operation parameters.
|
|
394
384
|
* @param options.context - The service context for dependencies.
|
|
395
|
-
* @param options.bulkActionId - Optional batch correlation id (TAT-3150).
|
|
396
385
|
* @returns The result of the operation.
|
|
397
386
|
*/
|
|
398
387
|
async cancelOrder(options) {
|
|
399
|
-
const { provider, params, context
|
|
388
|
+
const { provider, params, context } = options;
|
|
400
389
|
const traceId = (0, uuid_1.v4)();
|
|
401
390
|
const startTime = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now();
|
|
402
391
|
let traceData;
|
|
403
|
-
// Shared attribution + bulk correlation props (TAT-3080, TAT-3150)
|
|
404
|
-
const cancelExtraProps = {
|
|
405
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
406
|
-
...(bulkActionId && {
|
|
407
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.BULK_ACTION_ID]: bulkActionId,
|
|
408
|
-
}),
|
|
409
|
-
};
|
|
410
392
|
try {
|
|
411
393
|
// Start trace for the entire operation
|
|
412
394
|
__classPrivateFieldGet(this, _TradingService_deps, "f").tracer.trace({
|
|
@@ -422,11 +404,6 @@ class TradingService {
|
|
|
422
404
|
orderId: params.orderId,
|
|
423
405
|
},
|
|
424
406
|
});
|
|
425
|
-
// Emit submitted event before the provider round-trip (TAT-3134)
|
|
426
|
-
__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_trackSubmitted).call(this, types_1.PerpsAnalyticsEvent.OrderCancelTransaction, {
|
|
427
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
428
|
-
...cancelExtraProps,
|
|
429
|
-
});
|
|
430
407
|
// Execute order cancellation
|
|
431
408
|
const result = await provider.cancelOrder(params);
|
|
432
409
|
const completionDuration = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now() - startTime;
|
|
@@ -442,7 +419,6 @@ class TradingService {
|
|
|
442
419
|
[eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.EXECUTED,
|
|
443
420
|
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
444
421
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
|
|
445
|
-
...cancelExtraProps,
|
|
446
422
|
});
|
|
447
423
|
traceData = { success: true, orderId: params.orderId };
|
|
448
424
|
}
|
|
@@ -453,7 +429,6 @@ class TradingService {
|
|
|
453
429
|
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
454
430
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
|
|
455
431
|
[eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE]: result.error ?? 'Unknown error',
|
|
456
|
-
...cancelExtraProps,
|
|
457
432
|
});
|
|
458
433
|
__classPrivateFieldGet(this, _TradingService_deps, "f").logger.error((0, errorUtils_1.ensureError)(result.error, 'TradingService.cancelOrder'), __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_getErrorContext).call(this, 'cancelOrder', {
|
|
459
434
|
symbol: params.symbol,
|
|
@@ -472,7 +447,6 @@ class TradingService {
|
|
|
472
447
|
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
473
448
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
|
|
474
449
|
[eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE]: error instanceof Error ? error.message : 'Unknown error',
|
|
475
|
-
...cancelExtraProps,
|
|
476
450
|
});
|
|
477
451
|
__classPrivateFieldGet(this, _TradingService_deps, "f").logger.error((0, errorUtils_1.ensureError)(error, 'TradingService.cancelOrder'), __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_getErrorContext).call(this, 'cancelOrder', { symbol: params.symbol }));
|
|
478
452
|
traceData = {
|
|
@@ -503,8 +477,6 @@ class TradingService {
|
|
|
503
477
|
async cancelOrders(options) {
|
|
504
478
|
const { provider, params, context, withStreamPause } = options;
|
|
505
479
|
const traceId = (0, uuid_1.v4)();
|
|
506
|
-
// Correlation id linking every per-item event to the batch summary (TAT-3150)
|
|
507
|
-
const bulkActionId = (0, uuid_1.v4)();
|
|
508
480
|
const startTime = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now();
|
|
509
481
|
let operationResult = null;
|
|
510
482
|
let operationError = null;
|
|
@@ -567,7 +539,6 @@ class TradingService {
|
|
|
567
539
|
provider,
|
|
568
540
|
params: { symbol: order.symbol, orderId: order.orderId },
|
|
569
541
|
context,
|
|
570
|
-
bulkActionId,
|
|
571
542
|
})));
|
|
572
543
|
// Aggregate results
|
|
573
544
|
const successCount = results.filter((res) => res.status === 'fulfilled' && res.value.success).length;
|
|
@@ -625,7 +596,6 @@ class TradingService {
|
|
|
625
596
|
? eventNames_1.PERPS_EVENT_VALUE.STATUS.EXECUTED
|
|
626
597
|
: eventNames_1.PERPS_EVENT_VALUE.STATUS.FAILED,
|
|
627
598
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
|
|
628
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.BULK_ACTION_ID]: bulkActionId,
|
|
629
599
|
};
|
|
630
600
|
if (operationError) {
|
|
631
601
|
batchCancelProps[eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE] =
|
|
@@ -647,11 +617,10 @@ class TradingService {
|
|
|
647
617
|
* @param options.params - The operation parameters.
|
|
648
618
|
* @param options.context - The service context for dependencies.
|
|
649
619
|
* @param options.reportOrderToDataLake - The report order to data lake value.
|
|
650
|
-
* @param options.bulkActionId - Optional batch correlation id (TAT-3150).
|
|
651
620
|
* @returns The result of the operation.
|
|
652
621
|
*/
|
|
653
622
|
async closePosition(options) {
|
|
654
|
-
const { provider, params, context, reportOrderToDataLake
|
|
623
|
+
const { provider, params, context, reportOrderToDataLake } = options;
|
|
655
624
|
const traceId = (0, uuid_1.v4)();
|
|
656
625
|
const startTime = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now();
|
|
657
626
|
let position;
|
|
@@ -674,15 +643,6 @@ class TradingService {
|
|
|
674
643
|
symbol: params.symbol,
|
|
675
644
|
context,
|
|
676
645
|
});
|
|
677
|
-
// Emit submitted event before the provider round-trip (TAT-3134)
|
|
678
|
-
__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_trackSubmitted).call(this, types_1.PerpsAnalyticsEvent.PositionCloseTransaction, {
|
|
679
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
680
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ORDER_TYPE]: params.orderType ?? eventNames_1.PERPS_EVENT_VALUE.ORDER_TYPE.MARKET,
|
|
681
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
682
|
-
...(bulkActionId && {
|
|
683
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.BULK_ACTION_ID]: bulkActionId,
|
|
684
|
-
}),
|
|
685
|
-
});
|
|
686
646
|
// Calculate fee discount with measurement
|
|
687
647
|
const feeDiscountBips = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
688
648
|
// Execute position close with fee discount management
|
|
@@ -720,7 +680,6 @@ class TradingService {
|
|
|
720
680
|
params,
|
|
721
681
|
context,
|
|
722
682
|
duration: completionDuration,
|
|
723
|
-
bulkActionId,
|
|
724
683
|
});
|
|
725
684
|
return result;
|
|
726
685
|
}
|
|
@@ -738,7 +697,6 @@ class TradingService {
|
|
|
738
697
|
params,
|
|
739
698
|
context,
|
|
740
699
|
duration: completionDuration,
|
|
741
|
-
bulkActionId,
|
|
742
700
|
});
|
|
743
701
|
__classPrivateFieldGet(this, _TradingService_deps, "f").logger.error((0, errorUtils_1.ensureError)(error, 'TradingService.closePosition'), {
|
|
744
702
|
tags: {
|
|
@@ -778,8 +736,6 @@ class TradingService {
|
|
|
778
736
|
async closePositions(options) {
|
|
779
737
|
const { provider, params, context } = options;
|
|
780
738
|
const traceId = (0, uuid_1.v4)();
|
|
781
|
-
// Correlation id linking every per-item event to the batch summary (TAT-3150)
|
|
782
|
-
const bulkActionId = (0, uuid_1.v4)();
|
|
783
739
|
const startTime = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now();
|
|
784
740
|
let operationResult = null;
|
|
785
741
|
let operationError = null;
|
|
@@ -842,7 +798,6 @@ class TradingService {
|
|
|
842
798
|
params: { symbol: position.symbol },
|
|
843
799
|
context,
|
|
844
800
|
reportOrderToDataLake: () => Promise.resolve({ success: true }), // No-op for batch fallback
|
|
845
|
-
bulkActionId,
|
|
846
801
|
})));
|
|
847
802
|
// Aggregate results
|
|
848
803
|
const successCount = results.filter((res) => res.status === 'fulfilled' && res.value.success).length;
|
|
@@ -903,7 +858,6 @@ class TradingService {
|
|
|
903
858
|
? eventNames_1.PERPS_EVENT_VALUE.STATUS.EXECUTED
|
|
904
859
|
: eventNames_1.PERPS_EVENT_VALUE.STATUS.FAILED,
|
|
905
860
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
|
|
906
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.BULK_ACTION_ID]: bulkActionId,
|
|
907
861
|
};
|
|
908
862
|
if (operationError) {
|
|
909
863
|
batchCloseProps[eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE] =
|
|
@@ -960,12 +914,6 @@ class TradingService {
|
|
|
960
914
|
stopLossPrice: params.stopLossPrice ?? '',
|
|
961
915
|
},
|
|
962
916
|
});
|
|
963
|
-
// Emit submitted event before the provider round-trip (TAT-3134)
|
|
964
|
-
__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_trackSubmitted).call(this, types_1.PerpsAnalyticsEvent.RiskManagement, {
|
|
965
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
966
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.SOURCE]: source,
|
|
967
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
968
|
-
});
|
|
969
917
|
// Get fee discount from rewards
|
|
970
918
|
const feeDiscountBips = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
971
919
|
// Execute with fee discount management
|
|
@@ -1056,8 +1004,6 @@ class TradingService {
|
|
|
1056
1004
|
...(errorMessage && {
|
|
1057
1005
|
[eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE]: errorMessage,
|
|
1058
1006
|
}),
|
|
1059
|
-
// Discovery attribution (TAT-3080)
|
|
1060
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
1061
1007
|
};
|
|
1062
1008
|
// Track event once with all properties
|
|
1063
1009
|
__classPrivateFieldGet(this, _TradingService_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.RiskManagement, eventProperties);
|
|
@@ -1177,10 +1123,6 @@ class TradingService {
|
|
|
1177
1123
|
const isCurrentlyLong = parseFloat(position.size) > 0;
|
|
1178
1124
|
const oppositeDirection = !isCurrentlyLong;
|
|
1179
1125
|
const flipSize = positionSize * 2;
|
|
1180
|
-
// Direction-specific flip action, shared by the submitted and terminal events
|
|
1181
|
-
const flipAction = isCurrentlyLong
|
|
1182
|
-
? eventNames_1.PERPS_EVENT_VALUE.ACTION.FLIP_LONG_TO_SHORT
|
|
1183
|
-
: eventNames_1.PERPS_EVENT_VALUE.ACTION.FLIP_SHORT_TO_LONG;
|
|
1184
1126
|
// Create order params for flip
|
|
1185
1127
|
// Use 2x position size: 1x to close current position + 1x to open opposite position.
|
|
1186
1128
|
// Do not pass the position entry price as currentPrice: the provider must fetch
|
|
@@ -1192,19 +1134,6 @@ class TradingService {
|
|
|
1192
1134
|
orderType: 'market',
|
|
1193
1135
|
leverage: position.leverage?.value,
|
|
1194
1136
|
};
|
|
1195
|
-
// Emit submitted event before the provider round-trip, keeping flip
|
|
1196
|
-
// trades aligned with the consolidated placeOrder pipeline.
|
|
1197
|
-
__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_trackSubmitted).call(this, types_1.PerpsAnalyticsEvent.TradeTransaction, {
|
|
1198
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: position.symbol,
|
|
1199
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.DIRECTION]: oppositeDirection
|
|
1200
|
-
? eventNames_1.PERPS_EVENT_VALUE.DIRECTION.LONG
|
|
1201
|
-
: eventNames_1.PERPS_EVENT_VALUE.DIRECTION.SHORT,
|
|
1202
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ORDER_TYPE]: 'market',
|
|
1203
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.LEVERAGE]: position.leverage?.value || 1,
|
|
1204
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ORDER_SIZE]: positionSize,
|
|
1205
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ACTION]: flipAction,
|
|
1206
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, trackingData),
|
|
1207
|
-
});
|
|
1208
1137
|
// Place flip order (HyperLiquid handles margin transfer automatically)
|
|
1209
1138
|
const result = await provider.placeOrder(orderParams);
|
|
1210
1139
|
const completionDuration = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now() - startTime;
|
|
@@ -1217,6 +1146,9 @@ class TradingService {
|
|
|
1217
1146
|
});
|
|
1218
1147
|
}
|
|
1219
1148
|
// Track success analytics with direction-specific flip action
|
|
1149
|
+
const flipAction = isCurrentlyLong
|
|
1150
|
+
? eventNames_1.PERPS_EVENT_VALUE.ACTION.FLIP_LONG_TO_SHORT
|
|
1151
|
+
: eventNames_1.PERPS_EVENT_VALUE.ACTION.FLIP_SHORT_TO_LONG;
|
|
1220
1152
|
__classPrivateFieldGet(this, _TradingService_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.TradeTransaction, {
|
|
1221
1153
|
[eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.EXECUTED,
|
|
1222
1154
|
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: position.symbol,
|
|
@@ -1229,40 +1161,17 @@ class TradingService {
|
|
|
1229
1161
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
|
|
1230
1162
|
[eventNames_1.PERPS_EVENT_PROPERTY.ACTION]: flipAction,
|
|
1231
1163
|
[eventNames_1.PERPS_EVENT_PROPERTY.ORDER_VALUE]: positionSize * executedPrice,
|
|
1232
|
-
// MetaMask fee on flip trades (TAT-3146)
|
|
1233
|
-
...(trackingData?.metamaskFee !== undefined && {
|
|
1234
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.METAMASK_FEE]: trackingData.metamaskFee,
|
|
1235
|
-
}),
|
|
1236
1164
|
...(trackingData?.vipTier !== undefined && {
|
|
1237
1165
|
[eventNames_1.PERPS_EVENT_PROPERTY.VIP_TIER]: trackingData.vipTier,
|
|
1238
1166
|
}),
|
|
1239
1167
|
...(trackingData?.vipDiscount !== undefined && {
|
|
1240
1168
|
[eventNames_1.PERPS_EVENT_PROPERTY.VIP_DISCOUNT]: trackingData.vipDiscount,
|
|
1241
1169
|
}),
|
|
1242
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, trackingData),
|
|
1243
1170
|
});
|
|
1244
1171
|
// Invalidate standalone caches so external hooks refresh
|
|
1245
1172
|
__classPrivateFieldGet(this, _TradingService_deps, "f").cacheInvalidator.invalidate({ cacheType: 'positions' });
|
|
1246
1173
|
__classPrivateFieldGet(this, _TradingService_deps, "f").cacheInvalidator.invalidate({ cacheType: 'accountState' });
|
|
1247
1174
|
}
|
|
1248
|
-
else {
|
|
1249
|
-
// Provider rejected the flip without throwing: emit a terminal failed
|
|
1250
|
-
// event so every submitted flip is paired with executed or failed.
|
|
1251
|
-
__classPrivateFieldGet(this, _TradingService_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.TradeTransaction, {
|
|
1252
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.FAILED,
|
|
1253
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: position.symbol,
|
|
1254
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ACTION]: flipAction,
|
|
1255
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
|
|
1256
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE]: result.error ?? 'Unknown error',
|
|
1257
|
-
...(trackingData?.vipTier !== undefined && {
|
|
1258
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.VIP_TIER]: trackingData.vipTier,
|
|
1259
|
-
}),
|
|
1260
|
-
...(trackingData?.vipDiscount !== undefined && {
|
|
1261
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.VIP_DISCOUNT]: trackingData.vipDiscount,
|
|
1262
|
-
}),
|
|
1263
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, trackingData),
|
|
1264
|
-
});
|
|
1265
|
-
}
|
|
1266
1175
|
__classPrivateFieldGet(this, _TradingService_deps, "f").tracer.endTrace({
|
|
1267
1176
|
name: types_1.PerpsTraceNames.FlipPosition,
|
|
1268
1177
|
id: traceId,
|
|
@@ -1291,7 +1200,6 @@ class TradingService {
|
|
|
1291
1200
|
...(trackingData?.vipDiscount !== undefined && {
|
|
1292
1201
|
[eventNames_1.PERPS_EVENT_PROPERTY.VIP_DISCOUNT]: trackingData.vipDiscount,
|
|
1293
1202
|
}),
|
|
1294
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, trackingData),
|
|
1295
1203
|
});
|
|
1296
1204
|
__classPrivateFieldGet(this, _TradingService_deps, "f").tracer.endTrace({
|
|
1297
1205
|
name: types_1.PerpsTraceNames.FlipPosition,
|
|
@@ -1309,28 +1217,6 @@ _TradingService_deps = new WeakMap(), _TradingService_controllerDeps = new WeakM
|
|
|
1309
1217
|
method,
|
|
1310
1218
|
...additionalContext,
|
|
1311
1219
|
};
|
|
1312
|
-
}, _TradingService_buildAttributionProperties = function _TradingService_buildAttributionProperties(trackingData) {
|
|
1313
|
-
const properties = {};
|
|
1314
|
-
if (trackingData?.entryPoint !== undefined) {
|
|
1315
|
-
properties[eventNames_1.PERPS_EVENT_PROPERTY.ENTRY_POINT] = trackingData.entryPoint;
|
|
1316
|
-
}
|
|
1317
|
-
if (trackingData?.discoverySource !== undefined) {
|
|
1318
|
-
properties[eventNames_1.PERPS_EVENT_PROPERTY.DISCOVERY_SOURCE] =
|
|
1319
|
-
trackingData.discoverySource;
|
|
1320
|
-
}
|
|
1321
|
-
if (trackingData?.perpDiscoverySource !== undefined) {
|
|
1322
|
-
properties[eventNames_1.PERPS_EVENT_PROPERTY.PERP_DISCOVERY_SOURCE] =
|
|
1323
|
-
trackingData.perpDiscoverySource;
|
|
1324
|
-
}
|
|
1325
|
-
if (trackingData?.hlFeeRate !== undefined) {
|
|
1326
|
-
properties[eventNames_1.PERPS_EVENT_PROPERTY.HL_FEE_RATE] = trackingData.hlFeeRate;
|
|
1327
|
-
}
|
|
1328
|
-
return properties;
|
|
1329
|
-
}, _TradingService_trackSubmitted = function _TradingService_trackSubmitted(event, properties) {
|
|
1330
|
-
__classPrivateFieldGet(this, _TradingService_deps, "f").metrics.trackPerpsEvent(event, {
|
|
1331
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.SUBMITTED,
|
|
1332
|
-
...properties,
|
|
1333
|
-
});
|
|
1334
1220
|
}, _TradingService_trackOrderResult = function _TradingService_trackOrderResult(options) {
|
|
1335
1221
|
const { result, error, params, duration } = options;
|
|
1336
1222
|
const status = result?.success === true
|
|
@@ -1440,8 +1326,6 @@ _TradingService_deps = new WeakMap(), _TradingService_controllerDeps = new WeakM
|
|
|
1440
1326
|
Object.keys(params.trackingData.abTests).length > 0) {
|
|
1441
1327
|
properties[eventNames_1.PERPS_EVENT_PROPERTY.AB_TESTS] = params.trackingData.abTests;
|
|
1442
1328
|
}
|
|
1443
|
-
// Propagate discovery attribution + hl_fee_rate (TAT-3080, TAT-3149)
|
|
1444
|
-
Object.assign(properties, __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData));
|
|
1445
1329
|
__classPrivateFieldGet(this, _TradingService_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.TradeTransaction, properties);
|
|
1446
1330
|
}, _TradingService_handleOrderSuccess =
|
|
1447
1331
|
/**
|
|
@@ -1622,12 +1506,6 @@ async function _TradingService_loadPositionData(options) {
|
|
|
1622
1506
|
...(params.trackingData?.vipDiscount !== undefined && {
|
|
1623
1507
|
[eventNames_1.PERPS_EVENT_PROPERTY.VIP_DISCOUNT]: params.trackingData.vipDiscount,
|
|
1624
1508
|
}),
|
|
1625
|
-
// Leverage on close events (TAT-3147)
|
|
1626
|
-
...(position.leverage?.value !== undefined && {
|
|
1627
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.LEVERAGE]: position.leverage.value,
|
|
1628
|
-
}),
|
|
1629
|
-
// Discovery attribution + hl_fee_rate (TAT-3080, TAT-3149)
|
|
1630
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
1631
1509
|
};
|
|
1632
1510
|
// Calculate and add order value in USD (size * price)
|
|
1633
1511
|
const closeAssetPrice = result?.averagePrice
|
|
@@ -1655,31 +1533,8 @@ async function _TradingService_loadPositionData(options) {
|
|
|
1655
1533
|
}),
|
|
1656
1534
|
};
|
|
1657
1535
|
}, _TradingService_trackPositionCloseResult = function _TradingService_trackPositionCloseResult(options) {
|
|
1658
|
-
const { position, result, error, params, duration
|
|
1659
|
-
// Bulk action correlation id for batch close events (TAT-3150)
|
|
1660
|
-
const bulkActionProps = bulkActionId
|
|
1661
|
-
? { [eventNames_1.PERPS_EVENT_PROPERTY.BULK_ACTION_ID]: bulkActionId }
|
|
1662
|
-
: {};
|
|
1536
|
+
const { position, result, error, params, duration } = options;
|
|
1663
1537
|
if (!position) {
|
|
1664
|
-
// No local position record, yet closePosition already emitted a
|
|
1665
|
-
// submitted event and the close may still complete at the provider.
|
|
1666
|
-
// Emit a terminal (executed/failed) event so every submitted close has a
|
|
1667
|
-
// matching outcome, even without position-derived metrics.
|
|
1668
|
-
const status = result?.success === true
|
|
1669
|
-
? eventNames_1.PERPS_EVENT_VALUE.STATUS.EXECUTED
|
|
1670
|
-
: eventNames_1.PERPS_EVENT_VALUE.STATUS.FAILED;
|
|
1671
|
-
const errorMessage = error?.message ?? result?.error;
|
|
1672
|
-
__classPrivateFieldGet(this, _TradingService_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.PositionCloseTransaction, {
|
|
1673
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: status,
|
|
1674
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
|
|
1675
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ORDER_TYPE]: params.orderType ?? eventNames_1.PERPS_EVENT_VALUE.ORDER_TYPE.MARKET,
|
|
1676
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: duration,
|
|
1677
|
-
...(errorMessage && {
|
|
1678
|
-
[eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE]: errorMessage,
|
|
1679
|
-
}),
|
|
1680
|
-
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
1681
|
-
...bulkActionProps,
|
|
1682
|
-
});
|
|
1683
1538
|
return;
|
|
1684
1539
|
}
|
|
1685
1540
|
const metrics = result
|
|
@@ -1708,7 +1563,6 @@ async function _TradingService_loadPositionData(options) {
|
|
|
1708
1563
|
[eventNames_1.PERPS_EVENT_PROPERTY.AMOUNT_FILLED]: metrics.filledSize,
|
|
1709
1564
|
[eventNames_1.PERPS_EVENT_PROPERTY.REMAINING_AMOUNT]: metrics.requestedSize - metrics.filledSize,
|
|
1710
1565
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: duration,
|
|
1711
|
-
...bulkActionProps,
|
|
1712
1566
|
});
|
|
1713
1567
|
}
|
|
1714
1568
|
// Determine status
|
|
@@ -1721,7 +1575,6 @@ async function _TradingService_loadPositionData(options) {
|
|
|
1721
1575
|
__classPrivateFieldGet(this, _TradingService_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.PositionCloseTransaction, {
|
|
1722
1576
|
...eventProperties,
|
|
1723
1577
|
[eventNames_1.PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: duration,
|
|
1724
|
-
...bulkActionProps,
|
|
1725
1578
|
});
|
|
1726
1579
|
}, _TradingService_handleDataLakeReporting = function _TradingService_handleDataLakeReporting(reportOrderToDataLake, symbol, context) {
|
|
1727
1580
|
reportOrderToDataLake({
|