@usherlabs/cex-broker 0.2.10 → 0.2.12

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.
@@ -310995,6 +310995,64 @@ var CCXT_METHODS_WITH_VERITY = [
310995
310995
  "fetchWithdrawal",
310996
310996
  "fetchAccountId"
310997
310997
  ];
310998
+ var Action = {
310999
+ NoAction: 0,
311000
+ Deposit: 1,
311001
+ Withdraw: 2,
311002
+ CreateOrder: 3,
311003
+ GetOrderDetails: 4,
311004
+ CancelOrder: 5,
311005
+ FetchBalances: 6,
311006
+ FetchDepositAddresses: 7,
311007
+ FetchTicker: 8,
311008
+ FetchCurrency: 9,
311009
+ Call: 10,
311010
+ FetchAccountId: 11,
311011
+ FetchFees: 12,
311012
+ InternalTransfer: 13
311013
+ };
311014
+ var SubscriptionType = {
311015
+ NO_ACTION: 0,
311016
+ ORDERBOOK: 1,
311017
+ TRADES: 2,
311018
+ TICKER: 3,
311019
+ OHLCV: 4,
311020
+ BALANCE: 5,
311021
+ ORDERS: 6
311022
+ };
311023
+ function resolveEnumValue(enumValues, value) {
311024
+ if (typeof value === "number") {
311025
+ return Object.values(enumValues).includes(value) ? value : undefined;
311026
+ }
311027
+ if (typeof value === "string" && Object.hasOwn(enumValues, value)) {
311028
+ return enumValues[value];
311029
+ }
311030
+ return;
311031
+ }
311032
+ function createEnumNameMap(enumValues) {
311033
+ return Object.fromEntries(Object.entries(enumValues).map(([name, value]) => [value, name]));
311034
+ }
311035
+ var actionNames = createEnumNameMap(Action);
311036
+ var subscriptionTypeNames = createEnumNameMap(SubscriptionType);
311037
+ function getActionName(action) {
311038
+ if (typeof action === "string" && Object.hasOwn(Action, action)) {
311039
+ return action;
311040
+ }
311041
+ return typeof action === "number" ? actionNames[action] ?? `unknown_${action}` : `unknown_${action ?? "undefined"}`;
311042
+ }
311043
+ function getSubscriptionTypeName(subscriptionType) {
311044
+ if (typeof subscriptionType === "string" && Object.hasOwn(SubscriptionType, subscriptionType)) {
311045
+ return subscriptionType;
311046
+ }
311047
+ return typeof subscriptionType === "number" ? subscriptionTypeNames[subscriptionType] ?? `unknown_${subscriptionType}` : `unknown_${subscriptionType ?? "undefined"}`;
311048
+ }
311049
+ function resolveAction(action) {
311050
+ return resolveEnumValue(Action, action);
311051
+ }
311052
+ function resolveSubscriptionType(type2) {
311053
+ const resolvedType = resolveEnumValue(SubscriptionType, type2);
311054
+ return resolvedType === undefined || resolvedType === SubscriptionType.NO_ACTION ? SubscriptionType.ORDERBOOK : resolvedType;
311055
+ }
310998
311056
 
310999
311057
  // node_modules/@loglayer/plugin-opentelemetry/dist/index.mjs
311000
311058
  var import_api = __toESM(require_src5(), 1);
