@tradejs/node 2.0.17 → 2.0.19

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.mjs CHANGED
@@ -3,25 +3,19 @@ import {
3
3
  KLINE_CONCURRENCY_LIMIT,
4
4
  SCREENSHOT_CONCURRENCY_LIMIT
5
5
  } from "./chunk-KMJQQ53K.mjs";
6
- import {
7
- require_lodash
8
- } from "./chunk-GPR56UYQ.mjs";
9
6
  import {
10
7
  askAI
11
- } from "./chunk-WK5EUCX5.mjs";
12
- import "./chunk-QVSMINLG.mjs";
8
+ } from "./chunk-4AVFJMQL.mjs";
13
9
  import {
14
10
  getTradejsProjectCwd,
15
11
  loadTradejsConfig
16
12
  } from "./chunk-WS5DYEVZ.mjs";
17
- import {
18
- __toESM
19
- } from "./chunk-UV2HVMKZ.mjs";
13
+ import "./chunk-Y6FXYEAI.mjs";
20
14
 
21
15
  // src/cli.ts
22
- var import_lodash = __toESM(require_lodash());
23
16
  import fs2 from "fs/promises";
24
17
  import path2 from "path";
18
+ import _ from "lodash";
25
19
  import ProgressBar from "progress";
26
20
  import chalk from "chalk";
27
21
  import { runWithConcurrency } from "@tradejs/core/async";
@@ -38,7 +32,7 @@ import {
38
32
  redisKeys
39
33
  } from "@tradejs/infra/redis";
40
34
  import { logger as logger3 } from "@tradejs/infra/logger";
41
- import { getDataEdgesForSymbols } from "@tradejs/infra/timescale";
35
+ import { getDataEdgesForSymbols } from "@tradejs/infra/timescale/candles";
42
36
 
43
37
  // src/screenshot.ts
44
38
  import fs from "fs/promises";
@@ -1230,7 +1224,7 @@ var getTickers = async (connector, include = "", exclude = "", limit, chunk, que
1230
1224
  const [currentChunk, chunksCount] = chunk.split("/").map((c) => parseInt(c));
1231
1225
  logger3.info("chunk: %d / %d", currentChunk, chunksCount);
1232
1226
  const chunkSize = Math.ceil(tickers.length / chunksCount);
1233
- const chunks = import_lodash.default.chunk(tickers, chunkSize);
1227
+ const chunks = _.chunk(tickers, chunkSize);
1234
1228
  tickers = chunks[currentChunk - 1];
1235
1229
  }
1236
1230
  return tickers.filter((t) => !excludeTickers.includes(t));
@@ -12,7 +12,7 @@ import {
12
12
  resolveConnectorName
13
13
  } from "./chunk-V3YMKE4I.mjs";
14
14
  import "./chunk-WS5DYEVZ.mjs";
