@tradejs/connectors 3.1.27 → 3.1.28-beta.251

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/index.js CHANGED
@@ -423,6 +423,7 @@ var resolveKlineRetryDelayMs = (res, attempt) => {
423
423
  };
424
424
  var ByBitConnectorCreator = async (config, runtime) => {
425
425
  const logger = getConnectorLogger(runtime);
426
+ const resolveTradingAccount = getConnectorAccountResolver(runtime);
426
427
  let state = {};
427
428
  const universe = (0, import_types.resolveConnectorUniverse)(
428
429
  BYBIT_CAPABILITIES,
@@ -430,6 +431,8 @@ var ByBitConnectorCreator = async (config, runtime) => {
430
431
  );
431
432
  let publicClientPromise = null;
432
433
  let privateClientPromise = null;
434
+ let privateClientInitialized = false;
435
+ let privateClientAccountSnapshot = null;
433
436
  const positionSnapshotCache = /* @__PURE__ */ new Map();
434
437
  const inflightPositionSnapshots = /* @__PURE__ */ new Map();
435
438
  const getPublicClient = async () => {
@@ -437,8 +440,36 @@ var ByBitConnectorCreator = async (config, runtime) => {
437
440
  return publicClientPromise;
438
441
  };
439
442
  const getPrivateClient = async () => {
440
- privateClientPromise ??= getClient(config, "private", runtime);
441
- return privateClientPromise;
443
+ const account = await resolveTradingAccount({
444
+ userName: config.userName,
445
+ accountId: config.accountId,
446
+ provider: "bybit",
447
+ universe: config.universe
448
+ });
449
+ const nextSnapshot = account ? {
450
+ id: account.id,
451
+ apiKey: account.apiKey,
452
+ apiSecret: account.apiSecret,
453
+ environment: account.environment
454
+ } : null;
455
+ const credentialsChanged = privateClientInitialized && (privateClientAccountSnapshot?.id !== nextSnapshot?.id || privateClientAccountSnapshot?.apiKey !== nextSnapshot?.apiKey || privateClientAccountSnapshot?.apiSecret !== nextSnapshot?.apiSecret || privateClientAccountSnapshot?.environment !== nextSnapshot?.environment);
456
+ if (!privateClientInitialized || credentialsChanged) {
457
+ if (privateClientInitialized && privateClientAccountSnapshot?.environment !== nextSnapshot?.environment) {
458
+ publicClientPromise = null;
459
+ }
460
+ privateClientPromise = getClient(config, "private", runtime);
461
+ privateClientAccountSnapshot = nextSnapshot;
462
+ privateClientInitialized = true;
463
+ positionSnapshotCache.clear();
464
+ inflightPositionSnapshots.clear();
465
+ }
466
+ try {
467
+ return await privateClientPromise;
468
+ } catch (error) {
469
+ privateClientPromise = null;
470
+ privateClientInitialized = false;
471
+ throw error;
472
+ }
442
473
  };
443
474
  const instrumentCache = /* @__PURE__ */ new Map();
444
475
  const fetchInstrumentGroup = async (symbolType) => {
package/dist/index.mjs CHANGED
@@ -375,6 +375,7 @@ var resolveKlineRetryDelayMs = (res, attempt) => {
375
375
  };
376
376
  var ByBitConnectorCreator = async (config, runtime) => {
377
377
  const logger = getConnectorLogger(runtime);
378
+ const resolveTradingAccount = getConnectorAccountResolver(runtime);
378
379
  let state = {};
379
380
  const universe = resolveConnectorUniverse(
380
381
  BYBIT_CAPABILITIES,
@@ -382,6 +383,8 @@ var ByBitConnectorCreator = async (config, runtime) => {
382
383
  );
383
384
  let publicClientPromise = null;
384
385
  let privateClientPromise = null;
386
+ let privateClientInitialized = false;
387
+ let privateClientAccountSnapshot = null;
385
388
  const positionSnapshotCache = /* @__PURE__ */ new Map();
386
389
  const inflightPositionSnapshots = /* @__PURE__ */ new Map();
387
390
  const getPublicClient = async () => {
@@ -389,8 +392,36 @@ var ByBitConnectorCreator = async (config, runtime) => {
389
392
  return publicClientPromise;
390
393
  };
391
394
  const getPrivateClient = async () => {
392
- privateClientPromise ??= getClient(config, "private", runtime);
393
- return privateClientPromise;
395
+ const account = await resolveTradingAccount({
396
+ userName: config.userName,
397
+ accountId: config.accountId,
398
+ provider: "bybit",
399
+ universe: config.universe
400
+ });
401
+ const nextSnapshot = account ? {
402
+ id: account.id,
403
+ apiKey: account.apiKey,
404
+ apiSecret: account.apiSecret,
405
+ environment: account.environment
406
+ } : null;
407
+ const credentialsChanged = privateClientInitialized && (privateClientAccountSnapshot?.id !== nextSnapshot?.id || privateClientAccountSnapshot?.apiKey !== nextSnapshot?.apiKey || privateClientAccountSnapshot?.apiSecret !== nextSnapshot?.apiSecret || privateClientAccountSnapshot?.environment !== nextSnapshot?.environment);
408
+ if (!privateClientInitialized || credentialsChanged) {
409
+ if (privateClientInitialized && privateClientAccountSnapshot?.environment !== nextSnapshot?.environment) {
410
+ publicClientPromise = null;
411
+ }
412
+ privateClientPromise = getClient(config, "private", runtime);
413
+ privateClientAccountSnapshot = nextSnapshot;
414
+ privateClientInitialized = true;
415
+ positionSnapshotCache.clear();
416
+ inflightPositionSnapshots.clear();
417
+ }
418
+ try {
419
+ return await privateClientPromise;
420
+ } catch (error) {
421
+ privateClientPromise = null;
422
+ privateClientInitialized = false;
423
+ throw error;
424
+ }
394
425
  };
395
426
  const instrumentCache = /* @__PURE__ */ new Map();
396
427
  const fetchInstrumentGroup = async (symbolType) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/connectors",
3
- "version": "3.1.27",
3
+ "version": "3.1.28-beta.251",
4
4
  "description": "MIT-licensed exchange connectors and market data providers for the TradeJS framework.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -39,8 +39,8 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@tradejs/core": "^3.1.27",
43
- "@tradejs/types": "^3.1.27",
42
+ "@tradejs/core": "^3.1.28-beta.251",
43
+ "@tradejs/types": "^3.1.28-beta.251",
44
44
  "bybit-api": "^4.7.1",
45
45
  "chalk": "4.1.2",
46
46
  "lodash": "^4.18.1"