@@ -314338,36 +314396,9 @@ function createOtelLogsFromEnv() {
314338
314396
 
314339
314397
  // src/server.ts
314340
314398
  var grpc = __toESM(require_src3(), 1);
314341
- var protoLoader = __toESM(require_src2(), 1);
314342
314399
 
314343
- // src/proto/cex_broker/Action.ts
314344
- var Action = {
314345
- NoAction: 0,
314346
- Deposit: 1,
314347
- Withdraw: 2,
314348
- CreateOrder: 3,
314349
- GetOrderDetails: 4,
314350
- CancelOrder: 5,
314351
- FetchBalances: 6,
314352
- FetchDepositAddresses: 7,
314353
- FetchTicker: 8,
314354
- FetchCurrency: 9,
314355
- Call: 10,
314356
- FetchAccountId: 11,
314357
- FetchFees: 12,
314358
- InternalTransfer: 13
314359
- };
314360
-
314361
- // src/proto/cex_broker/SubscriptionType.ts
314362
- var SubscriptionType = {
314363
- NO_ACTION: 0,
314364
- ORDERBOOK: 1,
314365
- TRADES: 2,
314366
- TICKER: 3,
314367
- OHLCV: 4,
314368
- BALANCE: 5,
314369
- ORDERS: 6
314370
- };
314400
+ // src/proto-package-definition.ts
314401
+ var protoLoader = __toESM(require_src2(), 1);
314371
314402
 
314372
314403
  // src/proto/node.descriptor.ts
314373
314404
  var descriptor = {
@@ -314496,6 +314527,18 @@ var descriptor = {
314496
314527
  };
314497
314528
  var node_descriptor_default = descriptor;
314498
314529
 
314530
+ // src/proto-loader-options.ts
314531
+ var PROTO_LOADER_OPTIONS = {
314532
+ keepCase: true,
314533
+ longs: String,
314534
+ enums: String,
314535
+ defaults: true,
314536
+ oneofs: true
314537
+ };
314538
+
314539
+ // src/proto-package-definition.ts
314540
+ var CEX_BROKER_PACKAGE_DEFINITION = protoLoader.fromJSON(node_descriptor_default, PROTO_LOADER_OPTIONS);
314541
+
314499
314542
  // node_modules/zod/v4/classic/external.js
314500
314543
  var exports_external = {};
314501
314544
  __export(exports_external, {
@@ -328102,8 +328145,7 @@ var FetchFeesPayloadSchema = exports_external.object({
328102
328145
  });
328103
328146
 
328104
328147
  // src/server.ts
328105
- var packageDef = protoLoader.fromJSON(node_descriptor_default);
328106
- var grpcObj = grpc.loadPackageDefinition(packageDef);
328148
+ var grpcObj = grpc.loadPackageDefinition(CEX_BROKER_PACKAGE_DEFINITION);
328107
328149
  var cexNode = grpcObj.cex_broker;
328108
328150
  function parsePayload(schema, rawPayload) {
328109
328151
  const parsed = schema.safeParse(rawPayload ?? {});
@@ -328157,13 +328199,14 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
328157
328199
  server.addService(cexNode.cex_service.service, {
328158
328200
  ExecuteAction: async (call, callback) => {
328159
328201
  const startTime = Date.now();
328160
- const { action, cex: cex3, symbol: symbol2 } = call.request;
328202
+ const { action: rawAction, cex: cex3, symbol: symbol2 } = call.request;
328203
+ const action = resolveAction(rawAction);
328161
328204
  let actionCompleted = false;
328162
328205
  const wrappedCallback = (error48, value) => {
328163
328206
  if (!actionCompleted) {
328164
328207
  actionCompleted = true;
328165
328208
  const latency = Date.now() - startTime;
328166
- const actionName = action !== undefined && action in Action ? Action[action] : `unknown_${action ?? "undefined"}`;
328209
+ const actionName = getActionName(action);
328167
328210
  otelMetrics?.recordHistogram("execute_action_duration_ms", latency, {
328168
328211
  action: actionName,
328169
328212
  cex: cex3 || "unknown"
@@ -328189,7 +328232,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
328189
328232
  cex: cex3,
328190
328233
  symbol: symbol2
328191
328234
  });
328192
- const actionName = action !== undefined && action in Action ? Action[action] : `unknown_${action ?? "undefined"}`;
328235
+ const actionName = getActionName(action);
328193
328236
  otelMetrics?.recordCounter("execute_action_requests_total", 1, {
328194
328237
  action: actionName,
328195
328238
  cex: cex3 || "unknown"
@@ -328845,20 +328888,13 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
328845
328888
  try {
328846
328889
  const request = call.request;
328847
328890
  const { cex: cex3, symbol: symbol2, type: type2, options } = request;
328848
- const subscriptionType = type2 !== undefined ? type2 : SubscriptionType.ORDERBOOK;
328891
+ const subscriptionType = resolveSubscriptionType(type2);
328849
328892
  log.info(`Request - Subscribe:`, {
328850
328893
  cex: request.cex,
328851
328894
  symbol: request.symbol,
328852
328895
  type: subscriptionType
328853
328896
  });
328854
- const subscriptionTypeName = (() => {
328855
- for (const [key, value] of Object.entries(SubscriptionType)) {
328856
- if (value === subscriptionType && Number.isNaN(Number(key))) {
328857
- return key;
328858
- }
328859
- }
328860
- return `unknown_${subscriptionType}`;
328861
- })();
328897
+ const subscriptionTypeName = getSubscriptionTypeName(subscriptionType);
328862
328898
  otelMetrics?.recordCounter("subscribe_requests_total", 1, {
328863
328899
  cex: cex3 || "unknown",
328864
328900
  symbol: symbol2 || "unknown",
@@ -328946,7 +328982,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
328946
328982
  data: JSON.stringify(ticker),
328947
328983
  timestamp: Date.now(),
328948
328984
  symbol: symbol2,
328949
- type: type2
328985
+ type: subscriptionType
328950
328986
  });
328951
328987
  }
328952
328988
  } catch (error48) {
@@ -328971,7 +329007,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
328971
329007
  data: JSON.stringify(ohlcv),
328972
329008
  timestamp: Date.now(),
328973
329009
  symbol: symbol2,
328974
- type: type2
329010
+ type: subscriptionType
328975
329011
  });
328976
329012
  }
328977
329013
  } catch (error48) {
@@ -328995,7 +329031,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
328995
329031
  data: JSON.stringify(balance),
328996
329032
  timestamp: Date.now(),
328997
329033
  symbol: symbol2,
328998
- type: type2
329034
+ type: subscriptionType
328999
329035
  });
329000
329036
  }
329001
329037
  } catch (error48) {
@@ -329019,7 +329055,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
329019
329055
  data: JSON.stringify(orders),
329020
329056
  timestamp: Date.now(),
329021
329057
  symbol: symbol2,
329022
- type: type2
329058
+ type: subscriptionType
329023
329059
  });
329024
329060
  }
329025
329061
  } catch (error48) {
@@ -329040,7 +329076,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
329040
329076
  data: JSON.stringify({ error: "Invalid subscription type" }),
329041
329077
  timestamp: Date.now(),
329042
329078
  symbol: symbol2,
329043
- type: type2
329079
+ type: subscriptionType
329044
329080
  });
329045
329081
  }
