@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
package/dist/figures.mjs
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// src/utils/figures/entryLinePointFigure.ts
|
|
2
|
+
var createEntryLinePointFigure = ({
|
|
3
|
+
coordinates,
|
|
4
|
+
overlay
|
|
5
|
+
}) => {
|
|
6
|
+
const line = overlay.extendData?.line;
|
|
7
|
+
const color = line?.color ?? "#facc15";
|
|
8
|
+
const size = Number(line?.width ?? 2);
|
|
9
|
+
const style = line?.style ?? "solid";
|
|
10
|
+
if (coordinates.length < 2) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
type: "line",
|
|
16
|
+
attrs: {
|
|
17
|
+
coordinates: [coordinates[0], coordinates[coordinates.length - 1]]
|
|
18
|
+
},
|
|
19
|
+
styles: { color, size, style }
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/utils/figures/entryPointsPointFigure.ts
|
|
25
|
+
var createEntryPointsPointFigure = ({
|
|
26
|
+
coordinates,
|
|
27
|
+
overlay
|
|
28
|
+
}) => {
|
|
29
|
+
const points = overlay.extendData?.points;
|
|
30
|
+
const color = points?.color ?? "#ef4444";
|
|
31
|
+
const r = Number(points?.radius ?? 4);
|
|
32
|
+
const figures = [];
|
|
33
|
+
coordinates.forEach(({ x, y }, index) => {
|
|
34
|
+
figures.push({
|
|
35
|
+
type: "circle",
|
|
36
|
+
key: `entry_pt_${index}`,
|
|
37
|
+
attrs: { x, y, r },
|
|
38
|
+
styles: {
|
|
39
|
+
style: "fill",
|
|
40
|
+
color
|
|
41
|
+
},
|
|
42
|
+
ignoreEvent: true
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return figures;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/utils/figures/entryZonePointFigure.ts
|
|
49
|
+
var createEntryZonePointFigure = ({
|
|
50
|
+
coordinates,
|
|
51
|
+
overlay
|
|
52
|
+
}) => {
|
|
53
|
+
const zone = overlay.extendData?.zone;
|
|
54
|
+
const color = zone?.color ?? "rgba(147,197,253,0.2)";
|
|
55
|
+
const borderColor = zone?.borderColor ?? "rgba(59,130,246,0.6)";
|
|
56
|
+
if (coordinates.length < 2) return [];
|
|
57
|
+
const [p1, p2] = coordinates;
|
|
58
|
+
const x = Math.min(p1.x, p2.x);
|
|
59
|
+
const y = Math.min(p1.y, p2.y);
|
|
60
|
+
const width = Math.abs(p2.x - p1.x);
|
|
61
|
+
const height = Math.abs(p2.y - p1.y);
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
type: "rect",
|
|
65
|
+
attrs: { x, y, width, height },
|
|
66
|
+
styles: { color, borderColor, size: 1 }
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/utils/figures/signalFiguresPipeline.ts
|
|
72
|
+
import { registerOverlay } from "klinecharts";
|
|
73
|
+
var baseFiguresRegistered = false;
|
|
74
|
+
var ensureBaseFigureOverlaysRegistered = () => {
|
|
75
|
+
if (baseFiguresRegistered) return;
|
|
76
|
+
registerOverlay({
|
|
77
|
+
name: "BacktestEntryLine",
|
|
78
|
+
totalStep: 2,
|
|
79
|
+
needDefaultPointFigure: false,
|
|
80
|
+
needDefaultXAxisFigure: false,
|
|
81
|
+
needDefaultYAxisFigure: false,
|
|
82
|
+
createPointFigures: createEntryLinePointFigure
|
|
83
|
+
});
|
|
84
|
+
registerOverlay({
|
|
85
|
+
name: "BacktestEntryPoints",
|
|
86
|
+
needDefaultPointFigure: true,
|
|
87
|
+
needDefaultXAxisFigure: false,
|
|
88
|
+
needDefaultYAxisFigure: false,
|
|
89
|
+
createPointFigures: createEntryPointsPointFigure
|
|
90
|
+
});
|
|
91
|
+
registerOverlay({
|
|
92
|
+
name: "BacktestEntryZone",
|
|
93
|
+
totalStep: 2,
|
|
94
|
+
needDefaultPointFigure: false,
|
|
95
|
+
needDefaultXAxisFigure: false,
|
|
96
|
+
needDefaultYAxisFigure: false,
|
|
97
|
+
createPointFigures: createEntryZonePointFigure
|
|
98
|
+
});
|
|
99
|
+
baseFiguresRegistered = true;
|
|
100
|
+
};
|
|
101
|
+
var toSortedPoints = (points = []) => [...points].sort((left, right) => left.timestamp - right.timestamp);
|
|
102
|
+
var convertTrendLineToFigures = (trendLine) => ({
|
|
103
|
+
lines: [
|
|
104
|
+
{
|
|
105
|
+
id: trendLine.id,
|
|
106
|
+
kind: "trendline",
|
|
107
|
+
points: toSortedPoints(trendLine.points ?? []),
|
|
108
|
+
color: trendLine.mode === "lows" ? "#facc15" : "#fb923c",
|
|
109
|
+
width: 2,
|
|
110
|
+
style: "solid"
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
points: [
|
|
114
|
+
{
|
|
115
|
+
id: `${trendLine.id}-points`,
|
|
116
|
+
kind: "trendline_points",
|
|
117
|
+
points: toSortedPoints([
|
|
118
|
+
...trendLine.points ?? [],
|
|
119
|
+
...trendLine.touches ?? []
|
|
120
|
+
]),
|
|
121
|
+
color: "#ef4444",
|
|
122
|
+
radius: 4
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
var normalizeSignalFigures = (signal) => {
|
|
127
|
+
const figures = signal?.figures;
|
|
128
|
+
if (!figures) return void 0;
|
|
129
|
+
const lines = [...figures.lines ?? []];
|
|
130
|
+
const points = [...figures.points ?? []];
|
|
131
|
+
const zones = [...figures.zones ?? []];
|
|
132
|
+
let merged = {
|
|
133
|
+
lines,
|
|
134
|
+
points,
|
|
135
|
+
zones
|
|
136
|
+
};
|
|
137
|
+
if (figures.trendLine) {
|
|
138
|
+
const fromTrendLine = convertTrendLineToFigures(figures.trendLine);
|
|
139
|
+
merged = {
|
|
140
|
+
lines: [...merged.lines ?? [], ...fromTrendLine.lines ?? []],
|
|
141
|
+
points: [...merged.points ?? [], ...fromTrendLine.points ?? []],
|
|
142
|
+
zones: [...merged.zones ?? [], ...fromTrendLine.zones ?? []]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (!merged.lines?.length && !merged.points?.length && !merged.zones?.length) {
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
...merged.lines?.length ? { lines: merged.lines } : {},
|
|
150
|
+
...merged.points?.length ? { points: merged.points } : {},
|
|
151
|
+
...merged.zones?.length ? { zones: merged.zones } : {}
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
var collectSignalFiguresFromOrderLog = (events) => {
|
|
155
|
+
const result = [];
|
|
156
|
+
const seenSignalIds = /* @__PURE__ */ new Set();
|
|
157
|
+
for (let index = 0; index < events.length; index++) {
|
|
158
|
+
const event = events[index];
|
|
159
|
+
if (!event.type?.startsWith("OPEN_")) continue;
|
|
160
|
+
const signal = event.signal;
|
|
161
|
+
if (!signal) continue;
|
|
162
|
+
const figures = normalizeSignalFigures(signal);
|
|
163
|
+
if (!figures) continue;
|
|
164
|
+
const signalId = signal.signalId;
|
|
165
|
+
if (signalId) {
|
|
166
|
+
if (seenSignalIds.has(signalId)) continue;
|
|
167
|
+
seenSignalIds.add(signalId);
|
|
168
|
+
}
|
|
169
|
+
result.push({ figures, signalId, index });
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
};
|
|
173
|
+
var drawSignalFigures = ({
|
|
174
|
+
chart,
|
|
175
|
+
idPrefix,
|
|
176
|
+
figures
|
|
177
|
+
}) => {
|
|
178
|
+
const created = [];
|
|
179
|
+
const lines = figures.lines ?? [];
|
|
180
|
+
const points = figures.points ?? [];
|
|
181
|
+
const zones = figures.zones ?? [];
|
|
182
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
183
|
+
const line = lines[lineIndex];
|
|
184
|
+
const linePoints = toSortedPoints(line.points ?? []);
|
|
185
|
+
if (linePoints.length < 2) continue;
|
|
186
|
+
const id = `${idPrefix}-line-${line.id ?? lineIndex}`;
|
|
187
|
+
chart.createOverlay({
|
|
188
|
+
name: "BacktestEntryLine",
|
|
189
|
+
id,
|
|
190
|
+
points: [linePoints[0], linePoints[linePoints.length - 1]],
|
|
191
|
+
zLevel: 10,
|
|
192
|
+
extendData: { line }
|
|
193
|
+
});
|
|
194
|
+
created.push({ name: "BacktestEntryLine", id });
|
|
195
|
+
}
|
|
196
|
+
for (let pointIndex = 0; pointIndex < points.length; pointIndex++) {
|
|
197
|
+
const pointsData = points[pointIndex];
|
|
198
|
+
const pointValues = toSortedPoints(pointsData.points ?? []);
|
|
199
|
+
if (pointValues.length === 0) continue;
|
|
200
|
+
const id = `${idPrefix}-points-${pointsData.id ?? pointIndex}`;
|
|
201
|
+
chart.createOverlay({
|
|
202
|
+
name: "BacktestEntryPoints",
|
|
203
|
+
id,
|
|
204
|
+
points: pointValues,
|
|
205
|
+
zLevel: 12,
|
|
206
|
+
extendData: { points: pointsData }
|
|
207
|
+
});
|
|
208
|
+
created.push({ name: "BacktestEntryPoints", id });
|
|
209
|
+
}
|
|
210
|
+
for (let zoneIndex = 0; zoneIndex < zones.length; zoneIndex++) {
|
|
211
|
+
const zone = zones[zoneIndex];
|
|
212
|
+
const id = `${idPrefix}-zone-${zone.id ?? zoneIndex}`;
|
|
213
|
+
chart.createOverlay({
|
|
214
|
+
name: "BacktestEntryZone",
|
|
215
|
+
id,
|
|
216
|
+
points: [zone.start, zone.end],
|
|
217
|
+
zLevel: 8,
|
|
218
|
+
extendData: { zone }
|
|
219
|
+
});
|
|
220
|
+
created.push({ name: "BacktestEntryZone", id });
|
|
221
|
+
}
|
|
222
|
+
return created;
|
|
223
|
+
};
|
|
224
|
+
var removeSignalFigures = (chart, overlays) => {
|
|
225
|
+
for (const overlay of overlays) {
|
|
226
|
+
chart.removeOverlay({ name: overlay.name, id: overlay.id });
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
export {
|
|
230
|
+
collectSignalFiguresFromOrderLog,
|
|
231
|
+
convertTrendLineToFigures,
|
|
232
|
+
createEntryLinePointFigure,
|
|
233
|
+
createEntryPointsPointFigure,
|
|
234
|
+
createEntryZonePointFigure,
|
|
235
|
+
drawSignalFigures,
|
|
236
|
+
ensureBaseFigureOverlaysRegistered,
|
|
237
|
+
normalizeSignalFigures,
|
|
238
|
+
removeSignalFigures
|
|
239
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
2
|
+
import { Candle, MlCandleIndicatorsSnapshot, IndicatorSnapshot, IndicatorsHistorySnapshot } from '@tradejs/types';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
var __pgPool__: Pool | undefined;
|
|
6
|
+
}
|
|
7
|
+
type DerivativesInterval = '15m' | '1h';
|
|
8
|
+
type DerivativesRow = {
|
|
9
|
+
symbol: string;
|
|
10
|
+
interval: DerivativesInterval;
|
|
11
|
+
ts: Date;
|
|
12
|
+
openInterest?: number | null;
|
|
13
|
+
fundingRate?: number | null;
|
|
14
|
+
liqLong?: number | null;
|
|
15
|
+
liqShort?: number | null;
|
|
16
|
+
liqTotal?: number | null;
|
|
17
|
+
source?: string | null;
|
|
18
|
+
};
|
|
19
|
+
type SpreadRow = {
|
|
20
|
+
symbol: string;
|
|
21
|
+
interval: DerivativesInterval;
|
|
22
|
+
ts: Date;
|
|
23
|
+
binancePrice?: number | null;
|
|
24
|
+
coinbasePrice?: number | null;
|
|
25
|
+
spread?: number | null;
|
|
26
|
+
source?: string | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
declare const buildMlCandleIndicators: (candles: Candle[], btcCandles: Candle[]) => MlCandleIndicatorsSnapshot;
|
|
30
|
+
type IndicatorValue = number | null | undefined;
|
|
31
|
+
type TrendlineIndicatorHistoryPush = (key: string, value: number | null | undefined) => void;
|
|
32
|
+
type TrendlineIndicators = {
|
|
33
|
+
maFast: IndicatorValue;
|
|
34
|
+
maMedium: IndicatorValue;
|
|
35
|
+
maSlow: IndicatorValue;
|
|
36
|
+
atr: IndicatorValue;
|
|
37
|
+
atrPct: IndicatorValue;
|
|
38
|
+
bbUpper: IndicatorValue;
|
|
39
|
+
bbMiddle: IndicatorValue;
|
|
40
|
+
bbLower: IndicatorValue;
|
|
41
|
+
obv: IndicatorValue;
|
|
42
|
+
smaObv: IndicatorValue;
|
|
43
|
+
macd: IndicatorValue;
|
|
44
|
+
macdSignal: IndicatorValue;
|
|
45
|
+
macdHistogram: IndicatorValue;
|
|
46
|
+
price24hPcnt: IndicatorValue;
|
|
47
|
+
price1hPcnt: IndicatorValue;
|
|
48
|
+
highPrice1h: IndicatorValue;
|
|
49
|
+
lowPrice1h: IndicatorValue;
|
|
50
|
+
volume1h: IndicatorValue;
|
|
51
|
+
highPrice24h: IndicatorValue;
|
|
52
|
+
lowPrice24h: IndicatorValue;
|
|
53
|
+
volume24h: IndicatorValue;
|
|
54
|
+
highLevel: IndicatorValue;
|
|
55
|
+
lowLevel: IndicatorValue;
|
|
56
|
+
prevClose: IndicatorValue;
|
|
57
|
+
correlation: IndicatorValue;
|
|
58
|
+
spread: IndicatorValue;
|
|
59
|
+
};
|
|
60
|
+
type CreateIndicatorsOptions = {
|
|
61
|
+
includeMlPayload?: boolean;
|
|
62
|
+
btcBinanceData?: Candle[];
|
|
63
|
+
btcCoinbaseData?: Candle[];
|
|
64
|
+
};
|
|
65
|
+
interface IndicatorPeriods {
|
|
66
|
+
maFast: number;
|
|
67
|
+
maMedium: number;
|
|
68
|
+
maSlow: number;
|
|
69
|
+
obvSma: number;
|
|
70
|
+
atr: number;
|
|
71
|
+
atrPctShort: number;
|
|
72
|
+
atrPctLong: number;
|
|
73
|
+
bb: number;
|
|
74
|
+
bbStd: number;
|
|
75
|
+
macdFast: number;
|
|
76
|
+
macdSlow: number;
|
|
77
|
+
macdSignal: number;
|
|
78
|
+
levelLookback: number;
|
|
79
|
+
levelDelay: number;
|
|
80
|
+
}
|
|
81
|
+
declare const applyIndicatorsToHistory: (indicators: TrendlineIndicators, pushIndicator: TrendlineIndicatorHistoryPush) => void;
|
|
82
|
+
declare const createIndicators: (data: Candle[], btcData?: Candle[], options?: CreateIndicatorsOptions & {
|
|
83
|
+
periods?: Partial<IndicatorPeriods>;
|
|
84
|
+
}) => {
|
|
85
|
+
next: (candle: Candle, btcCandle?: Candle) => IndicatorSnapshot | null;
|
|
86
|
+
result: () => IndicatorsHistorySnapshot;
|
|
87
|
+
};
|
|
88
|
+
declare const buildMlTimeframeIndicators: (candles: Candle[], periods?: Partial<IndicatorPeriods>) => Record<string, number[]>;
|
|
89
|
+
|
|
90
|
+
export { type DerivativesInterval as D, type IndicatorPeriods as I, type SpreadRow as S, type DerivativesRow as a, applyIndicatorsToHistory as b, buildMlCandleIndicators as c, buildMlTimeframeIndicators as d, createIndicators as e };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
2
|
+
import { Candle, MlCandleIndicatorsSnapshot, IndicatorSnapshot, IndicatorsHistorySnapshot } from '@tradejs/types';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
var __pgPool__: Pool | undefined;
|
|
6
|
+
}
|
|
7
|
+
type DerivativesInterval = '15m' | '1h';
|
|
8
|
+
type DerivativesRow = {
|
|
9
|
+
symbol: string;
|
|
10
|
+
interval: DerivativesInterval;
|
|
11
|
+
ts: Date;
|
|
12
|
+
openInterest?: number | null;
|
|
13
|
+
fundingRate?: number | null;
|
|
14
|
+
liqLong?: number | null;
|
|
15
|
+
liqShort?: number | null;
|
|
16
|
+
liqTotal?: number | null;
|
|
17
|
+
source?: string | null;
|
|
18
|
+
};
|
|
19
|
+
type SpreadRow = {
|
|
20
|
+
symbol: string;
|
|
21
|
+
interval: DerivativesInterval;
|
|
22
|
+
ts: Date;
|
|
23
|
+
binancePrice?: number | null;
|
|
24
|
+
coinbasePrice?: number | null;
|
|
25
|
+
spread?: number | null;
|
|
26
|
+
source?: string | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
declare const buildMlCandleIndicators: (candles: Candle[], btcCandles: Candle[]) => MlCandleIndicatorsSnapshot;
|
|
30
|
+
type IndicatorValue = number | null | undefined;
|
|
31
|
+
type TrendlineIndicatorHistoryPush = (key: string, value: number | null | undefined) => void;
|
|
32
|
+
type TrendlineIndicators = {
|
|
33
|
+
maFast: IndicatorValue;
|
|
34
|
+
maMedium: IndicatorValue;
|
|
35
|
+
maSlow: IndicatorValue;
|
|
36
|
+
atr: IndicatorValue;
|
|
37
|
+
atrPct: IndicatorValue;
|
|
38
|
+
bbUpper: IndicatorValue;
|
|
39
|
+
bbMiddle: IndicatorValue;
|
|
40
|
+
bbLower: IndicatorValue;
|
|
41
|
+
obv: IndicatorValue;
|
|
42
|
+
smaObv: IndicatorValue;
|
|
43
|
+
macd: IndicatorValue;
|
|
44
|
+
macdSignal: IndicatorValue;
|
|
45
|
+
macdHistogram: IndicatorValue;
|
|
46
|
+
price24hPcnt: IndicatorValue;
|
|
47
|
+
price1hPcnt: IndicatorValue;
|
|
48
|
+
highPrice1h: IndicatorValue;
|
|
49
|
+
lowPrice1h: IndicatorValue;
|
|
50
|
+
volume1h: IndicatorValue;
|
|
51
|
+
highPrice24h: IndicatorValue;
|
|
52
|
+
lowPrice24h: IndicatorValue;
|
|
53
|
+
volume24h: IndicatorValue;
|
|
54
|
+
highLevel: IndicatorValue;
|
|
55
|
+
lowLevel: IndicatorValue;
|
|
56
|
+
prevClose: IndicatorValue;
|
|
57
|
+
correlation: IndicatorValue;
|
|
58
|
+
spread: IndicatorValue;
|
|
59
|
+
};
|
|
60
|
+
type CreateIndicatorsOptions = {
|
|
61
|
+
includeMlPayload?: boolean;
|
|
62
|
+
btcBinanceData?: Candle[];
|
|
63
|
+
btcCoinbaseData?: Candle[];
|
|
64
|
+
};
|
|
65
|
+
interface IndicatorPeriods {
|
|
66
|
+
maFast: number;
|
|
67
|
+
maMedium: number;
|
|
68
|
+
maSlow: number;
|
|
69
|
+
obvSma: number;
|
|
70
|
+
atr: number;
|
|
71
|
+
atrPctShort: number;
|
|
72
|
+
atrPctLong: number;
|
|
73
|
+
bb: number;
|
|
74
|
+
bbStd: number;
|
|
75
|
+
macdFast: number;
|
|
76
|
+
macdSlow: number;
|
|
77
|
+
macdSignal: number;
|
|
78
|
+
levelLookback: number;
|
|
79
|
+
levelDelay: number;
|
|
80
|
+
}
|
|
81
|
+
declare const applyIndicatorsToHistory: (indicators: TrendlineIndicators, pushIndicator: TrendlineIndicatorHistoryPush) => void;
|
|
82
|
+
declare const createIndicators: (data: Candle[], btcData?: Candle[], options?: CreateIndicatorsOptions & {
|
|
83
|
+
periods?: Partial<IndicatorPeriods>;
|
|
84
|
+
}) => {
|
|
85
|
+
next: (candle: Candle, btcCandle?: Candle) => IndicatorSnapshot | null;
|
|
86
|
+
result: () => IndicatorsHistorySnapshot;
|
|
87
|
+
};
|
|
88
|
+
declare const buildMlTimeframeIndicators: (candles: Candle[], periods?: Partial<IndicatorPeriods>) => Record<string, number[]>;
|
|
89
|
+
|
|
90
|
+
export { type DerivativesInterval as D, type IndicatorPeriods as I, type SpreadRow as S, type DerivativesRow as a, applyIndicatorsToHistory as b, buildMlCandleIndicators as c, buildMlTimeframeIndicators as d, createIndicators as e };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { KlineChartItem, IndicatorPluginRenderer, Indicator, IndicatorPluginEntry, TrendLine, TrendLineOptions } from '@tradejs/types';
|
|
2
|
+
import { D as DerivativesInterval, a as DerivativesRow, S as SpreadRow } from './indicators-x3xKl3_W.mjs';
|
|
3
|
+
export { I as IndicatorPeriods, b as applyIndicatorsToHistory, c as buildMlCandleIndicators, d as buildMlTimeframeIndicators, e as createIndicators } from './indicators-x3xKl3_W.mjs';
|
|
4
|
+
import { KLineData } from 'klinecharts';
|
|
5
|
+
import 'pg';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Выравнивает два отсортированных массива свечей по timestamp.
|
|
9
|
+
* Оставляет только те свечи, которые есть в обоих массивах.
|
|
10
|
+
*/
|
|
11
|
+
declare const alignSortedCandlesByTimestamp: (coinCandles: KlineChartItem[], btcCandles: KlineChartItem[]) => {
|
|
12
|
+
alignedCoinCandles: KlineChartItem[];
|
|
13
|
+
alignedBtcCandles: KlineChartItem[];
|
|
14
|
+
};
|
|
15
|
+
/** Строим массив доходностей по close: (close[i] - close[i-1]) / close[i-1] */
|
|
16
|
+
declare const buildReturnsFromCandles: (candles: KlineChartItem[]) => number[];
|
|
17
|
+
/** Корреляция Пирсона между двумя числовыми рядами одинаковой длины */
|
|
18
|
+
declare const calculatePearsonCorrelation: (firstSeries: number[], secondSeries: number[]) => number | null;
|
|
19
|
+
/**
|
|
20
|
+
* Полный пайплайн:
|
|
21
|
+
* 1) выравниваем свечи монеты и BTC по timestamp
|
|
22
|
+
* 2) считаем доходности
|
|
23
|
+
* 3) считаем корреляцию доходностей
|
|
24
|
+
*/
|
|
25
|
+
declare const calculateCoinBtcCorrelation: (coinCandles: KlineChartItem[], btcCandles: KlineChartItem[]) => {
|
|
26
|
+
correlation: number | null;
|
|
27
|
+
alignedCoinCandles: KlineChartItem[];
|
|
28
|
+
alignedBtcCandles: KlineChartItem[];
|
|
29
|
+
coinReturns: number[];
|
|
30
|
+
btcReturns: number[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type CoinalyzePoint = {
|
|
34
|
+
symbol: string;
|
|
35
|
+
ts: number;
|
|
36
|
+
openInterest?: number | null;
|
|
37
|
+
fundingRate?: number | null;
|
|
38
|
+
liqLong?: number | null;
|
|
39
|
+
liqShort?: number | null;
|
|
40
|
+
liqTotal?: number | null;
|
|
41
|
+
};
|
|
42
|
+
declare const normalizeCoinalyzeSymbols: (input: unknown) => string[];
|
|
43
|
+
declare const normalizeDerivativesIntervals: (input: unknown) => DerivativesInterval[];
|
|
44
|
+
declare const toCoinalyzeTimestampMs: (value: unknown) => number | null;
|
|
45
|
+
declare const toFiniteNumber: (value: unknown) => number | null;
|
|
46
|
+
declare const toArrayData: <T>(value: unknown) => T[];
|
|
47
|
+
declare const mergeCoinalyzeMetrics: (params: {
|
|
48
|
+
symbol: string;
|
|
49
|
+
oiRaw: unknown;
|
|
50
|
+
fundingRaw: unknown;
|
|
51
|
+
liqRaw: unknown;
|
|
52
|
+
}) => CoinalyzePoint[];
|
|
53
|
+
declare const coinalyzePointsToRows: (points: CoinalyzePoint[], interval: DerivativesInterval, source: string) => DerivativesRow[];
|
|
54
|
+
|
|
55
|
+
declare const registerIndicatorEntries: (entries: readonly IndicatorPluginEntry[], source: string) => void;
|
|
56
|
+
declare const getRegisteredIndicatorEntries: () => IndicatorPluginEntry[];
|
|
57
|
+
declare const getPluginIndicatorCatalog: () => Indicator[];
|
|
58
|
+
type IndicatorRendererDescriptor = {
|
|
59
|
+
indicatorId: string;
|
|
60
|
+
renderer: IndicatorPluginRenderer;
|
|
61
|
+
};
|
|
62
|
+
declare const getPluginIndicatorRenderers: () => IndicatorRendererDescriptor[];
|
|
63
|
+
declare const resetIndicatorRegistryCache: () => void;
|
|
64
|
+
|
|
65
|
+
type SpreadValue = number | null | undefined;
|
|
66
|
+
type SpreadPointInput = {
|
|
67
|
+
timestamp: number;
|
|
68
|
+
spread?: SpreadValue;
|
|
69
|
+
binancePrice?: SpreadValue;
|
|
70
|
+
coinbasePrice?: SpreadValue;
|
|
71
|
+
};
|
|
72
|
+
declare const createSpreadSmoother: (window?: number) => {
|
|
73
|
+
next: (params: {
|
|
74
|
+
binancePrice?: SpreadValue;
|
|
75
|
+
coinbasePrice?: SpreadValue;
|
|
76
|
+
fallbackSpread?: SpreadValue;
|
|
77
|
+
}) => number | null;
|
|
78
|
+
};
|
|
79
|
+
declare const smoothSpreadSeries: (points: SpreadPointInput[], window?: number) => Array<{
|
|
80
|
+
timestamp: number;
|
|
81
|
+
spread: number | null;
|
|
82
|
+
}>;
|
|
83
|
+
type PricePoint = {
|
|
84
|
+
ts: number;
|
|
85
|
+
close: number;
|
|
86
|
+
};
|
|
87
|
+
declare const intervalToMs: (interval: DerivativesInterval) => number;
|
|
88
|
+
declare const coinbaseProductFromSymbol: (symbol: string) => string | null;
|
|
89
|
+
declare const alignSpreadRows: (params: {
|
|
90
|
+
symbol: string;
|
|
91
|
+
interval: DerivativesInterval;
|
|
92
|
+
binance: PricePoint[];
|
|
93
|
+
coinbase: PricePoint[];
|
|
94
|
+
source: string;
|
|
95
|
+
}) => SpreadRow[];
|
|
96
|
+
declare const rollingMeanStd: (values: number[], endIndex: number, window: number) => {
|
|
97
|
+
mean: number;
|
|
98
|
+
std: number;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
type Level = {
|
|
102
|
+
id: string;
|
|
103
|
+
price: number;
|
|
104
|
+
};
|
|
105
|
+
/** находим локальные минимумы (поддержка) и максимумы (сопротивление) */
|
|
106
|
+
declare const detectRawSupportResistance: (data: KLineData[], lookAround?: number) => {
|
|
107
|
+
supports: number[];
|
|
108
|
+
resistances: number[];
|
|
109
|
+
};
|
|
110
|
+
/** итоговый вывод (поддержка/сопротивление) с id */
|
|
111
|
+
declare const getSupportResistanceLevels: (data: KLineData[]) => {
|
|
112
|
+
supportLevels: Level[];
|
|
113
|
+
resistanceLevels: Level[];
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
type TrendlineEngine = {
|
|
117
|
+
next: (candle: KLineData) => TrendLine[];
|
|
118
|
+
nextMany: (candles: KLineData[]) => TrendLine[];
|
|
119
|
+
reset: () => void;
|
|
120
|
+
getLines: () => TrendLine[];
|
|
121
|
+
};
|
|
122
|
+
declare const createTrendlineEngine: (initialCandles: KLineData[], options: TrendLineOptions) => TrendlineEngine;
|
|
123
|
+
|
|
124
|
+
export { type CoinalyzePoint, type IndicatorRendererDescriptor, type PricePoint, type TrendlineEngine, alignSortedCandlesByTimestamp, alignSpreadRows, buildReturnsFromCandles, calculateCoinBtcCorrelation, calculatePearsonCorrelation, coinalyzePointsToRows, coinbaseProductFromSymbol, createSpreadSmoother, createTrendlineEngine, detectRawSupportResistance, getPluginIndicatorCatalog, getPluginIndicatorRenderers, getRegisteredIndicatorEntries, getSupportResistanceLevels, intervalToMs, mergeCoinalyzeMetrics, normalizeCoinalyzeSymbols, normalizeDerivativesIntervals, registerIndicatorEntries, resetIndicatorRegistryCache, rollingMeanStd, smoothSpreadSeries, toArrayData, toCoinalyzeTimestampMs, toFiniteNumber };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { KlineChartItem, IndicatorPluginRenderer, Indicator, IndicatorPluginEntry, TrendLine, TrendLineOptions } from '@tradejs/types';
|
|
2
|
+
import { D as DerivativesInterval, a as DerivativesRow, S as SpreadRow } from './indicators-x3xKl3_W.js';
|
|
3
|
+
export { I as IndicatorPeriods, b as applyIndicatorsToHistory, c as buildMlCandleIndicators, d as buildMlTimeframeIndicators, e as createIndicators } from './indicators-x3xKl3_W.js';
|
|
4
|
+
import { KLineData } from 'klinecharts';
|
|
5
|
+
import 'pg';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Выравнивает два отсортированных массива свечей по timestamp.
|
|
9
|
+
* Оставляет только те свечи, которые есть в обоих массивах.
|
|
10
|
+
*/
|
|
11
|
+
declare const alignSortedCandlesByTimestamp: (coinCandles: KlineChartItem[], btcCandles: KlineChartItem[]) => {
|
|
12
|
+
alignedCoinCandles: KlineChartItem[];
|
|
13
|
+
alignedBtcCandles: KlineChartItem[];
|
|
14
|
+
};
|
|
15
|
+
/** Строим массив доходностей по close: (close[i] - close[i-1]) / close[i-1] */
|
|
16
|
+
declare const buildReturnsFromCandles: (candles: KlineChartItem[]) => number[];
|
|
17
|
+
/** Корреляция Пирсона между двумя числовыми рядами одинаковой длины */
|
|
18
|
+
declare const calculatePearsonCorrelation: (firstSeries: number[], secondSeries: number[]) => number | null;
|
|
19
|
+
/**
|
|
20
|
+
* Полный пайплайн:
|
|
21
|
+
* 1) выравниваем свечи монеты и BTC по timestamp
|
|
22
|
+
* 2) считаем доходности
|
|
23
|
+
* 3) считаем корреляцию доходностей
|
|
24
|
+
*/
|
|
25
|
+
declare const calculateCoinBtcCorrelation: (coinCandles: KlineChartItem[], btcCandles: KlineChartItem[]) => {
|
|
26
|
+
correlation: number | null;
|
|
27
|
+
alignedCoinCandles: KlineChartItem[];
|
|
28
|
+
alignedBtcCandles: KlineChartItem[];
|
|
29
|
+
coinReturns: number[];
|
|
30
|
+
btcReturns: number[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type CoinalyzePoint = {
|
|
34
|
+
symbol: string;
|
|
35
|
+
ts: number;
|
|
36
|
+
openInterest?: number | null;
|
|
37
|
+
fundingRate?: number | null;
|
|
38
|
+
liqLong?: number | null;
|
|
39
|
+
liqShort?: number | null;
|
|
40
|
+
liqTotal?: number | null;
|
|
41
|
+
};
|
|
42
|
+
declare const normalizeCoinalyzeSymbols: (input: unknown) => string[];
|
|
43
|
+
declare const normalizeDerivativesIntervals: (input: unknown) => DerivativesInterval[];
|
|
44
|
+
declare const toCoinalyzeTimestampMs: (value: unknown) => number | null;
|
|
45
|
+
declare const toFiniteNumber: (value: unknown) => number | null;
|
|
46
|
+
declare const toArrayData: <T>(value: unknown) => T[];
|
|
47
|
+
declare const mergeCoinalyzeMetrics: (params: {
|
|
48
|
+
symbol: string;
|
|
49
|
+
oiRaw: unknown;
|
|
50
|
+
fundingRaw: unknown;
|
|
51
|
+
liqRaw: unknown;
|
|
52
|
+
}) => CoinalyzePoint[];
|
|
53
|
+
declare const coinalyzePointsToRows: (points: CoinalyzePoint[], interval: DerivativesInterval, source: string) => DerivativesRow[];
|
|
54
|
+
|
|
55
|
+
declare const registerIndicatorEntries: (entries: readonly IndicatorPluginEntry[], source: string) => void;
|
|
56
|
+
declare const getRegisteredIndicatorEntries: () => IndicatorPluginEntry[];
|
|
57
|
+
declare const getPluginIndicatorCatalog: () => Indicator[];
|
|
58
|
+
type IndicatorRendererDescriptor = {
|
|
59
|
+
indicatorId: string;
|
|
60
|
+
renderer: IndicatorPluginRenderer;
|
|
61
|
+
};
|
|
62
|
+
declare const getPluginIndicatorRenderers: () => IndicatorRendererDescriptor[];
|
|
63
|
+
declare const resetIndicatorRegistryCache: () => void;
|
|
64
|
+
|
|
65
|
+
type SpreadValue = number | null | undefined;
|
|
66
|
+
type SpreadPointInput = {
|
|
67
|
+
timestamp: number;
|
|
68
|
+
spread?: SpreadValue;
|
|
69
|
+
binancePrice?: SpreadValue;
|
|
70
|
+
coinbasePrice?: SpreadValue;
|
|
71
|
+
};
|
|
72
|
+
declare const createSpreadSmoother: (window?: number) => {
|
|
73
|
+
next: (params: {
|
|
74
|
+
binancePrice?: SpreadValue;
|
|
75
|
+
coinbasePrice?: SpreadValue;
|
|
76
|
+
fallbackSpread?: SpreadValue;
|
|
77
|
+
}) => number | null;
|
|
78
|
+
};
|
|
79
|
+
declare const smoothSpreadSeries: (points: SpreadPointInput[], window?: number) => Array<{
|
|
80
|
+
timestamp: number;
|
|
81
|
+
spread: number | null;
|
|
82
|
+
}>;
|
|
83
|
+
type PricePoint = {
|
|
84
|
+
ts: number;
|
|
85
|
+
close: number;
|
|
86
|
+
};
|
|
87
|
+
declare const intervalToMs: (interval: DerivativesInterval) => number;
|
|
88
|
+
declare const coinbaseProductFromSymbol: (symbol: string) => string | null;
|
|
89
|
+
declare const alignSpreadRows: (params: {
|
|
90
|
+
symbol: string;
|
|
91
|
+
interval: DerivativesInterval;
|
|
92
|
+
binance: PricePoint[];
|
|
93
|
+
coinbase: PricePoint[];
|
|
94
|
+
source: string;
|
|
95
|
+
}) => SpreadRow[];
|
|
96
|
+
declare const rollingMeanStd: (values: number[], endIndex: number, window: number) => {
|
|
97
|
+
mean: number;
|
|
98
|
+
std: number;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
type Level = {
|
|
102
|
+
id: string;
|
|
103
|
+
price: number;
|
|
104
|
+
};
|
|
105
|
+
/** находим локальные минимумы (поддержка) и максимумы (сопротивление) */
|
|
106
|
+
declare const detectRawSupportResistance: (data: KLineData[], lookAround?: number) => {
|
|
107
|
+
supports: number[];
|
|
108
|
+
resistances: number[];
|
|
109
|
+
};
|
|
110
|
+
/** итоговый вывод (поддержка/сопротивление) с id */
|
|
111
|
+
declare const getSupportResistanceLevels: (data: KLineData[]) => {
|
|
112
|
+
supportLevels: Level[];
|
|
113
|
+
resistanceLevels: Level[];
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
type TrendlineEngine = {
|
|
117
|
+
next: (candle: KLineData) => TrendLine[];
|
|
118
|
+
nextMany: (candles: KLineData[]) => TrendLine[];
|
|
119
|
+
reset: () => void;
|
|
120
|
+
getLines: () => TrendLine[];
|
|
121
|
+
};
|
|
122
|
+
declare const createTrendlineEngine: (initialCandles: KLineData[], options: TrendLineOptions) => TrendlineEngine;
|
|
123
|
+
|
|
124
|
+
export { type CoinalyzePoint, type IndicatorRendererDescriptor, type PricePoint, type TrendlineEngine, alignSortedCandlesByTimestamp, alignSpreadRows, buildReturnsFromCandles, calculateCoinBtcCorrelation, calculatePearsonCorrelation, coinalyzePointsToRows, coinbaseProductFromSymbol, createSpreadSmoother, createTrendlineEngine, detectRawSupportResistance, getPluginIndicatorCatalog, getPluginIndicatorRenderers, getRegisteredIndicatorEntries, getSupportResistanceLevels, intervalToMs, mergeCoinalyzeMetrics, normalizeCoinalyzeSymbols, normalizeDerivativesIntervals, registerIndicatorEntries, resetIndicatorRegistryCache, rollingMeanStd, smoothSpreadSeries, toArrayData, toCoinalyzeTimestampMs, toFiniteNumber };
|