@usherlabs/cex-broker 0.2.30 → 0.2.31
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/dist/commands/cli.js +57 -3
- package/dist/helpers/order-telemetry.d.ts +1 -1
- package/dist/index.js +58 -4
- package/dist/index.js.map +5 -5
- package/package.json +1 -1
package/dist/commands/cli.js
CHANGED
|
@@ -331489,6 +331489,7 @@ async function handleCreateOrder(ctx) {
|
|
|
331489
331489
|
}
|
|
331490
331490
|
};
|
|
331491
331491
|
let resolvedOrderTelemetry = {};
|
|
331492
|
+
let marketMetadataHash;
|
|
331492
331493
|
try {
|
|
331493
331494
|
if (!broker) {
|
|
331494
331495
|
return ctx.wrappedCallback({
|
|
@@ -331513,7 +331514,7 @@ async function handleCreateOrder(ctx) {
|
|
|
331513
331514
|
}
|
|
331514
331515
|
const telemetryIds = extractOrderTelemetryIds(createOrderParams);
|
|
331515
331516
|
const submissionTimestamp = new Date().toISOString();
|
|
331516
|
-
|
|
331517
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(brokerArchiver, broker, {
|
|
331517
331518
|
exchange: cex3,
|
|
331518
331519
|
accountSelector: selectedBrokerAccount?.label,
|
|
331519
331520
|
symbol: resolution.symbol,
|
|
@@ -331552,7 +331553,7 @@ async function handleCreateOrder(ctx) {
|
|
|
331552
331553
|
...extractOrderTelemetryIds(createOrderParams)
|
|
331553
331554
|
};
|
|
331554
331555
|
emitOrderExecutionTelemetryInBackground(otelMetrics, failedCreateContext, undefined, error48);
|
|
331555
|
-
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48);
|
|
331556
|
+
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48, { marketMetadataHash });
|
|
331556
331557
|
ctx.wrappedCallback({
|
|
331557
331558
|
code: grpc6.status.INTERNAL,
|
|
331558
331559
|
message: `Order Creation failed: ${sanitizeErrorDetail(error48)}`
|
|
@@ -332250,6 +332251,8 @@ async function handleTreasuryCall(ctx) {
|
|
|
332250
332251
|
const callValue = parsePayloadForAction(ctx, CallPayloadSchema);
|
|
332251
332252
|
if (callValue === null)
|
|
332252
332253
|
return;
|
|
332254
|
+
let createOrderContext;
|
|
332255
|
+
let marketMetadataHash;
|
|
332253
332256
|
try {
|
|
332254
332257
|
if (callValue.functionName.startsWith("_") || callValue.functionName.includes("constructor") || callValue.functionName.includes("prototype")) {
|
|
332255
332258
|
return ctx.wrappedCallback({
|
|
@@ -332272,8 +332275,41 @@ async function handleTreasuryCall(ctx) {
|
|
|
332272
332275
|
message: `Function not found on broker: ${callValue.functionName}`
|
|
332273
332276
|
}, null);
|
|
332274
332277
|
}
|
|
332278
|
+
if (callValue.functionName === "createOrder") {
|
|
332279
|
+
const [symbol2, orderType, side, quantity, price] = callValue.args;
|
|
332280
|
+
const requestedQuantity = asFiniteNumber(quantity);
|
|
332281
|
+
const requestedPrice = asFiniteNumber(price);
|
|
332282
|
+
const requestedNotional = requestedQuantity !== undefined && requestedPrice !== undefined ? asFiniteNumber(requestedQuantity * requestedPrice) : undefined;
|
|
332283
|
+
const telemetryIds = extractOrderTelemetryIds(callValue.params);
|
|
332284
|
+
const submissionTimestamp = new Date().toISOString();
|
|
332285
|
+
createOrderContext = {
|
|
332286
|
+
action: "CreateOrder",
|
|
332287
|
+
cex: ctx.cex,
|
|
332288
|
+
accountLabel: ctx.selectedBrokerAccount?.label,
|
|
332289
|
+
symbol: asNonEmptyString(symbol2),
|
|
332290
|
+
orderType: asNonEmptyString(orderType),
|
|
332291
|
+
side: asNonEmptyString(side),
|
|
332292
|
+
requestedQuantity,
|
|
332293
|
+
requestedNotional,
|
|
332294
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
332295
|
+
...telemetryIds
|
|
332296
|
+
};
|
|
332297
|
+
if (createOrderContext.symbol !== undefined) {
|
|
332298
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(ctx.brokerArchiver, broker, {
|
|
332299
|
+
exchange: ctx.cex,
|
|
332300
|
+
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
332301
|
+
symbol: createOrderContext.symbol,
|
|
332302
|
+
action: "CreateOrder",
|
|
332303
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
332304
|
+
...telemetryIds
|
|
332305
|
+
});
|
|
332306
|
+
}
|
|
332307
|
+
}
|
|
332275
332308
|
const result = await fn.apply(broker, argsArray);
|
|
332276
|
-
if (
|
|
332309
|
+
if (createOrderContext !== undefined) {
|
|
332310
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, result);
|
|
332311
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, result, undefined, { marketMetadataHash });
|
|
332312
|
+
} else if (callValue.functionName === "fetchWithdrawals") {
|
|
332277
332313
|
archiveWithdrawalObservationsInBackground(ctx.brokerArchiver, ctx.withdrawalObservationTracker, {
|
|
332278
332314
|
exchange: ctx.normalizedCex,
|
|
332279
332315
|
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
@@ -332285,6 +332321,11 @@ async function handleTreasuryCall(ctx) {
|
|
|
332285
332321
|
result: JSON.stringify(result)
|
|
332286
332322
|
});
|
|
332287
332323
|
} catch (error48) {
|
|
332324
|
+
if (createOrderContext !== undefined) {
|
|
332325
|
+
rethrowArchiveDurabilityError(error48);
|
|
332326
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, undefined, error48);
|
|
332327
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, undefined, error48, { marketMetadataHash });
|
|
332328
|
+
}
|
|
332288
332329
|
safeLogError("Call failed", error48);
|
|
332289
332330
|
rejectWithGrpcError(ctx, error48, {
|
|
332290
332331
|
message: getErrorMessage(error48),
|
|
@@ -332293,6 +332334,19 @@ async function handleTreasuryCall(ctx) {
|
|
|
332293
332334
|
});
|
|
332294
332335
|
}
|
|
332295
332336
|
}
|
|
332337
|
+
function asNonEmptyString(value) {
|
|
332338
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
332339
|
+
}
|
|
332340
|
+
function asFiniteNumber(value) {
|
|
332341
|
+
if (typeof value === "number") {
|
|
332342
|
+
return Number.isFinite(value) ? value : undefined;
|
|
332343
|
+
}
|
|
332344
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
332345
|
+
return;
|
|
332346
|
+
}
|
|
332347
|
+
const parsed = Number(value);
|
|
332348
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
332349
|
+
}
|
|
332296
332350
|
|
|
332297
332351
|
// src/handlers/execute-action/withdraw.ts
|
|
332298
332352
|
var grpc10 = __toESM(require_src3(), 1);
|
|
@@ -45,4 +45,4 @@ export type OrderExecutionTelemetry = {
|
|
|
45
45
|
export declare function emitOrderExecutionTelemetry(otelMetrics: OtelMetrics | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown): Promise<OrderExecutionTelemetry | undefined>;
|
|
46
46
|
export declare function buildOrderExecutionTelemetry(context: OrderTelemetryContext, order: unknown, error?: unknown): OrderExecutionTelemetry;
|
|
47
47
|
export declare function emitOrderExecutionTelemetryInBackground(otelMetrics: OtelMetrics | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown): void;
|
|
48
|
-
export declare function extractOrderTelemetryIds(params: Record<string,
|
|
48
|
+
export declare function extractOrderTelemetryIds(params: Record<string, unknown> | undefined): Pick<OrderTelemetryContext, "clientOrderId" | "idempotencyId" | "makerActionId">;
|
package/dist/index.js
CHANGED
|
@@ -307003,6 +307003,7 @@ async function handleCreateOrder(ctx) {
|
|
|
307003
307003
|
}
|
|
307004
307004
|
};
|
|
307005
307005
|
let resolvedOrderTelemetry = {};
|
|
307006
|
+
let marketMetadataHash;
|
|
307006
307007
|
try {
|
|
307007
307008
|
if (!broker) {
|
|
307008
307009
|
return ctx.wrappedCallback({
|
|
@@ -307027,7 +307028,7 @@ async function handleCreateOrder(ctx) {
|
|
|
307027
307028
|
}
|
|
307028
307029
|
const telemetryIds = extractOrderTelemetryIds(createOrderParams);
|
|
307029
307030
|
const submissionTimestamp = new Date().toISOString();
|
|
307030
|
-
|
|
307031
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(brokerArchiver, broker, {
|
|
307031
307032
|
exchange: cex3,
|
|
307032
307033
|
accountSelector: selectedBrokerAccount?.label,
|
|
307033
307034
|
symbol: resolution.symbol,
|
|
@@ -307066,7 +307067,7 @@ async function handleCreateOrder(ctx) {
|
|
|
307066
307067
|
...extractOrderTelemetryIds(createOrderParams)
|
|
307067
307068
|
};
|
|
307068
307069
|
emitOrderExecutionTelemetryInBackground(otelMetrics, failedCreateContext, undefined, error48);
|
|
307069
|
-
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48);
|
|
307070
|
+
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48, { marketMetadataHash });
|
|
307070
307071
|
ctx.wrappedCallback({
|
|
307071
307072
|
code: grpc6.status.INTERNAL,
|
|
307072
307073
|
message: `Order Creation failed: ${sanitizeErrorDetail(error48)}`
|
|
@@ -307764,6 +307765,8 @@ async function handleTreasuryCall(ctx) {
|
|
|
307764
307765
|
const callValue = parsePayloadForAction(ctx, CallPayloadSchema);
|
|
307765
307766
|
if (callValue === null)
|
|
307766
307767
|
return;
|
|
307768
|
+
let createOrderContext;
|
|
307769
|
+
let marketMetadataHash;
|
|
307767
307770
|
try {
|
|
307768
307771
|
if (callValue.functionName.startsWith("_") || callValue.functionName.includes("constructor") || callValue.functionName.includes("prototype")) {
|
|
307769
307772
|
return ctx.wrappedCallback({
|
|
@@ -307786,8 +307789,41 @@ async function handleTreasuryCall(ctx) {
|
|
|
307786
307789
|
message: `Function not found on broker: ${callValue.functionName}`
|
|
307787
307790
|
}, null);
|
|
307788
307791
|
}
|
|
307792
|
+
if (callValue.functionName === "createOrder") {
|
|
307793
|
+
const [symbol2, orderType, side, quantity, price] = callValue.args;
|
|
307794
|
+
const requestedQuantity = asFiniteNumber(quantity);
|
|
307795
|
+
const requestedPrice = asFiniteNumber(price);
|
|
307796
|
+
const requestedNotional = requestedQuantity !== undefined && requestedPrice !== undefined ? asFiniteNumber(requestedQuantity * requestedPrice) : undefined;
|
|
307797
|
+
const telemetryIds = extractOrderTelemetryIds(callValue.params);
|
|
307798
|
+
const submissionTimestamp = new Date().toISOString();
|
|
307799
|
+
createOrderContext = {
|
|
307800
|
+
action: "CreateOrder",
|
|
307801
|
+
cex: ctx.cex,
|
|
307802
|
+
accountLabel: ctx.selectedBrokerAccount?.label,
|
|
307803
|
+
symbol: asNonEmptyString(symbol2),
|
|
307804
|
+
orderType: asNonEmptyString(orderType),
|
|
307805
|
+
side: asNonEmptyString(side),
|
|
307806
|
+
requestedQuantity,
|
|
307807
|
+
requestedNotional,
|
|
307808
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
307809
|
+
...telemetryIds
|
|
307810
|
+
};
|
|
307811
|
+
if (createOrderContext.symbol !== undefined) {
|
|
307812
|
+
marketMetadataHash = await captureMarketMetadataSnapshot(ctx.brokerArchiver, broker, {
|
|
307813
|
+
exchange: ctx.cex,
|
|
307814
|
+
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
307815
|
+
symbol: createOrderContext.symbol,
|
|
307816
|
+
action: "CreateOrder",
|
|
307817
|
+
brokerObservedTimestamp: submissionTimestamp,
|
|
307818
|
+
...telemetryIds
|
|
307819
|
+
});
|
|
307820
|
+
}
|
|
307821
|
+
}
|
|
307789
307822
|
const result = await fn.apply(broker, argsArray);
|
|
307790
|
-
if (
|
|
307823
|
+
if (createOrderContext !== undefined) {
|
|
307824
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, result);
|
|
307825
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, result, undefined, { marketMetadataHash });
|
|
307826
|
+
} else if (callValue.functionName === "fetchWithdrawals") {
|
|
307791
307827
|
archiveWithdrawalObservationsInBackground(ctx.brokerArchiver, ctx.withdrawalObservationTracker, {
|
|
307792
307828
|
exchange: ctx.normalizedCex,
|
|
307793
307829
|
accountSelector: ctx.selectedBrokerAccount?.label,
|
|
@@ -307799,6 +307835,11 @@ async function handleTreasuryCall(ctx) {
|
|
|
307799
307835
|
result: JSON.stringify(result)
|
|
307800
307836
|
});
|
|
307801
307837
|
} catch (error48) {
|
|
307838
|
+
if (createOrderContext !== undefined) {
|
|
307839
|
+
rethrowArchiveDurabilityError(error48);
|
|
307840
|
+
emitOrderExecutionTelemetryInBackground(ctx.otelMetrics, createOrderContext, undefined, error48);
|
|
307841
|
+
archiveOrderExecutionInBackground(ctx.brokerArchiver, createOrderContext, undefined, error48, { marketMetadataHash });
|
|
307842
|
+
}
|
|
307802
307843
|
safeLogError("Call failed", error48);
|
|
307803
307844
|
rejectWithGrpcError(ctx, error48, {
|
|
307804
307845
|
message: getErrorMessage(error48),
|
|
@@ -307807,6 +307848,19 @@ async function handleTreasuryCall(ctx) {
|
|
|
307807
307848
|
});
|
|
307808
307849
|
}
|
|
307809
307850
|
}
|
|
307851
|
+
function asNonEmptyString(value) {
|
|
307852
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
307853
|
+
}
|
|
307854
|
+
function asFiniteNumber(value) {
|
|
307855
|
+
if (typeof value === "number") {
|
|
307856
|
+
return Number.isFinite(value) ? value : undefined;
|
|
307857
|
+
}
|
|
307858
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
307859
|
+
return;
|
|
307860
|
+
}
|
|
307861
|
+
const parsed = Number(value);
|
|
307862
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
307863
|
+
}
|
|
307810
307864
|
|
|
307811
307865
|
// src/handlers/execute-action/withdraw.ts
|
|
307812
307866
|
import * as grpc10 from "@grpc/grpc-js";
|
|
@@ -310126,4 +310180,4 @@ export {
|
|
|
310126
310180
|
CEXBroker as default
|
|
310127
310181
|
};
|
|
310128
310182
|
|
|
310129
|
-
//# debugId=
|
|
310183
|
+
//# debugId=1AF34CD02AB617AA64756E2164756E21
|