329046
329082
  } catch (error48) {
@@ -1 +1,34 @@
1
1
  export declare const CCXT_METHODS_WITH_VERITY: string[];
2
+ export declare const Action: {
3
+ readonly NoAction: 0;
4
+ readonly Deposit: 1;
5
+ readonly Withdraw: 2;
6
+ readonly CreateOrder: 3;
7
+ readonly GetOrderDetails: 4;
8
+ readonly CancelOrder: 5;
9
+ readonly FetchBalances: 6;
10
+ readonly FetchDepositAddresses: 7;
11
+ readonly FetchTicker: 8;
12
+ readonly FetchCurrency: 9;
13
+ readonly Call: 10;
14
+ readonly FetchAccountId: 11;
15
+ readonly FetchFees: 12;
16
+ readonly InternalTransfer: 13;
17
+ };
18
+ export declare const SubscriptionType: {
19
+ readonly NO_ACTION: 0;
20
+ readonly ORDERBOOK: 1;
21
+ readonly TRADES: 2;
22
+ readonly TICKER: 3;
23
+ readonly OHLCV: 4;
24
+ readonly BALANCE: 5;
25
+ readonly ORDERS: 6;
26
+ };
27
+ export type Action = (typeof Action)[keyof typeof Action];
28
+ export type ActionName = keyof typeof Action;
29
+ export type SubscriptionType = (typeof SubscriptionType)[keyof typeof SubscriptionType];
30
+ export type SubscriptionTypeName = keyof typeof SubscriptionType;
31
+ export declare function getActionName(action: unknown): string;
32
+ export declare function getSubscriptionTypeName(subscriptionType: unknown): string;
33
+ export declare function resolveAction(action: Action | ActionName | undefined): Action | undefined;
34
+ export declare function resolveSubscriptionType(type: SubscriptionType | SubscriptionTypeName | undefined): SubscriptionType;
package/dist/index.js CHANGED
@@ -270118,6 +270118,64 @@ var CCXT_METHODS_WITH_VERITY = [
270118
270118
  "fetchWithdrawal",
270119
270119
  "fetchAccountId"
270120
270120
  ];
270121
+ var Action = {
270122
+ NoAction: 0,
270123
+ Deposit: 1,
270124
+ Withdraw: 2,
270125
+ CreateOrder: 3,
270126
+ GetOrderDetails: 4,
270127
+ CancelOrder: 5,
270128
+ FetchBalances: 6,
270129
+ FetchDepositAddresses: 7,
270130
+ FetchTicker: 8,
270131
+ FetchCurrency: 9,
270132
+ Call: 10,
270133
+ FetchAccountId: 11,
270134
+ FetchFees: 12,
270135
+ InternalTransfer: 13
270136
+ };
270137
+ var SubscriptionType = {
270138
+ NO_ACTION: 0,
270139
+ ORDERBOOK: 1,
270140
+ TRADES: 2,
270141
+ TICKER: 3,
270142
+ OHLCV: 4,
270143
+ BALANCE: 5,
270144
+ ORDERS: 6
270145
+ };
270146
+ function resolveEnumValue(enumValues, value) {
270147
+ if (typeof value === "number") {
270148
+ return Object.values(enumValues).includes(value) ? value : undefined;
270149
+ }
270150
+ if (typeof value === "string" && Object.hasOwn(enumValues, value)) {
270151
+ return enumValues[value];
270152
+ }
270153
+ return;
270154
+ }
270155
+ function createEnumNameMap(enumValues) {
270156
+ return Object.fromEntries(Object.entries(enumValues).map(([name, value]) => [value, name]));
270157
+ }
270158
+ var actionNames = createEnumNameMap(Action);
270159
+ var subscriptionTypeNames = createEnumNameMap(SubscriptionType);
270160
+ function getActionName(action) {
270161
+ if (typeof action === "string" && Object.hasOwn(Action, action)) {
270162
+ return action;
270163
+ }
270164
+ return typeof action === "number" ? actionNames[action] ?? `unknown_${action}` : `unknown_${action ?? "undefined"}`;
270165
+ }
270166
+ function getSubscriptionTypeName(subscriptionType) {
270167
+ if (typeof subscriptionType === "string" && Object.hasOwn(SubscriptionType, subscriptionType)) {
270168
+ return subscriptionType;
270169
+ }
270170
+ return typeof subscriptionType === "number" ? subscriptionTypeNames[subscriptionType] ?? `unknown_${subscriptionType}` : `unknown_${subscriptionType ?? "undefined"}`;
270171
+ }
270172
+ function resolveAction(action) {
270173
+ return resolveEnumValue(Action, action);
270174
+ }
270175
+ function resolveSubscriptionType(type2) {
270176
+ const resolvedType = resolveEnumValue(SubscriptionType, type2);
270177
+ return resolvedType === undefined || resolvedType === SubscriptionType.NO_ACTION ? SubscriptionType.ORDERBOOK : resolvedType;
270178
+ }
270121
270179
 
270122
270180
  // node_modules/@loglayer/plugin-opentelemetry/dist/index.mjs
270123
270181
  var import_api = __toESM(require_src2(), 1);
@@ -277291,36 +277349,9 @@ function createOtelLogsFromEnv() {
277291
277349
 
277292
277350
  // src/server.ts
277293
277351
  import * as grpc from "@grpc/grpc-js";
277294
- import * as protoLoader from "@grpc/proto-loader";
277295
277352
 
277296
- // src/proto/cex_broker/Action.ts
277297
- var Action = {
277298
- NoAction: 0,
277299
- Deposit: 1,
277300
- Withdraw: 2,
277301
- CreateOrder: 3,
277302
- GetOrderDetails: 4,
277303
- CancelOrder: 5,
277304
- FetchBalances: 6,
277305
- FetchDepositAddresses: 7,
277306
- FetchTicker: 8,
277307
- FetchCurrency: 9,
277308
- Call: 10,
277309
- FetchAccountId: 11,
277310
- FetchFees: 12,
277311
- InternalTransfer: 13
277312
- };
277313
-
277314
- // src/proto/cex_broker/SubscriptionType.ts
277315
- var SubscriptionType = {
277316
- NO_ACTION: 0,
277317
- ORDERBOOK: 1,
277318
- TRADES: 2,
277319
- TICKER: 3,
277320
- OHLCV: 4,
277321
- BALANCE: 5,
277322
- ORDERS: 6
277323
- };
277353
+ // src/proto-package-definition.ts
277354
+ import * as protoLoader from "@grpc/proto-loader";
277324
277355
 
277325
277356
  // src/proto/node.descriptor.ts
277326
277357
  var descriptor = {
@@ -277449,6 +277480,18 @@ var descriptor = {
277449
277480
  };
277450
277481
  var node_descriptor_default = descriptor;
277451
277482
 
277483
+ // src/proto-loader-options.ts
277484
+ var PROTO_LOADER_OPTIONS = {
277485
+ keepCase: true,
277486
+ longs: String,
277487
+ enums: String,
277488
+ defaults: true,
277489
+ oneofs: true
277490
+ };
277491
+
277492
+ // src/proto-package-definition.ts
277493
+ var CEX_BROKER_PACKAGE_DEFINITION = protoLoader.fromJSON(node_descriptor_default, PROTO_LOADER_OPTIONS);
277494
+
277452
277495
  // node_modules/zod/v4/classic/external.js
277453
277496
  var exports_external = {};
277454
277497
  __export(exports_external, {
@@ -291055,8 +291098,7 @@ var FetchFeesPayloadSchema = exports_external.object({
291055
291098
  });
291056
291099
 
291057
291100
  // src/server.ts
291058
- var packageDef = protoLoader.fromJSON(node_descriptor_default);
291059
- var grpcObj = grpc.loadPackageDefinition(packageDef);
291101
+ var grpcObj = grpc.loadPackageDefinition(CEX_BROKER_PACKAGE_DEFINITION);
291060
291102
  var cexNode = grpcObj.cex_broker;
291061
291103
  function parsePayload(schema, rawPayload) {
291062
291104
  const parsed = schema.safeParse(rawPayload ?? {});
@@ -291110,13 +291152,14 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291110
291152
  server.addService(cexNode.cex_service.service, {
291111
291153
  ExecuteAction: async (call, callback) => {
291112
291154
  const startTime = Date.now();
291113
- const { action, cex: cex3, symbol: symbol2 } = call.request;
291155
+ const { action: rawAction, cex: cex3, symbol: symbol2 } = call.request;
291156
+ const action = resolveAction(rawAction);
291114
291157
  let actionCompleted = false;
291115
291158
  const wrappedCallback = (error48, value) => {
291116
291159
  if (!actionCompleted) {
291117
291160
  actionCompleted = true;
291118
291161
  const latency = Date.now() - startTime;
291119
- const actionName = action !== undefined && action in Action ? Action[action] : `unknown_${action ?? "undefined"}`;
291162
+ const actionName = getActionName(action);
291120
291163
  otelMetrics?.recordHistogram("execute_action_duration_ms", latency, {
291121
291164
  action: actionName,
291122
291165
  cex: cex3 || "unknown"
@@ -291142,7 +291185,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291142
291185
  cex: cex3,
291143
291186
  symbol: symbol2
291144
291187
  });
291145
- const actionName = action !== undefined && action in Action ? Action[action] : `unknown_${action ?? "undefined"}`;
291188
+ const actionName = getActionName(action);
291146
291189
  otelMetrics?.recordCounter("execute_action_requests_total", 1, {
291147
291190
  action: actionName,
291148
291191
  cex: cex3 || "unknown"
@@ -291798,20 +291841,13 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291798
291841
  try {
291799
291842
  const request = call.request;
291800
291843
  const { cex: cex3, symbol: symbol2, type: type2, options } = request;
291801
- const subscriptionType = type2 !== undefined ? type2 : SubscriptionType.ORDERBOOK;
291844
+ const subscriptionType = resolveSubscriptionType(type2);
291802
291845
  log.info(`Request - Subscribe:`, {
291803
291846
  cex: request.cex,
291804
291847
  symbol: request.symbol,
291805
291848
  type: subscriptionType
291806
291849
  });
291807
- const subscriptionTypeName = (() => {
291808
- for (const [key, value] of Object.entries(SubscriptionType)) {
291809
- if (value === subscriptionType && Number.isNaN(Number(key))) {
291810
- return key;
291811
- }
291812
- }
291813
- return `unknown_${subscriptionType}`;
291814
- })();
291850
+ const subscriptionTypeName = getSubscriptionTypeName(subscriptionType);
291815
291851
  otelMetrics?.recordCounter("subscribe_requests_total", 1, {
291816
291852
  cex: cex3 || "unknown",
291817
291853
  symbol: symbol2 || "unknown",
@@ -291899,7 +291935,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291899
291935
  data: JSON.stringify(ticker),
291900
291936
  timestamp: Date.now(),
291901
291937
  symbol: symbol2,
291902
- type: type2
291938
+ type: subscriptionType
291903
291939
  });
291904
291940
  }
291905
291941
  } catch (error48) {
@@ -291924,7 +291960,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291924
291960
  data: JSON.stringify(ohlcv),
291925
291961
  timestamp: Date.now(),
291926
291962
  symbol: symbol2,
291927
- type: type2
291963
+ type: subscriptionType
291928
291964
  });
291929
291965
  }
291930
291966
  } catch (error48) {
@@ -291948,7 +291984,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291948
291984
  data: JSON.stringify(balance),
291949
291985
  timestamp: Date.now(),
291950
291986
  symbol: symbol2,
291951
- type: type2
291987
+ type: subscriptionType
291952
291988
  });
291953
291989
  }
291954
291990
  } catch (error48) {
@@ -291972,7 +292008,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291972
292008
  data: JSON.stringify(orders),
291973
292009
  timestamp: Date.now(),
291974
292010
  symbol: symbol2,
291975
- type: type2
292011
+ type: subscriptionType
291976
292012
  });
291977
292013
  }
291978
292014
  } catch (error48) {
@@ -291993,7 +292029,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291993
292029
  data: JSON.stringify({ error: "Invalid subscription type" }),
291994
292030
  timestamp: Date.now(),
291995
292031
  symbol: symbol2,
291996
- type: type2
292032
+ type: subscriptionType
291997
292033
  });
291998
292034
  }
291999
292035
  } catch (error48) {
@@ -292324,4 +292360,4 @@ export {
292324
292360
  CEXBroker as default
292325
292361
  };
292326
292362
 
292327
- //# debugId=AC580D825044D41564756E2164756E21
292363
+ //# debugId=F5D3244110461CF964756E2164756E21