@usherlabs/cex-broker 0.1.7 → 0.1.9

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.
@@ -289979,7 +289979,8 @@ class Logger extends BaseLogger {
289979
289979
  // src/helpers/logger.ts
289980
289980
  var log = new Logger({
289981
289981
  type: "pretty",
289982
- stylePrettyLogs: false
289982
+ stylePrettyLogs: false,
289983
+ minLevel: process.env.LOG_LEVEL === "debug" ? 0 : 3
289983
289984
  });
289984
289985
 
289985
289986
  // src/helpers/index.ts
@@ -290013,6 +290014,9 @@ function createBroker(cex3, metadata, useVerity, verityProverUrl) {
290013
290014
  recvWindow: 60000
290014
290015
  }
290015
290016
  });
290017
+ if (process.env.CEX_BROKER_SANDBOX_MODE === "true") {
290018
+ exchange.setSandboxMode(true);
290019
+ }
290016
290020
  exchange.options.recvWindow = 60000;
290017
290021
  return exchange;
290018
290022
  }
@@ -290153,17 +290157,19 @@ var Action = {
290153
290157
  GetOrderDetails: 4,
290154
290158
  CancelOrder: 5,
290155
290159
  FetchBalance: 6,
290156
- FetchDepositAddresses: 7
290160
+ FetchBalances: 7,
290161
+ FetchDepositAddresses: 8
290157
290162
  };
290158
290163
 
290159
290164
  // src/proto/cex_broker/SubscriptionType.ts
290160
290165
  var SubscriptionType = {
290161
- ORDERBOOK: 0,
290162
- TRADES: 1,
290163
- TICKER: 2,
290164
- OHLCV: 3,
290165
- BALANCE: 4,
290166
- ORDERS: 5
290166
+ NO_ACTION: 0,
290167
+ ORDERBOOK: 1,
290168
+ TRADES: 2,
290169
+ TICKER: 3,
290170
+ OHLCV: 4,
290171
+ BALANCE: 5,
290172
+ ORDERS: 6
290167
290173
  };
290168
290174
 
290169
290175
  // src/server.ts
@@ -290180,6 +290186,11 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290180
290186
  const server = new grpc.Server;
290181
290187
  server.addService(cexNode.cex_service.service, {
290182
290188
  ExecuteAction: async (call, callback) => {
290189
+ log.info(`Request - ExecuteAction: ${JSON.stringify({
290190
+ action: call.request.action,
290191
+ cex: call.request.cex,
290192
+ symbol: call.request.symbol
290193
+ })}`);
290183
290194
  if (!authenticateRequest(call, whitelistIps)) {
290184
290195
  return callback({
290185
290196
  code: grpc.status.PERMISSION_DENIED,
@@ -290447,6 +290458,22 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290447
290458
  }, null);
290448
290459
  }
290449
290460
  break;
290461
+ case Action.FetchBalances:
290462
+ try {
290463
+ const balance = await broker.fetchFreeBalance({
290464
+ ...call.request.payload ?? {}
290465
+ });
290466
+ callback(null, {
290467
+ result: useVerity ? broker.last_proof : JSON.stringify(balance)
290468
+ });
290469
+ } catch (error) {
290470
+ log.error(`Error fetching balance from ${cex3}:`, error);
290471
+ callback({
290472
+ code: grpc.status.INTERNAL,
290473
+ message: `Failed to fetch balance from ${cex3}`
290474
+ }, null);
290475
+ }
290476
+ break;
290450
290477
  default:
290451
290478
  return callback({
290452
290479
  code: grpc.status.INVALID_ARGUMENT,
@@ -290455,6 +290482,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290455
290482
  }
290456
290483
  },
290457
290484
  Subscribe: async (call) => {
290485
+ const request = call.request;
290458
290486
  if (!authenticateRequest(call, whitelistIps)) {
290459
290487
  call.emit("error", {
290460
290488
  code: grpc.status.PERMISSION_DENIED,
@@ -290465,16 +290493,22 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290465
290493
  const metadata = call.metadata;
290466
290494
  let broker = null;
290467
290495
  try {
290468
- const request = call.request;
290469
- const { cex: cex3, symbol, type: type2, options } = request;
290470
- if (!cex3 || !symbol || type2 === undefined) {
290496
+ const request2 = call.request;
290497
+ const { cex: cex3, symbol, type: type2, options } = request2;
290498
+ const subscriptionType = type2 !== undefined ? type2 : SubscriptionType.ORDERBOOK;
290499
+ log.info(`Request - Subscribe: ${JSON.stringify({
290500
+ cex: request2.cex,
290501
+ symbol: request2.symbol,
290502
+ type: subscriptionType
290503
+ })}`);
290504
+ if (!cex3 || !symbol) {
290471
290505
  call.write({
290472
290506
  data: JSON.stringify({
290473
290507
  error: "cex, symbol, and type are required"
290474
290508
  }),
290475
290509
  timestamp: Date.now(),
290476
290510
  symbol: symbol || "",
290477
- type: type2 || SubscriptionType.ORDERBOOK
290511
+ type: subscriptionType
290478
290512
  });
290479
290513
  call.end();
290480
290514
  return;
@@ -290487,12 +290521,12 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290487
290521
  }),
290488
290522
  timestamp: Date.now(),
290489
290523
  symbol,
290490
- type: type2
290524
+ type: subscriptionType
290491
290525
  });
290492
290526
  call.end();
290493
290527
  return;
290494
290528
  }
290495
- switch (type2) {
290529
+ switch (subscriptionType) {
290496
290530
  case SubscriptionType.ORDERBOOK:
290497
290531
  try {
290498
290532
  while (true) {
@@ -290501,7 +290535,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290501
290535
  data: JSON.stringify(orderbook),
290502
290536
  timestamp: Date.now(),
290503
290537
  symbol,
290504
- type: type2
290538
+ type: subscriptionType
290505
290539
  });
290506
290540
  }
290507
290541
  } catch (error) {
@@ -290513,7 +290547,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290513
290547
  }),
290514
290548
  timestamp: Date.now(),
290515
290549
  symbol,
290516
- type: type2
290550
+ type: subscriptionType
290517
290551
  });
290518
290552
  }
290519
290553
  break;
@@ -290525,7 +290559,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290525
290559
  data: JSON.stringify(trades),
290526
290560
  timestamp: Date.now(),
290527
290561
  symbol,
290528
- type: type2
290562
+ type: subscriptionType
290529
290563
  });
