@tradejs/node 1.0.2 → 1.0.4

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/cli.js CHANGED
@@ -1361,11 +1361,11 @@ var require_lodash = __commonJS({
1361
1361
  return isFunction(object[key]);
1362
1362
  });
1363
1363
  }
1364
- function baseGet(object, path2) {
1365
- path2 = castPath(path2, object);
1366
- var index = 0, length = path2.length;
1364
+ function baseGet(object, path3) {
1365
+ path3 = castPath(path3, object);
1366
+ var index = 0, length = path3.length;
1367
1367
  while (object != null && index < length) {
1368
- object = object[toKey(path2[index++])];
1368
+ object = object[toKey(path3[index++])];
1369
1369
  }
1370
1370
  return index && index == length ? object : undefined2;
1371
1371
  }
@@ -1429,10 +1429,10 @@ var require_lodash = __commonJS({
1429
1429
  });
1430
1430
  return accumulator;
1431
1431
  }
1432
- function baseInvoke(object, path2, args) {
1433
- path2 = castPath(path2, object);
1434
- object = parent(object, path2);
1435
- var func = object == null ? object : object[toKey(last(path2))];
1432
+ function baseInvoke(object, path3, args) {
1433
+ path3 = castPath(path3, object);
1434
+ object = parent(object, path3);
1435
+ var func = object == null ? object : object[toKey(last(path3))];
1436
1436
  return func == null ? undefined2 : apply(func, object, args);
1437
1437
  }
1438
1438
  function baseIsArguments(value) {
@@ -1588,13 +1588,13 @@ var require_lodash = __commonJS({
1588
1588
  return object === source || baseIsMatch(object, source, matchData);
1589
1589
  };
1590
1590
  }
1591
- function baseMatchesProperty(path2, srcValue) {
1592
- if (isKey(path2) && isStrictComparable(srcValue)) {
1593
- return matchesStrictComparable(toKey(path2), srcValue);
1591
+ function baseMatchesProperty(path3, srcValue) {
1592
+ if (isKey(path3) && isStrictComparable(srcValue)) {
1593
+ return matchesStrictComparable(toKey(path3), srcValue);
1594
1594
  }
1595
1595
  return function(object) {
1596
- var objValue = get(object, path2);
1597
- return objValue === undefined2 && objValue === srcValue ? hasIn(object, path2) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
1596
+ var objValue = get(object, path3);
1597
+ return objValue === undefined2 && objValue === srcValue ? hasIn(object, path3) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
1598
1598
  };
1599
1599
  }
1600
1600
  function baseMerge(object, source, srcIndex, customizer, stack) {
@@ -1691,23 +1691,23 @@ var require_lodash = __commonJS({
1691
1691
  });
1692
1692
  }
1693
1693
  function basePick(object, paths) {
1694
- return basePickBy(object, paths, function(value, path2) {
1695
- return hasIn(object, path2);
1694
+ return basePickBy(object, paths, function(value, path3) {
1695
+ return hasIn(object, path3);
1696
1696
  });
1697
1697
  }
1698
1698
  function basePickBy(object, paths, predicate) {
1699
1699
  var index = -1, length = paths.length, result2 = {};
1700
1700
  while (++index < length) {
1701
- var path2 = paths[index], value = baseGet(object, path2);
1702
- if (predicate(value, path2)) {
1703
- baseSet(result2, castPath(path2, object), value);
1701
+ var path3 = paths[index], value = baseGet(object, path3);
1702
+ if (predicate(value, path3)) {
1703
+ baseSet(result2, castPath(path3, object), value);
1704
1704
  }
1705
1705
  }
1706
1706
  return result2;
1707
1707
  }
1708
- function basePropertyDeep(path2) {
1708
+ function basePropertyDeep(path3) {
1709
1709
  return function(object) {
1710
- return baseGet(object, path2);
1710
+ return baseGet(object, path3);
1711
1711
  };
1712
1712
  }
1713
1713
  function basePullAll(array, values2, iteratee2, comparator) {
@@ -1781,14 +1781,14 @@ var require_lodash = __commonJS({
1781
1781
  var array = values(collection);
1782
1782
  return shuffleSelf(array, baseClamp(n, 0, array.length));
1783
1783
  }
1784
- function baseSet(object, path2, value, customizer) {
1784
+ function baseSet(object, path3, value, customizer) {
1785
1785
  if (!isObject(object)) {
1786
1786
  return object;
1787
1787
  }
1788
- path2 = castPath(path2, object);
1789
- var index = -1, length = path2.length, lastIndex = length - 1, nested = object;
1788
+ path3 = castPath(path3, object);
1789
+ var index = -1, length = path3.length, lastIndex = length - 1, nested = object;
1790
1790
  while (nested != null && ++index < length) {
1791
- var key = toKey(path2[index]), newValue = value;
1791
+ var key = toKey(path3[index]), newValue = value;
1792
1792
  if (key === "__proto__" || key === "constructor" || key === "prototype") {
1793
1793
  return object;
1794
1794
  }
@@ -1796,7 +1796,7 @@ var require_lodash = __commonJS({
1796
1796
  var objValue = nested[key];
1797
1797
  newValue = customizer ? customizer(objValue, key, nested) : undefined2;
1798
1798
  if (newValue === undefined2) {
1799
- newValue = isObject(objValue) ? objValue : isIndex(path2[index + 1]) ? [] : {};
1799
+ newValue = isObject(objValue) ? objValue : isIndex(path3[index + 1]) ? [] : {};
1800
1800
  }
1801
1801
  }
1802
1802
  assignValue(nested, key, newValue);
@@ -1962,13 +1962,13 @@ var require_lodash = __commonJS({
1962
1962
  }
1963
1963
  return result2;
1964
1964
  }
1965
- function baseUnset(object, path2) {
1966
- path2 = castPath(path2, object);
1967
- object = parent(object, path2);
1968
- return object == null || delete object[toKey(last(path2))];
1965
+ function baseUnset(object, path3) {
1966
+ path3 = castPath(path3, object);
1967
+ object = parent(object, path3);
1968
+ return object == null || delete object[toKey(last(path3))];
1969
1969
  }
1970
- function baseUpdate(object, path2, updater, customizer) {
1971
- return baseSet(object, path2, updater(baseGet(object, path2)), customizer);
1970
+ function baseUpdate(object, path3, updater, customizer) {
1971
+ return baseSet(object, path3, updater(baseGet(object, path3)), customizer);
1972
1972
  }
1973
1973
  function baseWhile(array, predicate, isDrop, fromRight) {
1974
1974
  var length = array.length, index = fromRight ? length : -1;
@@ -2851,11 +2851,11 @@ var require_lodash = __commonJS({
2851
2851
  var match = source.match(reWrapDetails);
2852
2852
  return match ? match[1].split(reSplitDetails) : [];
2853
2853
  }
2854
- function hasPath(object, path2, hasFunc) {
2855
- path2 = castPath(path2, object);
2856
- var index = -1, length = path2.length, result2 = false;
2854
+ function hasPath(object, path3, hasFunc) {
2855
+ path3 = castPath(path3, object);
2856
+ var index = -1, length = path3.length, result2 = false;
2857
2857
  while (++index < length) {
2858
- var key = toKey(path2[index]);
2858
+ var key = toKey(path3[index]);
2859
2859
  if (!(result2 = object != null && hasFunc(object, key))) {
2860
2860
  break;
2861
2861
  }
@@ -3057,8 +3057,8 @@ var require_lodash = __commonJS({
3057
3057
  return apply(func, this, otherArgs);
3058
3058
  };
3059
3059
  }
3060
- function parent(object, path2) {
3061
- return path2.length < 2 ? object : baseGet(object, baseSlice(path2, 0, -1));
3060
+ function parent(object, path3) {
3061
+ return path3.length < 2 ? object : baseGet(object, baseSlice(path3, 0, -1));
3062
3062
  }
3063
3063
  function reorder(array, indexes) {
3064
3064
  var arrLength = array.length, length = nativeMin(indexes.length, arrLength), oldArray = copyArray(array);
@@ -3693,10 +3693,10 @@ var require_lodash = __commonJS({
3693
3693
  }
3694
3694
  return isString(collection) ? fromIndex <= length && collection.indexOf(value, fromIndex) > -1 : !!length && baseIndexOf(collection, value, fromIndex) > -1;
3695
3695
  }
3696
- var invokeMap = baseRest(function(collection, path2, args) {
3697
- var index = -1, isFunc = typeof path2 == "function", result2 = isArrayLike(collection) ? Array2(collection.length) : [];
3696
+ var invokeMap = baseRest(function(collection, path3, args) {
3697
+ var index = -1, isFunc = typeof path3 == "function", result2 = isArrayLike(collection) ? Array2(collection.length) : [];
3698
3698
  baseEach(collection, function(value) {
3699
- result2[++index] = isFunc ? apply(path2, value, args) : baseInvoke(value, path2, args);
3699
+ result2[++index] = isFunc ? apply(path3, value, args) : baseInvoke(value, path3, args);
3700
3700
  });
3701
3701
  return result2;
3702
3702
  });
@@ -4348,15 +4348,15 @@ var require_lodash = __commonJS({
4348
4348
  function functionsIn(object) {
4349
4349
  return object == null ? [] : baseFunctions(object, keysIn(object));
4350
4350
  }
4351
- function get(object, path2, defaultValue) {
4352
- var result2 = object == null ? undefined2 : baseGet(object, path2);
4351
+ function get(object, path3, defaultValue) {
4352
+ var result2 = object == null ? undefined2 : baseGet(object, path3);
4353
4353
  return result2 === undefined2 ? defaultValue : result2;
4354
4354
  }
4355
- function has(object, path2) {
4356
- return object != null && hasPath(object, path2, baseHas);
4355
+ function has(object, path3) {
4356
+ return object != null && hasPath(object, path3, baseHas);
4357
4357
  }
4358
- function hasIn(object, path2) {
4359
- return object != null && hasPath(object, path2, baseHasIn);
4358
+ function hasIn(object, path3) {
4359
+ return object != null && hasPath(object, path3, baseHasIn);
4360
4360
  }
4361
4361
  var invert = createInverter(function(result2, value, key) {
4362
4362
  if (value != null && typeof value.toString != "function") {
@@ -4409,10 +4409,10 @@ var require_lodash = __commonJS({
4409
4409
  return result2;
4410
4410
  }
4411
4411
  var isDeep = false;
4412
- paths = arrayMap(paths, function(path2) {
4413
- path2 = castPath(path2, object);
4414
- isDeep || (isDeep = path2.length > 1);
4415
- return path2;
4412
+ paths = arrayMap(paths, function(path3) {
4413
+ path3 = castPath(path3, object);
4414
+ isDeep || (isDeep = path3.length > 1);
4415
+ return path3;
4416
4416
  });
4417
4417
  copyObject(object, getAllKeysIn(object), result2);
4418
4418
  if (isDeep) {
@@ -4438,19 +4438,19 @@ var require_lodash = __commonJS({
4438
4438
  return [prop];
4439
4439
  });
4440
4440
  predicate = getIteratee(predicate);
4441
- return basePickBy(object, props, function(value, path2) {
4442
- return predicate(value, path2[0]);
4441
+ return basePickBy(object, props, function(value, path3) {
4442
+ return predicate(value, path3[0]);
4443
4443
  });
4444
4444
  }
4445
- function result(object, path2, defaultValue) {
4446
- path2 = castPath(path2, object);
4447
- var index = -1, length = path2.length;
4445
+ function result(object, path3, defaultValue) {
4446
+ path3 = castPath(path3, object);
4447
+ var index = -1, length = path3.length;
4448
4448
  if (!length) {
4449
4449
  length = 1;
4450
4450
  object = undefined2;
4451
4451
  }
4452
4452
  while (++index < length) {
4453
- var value = object == null ? undefined2 : object[toKey(path2[index])];
4453
+ var value = object == null ? undefined2 : object[toKey(path3[index])];
4454
4454
  if (value === undefined2) {
4455
4455
  index = length;
4456
4456
  value = defaultValue;
@@ -4459,12 +4459,12 @@ var require_lodash = __commonJS({
4459
4459
  }
4460
4460
  return object;
4461
4461
  }
4462
- function set(object, path2, value) {
4463
- return object == null ? object : baseSet(object, path2, value);
4462
+ function set(object, path3, value) {
4463
+ return object == null ? object : baseSet(object, path3, value);
4464
4464
  }
4465
- function setWith(object, path2, value, customizer) {
4465
+ function setWith(object, path3, value, customizer) {
4466
4466
  customizer = typeof customizer == "function" ? customizer : undefined2;
4467
- return object == null ? object : baseSet(object, path2, value, customizer);
4467
+ return object == null ? object : baseSet(object, path3, value, customizer);
4468
4468
  }
4469
4469
  var toPairs = createToPairs(keys);
4470
4470
  var toPairsIn = createToPairs(keysIn);
@@ -4486,15 +4486,15 @@ var require_lodash = __commonJS({
4486
4486
  });
4487
4487
  return accumulator;
4488
4488
  }
4489
- function unset(object, path2) {
4490
- return object == null ? true : baseUnset(object, path2);
4489
+ function unset(object, path3) {
4490
+ return object == null ? true : baseUnset(object, path3);
4491
4491
  }
4492
- function update2(object, path2, updater) {
4493
- return object == null ? object : baseUpdate(object, path2, castFunction(updater));
4492
+ function update2(object, path3, updater) {
4493
+ return object == null ? object : baseUpdate(object, path3, castFunction(updater));
4494
4494
  }
4495
- function updateWith(object, path2, updater, customizer) {
4495
+ function updateWith(object, path3, updater, customizer) {
4496
4496
  customizer = typeof customizer == "function" ? customizer : undefined2;
4497
- return object == null ? object : baseUpdate(object, path2, castFunction(updater), customizer);
4497
+ return object == null ? object : baseUpdate(object, path3, castFunction(updater), customizer);
4498
4498
  }
4499
4499
  function values(object) {
4500
4500
  return object == null ? [] : baseValues(object, keys(object));
@@ -4875,17 +4875,17 @@ var require_lodash = __commonJS({
4875
4875
  function matches(source) {
4876
4876
  return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
4877
4877
  }
4878
- function matchesProperty(path2, srcValue) {
4879
- return baseMatchesProperty(path2, baseClone(srcValue, CLONE_DEEP_FLAG));
4878
+ function matchesProperty(path3, srcValue) {
4879
+ return baseMatchesProperty(path3, baseClone(srcValue, CLONE_DEEP_FLAG));
4880
4880
  }
4881
- var method = baseRest(function(path2, args) {
4881
+ var method = baseRest(function(path3, args) {
4882
4882
  return function(object) {
4883
- return baseInvoke(object, path2, args);
4883
+ return baseInvoke(object, path3, args);
4884
4884
  };
4885
4885
  });
4886
4886
  var methodOf = baseRest(function(object, args) {
4887
- return function(path2) {
4888
- return baseInvoke(object, path2, args);
4887
+ return function(path3) {
4888
+ return baseInvoke(object, path3, args);
4889
4889
  };
4890
4890
  });
4891
4891
  function mixin(object, source, options) {
@@ -4932,12 +4932,12 @@ var require_lodash = __commonJS({
4932
4932
  var over = createOver(arrayMap);
4933
4933
  var overEvery = createOver(arrayEvery);
4934
4934
  var overSome = createOver(arraySome);
4935
- function property(path2) {
4936
- return isKey(path2) ? baseProperty(toKey(path2)) : basePropertyDeep(path2);
4935
+ function property(path3) {
4936
+ return isKey(path3) ? baseProperty(toKey(path3)) : basePropertyDeep(path3);
4937
4937
  }
4938
4938
  function propertyOf(object) {
4939
- return function(path2) {
4940
- return object == null ? undefined2 : baseGet(object, path2);
4939
+ return function(path3) {
4940
+ return object == null ? undefined2 : baseGet(object, path3);
4941
4941
  };
4942
4942
  }
4943
4943
  var range = createRange();
@@ -5390,12 +5390,12 @@ var require_lodash = __commonJS({
5390
5390
  LazyWrapper.prototype.findLast = function(predicate) {
5391
5391
  return this.reverse().find(predicate);
5392
5392
  };
5393
- LazyWrapper.prototype.invokeMap = baseRest(function(path2, args) {
5394
- if (typeof path2 == "function") {
5393
+ LazyWrapper.prototype.invokeMap = baseRest(function(path3, args) {
5394
+ if (typeof path3 == "function") {
5395
5395
  return new LazyWrapper(this);
5396
5396
  }
5397
5397
  return this.map(function(value) {
5398
- return baseInvoke(value, path2, args);
5398
+ return baseInvoke(value, path3, args);
5399
5399
  });
5400
5400
  });
5401
5401
  LazyWrapper.prototype.reject = function(predicate) {
@@ -5578,13 +5578,45 @@ var import_indicators = require("@tradejs/core/indicators");
5578
5578
  var import_logger2 = require("@tradejs/infra/logger");
5579
5579
 
5580
5580
  // src/tradejsConfig.ts
5581
+ var import_path = __toESM(require("path"));
5581
5582
  var import_logger = require("@tradejs/infra/logger");
5583
+ var getTradejsProjectCwd = (cwd) => {
5584
+ const explicit = String(cwd ?? "").trim();
5585
+ if (explicit) {
5586
+ return import_path.default.resolve(explicit);
5587
+ }
5588
+ const fromEnv = String(process.env.PROJECT_CWD || "").trim();
5589
+ if (fromEnv) {
5590
+ return import_path.default.resolve(fromEnv);
5591
+ }
5592
+ return process.cwd();
5593
+ };
5582
5594
 
5583
5595
  // src/strategy/manifests.ts
5584
- var strategyCreators = /* @__PURE__ */ new Map();
5585
- var strategyManifestsMap = /* @__PURE__ */ new Map();
5586
- var getStrategyManifest = (name) => {
5587
- return name ? strategyManifestsMap.get(name) : void 0;
5596
+ var createStrategyRegistryState = () => ({
5597
+ strategyCreators: /* @__PURE__ */ new Map(),
5598
+ strategyManifestsMap: /* @__PURE__ */ new Map(),
5599
+ pluginsLoadPromise: null
5600
+ });
5601
+ var registryStateByProjectRoot = /* @__PURE__ */ new Map();
5602
+ var getStrategyRegistryState = (cwd = getTradejsProjectCwd()) => {
5603
+ const projectRoot = getTradejsProjectCwd(cwd);
5604
+ let state = registryStateByProjectRoot.get(projectRoot);
5605
+ if (!state) {
5606
+ state = createStrategyRegistryState();
5607
+ registryStateByProjectRoot.set(projectRoot, state);
5608
+ }
5609
+ return {
5610
+ projectRoot,
5611
+ state
5612
+ };
5613
+ };
5614
+ var getStrategyManifest = (name, cwd = getTradejsProjectCwd()) => {
5615
+ if (!name) {
5616
+ return void 0;
5617
+ }
5618
+ const { state } = getStrategyRegistryState(cwd);
5619
+ return state.strategyManifestsMap.get(name);
5588
5620
  };
5589
5621
  var strategies = new Proxy(
5590
5622
  {},
@@ -5593,10 +5625,10 @@ var strategies = new Proxy(
5593
5625
  if (typeof property !== "string") {
5594
5626
  return void 0;
5595
5627
  }
5596
- return strategyCreators.get(property);
5628
+ return getStrategyRegistryState().state.strategyCreators.get(property);
5597
5629
  },
5598
5630
  ownKeys: () => {
5599
- return [...strategyCreators.keys()];
5631
+ return [...getStrategyRegistryState().state.strategyCreators.keys()];
5600
5632
  },
5601
5633
  getOwnPropertyDescriptor: () => ({
5602
5634
  enumerable: true,
@@ -5862,24 +5894,21 @@ var askAI = async (signal) => {
5862
5894
 
5863
5895
  // src/screenshot.ts
5864
5896
  var import_promises = __toESM(require("fs/promises"));
5865
- var import_path = __toESM(require("path"));
5897
+ var import_path2 = __toESM(require("path"));
5866
5898
  var import_puppeteer = __toESM(require("puppeteer"));
5867
5899
  var import_async = require("@tradejs/core/async");
5868
5900
  var import_redis2 = require("@tradejs/infra/redis");
5869
5901
  var { APP_URL } = process.env;
5870
- var getProjectRoot = () => {
5871
- const fromEnv = String(process.env.PROJECT_CWD || "").trim();
5872
- return fromEnv ? import_path.default.resolve(fromEnv) : process.cwd();
5873
- };
5874
- var getScreenshotsDir = () => import_path.default.join(getProjectRoot(), "data", "screenshots");
5902
+ var getProjectRoot = (projectRoot) => import_path2.default.resolve(getTradejsProjectCwd(projectRoot));
5903
+ var getScreenshotsDir = (projectRoot) => import_path2.default.join(getProjectRoot(projectRoot), "data", "screenshots");
5875
5904
  var getImageUrl = ({ symbol, signalId, interval }) => `${APP_URL}/api/files/screenshot/${symbol}_${signalId}_${interval}`;
5876
- var getScreenshotPath = ({ symbol, signalId, interval }) => {
5877
- return import_path.default.join(
5878
- getScreenshotsDir(),
5905
+ var getScreenshotPath = ({ symbol, signalId, interval }, projectRoot) => {
5906
+ return import_path2.default.join(
5907
+ getScreenshotsDir(projectRoot),
5879
5908
  `${symbol}_${signalId}_${interval}.png`
5880
5909
  );
5881
5910
  };
5882
- var screenDashboard = async (signal) => {
5911
+ var screenDashboard = async (signal, projectRoot) => {
5883
5912
  const { symbol, signalId, interval } = signal;
5884
5913
  const rootUser = await (0, import_redis2.getData)(import_redis2.redisKeys.user("root"), null);
5885
5914
  const token2 = rootUser && typeof rootUser === "object" ? rootUser.token : null;
@@ -5907,9 +5936,9 @@ var screenDashboard = async (signal) => {
5907
5936
  `${APP_URL}/routes/dashboard/bybit/${symbol}/${interval}/?signalId=${signalId}&autoZoom=true${tokenParam}`
5908
5937
  );
5909
5938
  await (0, import_async.delay)(1e4);
5910
- await import_promises.default.mkdir(getScreenshotsDir(), { recursive: true });
5939
+ await import_promises.default.mkdir(getScreenshotsDir(projectRoot), { recursive: true });
5911
5940
  await page.screenshot({
5912
- path: getScreenshotPath(signal)
5941
+ path: getScreenshotPath(signal, projectRoot)
5913
5942
  });
5914
5943
  } finally {
5915
5944
  await page.close();
@@ -6083,12 +6112,14 @@ var sendSignal = async (signal, imgInterval, analysis) => {
6083
6112
  });
6084
6113
  const data = await res.json();
6085
6114
  if (!data?.ok) {
6115
+ import_logger3.logger.error("tg sendPhoto failed: %s", JSON.stringify(data));
6086
6116
  await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
6087
6117
  method: "POST",
6088
6118
  headers: { "Content-Type": "application/json" },
6089
6119
  body: JSON.stringify({
6090
6120
  chat_id: chatId,
6091
- text: JSON.stringify(data),
6121
+ text: message,
6122
+ reply_markup: markup,
6092
6123
  parse_mode: "HTML"
6093
6124
  })
6094
6125
  });
@@ -6156,9 +6187,11 @@ var sendSignalAnalysis = async (signal, analysis) => {
6156
6187
  };
6157
6188
 
6158
6189
  // src/cli.ts
6190
+ var getProjectRoot2 = () => getTradejsProjectCwd();
6159
6191
  var cleanFiles = async (dir) => {
6160
6192
  let completed = 0;
6161
- const files = await (0, import_files.getFiles)(dir);
6193
+ const projectRoot = getProjectRoot2();
6194
+ const files = await (0, import_files.getFiles)(dir, projectRoot);
6162
6195
  const bar = new import_progress.default(":current/:total [:bar][:percent] :eta(s)", {
6163
6196
  total: files.length,
6164
6197
  width: 30
@@ -6286,6 +6319,7 @@ var getTickers = async (connector, include = "", exclude = "", limit, chunk) =>
6286
6319
  return tickers.filter((t) => !excludeTickers.includes(t));
6287
6320
  };
6288
6321
  var makeScreenshots = async (signals, interval) => {
6322
+ const projectRoot = getProjectRoot2();
6289
6323
  const bar = new import_progress.default(
6290
6324
  ":current/:total [:bar][:percent] :eta(s) :symbol",
6291
6325
  {
@@ -6299,7 +6333,7 @@ var makeScreenshots = async (signals, interval) => {
6299
6333
  SCREENSHOT_CONCURRENCY_LIMIT,
6300
6334
  async (signal) => {
6301
6335
  try {
6302
- await screenDashboard({ ...signal, interval });
6336
+ await screenDashboard({ ...signal, interval }, projectRoot);
6303
6337
  } catch (error) {
6304
6338
  import_logger4.logger.error(
6305
6339
  "Failed screenshot: %s (%s)",
@@ -6352,8 +6386,12 @@ var sendToTG = async (signals, imgInterval) => {
6352
6386
  if (analysis && typeof analysis === "object" && Object.keys(analysis).length > 0) {
6353
6387
  await sendSignalAnalysis(signal, analysis);
6354
6388
  }
6355
- } catch {
6356
- import_logger4.logger.error("Failed sent: %s", signal.symbol);
6389
+ } catch (err) {
6390
+ import_logger4.logger.error(
6391
+ "Failed sent: %s %s",
6392
+ signal.symbol,
6393
+ err?.message || String(err)
6394
+ );
6357
6395
  } finally {
6358
6396
  bar.tick(1, { symbol: import_chalk.default.gray(signal.symbol) });
6359
6397
  }
package/dist/cli.mjs CHANGED
@@ -9,9 +9,11 @@ import {
9
9
  } from "./chunk-GKDBAF3A.mjs";
10
10
  import {
11
11
  askAI
12
- } from "./chunk-ZIMX3JX2.mjs";
13
- import "./chunk-MHCXPD2B.mjs";
14
- import "./chunk-DE7ADBIR.mjs";
12
+ } from "./chunk-LMAKIC3C.mjs";
13
+ import "./chunk-ZY6ULOWK.mjs";
14
+ import {
15
+ getTradejsProjectCwd
16
+ } from "./chunk-P2ZUWONT.mjs";
15
17
  import {
16
18
  __toESM
17
19
  } from "./chunk-6DZX6EAA.mjs";
@@ -43,19 +45,16 @@ import puppeteer from "puppeteer";
43
45
  import { delay } from "@tradejs/core/async";
44
46
  import { getData, redisKeys } from "@tradejs/infra/redis";
45
47
  var { APP_URL } = process.env;
46
- var getProjectRoot = () => {
47
- const fromEnv = String(process.env.PROJECT_CWD || "").trim();
48
- return fromEnv ? path.resolve(fromEnv) : process.cwd();
49
- };
50
- var getScreenshotsDir = () => path.join(getProjectRoot(), "data", "screenshots");
48
+ var getProjectRoot = (projectRoot) => path.resolve(getTradejsProjectCwd(projectRoot));
49
+ var getScreenshotsDir = (projectRoot) => path.join(getProjectRoot(projectRoot), "data", "screenshots");
51
50
  var getImageUrl = ({ symbol, signalId, interval }) => `${APP_URL}/api/files/screenshot/${symbol}_${signalId}_${interval}`;
52
- var getScreenshotPath = ({ symbol, signalId, interval }) => {
51
+ var getScreenshotPath = ({ symbol, signalId, interval }, projectRoot) => {
53
52
  return path.join(
54
- getScreenshotsDir(),
53
+ getScreenshotsDir(projectRoot),
55
54
  `${symbol}_${signalId}_${interval}.png`
56
55
  );
57
56
  };
58
- var screenDashboard = async (signal) => {
57
+ var screenDashboard = async (signal, projectRoot) => {
59
58
  const { symbol, signalId, interval } = signal;
60
59
  const rootUser = await getData(redisKeys.user("root"), null);
61
60
  const token2 = rootUser && typeof rootUser === "object" ? rootUser.token : null;
@@ -83,9 +82,9 @@ var screenDashboard = async (signal) => {
83
82
  `${APP_URL}/routes/dashboard/bybit/${symbol}/${interval}/?signalId=${signalId}&autoZoom=true${tokenParam}`
84
83
  );
85
84
  await delay(1e4);
86
- await fs.mkdir(getScreenshotsDir(), { recursive: true });
85
+ await fs.mkdir(getScreenshotsDir(projectRoot), { recursive: true });
87
86
  await page.screenshot({
88
- path: getScreenshotPath(signal)
87
+ path: getScreenshotPath(signal, projectRoot)
89
88
  });
90
89
  } finally {
91
90
  await page.close();
@@ -259,12 +258,14 @@ var sendSignal = async (signal, imgInterval, analysis) => {
259
258
  });
260
259
  const data = await res.json();
261
260
  if (!data?.ok) {
261
+ logger.error("tg sendPhoto failed: %s", JSON.stringify(data));
262
262
  await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
263
263
  method: "POST",
264
264
  headers: { "Content-Type": "application/json" },
265
265
  body: JSON.stringify({
266
266
  chat_id: chatId,
267
- text: JSON.stringify(data),
267
+ text: message,
268
+ reply_markup: markup,
268
269
  parse_mode: "HTML"
269
270
  })
270
271
  });
@@ -332,9 +333,11 @@ var sendSignalAnalysis = async (signal, analysis) => {
332
333
  };
333
334
 
334
335
  // src/cli.ts
336
+ var getProjectRoot2 = () => getTradejsProjectCwd();
335
337
  var cleanFiles = async (dir) => {
336
338
  let completed = 0;
337
- const files = await getFiles(dir);
339
+ const projectRoot = getProjectRoot2();
340
+ const files = await getFiles(dir, projectRoot);
338
341
  const bar = new ProgressBar(":current/:total [:bar][:percent] :eta(s)", {
339
342
  total: files.length,
340
343
  width: 30
@@ -462,6 +465,7 @@ var getTickers = async (connector, include = "", exclude = "", limit, chunk) =>
462
465
  return tickers.filter((t) => !excludeTickers.includes(t));
463
466
  };
464
467
  var makeScreenshots = async (signals, interval) => {
468
+ const projectRoot = getProjectRoot2();
465
469
  const bar = new ProgressBar(
466
470
  ":current/:total [:bar][:percent] :eta(s) :symbol",
467
471
  {
@@ -475,7 +479,7 @@ var makeScreenshots = async (signals, interval) => {
475
479
  SCREENSHOT_CONCURRENCY_LIMIT,
476
480
  async (signal) => {
477
481
  try {
478
- await screenDashboard({ ...signal, interval });
482
+ await screenDashboard({ ...signal, interval }, projectRoot);
479
483
  } catch (error) {
480
484
  logger2.error(
481
485
  "Failed screenshot: %s (%s)",
@@ -528,8 +532,12 @@ var sendToTG = async (signals, imgInterval) => {
528
532
  if (analysis && typeof analysis === "object" && Object.keys(analysis).length > 0) {
529
533
  await sendSignalAnalysis(signal, analysis);
530
534
  }
531
- } catch {
532
- logger2.error("Failed sent: %s", signal.symbol);
535
+ } catch (err) {
536
+ logger2.error(
537
+ "Failed sent: %s %s",
538
+ signal.symbol,
539
+ err?.message || String(err)
540
+ );
533
541
  } finally {
534
542
  bar.tick(1, { symbol: chalk.gray(signal.symbol) });
535
543
  }
@@ -6,15 +6,15 @@ declare const BUILTIN_CONNECTOR_NAMES: {
6
6
  readonly Coinbase: "Coinbase";
7
7
  readonly Test: "Test";
8
8
  };
9
- declare const ensureConnectorPluginsLoaded: () => Promise<void>;
10
- declare const getConnectorCreatorByName: (connectorName: unknown) => Promise<ConnectorCreator | undefined>;
11
- declare const getConnectorNameByProvider: (provider: unknown) => Promise<string | undefined>;
12
- declare const getConnectorCreatorByProvider: (provider: unknown) => Promise<ConnectorCreator | undefined>;
13
- declare const resolveConnectorName: (providerOrName: unknown) => Promise<string | undefined>;
14
- declare const getAvailableConnectorNames: () => Promise<string[]>;
15
- declare const getAvailableConnectorProviders: () => Promise<string[]>;
16
- declare const registerConnectorEntries: (entries: readonly ConnectorRegistryEntry[]) => void;
17
- declare const resetConnectorRegistryCache: () => void;
9
+ declare const ensureConnectorPluginsLoaded: (cwd?: string) => Promise<void>;
10
+ declare const getConnectorCreatorByName: (connectorName: unknown, cwd?: string) => Promise<ConnectorCreator | undefined>;
11
+ declare const getConnectorNameByProvider: (provider: unknown, cwd?: string) => Promise<string | undefined>;
12
+ declare const getConnectorCreatorByProvider: (provider: unknown, cwd?: string) => Promise<ConnectorCreator | undefined>;
13
+ declare const resolveConnectorName: (providerOrName: unknown, cwd?: string) => Promise<string | undefined>;
14
+ declare const getAvailableConnectorNames: (cwd?: string) => Promise<string[]>;
15
+ declare const getAvailableConnectorProviders: (cwd?: string) => Promise<string[]>;
16
+ declare const registerConnectorEntries: (entries: readonly ConnectorRegistryEntry[], cwd?: string) => void;
17
+ declare const resetConnectorRegistryCache: (cwd?: string) => void;
18
18
  declare const DEFAULT_CONNECTOR_NAME: "ByBit";
19
19
 
20
20
  export { BUILTIN_CONNECTOR_NAMES, DEFAULT_CONNECTOR_NAME, ensureConnectorPluginsLoaded, getAvailableConnectorNames, getAvailableConnectorProviders, getConnectorCreatorByName, getConnectorCreatorByProvider, getConnectorNameByProvider, registerConnectorEntries, resetConnectorRegistryCache, resolveConnectorName };
@@ -6,15 +6,15 @@ declare const BUILTIN_CONNECTOR_NAMES: {
6
6
  readonly Coinbase: "Coinbase";
7
7
  readonly Test: "Test";
8
8
  };
9
- declare const ensureConnectorPluginsLoaded: () => Promise<void>;
10
- declare const getConnectorCreatorByName: (connectorName: unknown) => Promise<ConnectorCreator | undefined>;
11
- declare const getConnectorNameByProvider: (provider: unknown) => Promise<string | undefined>;
12
- declare const getConnectorCreatorByProvider: (provider: unknown) => Promise<ConnectorCreator | undefined>;
13
- declare const resolveConnectorName: (providerOrName: unknown) => Promise<string | undefined>;
14
- declare const getAvailableConnectorNames: () => Promise<string[]>;
15
- declare const getAvailableConnectorProviders: () => Promise<string[]>;
16
- declare const registerConnectorEntries: (entries: readonly ConnectorRegistryEntry[]) => void;
17
- declare const resetConnectorRegistryCache: () => void;
9
+ declare const ensureConnectorPluginsLoaded: (cwd?: string) => Promise<void>;
10
+ declare const getConnectorCreatorByName: (connectorName: unknown, cwd?: string) => Promise<ConnectorCreator | undefined>;
11
+ declare const getConnectorNameByProvider: (provider: unknown, cwd?: string) => Promise<string | undefined>;
12
+ declare const getConnectorCreatorByProvider: (provider: unknown, cwd?: string) => Promise<ConnectorCreator | undefined>;
13
+ declare const resolveConnectorName: (providerOrName: unknown, cwd?: string) => Promise<string | undefined>;
14
+ declare const getAvailableConnectorNames: (cwd?: string) => Promise<string[]>;
15
+ declare const getAvailableConnectorProviders: (cwd?: string) => Promise<string[]>;
16
+ declare const registerConnectorEntries: (entries: readonly ConnectorRegistryEntry[], cwd?: string) => void;
17
+ declare const resetConnectorRegistryCache: (cwd?: string) => void;
18
18
  declare const DEFAULT_CONNECTOR_NAME: "ByBit";
19
19
 
20
20
  export { BUILTIN_CONNECTOR_NAMES, DEFAULT_CONNECTOR_NAME, ensureConnectorPluginsLoaded, getAvailableConnectorNames, getAvailableConnectorProviders, getConnectorCreatorByName, getConnectorCreatorByProvider, getConnectorNameByProvider, registerConnectorEntries, resetConnectorRegistryCache, resolveConnectorName };