15
- import "./chunk-UV2HVMKZ.mjs";
15
+ import "./chunk-Y6FXYEAI.mjs";
16
16
  export {
17
17
  BUILTIN_CONNECTOR_NAMES,
18
18
  DEFAULT_CONNECTOR_NAME,
@@ -4,7 +4,7 @@ import {
4
4
  SCREENSHOT_CONCURRENCY_LIMIT,
5
5
  TG_CONCURRENCY_LIMIT
6
6
  } from "./chunk-KMJQQ53K.mjs";
7
- import "./chunk-UV2HVMKZ.mjs";
7
+ import "./chunk-Y6FXYEAI.mjs";
8
8
  export {
9
9
  AI_CONCURRENCY_LIMIT,
10
10
  KLINE_CONCURRENCY_LIMIT,
package/dist/pine.mjs CHANGED
@@ -1,17 +1,126 @@
1
1
  import {
2
- createPineScriptLoader,
3
- getLatestPineBooleanPlotValue,
4
- getLatestPineBooleanPlotValues,
5
- getLatestPineNumberPlotValue,
6
- getLatestPineNumberPlotValues,
7
- getLatestPineRawPlotValue,
8
- getPinePlotSeries,
9
- loadPineScriptFile,
10
- runPineScript,
11
- toFiniteNumber,
12
- toPineBoolean
13
- } from "./chunk-IQKMII6L.mjs";
14
- import "./chunk-UV2HVMKZ.mjs";
2
+ __require
3
+ } from "./chunk-Y6FXYEAI.mjs";
4
+
5
+ // src/pine.ts
6
+ import fs from "fs";
7
+ import path from "path";
8
+ var getPinePlotSeries = (context, plotName) => {
9
+ const name = String(plotName || "").trim();
10
+ if (!name) return [];
11
+ const data = context?.plots?.[name]?.data;
12
+ return Array.isArray(data) ? data : [];
13
+ };
14
+ var getLatestPineRawPlotValue = (context, plotName) => {
15
+ const series = getPinePlotSeries(context, plotName);
16
+ if (!series.length) return void 0;
17
+ return series[series.length - 1]?.value;
18
+ };
19
+ var getLatestPineNumberPlotValue = (context, plotName) => toFiniteNumber(getLatestPineRawPlotValue(context, plotName)) ?? null;
20
+ var getLatestPineBooleanPlotValue = (context, plotName) => toPineBoolean(getLatestPineRawPlotValue(context, plotName));
21
+ var getLatestPineNumberPlotValues = (context, plotNames) => Object.fromEntries(
22
+ plotNames.map((plotName) => [
23
+ plotName,
24
+ getLatestPineNumberPlotValue(context, plotName)
25
+ ])
26
+ );
27
+ var getLatestPineBooleanPlotValues = (context, plotNames) => Object.fromEntries(
28
+ plotNames.map((plotName) => [
29
+ plotName,
30
+ getLatestPineBooleanPlotValue(context, plotName)
31
+ ])
32
+ );
33
+ var toFiniteNumber = (value) => {
34
+ if (typeof value !== "number" || !Number.isFinite(value)) {
35
+ return void 0;
36
+ }
37
+ return value;
38
+ };
39
+ var toPineBoolean = (value) => {
40
+ if (typeof value === "boolean") return value;
41
+ if (typeof value === "number") return Number.isFinite(value) && value !== 0;
42
+ return false;
43
+ };
44
+ var loadPinets = () => {
45
+ const resolvedPath = __require.resolve("pinets");
46
+ const cjsPath = resolvedPath.includes("pinets.min.browser") ? resolvedPath.replace(/pinets\.min\.browser(\.es)?\.js$/, "pinets.min.cjs") : resolvedPath;
47
+ return __require(cjsPath);
48
+ };
49
+ var loadPineScriptFile = (filePath, fallback = "") => {
50
+ const resolvedPath = String(filePath || "").trim();
51
+ if (!resolvedPath) {
52
+ return fallback;
53
+ }
54
+ try {
55
+ return fs.readFileSync(resolvedPath, "utf8").trim();
56
+ } catch {
57
+ return fallback;
58
+ }
59
+ };
60
+ var createPineScriptLoader = (baseDir) => {
61
+ const resolvedBaseDir = path.resolve(baseDir);
62
+ return (fileNameOrPath, fallback = "") => {
63
+ const rawPath = String(fileNameOrPath || "").trim();
64
+ if (!rawPath) {
65
+ return fallback;
66
+ }
67
+ const resolvedPath = path.isAbsolute(rawPath) ? rawPath : path.resolve(resolvedBaseDir, rawPath);
68
+ return loadPineScriptFile(resolvedPath, fallback);
69
+ };
70
+ };
71
+ var MINUTE_MS = 6e4;
72
+ var normalizeTimestampMs = (timestamp) => timestamp < 1e12 ? timestamp * 1e3 : timestamp;
73
+ var resolveCandleDuration = (candles) => {
74
+ if (candles.length < 2) {
75
+ return MINUTE_MS;
76
+ }
77
+ const first = normalizeTimestampMs(candles[0].timestamp);
78
+ const second = normalizeTimestampMs(candles[1].timestamp);
79
+ const duration = Math.max(second - first, MINUTE_MS);
80
+ return Number.isFinite(duration) && duration > 0 ? duration : MINUTE_MS;
81
+ };
82
+ var toPineRuntimeCandles = (candles) => {
83
+ const candleDuration = resolveCandleDuration(candles);
84
+ return candles.map((candle) => {
85
+ const openTime = normalizeTimestampMs(candle.timestamp);
86
+ return {
87
+ open: Number(candle.open),
88
+ high: Number(candle.high),
89
+ low: Number(candle.low),
90
+ close: Number(candle.close),
91
+ volume: Number(candle.volume ?? 0),
92
+ openTime,
93
+ closeTime: openTime + candleDuration
94
+ };
95
+ });
96
+ };
97
+ var runPineScript = async ({
98
+ candles,
99
+ script,
100
+ symbol = "SYMBOL",
101
+ timeframe = "15",
102
+ inputs = {},
103
+ limit
104
+ }) => {
105
+ const { PineTS, Indicator } = loadPinets();
106
+ const trimmedScript = String(script || "").trim();
107
+ if (!trimmedScript) {
108
+ throw new Error("Pine script is empty");
109
+ }
110
+ if (!Array.isArray(candles) || candles.length === 0) {
111
+ throw new Error("No candles provided for Pine script execution");
112
+ }
113
+ const pineCandles = toPineRuntimeCandles(candles);
114
+ const pine = new PineTS(
115
+ pineCandles,
116
+ symbol,
117
+ timeframe,
118
+ Math.max(1, limit ?? pineCandles.length)
119
+ );
120
+ const indicator = new Indicator(trimmedScript, inputs);
121
+ const context = await pine.run(indicator);
122
+ return context;
123
+ };
15
124
  export {
16
125
  createPineScriptLoader,
17
126
  getLatestPineBooleanPlotValue,