290530
290564
  }
290531
290565
  } catch (error) {
@@ -290537,7 +290571,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290537
290571
  }),
290538
290572
  timestamp: Date.now(),
290539
290573
  symbol,
290540
- type: type2
290574
+ type: subscriptionType
290541
290575
  });
290542
290576
  }
290543
290577
  break;
@@ -290561,7 +290595,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290561
290595
  }),
290562
290596
  timestamp: Date.now(),
290563
290597
  symbol,
290564
- type: type2
290598
+ type: subscriptionType
290565
290599
  });
290566
290600
  }
290567
290601
  break;
@@ -290586,7 +290620,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290586
290620
  }),
290587
290621
  timestamp: Date.now(),
290588
290622
  symbol,
290589
- type: type2
290623
+ type: subscriptionType
290590
290624
  });
290591
290625
  }
290592
290626
  break;
@@ -290610,7 +290644,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290610
290644
  }),
290611
290645
  timestamp: Date.now(),
290612
290646
  symbol,
290613
- type: type2
290647
+ type: subscriptionType
290614
290648
  });
290615
290649
  }
290616
290650
  break;
@@ -290634,7 +290668,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290634
290668
  }),
290635
290669
  timestamp: Date.now(),
290636
290670
  symbol,
290637
- type: type2
290671
+ type: subscriptionType
290638
290672
  });
290639
290673
  }
290640
290674
  break;
@@ -290895,6 +290929,9 @@ class CEXBroker {
290895
290929
  recvWindow: 60000
290896
290930
  }
290897
290931
  });
