@tradejs/core 1.0.0
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/README.md +60 -0
- package/dist/api.d.mts +7 -0
- package/dist/api.d.ts +7 -0
- package/dist/api.js +64 -0
- package/dist/api.mjs +39 -0
- package/dist/async.d.mts +4 -0
- package/dist/async.d.ts +4 -0
- package/dist/async.js +48 -0
- package/dist/async.mjs +20 -0
- package/dist/backtest.d.mts +45 -0
- package/dist/backtest.d.ts +45 -0
- package/dist/backtest.js +574 -0
- package/dist/backtest.mjs +355 -0
- package/dist/chunk-AYC2QVKI.mjs +35 -0
- package/dist/chunk-JG2QPVAV.mjs +190 -0
- package/dist/chunk-LIGD3WWX.mjs +1545 -0
- package/dist/chunk-M7QGVZ3J.mjs +61 -0
- package/dist/chunk-NQ7D3T4E.mjs +10 -0
- package/dist/chunk-PXLXXXLA.mjs +67 -0
- package/dist/config.d.mts +14 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +49 -0
- package/dist/config.mjs +21 -0
- package/dist/constants.d.mts +41 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.js +238 -0
- package/dist/constants.mjs +50 -0
- package/dist/data.d.mts +9 -0
- package/dist/data.d.ts +9 -0
- package/dist/data.js +100 -0
- package/dist/data.mjs +12 -0
- package/dist/figures.d.mts +103 -0
- package/dist/figures.d.ts +103 -0
- package/dist/figures.js +274 -0
- package/dist/figures.mjs +239 -0
- package/dist/indicators-x3xKl3_W.d.mts +90 -0
- package/dist/indicators-x3xKl3_W.d.ts +90 -0
- package/dist/indicators.d.mts +124 -0
- package/dist/indicators.d.ts +124 -0
- package/dist/indicators.js +1631 -0
- package/dist/indicators.mjs +66 -0
- package/dist/json.d.mts +3 -0
- package/dist/json.d.ts +3 -0
- package/dist/json.js +34 -0
- package/dist/json.mjs +7 -0
- package/dist/math.d.mts +35 -0
- package/dist/math.d.ts +35 -0
- package/dist/math.js +98 -0
- package/dist/math.mjs +38 -0
- package/dist/pine.d.mts +29 -0
- package/dist/pine.d.ts +29 -0
- package/dist/pine.js +59 -0
- package/dist/pine.mjs +29 -0
- package/dist/strategies.d.mts +104 -0
- package/dist/strategies.d.ts +104 -0
- package/dist/strategies.js +1080 -0
- package/dist/strategies.mjs +390 -0
- package/dist/tickers.d.mts +7 -0
- package/dist/tickers.d.ts +7 -0
- package/dist/tickers.js +166 -0
- package/dist/tickers.mjs +125 -0
- package/dist/time-DEyFa2vI.d.mts +11 -0
- package/dist/time-DEyFa2vI.d.ts +11 -0
- package/dist/time.d.mts +2 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +58 -0
- package/dist/time.mjs +15 -0
- package/package.json +99 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
alignSortedCandlesByTimestamp,
|
|
3
|
+
alignSpreadRows,
|
|
4
|
+
applyIndicatorsToHistory,
|
|
5
|
+
buildMlCandleIndicators,
|
|
6
|
+
buildMlTimeframeIndicators,
|
|
7
|
+
buildReturnsFromCandles,
|
|
8
|
+
calculateCoinBtcCorrelation,
|
|
9
|
+
calculatePearsonCorrelation,
|
|
10
|
+
coinalyzePointsToRows,
|
|
11
|
+
coinbaseProductFromSymbol,
|
|
12
|
+
createIndicators,
|
|
13
|
+
createSpreadSmoother,
|
|
14
|
+
createTrendlineEngine,
|
|
15
|
+
detectRawSupportResistance,
|
|
16
|
+
getPluginIndicatorCatalog,
|
|
17
|
+
getPluginIndicatorRenderers,
|
|
18
|
+
getRegisteredIndicatorEntries,
|
|
19
|
+
getSupportResistanceLevels,
|
|
20
|
+
intervalToMs,
|
|
21
|
+
mergeCoinalyzeMetrics,
|
|
22
|
+
normalizeCoinalyzeSymbols,
|
|
23
|
+
normalizeDerivativesIntervals,
|
|
24
|
+
registerIndicatorEntries,
|
|
25
|
+
resetIndicatorRegistryCache,
|
|
26
|
+
rollingMeanStd,
|
|
27
|
+
smoothSpreadSeries,
|
|
28
|
+
toArrayData,
|
|
29
|
+
toCoinalyzeTimestampMs,
|
|
30
|
+
toFiniteNumber
|
|
31
|
+
} from "./chunk-LIGD3WWX.mjs";
|
|
32
|
+
import "./chunk-AYC2QVKI.mjs";
|
|
33
|
+
import "./chunk-PXLXXXLA.mjs";
|
|
34
|
+
import "./chunk-JG2QPVAV.mjs";
|
|
35
|
+
import "./chunk-M7QGVZ3J.mjs";
|
|
36
|
+
export {
|
|
37
|
+
alignSortedCandlesByTimestamp,
|
|
38
|
+
alignSpreadRows,
|
|
39
|
+
applyIndicatorsToHistory,
|
|
40
|
+
buildMlCandleIndicators,
|
|
41
|
+
buildMlTimeframeIndicators,
|
|
42
|
+
buildReturnsFromCandles,
|
|
43
|
+
calculateCoinBtcCorrelation,
|
|
44
|
+
calculatePearsonCorrelation,
|
|
45
|
+
coinalyzePointsToRows,
|
|
46
|
+
coinbaseProductFromSymbol,
|
|
47
|
+
createIndicators,
|
|
48
|
+
createSpreadSmoother,
|
|
49
|
+
createTrendlineEngine,
|
|
50
|
+
detectRawSupportResistance,
|
|
51
|
+
getPluginIndicatorCatalog,
|
|
52
|
+
getPluginIndicatorRenderers,
|
|
53
|
+
getRegisteredIndicatorEntries,
|
|
54
|
+
getSupportResistanceLevels,
|
|
55
|
+
intervalToMs,
|
|
56
|
+
mergeCoinalyzeMetrics,
|
|
57
|
+
normalizeCoinalyzeSymbols,
|
|
58
|
+
normalizeDerivativesIntervals,
|
|
59
|
+
registerIndicatorEntries,
|
|
60
|
+
resetIndicatorRegistryCache,
|
|
61
|
+
rollingMeanStd,
|
|
62
|
+
smoothSpreadSeries,
|
|
63
|
+
toArrayData,
|
|
64
|
+
toCoinalyzeTimestampMs,
|
|
65
|
+
toFiniteNumber
|
|
66
|
+
};
|
package/dist/json.d.mts
ADDED
package/dist/json.d.ts
ADDED
package/dist/json.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/json.ts
|
|
21
|
+
var json_exports = {};
|
|
22
|
+
__export(json_exports, {
|
|
23
|
+
toJson: () => toJson
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(json_exports);
|
|
26
|
+
|
|
27
|
+
// src/utils/toJson.ts
|
|
28
|
+
var toJson = (data, stringify = false) => {
|
|
29
|
+
return stringify ? JSON.stringify(data, null, 2) : JSON.stringify(data);
|
|
30
|
+
};
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
toJson
|
|
34
|
+
});
|
package/dist/json.mjs
ADDED
package/dist/math.d.mts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PositionLogData } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
declare const diffRel: (a: number, b: number) => number;
|
|
4
|
+
declare const round: (value: number, precision?: number) => number;
|
|
5
|
+
/** Сумма чисел массива. */
|
|
6
|
+
declare const sum: (xs: number[]) => number;
|
|
7
|
+
/** Арифметическое среднее. Для пустого массива возвращает 0. */
|
|
8
|
+
declare const mean: (xs: number[]) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Абсолютные ретёрны на сделку в тех же единицах, что и amount (например, $).
|
|
11
|
+
* r_i^abs = close.amount - open.amount
|
|
12
|
+
*/
|
|
13
|
+
declare const absReturns: (data: PositionLogData) => number[];
|
|
14
|
+
/**
|
|
15
|
+
* Относительные ретёрны на сделку (доли).
|
|
16
|
+
* r_i^rel = (close - open) / open
|
|
17
|
+
* Пример: +0.02 = +2%
|
|
18
|
+
*/
|
|
19
|
+
declare const relReturns: (data: PositionLogData) => number[];
|
|
20
|
+
/**
|
|
21
|
+
* Уплощённая временная линия equity: берём точки (open, close) каждой позиции
|
|
22
|
+
* и сортируем по времени. Это «суррогат» equity-кривой.
|
|
23
|
+
* ВАЖНО: если между позициями ничего не меняется, текущий подход «переносит»
|
|
24
|
+
* последний известный amount вплоть до следующей точки.
|
|
25
|
+
*/
|
|
26
|
+
declare const equityPoints: (data: PositionLogData) => {
|
|
27
|
+
ts: number;
|
|
28
|
+
amount: number;
|
|
29
|
+
}[];
|
|
30
|
+
declare const formatNumber: (n?: number | null, digits?: number) => string | null;
|
|
31
|
+
|
|
32
|
+
declare const asPositiveInt: (value: unknown, fallback: number) => number;
|
|
33
|
+
declare const asPositiveNumber: (value: unknown, fallback: number) => number;
|
|
34
|
+
|
|
35
|
+
export { absReturns, asPositiveInt, asPositiveNumber, diffRel, equityPoints, formatNumber, mean, relReturns, round, sum };
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PositionLogData } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
declare const diffRel: (a: number, b: number) => number;
|
|
4
|
+
declare const round: (value: number, precision?: number) => number;
|
|
5
|
+
/** Сумма чисел массива. */
|
|
6
|
+
declare const sum: (xs: number[]) => number;
|
|
7
|
+
/** Арифметическое среднее. Для пустого массива возвращает 0. */
|
|
8
|
+
declare const mean: (xs: number[]) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Абсолютные ретёрны на сделку в тех же единицах, что и amount (например, $).
|
|
11
|
+
* r_i^abs = close.amount - open.amount
|
|
12
|
+
*/
|
|
13
|
+
declare const absReturns: (data: PositionLogData) => number[];
|
|
14
|
+
/**
|
|
15
|
+
* Относительные ретёрны на сделку (доли).
|
|
16
|
+
* r_i^rel = (close - open) / open
|
|
17
|
+
* Пример: +0.02 = +2%
|
|
18
|
+
*/
|
|
19
|
+
declare const relReturns: (data: PositionLogData) => number[];
|
|
20
|
+
/**
|
|
21
|
+
* Уплощённая временная линия equity: берём точки (open, close) каждой позиции
|
|
22
|
+
* и сортируем по времени. Это «суррогат» equity-кривой.
|
|
23
|
+
* ВАЖНО: если между позициями ничего не меняется, текущий подход «переносит»
|
|
24
|
+
* последний известный amount вплоть до следующей точки.
|
|
25
|
+
*/
|
|
26
|
+
declare const equityPoints: (data: PositionLogData) => {
|
|
27
|
+
ts: number;
|
|
28
|
+
amount: number;
|
|
29
|
+
}[];
|
|
30
|
+
declare const formatNumber: (n?: number | null, digits?: number) => string | null;
|
|
31
|
+
|
|
32
|
+
declare const asPositiveInt: (value: unknown, fallback: number) => number;
|
|
33
|
+
declare const asPositiveNumber: (value: unknown, fallback: number) => number;
|
|
34
|
+
|
|
35
|
+
export { absReturns, asPositiveInt, asPositiveNumber, diffRel, equityPoints, formatNumber, mean, relReturns, round, sum };
|
package/dist/math.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/math.ts
|
|
31
|
+
var math_exports = {};
|
|
32
|
+
__export(math_exports, {
|
|
33
|
+
absReturns: () => absReturns,
|
|
34
|
+
asPositiveInt: () => asPositiveInt,
|
|
35
|
+
asPositiveNumber: () => asPositiveNumber,
|
|
36
|
+
diffRel: () => diffRel,
|
|
37
|
+
equityPoints: () => equityPoints,
|
|
38
|
+
formatNumber: () => formatNumber,
|
|
39
|
+
mean: () => mean,
|
|
40
|
+
relReturns: () => relReturns,
|
|
41
|
+
round: () => round,
|
|
42
|
+
sum: () => sum
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(math_exports);
|
|
45
|
+
|
|
46
|
+
// src/utils/math.ts
|
|
47
|
+
var import_lodash = __toESM(require("lodash"));
|
|
48
|
+
var diffRel = (a, b) => {
|
|
49
|
+
const min = import_lodash.default.min([a, b]) || 0;
|
|
50
|
+
const max = import_lodash.default.max([a, b]) || 0;
|
|
51
|
+
if (!min || !max) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
return (max - min) / max;
|
|
55
|
+
};
|
|
56
|
+
var round = (value, precision = 2) => precision > 0 ? Math.round(value * 10 ** precision) / 10 ** precision : Math.round(value);
|
|
57
|
+
var sum = (xs) => xs.reduce((a, b) => a + b, 0);
|
|
58
|
+
var mean = (xs) => xs.length ? sum(xs) / xs.length : 0;
|
|
59
|
+
var absReturns = (data) => data.map((p) => p.close.amount - p.open.amount);
|
|
60
|
+
var relReturns = (data) => data.map((p) => (p.close.amount - p.open.amount) / p.open.amount);
|
|
61
|
+
var equityPoints = (data) => data.flatMap((p) => [
|
|
62
|
+
{ ts: p.open.timestamp, amount: p.open.amount },
|
|
63
|
+
{ ts: p.close.timestamp, amount: p.close.amount }
|
|
64
|
+
]).sort((a, b) => a.ts - b.ts);
|
|
65
|
+
var formatNumber = (n, digits = 6) => {
|
|
66
|
+
if (n === null || n === void 0 || !Number.isFinite(n)) return null;
|
|
67
|
+
const useDigits = Math.abs(n) >= 1e3 ? 0 : digits;
|
|
68
|
+
return n.toFixed(useDigits);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/utils/number.ts
|
|
72
|
+
var asPositiveInt = (value, fallback) => {
|
|
73
|
+
const next = Number(value);
|
|
74
|
+
if (!Number.isFinite(next) || next <= 0) {
|
|
75
|
+
return fallback;
|
|
76
|
+
}
|
|
77
|
+
return Math.floor(next);
|
|
78
|
+
};
|
|
79
|
+
var asPositiveNumber = (value, fallback) => {
|
|
80
|
+
const next = Number(value);
|
|
81
|
+
if (!Number.isFinite(next) || next <= 0) {
|
|
82
|
+
return fallback;
|
|
83
|
+
}
|
|
84
|
+
return next;
|
|
85
|
+
};
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
absReturns,
|
|
89
|
+
asPositiveInt,
|
|
90
|
+
asPositiveNumber,
|
|
91
|
+
diffRel,
|
|
92
|
+
equityPoints,
|
|
93
|
+
formatNumber,
|
|
94
|
+
mean,
|
|
95
|
+
relReturns,
|
|
96
|
+
round,
|
|
97
|
+
sum
|
|
98
|
+
});
|
package/dist/math.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
absReturns,
|
|
3
|
+
diffRel,
|
|
4
|
+
equityPoints,
|
|
5
|
+
formatNumber,
|
|
6
|
+
mean,
|
|
7
|
+
relReturns,
|
|
8
|
+
round,
|
|
9
|
+
sum
|
|
10
|
+
} from "./chunk-AYC2QVKI.mjs";
|
|
11
|
+
|
|
12
|
+
// src/utils/number.ts
|
|
13
|
+
var asPositiveInt = (value, fallback) => {
|
|
14
|
+
const next = Number(value);
|
|
15
|
+
if (!Number.isFinite(next) || next <= 0) {
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
return Math.floor(next);
|
|
19
|
+
};
|
|
20
|
+
var asPositiveNumber = (value, fallback) => {
|
|
21
|
+
const next = Number(value);
|
|
22
|
+
if (!Number.isFinite(next) || next <= 0) {
|
|
23
|
+
return fallback;
|
|
24
|
+
}
|
|
25
|
+
return next;
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
absReturns,
|
|
29
|
+
asPositiveInt,
|
|
30
|
+
asPositiveNumber,
|
|
31
|
+
diffRel,
|
|
32
|
+
equityPoints,
|
|
33
|
+
formatNumber,
|
|
34
|
+
mean,
|
|
35
|
+
relReturns,
|
|
36
|
+
round,
|
|
37
|
+
sum
|
|
38
|
+
};
|
package/dist/pine.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
28
|
+
|
|
29
|
+
export { type PineContextLike, type PinePlotPoint, type RunPineScriptParams, asFiniteNumber, asPineBoolean, getLatestPinePlotValue, getPinePlotSeries };
|
package/dist/pine.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
28
|
+
|
|
29
|
+
export { type PineContextLike, type PinePlotPoint, type RunPineScriptParams, asFiniteNumber, asPineBoolean, getLatestPinePlotValue, getPinePlotSeries };
|
package/dist/pine.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/pine.ts
|
|
21
|
+
var pine_exports = {};
|
|
22
|
+
__export(pine_exports, {
|
|
23
|
+
asFiniteNumber: () => asFiniteNumber,
|
|
24
|
+
asPineBoolean: () => asPineBoolean,
|
|
25
|
+
getLatestPinePlotValue: () => getLatestPinePlotValue,
|
|
26
|
+
getPinePlotSeries: () => getPinePlotSeries
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(pine_exports);
|
|
29
|
+
|
|
30
|
+
// src/utils/pineShared.ts
|
|
31
|
+
var getPinePlotSeries = (context, plotName) => {
|
|
32
|
+
const name = String(plotName || "").trim();
|
|
33
|
+
if (!name) return [];
|
|
34
|
+
const data = context?.plots?.[name]?.data;
|
|
35
|
+
return Array.isArray(data) ? data : [];
|
|
36
|
+
};
|
|
37
|
+
var getLatestPinePlotValue = (context, plotName) => {
|
|
38
|
+
const series = getPinePlotSeries(context, plotName);
|
|
39
|
+
if (!series.length) return void 0;
|
|
40
|
+
return series[series.length - 1]?.value;
|
|
41
|
+
};
|
|
42
|
+
var asFiniteNumber = (value) => {
|
|
43
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
var asPineBoolean = (value) => {
|
|
49
|
+
if (typeof value === "boolean") return value;
|
|
50
|
+
if (typeof value === "number") return Number.isFinite(value) && value !== 0;
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
asFiniteNumber,
|
|
56
|
+
asPineBoolean,
|
|
57
|
+
getLatestPinePlotValue,
|
|
58
|
+
getPinePlotSeries
|
|
59
|
+
});
|
package/dist/pine.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/utils/pineShared.ts
|
|
2
|
+
var getPinePlotSeries = (context, plotName) => {
|
|
3
|
+
const name = String(plotName || "").trim();
|
|
4
|
+
if (!name) return [];
|
|
5
|
+
const data = context?.plots?.[name]?.data;
|
|
6
|
+
return Array.isArray(data) ? data : [];
|
|
7
|
+
};
|
|
8
|
+
var getLatestPinePlotValue = (context, plotName) => {
|
|
9
|
+
const series = getPinePlotSeries(context, plotName);
|
|
10
|
+
if (!series.length) return void 0;
|
|
11
|
+
return series[series.length - 1]?.value;
|
|
12
|
+
};
|
|
13
|
+
var asFiniteNumber = (value) => {
|
|
14
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
var asPineBoolean = (value) => {
|
|
20
|
+
if (typeof value === "boolean") return value;
|
|
21
|
+
if (typeof value === "number") return Number.isFinite(value) && value !== 0;
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
asFiniteNumber,
|
|
26
|
+
asPineBoolean,
|
|
27
|
+
getLatestPinePlotValue,
|
|
28
|
+
getPinePlotSeries
|
|
29
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, BacktestPriceMode, StrategyMarketSnapshot, BuildStrategySignalDraft, StrategyEntrySignalContext, StrategyEntryOrderPlan, StrategyEntryRuntimeOptions, StrategyDecision, BuildStrategySignalParams, Signal, StrategyAPI, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions } from '@tradejs/types';
|
|
2
|
+
import { I as IndicatorPeriods } from './indicators-x3xKl3_W.mjs';
|
|
3
|
+
import 'pg';
|
|
4
|
+
|
|
5
|
+
type IndicatorPeriodsConfig = Partial<Record<'MA_FAST' | 'MA_MEDIUM' | 'MA_SLOW' | 'OBV_SMA' | 'ATR' | 'ATR_PCT_SHORT' | 'ATR_PCT_LONG' | 'BB' | 'BB_STD' | 'MACD_FAST' | 'MACD_SLOW' | 'MACD_SIGNAL' | 'LEVEL_LOOKBACK' | 'LEVEL_DELAY', number>>;
|
|
6
|
+
declare const buildDefaultIndicatorPeriods: (config: IndicatorPeriodsConfig) => Partial<IndicatorPeriods>;
|
|
7
|
+
interface StrategyIndicatorsStateParams {
|
|
8
|
+
env: string;
|
|
9
|
+
data: KlineChartData;
|
|
10
|
+
btcData: KlineChartData;
|
|
11
|
+
btcBinanceData?: KlineChartData;
|
|
12
|
+
btcCoinbaseData?: KlineChartData;
|
|
13
|
+
periods?: Partial<IndicatorPeriods>;
|
|
14
|
+
}
|
|
15
|
+
declare const createStrategyIndicatorsState: ({ env, data, btcData, btcBinanceData, btcCoinbaseData, periods, }: StrategyIndicatorsStateParams) => StrategyIndicatorsState;
|
|
16
|
+
|
|
17
|
+
interface StrategyMarketSnapshotParams {
|
|
18
|
+
env: string;
|
|
19
|
+
connector: Connector;
|
|
20
|
+
symbol: string;
|
|
21
|
+
interval: Interval;
|
|
22
|
+
cachedData: KlineChartData;
|
|
23
|
+
preloadStart: number;
|
|
24
|
+
backtestPriceMode?: BacktestPriceMode;
|
|
25
|
+
}
|
|
26
|
+
declare const getStrategyMarketSnapshot: ({ env, connector, symbol, interval, cachedData, preloadStart, backtestPriceMode, }: StrategyMarketSnapshotParams) => Promise<StrategyMarketSnapshot>;
|
|
27
|
+
declare const calculateRiskRatio: ({ direction, currentPrice, takeProfitPrice, stopLossPrice, }: {
|
|
28
|
+
direction: Direction;
|
|
29
|
+
currentPrice: number;
|
|
30
|
+
takeProfitPrice: number;
|
|
31
|
+
stopLossPrice: number;
|
|
32
|
+
}) => number;
|
|
33
|
+
interface DirectionalTpSlPricesParams {
|
|
34
|
+
price: number;
|
|
35
|
+
direction: Direction;
|
|
36
|
+
takeProfitDelta: number;
|
|
37
|
+
stopLossDelta: number;
|
|
38
|
+
unit?: 'percent' | 'ratio';
|
|
39
|
+
maxLossValue?: number;
|
|
40
|
+
feePercent?: number;
|
|
41
|
+
}
|
|
42
|
+
interface DirectionalTpSlPricesResult {
|
|
43
|
+
stopLossPrice: number;
|
|
44
|
+
takeProfitPrice: number;
|
|
45
|
+
riskRatio: number;
|
|
46
|
+
qty?: number;
|
|
47
|
+
}
|
|
48
|
+
declare const getDirectionalTpSlPrices: ({ price, direction, takeProfitDelta, stopLossDelta, unit, maxLossValue, feePercent, }: DirectionalTpSlPricesParams) => DirectionalTpSlPricesResult;
|
|
49
|
+
|
|
50
|
+
type AiRuntimeConfigLike = {
|
|
51
|
+
AI_ENABLED?: boolean;
|
|
52
|
+
MIN_AI_QUALITY?: number;
|
|
53
|
+
};
|
|
54
|
+
type MlRuntimeConfigLike = {
|
|
55
|
+
ML_ENABLED?: boolean;
|
|
56
|
+
ML_THRESHOLD?: number;
|
|
57
|
+
};
|
|
58
|
+
declare const mapAiRuntimeFromConfig: <TConfig extends AiRuntimeConfigLike>(config: TConfig, overrides?: Partial<StrategyRuntimeAiOptions>) => StrategyRuntimeAiOptions;
|
|
59
|
+
declare const mapMlRuntimeFromConfig: <TConfig extends MlRuntimeConfigLike>(config: TConfig, overrides?: Partial<StrategyRuntimeMlOptions>) => StrategyRuntimeMlOptions;
|
|
60
|
+
declare const buildStrategySignal: ({ signalId, strategy, symbol, interval, direction, timestamp, prices, figures, indicators, additionalIndicators, isConfigFromBacktest, }: BuildStrategySignalParams) => Signal;
|
|
61
|
+
interface BuildEntrySignalDecisionParams {
|
|
62
|
+
code: string;
|
|
63
|
+
entryContext: StrategyEntrySignalContext;
|
|
64
|
+
figures?: BuildStrategySignalDraft['figures'];
|
|
65
|
+
indicators?: BuildStrategySignalDraft['indicators'];
|
|
66
|
+
additionalIndicators?: BuildStrategySignalDraft['additionalIndicators'];
|
|
67
|
+
signalId?: BuildStrategySignalDraft['signalId'];
|
|
68
|
+
orderPlan: StrategyEntryOrderPlan;
|
|
69
|
+
runtime?: StrategyEntryRuntimeOptions;
|
|
70
|
+
}
|
|
71
|
+
declare const buildEntrySignalDecision: <TFigures extends BuildStrategySignalDraft["figures"] = BuildStrategySignalDraft["figures"], TIndicators extends BuildStrategySignalDraft["indicators"] = BuildStrategySignalDraft["indicators"], TAdditional extends BuildStrategySignalDraft["additionalIndicators"] = BuildStrategySignalDraft["additionalIndicators"]>({ code, entryContext, figures, indicators, additionalIndicators, signalId, orderPlan, runtime, }: Omit<BuildEntrySignalDecisionParams, "figures" | "indicators" | "additionalIndicators"> & {
|
|
72
|
+
figures?: TFigures;
|
|
73
|
+
indicators?: TIndicators;
|
|
74
|
+
additionalIndicators?: TAdditional;
|
|
75
|
+
}) => StrategyDecision;
|
|
76
|
+
interface CreateStrategyAPIParams {
|
|
77
|
+
strategy: Signal['strategy'];
|
|
78
|
+
symbol: Signal['symbol'];
|
|
79
|
+
interval: Signal['interval'];
|
|
80
|
+
env: string;
|
|
81
|
+
connector: Connector;
|
|
82
|
+
cachedData: KlineChartData;
|
|
83
|
+
indicatorsState?: {
|
|
84
|
+
next: (candle: KlineChartData[number], btcCandle: KlineChartData[number]) => unknown;
|
|
85
|
+
};
|
|
86
|
+
preloadStart?: number;
|
|
87
|
+
backtestPriceMode?: BacktestPriceMode;
|
|
88
|
+
isConfigFromBacktest?: Signal['isConfigFromBacktest'];
|
|
89
|
+
}
|
|
90
|
+
declare const createStrategyAPI: ({ strategy, symbol, interval, env, connector, cachedData, indicatorsState, preloadStart, backtestPriceMode, isConfigFromBacktest, }: CreateStrategyAPIParams) => StrategyAPI;
|
|
91
|
+
|
|
92
|
+
interface LastTradeController {
|
|
93
|
+
isInCooldown: (timestamp: number) => boolean;
|
|
94
|
+
markTrade: (timestamp: number) => void;
|
|
95
|
+
getLastTradeTimestamp: () => number | null;
|
|
96
|
+
}
|
|
97
|
+
interface CreateLastTradeControllerParams {
|
|
98
|
+
env?: string;
|
|
99
|
+
enabled?: boolean;
|
|
100
|
+
cooldownMs?: number;
|
|
101
|
+
}
|
|
102
|
+
declare const createLastTradeController: ({ env, enabled, cooldownMs, }: CreateLastTradeControllerParams) => LastTradeController;
|
|
103
|
+
|
|
104
|
+
export { buildDefaultIndicatorPeriods, buildEntrySignalDecision, buildStrategySignal, calculateRiskRatio, createLastTradeController, createStrategyAPI, createStrategyIndicatorsState, getDirectionalTpSlPrices, getStrategyMarketSnapshot, mapAiRuntimeFromConfig, mapMlRuntimeFromConfig };
|