@tradejs/node 1.0.0 → 1.0.2

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.
@@ -5,7 +5,32 @@ import {
5
5
  // src/pine.ts
6
6
  import fs from "fs";
7
7
  import path from "path";
8
- export * from "@tradejs/core/pine";
8
+
9
+ // src/pineShared.ts
10
+ var getPinePlotSeries = (context, plotName) => {
11
+ const name = String(plotName || "").trim();
12
+ if (!name) return [];
13
+ const data = context?.plots?.[name]?.data;
14
+ return Array.isArray(data) ? data : [];
15
+ };
16
+ var getLatestPinePlotValue = (context, plotName) => {
17
+ const series = getPinePlotSeries(context, plotName);
18
+ if (!series.length) return void 0;
19
+ return series[series.length - 1]?.value;
20
+ };
21
+ var asFiniteNumber = (value) => {
22
+ if (typeof value !== "number" || !Number.isFinite(value)) {
23
+ return void 0;
24
+ }
25
+ return value;
26
+ };
27
+ var asPineBoolean = (value) => {
28
+ if (typeof value === "boolean") return value;
29
+ if (typeof value === "number") return Number.isFinite(value) && value !== 0;
30
+ return false;
31
+ };
32
+
33
+ // src/pine.ts
9
34
  var loadPinets = () => {
10
35
  const resolvedPath = __require.resolve("pinets");
11
36
  const cjsPath = resolvedPath.includes("pinets.min.browser") ? resolvedPath.replace(/pinets\.min\.browser(\.es)?\.js$/, "pinets.min.cjs") : resolvedPath;
@@ -88,6 +113,10 @@ var runPineScript = async ({
88
113
  };
89
114
 
90
115
  export {
116
+ getPinePlotSeries,
117
+ getLatestPinePlotValue,
118
+ asFiniteNumber,
119
+ asPineBoolean,
91
120
  loadPineScript,
92
121
  createLoadPineScript,
93
122
  runPineScript
package/dist/pine.d.mts CHANGED
@@ -1,8 +1,33 @@
1
- import { RunPineScriptParams, PineContextLike } from '@tradejs/core/pine';
2
- export * from '@tradejs/core/pine';
1
+ import { Candle } from '@tradejs/types';
2
+
3
+ interface PinePlotPoint {
4
+ title?: string;
5
+ time?: number;
6
+ value?: unknown;
7
+ options?: Record<string, unknown>;
8
+ }
9
+ interface PineContextLike {
10
+ plots?: Record<string, {
11
+ data?: PinePlotPoint[];
12
+ }>;
13
+ result?: Record<string, unknown>;
14
+ [key: string]: unknown;
15
+ }
16
+ interface RunPineScriptParams {
17
+ candles: Candle[];
18
+ script: string;
19
+ symbol?: string;
20
+ timeframe?: string;
21
+ inputs?: Record<string, unknown>;
22
+ limit?: number;
23
+ }
24
+ declare const getPinePlotSeries: (context: PineContextLike, plotName: string) => PinePlotPoint[];
25
+ declare const getLatestPinePlotValue: (context: PineContextLike, plotName: string) => unknown;
26
+ declare const asFiniteNumber: (value: unknown) => number | undefined;
27
+ declare const asPineBoolean: (value: unknown) => boolean;
3
28
 
4
29
  declare const loadPineScript: (filePath: string, fallback?: string) => string;
5
30
  declare const createLoadPineScript: (baseDir: string) => ((fileNameOrPath: string, fallback?: string) => string);
6
31
  declare const runPineScript: ({ candles, script, symbol, timeframe, inputs, limit, }: RunPineScriptParams) => Promise<PineContextLike>;
7
32
 
8
- export { createLoadPineScript, loadPineScript, runPineScript };
33
+ export { type PineContextLike, type PinePlotPoint, type RunPineScriptParams, asFiniteNumber, asPineBoolean, createLoadPineScript, getLatestPinePlotValue, getPinePlotSeries, loadPineScript, runPineScript };
package/dist/pine.d.ts CHANGED
@@ -1,8 +1,33 @@
1
- import { RunPineScriptParams, PineContextLike } from '@tradejs/core/pine';
2
- export * from '@tradejs/core/pine';
1
+ import { Candle } from '@tradejs/types';
2
+
3
+ interface PinePlotPoint {
4
+ title?: string;
5
+ time?: number;
6
+ value?: unknown;
7
+ options?: Record<string, unknown>;
8
+ }
9
+ interface PineContextLike {
10
+ plots?: Record<string, {
11
+ data?: PinePlotPoint[];
12
+ }>;
13
+ result?: Record<string, unknown>;
14
+ [key: string]: unknown;
15
+ }
16
+ interface RunPineScriptParams {
17
+ candles: Candle[];
18
+ script: string;
19
+ symbol?: string;
20
+ timeframe?: string;
21
+ inputs?: Record<string, unknown>;
22
+ limit?: number;
23
+ }
24
+ declare const getPinePlotSeries: (context: PineContextLike, plotName: string) => PinePlotPoint[];
25
+ declare const getLatestPinePlotValue: (context: PineContextLike, plotName: string) => unknown;
26
+ declare const asFiniteNumber: (value: unknown) => number | undefined;
27
+ declare const asPineBoolean: (value: unknown) => boolean;
3
28
 
4
29
  declare const loadPineScript: (filePath: string, fallback?: string) => string;
5
30
  declare const createLoadPineScript: (baseDir: string) => ((fileNameOrPath: string, fallback?: string) => string);
6
31
  declare const runPineScript: ({ candles, script, symbol, timeframe, inputs, limit, }: RunPineScriptParams) => Promise<PineContextLike>;
7
32
 
8
- export { createLoadPineScript, loadPineScript, runPineScript };
33
+ export { type PineContextLike, type PinePlotPoint, type RunPineScriptParams, asFiniteNumber, asPineBoolean, createLoadPineScript, getLatestPinePlotValue, getPinePlotSeries, loadPineScript, runPineScript };
package/dist/pine.js CHANGED
@@ -17,7 +17,6 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
21
  // If the importer is in node compatibility mode or this is not an ESM
23
22
  // file that has been converted to a CommonJS file using a Babel-
@@ -31,14 +30,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
30
  // src/pine.ts
32
31
  var pine_exports = {};
33
32
  __export(pine_exports, {
33
+ asFiniteNumber: () => asFiniteNumber,
34
+ asPineBoolean: () => asPineBoolean,
34
35
  createLoadPineScript: () => createLoadPineScript,
36
+ getLatestPinePlotValue: () => getLatestPinePlotValue,
37
+ getPinePlotSeries: () => getPinePlotSeries,
35
38
  loadPineScript: () => loadPineScript,
36
39
  runPineScript: () => runPineScript
37
40
  });
38
41
  module.exports = __toCommonJS(pine_exports);
39
42
  var import_node_fs = __toESM(require("fs"));
40
43
  var import_node_path = __toESM(require("path"));
41
- __reExport(pine_exports, require("@tradejs/core/pine"), module.exports);
44
+
45
+ // src/pineShared.ts
46
+ var getPinePlotSeries = (context, plotName) => {
47
+ const name = String(plotName || "").trim();
48
+ if (!name) return [];
49
+ const data = context?.plots?.[name]?.data;
50
+ return Array.isArray(data) ? data : [];
51
+ };
52
+ var getLatestPinePlotValue = (context, plotName) => {
53
+ const series = getPinePlotSeries(context, plotName);
54
+ if (!series.length) return void 0;
55
+ return series[series.length - 1]?.value;
56
+ };
57
+ var asFiniteNumber = (value) => {
58
+ if (typeof value !== "number" || !Number.isFinite(value)) {
59
+ return void 0;
60
+ }
61
+ return value;
62
+ };
63
+ var asPineBoolean = (value) => {
64
+ if (typeof value === "boolean") return value;
65
+ if (typeof value === "number") return Number.isFinite(value) && value !== 0;
66
+ return false;
67
+ };
68
+
69
+ // src/pine.ts
42
70
  var loadPinets = () => {
43
71
  const resolvedPath = require.resolve("pinets");
44
72
  const cjsPath = resolvedPath.includes("pinets.min.browser") ? resolvedPath.replace(/pinets\.min\.browser(\.es)?\.js$/, "pinets.min.cjs") : resolvedPath;
@@ -121,8 +149,11 @@ var runPineScript = async ({
121
149
  };
122
150
  // Annotate the CommonJS export names for ESM import in node:
123
151
  0 && (module.exports = {
152
+ asFiniteNumber,
153
+ asPineBoolean,
124
154
  createLoadPineScript,
155
+ getLatestPinePlotValue,
156
+ getPinePlotSeries,
125
157
  loadPineScript,
126
- runPineScript,
127
- ...require("@tradejs/core/pine")
158
+ runPineScript
128
159
  });
package/dist/pine.mjs CHANGED
@@ -1,11 +1,19 @@
1
1
  import {
2
+ asFiniteNumber,
3
+ asPineBoolean,
2
4
  createLoadPineScript,
5
+ getLatestPinePlotValue,
6
+ getPinePlotSeries,
3
7
  loadPineScript,
4
8
  runPineScript
5
- } from "./chunk-CVTV6S2V.mjs";
9
+ } from "./chunk-OB4CSYDJ.mjs";
6
10
  import "./chunk-6DZX6EAA.mjs";
7
11
  export {
12
+ asFiniteNumber,
13
+ asPineBoolean,
8
14
  createLoadPineScript,
15
+ getLatestPinePlotValue,
16
+ getPinePlotSeries,
9
17
  loadPineScript,
10
18
  runPineScript
11
19
  };
@@ -6518,20 +6518,8 @@ var executeEntryOrder = async ({
6518
6518
  };
6519
6519
 
6520
6520
  // src/pine.ts
6521
- var pine_exports = {};
6522
- __export(pine_exports, {
6523
- createLoadPineScript: () => createLoadPineScript,
6524
- loadPineScript: () => loadPineScript,
6525
- runPineScript: () => runPineScript
6526
- });
6527
6521
  var import_node_fs = __toESM(require("fs"));
6528
6522
  var import_node_path = __toESM(require("path"));
6529
- __reExport(pine_exports, require("@tradejs/core/pine"));
6530
- var loadPinets = () => {
6531
- const resolvedPath = require.resolve("pinets");
6532
- const cjsPath = resolvedPath.includes("pinets.min.browser") ? resolvedPath.replace(/pinets\.min\.browser(\.es)?\.js$/, "pinets.min.cjs") : resolvedPath;
6533
- return require(cjsPath);
6534
- };
6535
6523
  var loadPineScript = (filePath, fallback = "") => {
6536
6524
  const resolvedPath = String(filePath || "").trim();
6537
6525
  if (!resolvedPath) {
@@ -6554,59 +6542,6 @@ var createLoadPineScript = (baseDir) => {
6554
6542
  return loadPineScript(resolvedPath, fallback);
6555
6543
  };
6556
6544
  };
6557
- var MINUTE_MS = 6e4;
6558
- var normalizeTimestampMs = (timestamp) => timestamp < 1e12 ? timestamp * 1e3 : timestamp;
6559
- var resolveCandleDuration = (candles) => {
6560
- if (candles.length < 2) {
6561
- return MINUTE_MS;
6562
- }
6563
- const first = normalizeTimestampMs(candles[0].timestamp);
6564
- const second = normalizeTimestampMs(candles[1].timestamp);
6565
- const duration = Math.max(second - first, MINUTE_MS);
6566
- return Number.isFinite(duration) && duration > 0 ? duration : MINUTE_MS;
6567
- };
6568
- var toPineRuntimeCandles = (candles) => {
6569
- const candleDuration = resolveCandleDuration(candles);
6570
- return candles.map((candle) => {
6571
- const openTime = normalizeTimestampMs(candle.timestamp);
6572
- return {
6573
- open: Number(candle.open),
6574
- high: Number(candle.high),
6575
- low: Number(candle.low),
6576
- close: Number(candle.close),
6577
- volume: Number(candle.volume ?? 0),
6578
- openTime,
6579
- closeTime: openTime + candleDuration
6580
- };
6581
- });
6582
- };
6583
- var runPineScript = async ({
6584
- candles,
6585
- script,
6586
- symbol = "SYMBOL",
6587
- timeframe = "15",
6588
- inputs = {},
6589
- limit
6590
- }) => {
6591
- const { PineTS, Indicator } = loadPinets();
6592
- const trimmedScript = String(script || "").trim();
6593
- if (!trimmedScript) {
6594
- throw new Error("Pine script is empty");
6595
- }
6596
- if (!Array.isArray(candles) || candles.length === 0) {
6597
- throw new Error("No candles provided for Pine script execution");
6598
- }
6599
- const pineCandles = toPineRuntimeCandles(candles);
6600
- const pine = new PineTS(
6601
- pineCandles,
6602
- symbol,
6603
- timeframe,
6604
- Math.max(1, limit ?? pineCandles.length)
6605
- );
6606
- const indicator = new Indicator(trimmedScript, inputs);
6607
- const context = await pine.run(indicator);
6608
- return context;
6609
- };
6610
6545
 
6611
6546
  // src/strategyRuntime.ts
6612
6547
  init_manifests();
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-GKDBAF3A.mjs";
7
7
  import {
8
8
  createLoadPineScript
9
- } from "./chunk-CVTV6S2V.mjs";
9
+ } from "./chunk-OB4CSYDJ.mjs";
10
10
  import "./chunk-5YNMSWL3.mjs";
11
11
  import {
12
12
  MAX_AI_SERIES_POINTS,
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "@tradejs/node",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Node-only TradeJS runtime for strategies, backtests, Pine loading, and plugin registries.",
5
+ "keywords": [
6
+ "tradejs",
7
+ "trading",
8
+ "backtesting",
9
+ "node",
10
+ "runtime",
11
+ "strategy",
12
+ "pine-script"
13
+ ],
5
14
  "files": [
6
15
  "dist"
7
16
  ],
@@ -45,9 +54,9 @@
45
54
  "dependencies": {
46
55
  "@langchain/core": "^0.3.68",
47
56
  "@langchain/openai": "^0.6.11",
48
- "@tradejs/core": "^1.0.0",
49
- "@tradejs/infra": "^1.0.0",
50
- "@tradejs/types": "^1.0.0",
57
+ "@tradejs/core": "^1.0.2",
58
+ "@tradejs/infra": "^1.0.2",
59
+ "@tradejs/types": "^1.0.2",
51
60
  "chalk": "4.1.2",
52
61
  "ioredis": "5.8.0",
53
62
  "pinets": "0.8.12",