290932
+ if (process.env.CEX_BROKER_SANDBOX_MODE === "true") {
290933
+ client.setSandboxMode(true);
290934
+ }
290898
290935
  this.brokers[broker] = {
290899
290936
  primary: client,
290900
290937
  secondaryBrokers
@@ -291041,7 +291078,7 @@ async function startBrokerCommand(policyPath, port, whitelistIps, url2) {
291041
291078
 
291042
291079
  // src/cli.ts
291043
291080
  var program2 = new Command;
291044
- program2.name("cex-broker").description("CLI to start the CEXBroker service").requiredOption("-p, --policy <path>", "Policy JSON file").option("--port <number>", "Port number (default: 8086)", "8086").option("-w", "--whitelist <addresses...>", "IPv4 address whitelist (space-separated list)").option("-vu", "--verityProverUrl <url>", "Verity Prover Url").action(async (options) => {
291081
+ program2.name("cex-broker").description("CLI to start the CEXBroker service").requiredOption("-p, --policy <path>", "Policy JSON file").option("--port <number>", "Port number (default: 8086)", "8086").option("-w, --whitelist <addresses...>", "IPv4 address whitelist (space-separated list)").option("--verityProverUrl <url>", "Verity Prover Url").action(async (options) => {
291045
291082
  try {
291046
291083
  if (options.whitelist) {
291047
291084
  const isValidIPv4 = (ip) => /^(\d{1,3}\.){3}\d{1,3}$/.test(ip) && ip.split(".").every((part) => Number(part) >= 0 && Number(part) <= 255);
package/dist/index.js CHANGED
@@ -285026,7 +285026,8 @@ class Logger extends BaseLogger {
285026
285026
  // src/helpers/logger.ts
285027
285027
  var log = new Logger({
285028
285028
  type: "pretty",
285029
- stylePrettyLogs: false
285029
+ stylePrettyLogs: false,
285030
+ minLevel: process.env.LOG_LEVEL === "debug" ? 0 : 3
285030
285031
  });
285031
285032
 
285032
285033
  // src/helpers/index.ts
@@ -285060,6 +285061,9 @@ function createBroker(cex3, metadata, useVerity, verityProverUrl) {
285060
285061
  recvWindow: 60000
285061
285062
  }
285062
285063
  });
285064
+ if (process.env.CEX_BROKER_SANDBOX_MODE === "true") {
285065
+ exchange.setSandboxMode(true);
285066
+ }
285063
285067
  exchange.options.recvWindow = 60000;
285064
285068
  return exchange;
285065
285069
  }
@@ -285200,17 +285204,19 @@ var Action = {
285200
285204
  GetOrderDetails: 4,
285201
285205
  CancelOrder: 5,
285202
285206
  FetchBalance: 6,
285203
- FetchDepositAddresses: 7
285207
+ FetchBalances: 7,
285208
+ FetchDepositAddresses: 8
285204
285209
  };
285205
285210
 
285206
285211
  // src/proto/cex_broker/SubscriptionType.ts
285207
285212
  var SubscriptionType = {
285208
- ORDERBOOK: 0,
285209
- TRADES: 1,
285210
- TICKER: 2,
285211
- OHLCV: 3,
285212
- BALANCE: 4,
285213
- ORDERS: 5
285213
+ NO_ACTION: 0,
285214
+ ORDERBOOK: 1,
285215
+ TRADES: 2,
285216
+ TICKER: 3,
285217
+ OHLCV: 4,
285218
+ BALANCE: 5,
285219
+ ORDERS: 6
285214
285220
  };
285215
285221
 
285216
285222
  // src/server.ts
@@ -285227,6 +285233,11 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285227
285233
  const server = new grpc.Server;
285228
285234
  server.addService(cexNode.cex_service.service, {
285229
285235
  ExecuteAction: async (call, callback) => {
285236
+ log.info(`Request - ExecuteAction: ${JSON.stringify({
285237
+ action: call.request.action,
285238
+ cex: call.request.cex,
285239
+ symbol: call.request.symbol
285240
+ })}`);
285230
285241
  if (!authenticateRequest(call, whitelistIps)) {
285231
285242
  return callback({
285232
285243
  code: grpc.status.PERMISSION_DENIED,
@@ -285494,6 +285505,22 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285494
285505
  }, null);
285495
285506
  }
285496
285507
  break;
285508
+ case Action.FetchBalances:
285509
+ try {
285510
+ const balance = await broker.fetchFreeBalance({
285511
+ ...call.request.payload ?? {}
285512
+ });
285513
+ callback(null, {
285514
+ result: useVerity ? broker.last_proof : JSON.stringify(balance)
285515
+ });
285516
+ } catch (error) {
285517
+ log.error(`Error fetching balance from ${cex3}:`, error);
285518
+ callback({
285519
+ code: grpc.status.INTERNAL,
285520
+ message: `Failed to fetch balance from ${cex3}`
285521
+ }, null);
285522
+ }
285523
+ break;
285497
285524
  default:
285498
285525
  return callback({
285499
285526
  code: grpc.status.INVALID_ARGUMENT,
@@ -285502,6 +285529,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285502
285529
  }
285503
285530
  },
285504
285531
  Subscribe: async (call) => {
285532
+ const request = call.request;
285505
285533
  if (!authenticateRequest(call, whitelistIps)) {
285506
285534
  call.emit("error", {
285507
285535
  code: grpc.status.PERMISSION_DENIED,
@@ -285512,16 +285540,22 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285512
285540
  const metadata = call.metadata;
285513
285541
  let broker = null;
285514
285542
  try {
285515
- const request = call.request;
285516
- const { cex: cex3, symbol, type: type2, options } = request;
285517
- if (!cex3 || !symbol || type2 === undefined) {
285543
+ const request2 = call.request;
285544
+ const { cex: cex3, symbol, type: type2, options } = request2;
285545
+ const subscriptionType = type2 !== undefined ? type2 : SubscriptionType.ORDERBOOK;
285546
+ log.info(`Request - Subscribe: ${JSON.stringify({
285547
+ cex: request2.cex,
285548
+ symbol: request2.symbol,
285549
+ type: subscriptionType
285550
+ })}`);
285551
+ if (!cex3 || !symbol) {
285518
285552
  call.write({
285519
285553
  data: JSON.stringify({
285520
285554
  error: "cex, symbol, and type are required"
285521
285555
  }),
285522
285556
  timestamp: Date.now(),
285523
285557
  symbol: symbol || "",
285524
- type: type2 || SubscriptionType.ORDERBOOK
285558
+ type: subscriptionType
285525
285559
  });
285526
285560
  call.end();
285527
285561
  return;
@@ -285534,12 +285568,12 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285534
285568
  }),
285535
285569
  timestamp: Date.now(),
285536
285570
  symbol,
285537
- type: type2
285571
+ type: subscriptionType
285538
285572
  });
285539
285573
  call.end();
285540
285574
  return;
285541
285575
  }
285542
- switch (type2) {
285576
+ switch (subscriptionType) {
285543
285577
  case SubscriptionType.ORDERBOOK:
285544
285578
  try {
285545
285579
  while (true) {
@@ -285548,7 +285582,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285548
285582
  data: JSON.stringify(orderbook),
285549
285583
  timestamp: Date.now(),
285550
285584
  symbol,
285551
- type: type2
285585
+ type: subscriptionType
285552
285586
  });
285553
285587
  }
285554
285588
  } catch (error) {
@@ -285560,7 +285594,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285560
285594
  }),
285561
285595
  timestamp: Date.now(),
285562
285596
  symbol,
285563
- type: type2
285597
+ type: subscriptionType
285564
285598
  });
285565
285599
  }
285566
285600
  break;
@@ -285572,7 +285606,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285572
285606
  data: JSON.stringify(trades),
285573
285607
  timestamp: Date.now(),
285574
285608
  symbol,
285575
- type: type2
285609
+ type: subscriptionType
285576
285610
  });
285577
285611
  }
285578
285612
  } catch (error) {
@@ -285584,7 +285618,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285584
285618
  }),
285585
285619
  timestamp: Date.now(),
285586
285620
  symbol,
285587
- type: type2
285621
+ type: subscriptionType
285588
285622
  });
285589
285623
  }
285590
285624
  break;
@@ -285608,7 +285642,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285608
285642
  }),
285609
285643
  timestamp: Date.now(),
285610
285644
  symbol,
285611
- type: type2
285645
+ type: subscriptionType
285612
285646
  });
285613
285647
  }
285614
285648
  break;
@@ -285633,7 +285667,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285633
285667
  }),
285634
285668
  timestamp: Date.now(),
285635
285669
  symbol,
285636
- type: type2
285670
+ type: subscriptionType
285637
285671
  });
285638
285672
  }
285639
285673
  break;
@@ -285657,7 +285691,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285657
285691
  }),
285658
285692
  timestamp: Date.now(),
285659
285693
  symbol,
285660
- type: type2
285694
+ type: subscriptionType
285661
285695
  });
285662
285696
  }
285663
285697
  break;
@@ -285681,7 +285715,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
285681
285715
  }),
285682
285716
  timestamp: Date.now(),
285683
285717
  symbol,
285684
- type: type2
285718
+ type: subscriptionType
285685
285719
  });
285686
285720
  }
285687
285721
  break;
@@ -285942,6 +285976,9 @@ class CEXBroker {
285942
285976
  recvWindow: 60000
285943
285977
  }
285944
285978
  });
285979
+ if (process.env.CEX_BROKER_SANDBOX_MODE === "true") {
285980
+ client.setSandboxMode(true);
285981
+ }
285945
285982
  this.brokers[broker] = {
285946
285983
  primary: client,
285947
285984
  secondaryBrokers
@@ -286082,4 +286119,4 @@ export {
286082
286119
  CEXBroker as default
286083
286120
  };
286084
286121
 
286085
- //# debugId=18C1DCDB521AE71364756E2164756E21
286122
+ //# debugId=653E3F4FDCC17C0364756E2164756E21