@tradejs/core 2.0.0 → 2.0.1

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.
@@ -130,6 +130,14 @@ var toFiniteNumber = (value, fallback = 0) => {
130
130
  };
131
131
 
132
132
  // src/utils/derivativesCoinalyze.ts
133
+ var DERIVATIVES_INTERVAL_MS = {
134
+ "15m": 15 * 60 * 1e3,
135
+ "1h": 60 * 60 * 1e3
136
+ };
137
+ var getLastClosedDerivativesBarStartMs = (timestamp, interval) => {
138
+ const intervalMs = DERIVATIVES_INTERVAL_MS[interval];
139
+ return Math.floor(timestamp / intervalMs) * intervalMs - intervalMs;
140
+ };
133
141
  var normalizeCoinalyzeSymbols = (input) => String(input ?? "").split(",").map((item) => item.trim().toUpperCase()).filter(Boolean);
134
142
  var normalizeDerivativesIntervals = (input) => parseDerivativesIntervals(input);
135
143
  var toCoinalyzeTimestampMs = (value) => {
@@ -210,6 +218,52 @@ var coinalyzePointsToRows = (points, interval, source) => points.map((point) =>
210
218
  liqTotal: point.liqTotal ?? null,
211
219
  source
212
220
  }));
221
+ var sumAvailable = (values) => {
222
+ const available = values.filter(
223
+ (value) => typeof value === "number" && Number.isFinite(value)
224
+ );
225
+ return available.length ? available.reduce((total, value) => total + value, 0) : null;
226
+ };
227
+ var getLiquidationTotal = (row) => typeof row.liqTotal === "number" && Number.isFinite(row.liqTotal) ? row.liqTotal : sumAvailable([row.liqLong, row.liqShort]);
228
+ var deriveCoinalyzeHourlyRowsFrom15m = (rows) => {
229
+ const quarterHourMs = DERIVATIVES_INTERVAL_MS["15m"];
230
+ const hourMs = DERIVATIVES_INTERVAL_MS["1h"];
231
+ const rowsByHour = /* @__PURE__ */ new Map();
232
+ for (const row of rows ?? []) {
233
+ if (row.interval !== "15m") continue;
234
+ const timestamp = row.ts.getTime();
235
+ if (!Number.isFinite(timestamp) || timestamp % quarterHourMs !== 0) {
236
+ continue;
237
+ }
238
+ const hourStart = Math.floor(timestamp / hourMs) * hourMs;
239
+ const hourRows = rowsByHour.get(hourStart) ?? /* @__PURE__ */ new Map();
240
+ hourRows.set(timestamp, row);
241
+ rowsByHour.set(hourStart, hourRows);
242
+ }
243
+ const hourlyRows = [];
244
+ for (const [hourStart, hourRows] of [...rowsByHour.entries()].sort(
245
+ ([left], [right]) => left - right
246
+ )) {
247
+ const expectedRows = [0, 1, 2, 3].map(
248
+ (offset) => hourRows.get(hourStart + offset * quarterHourMs)
249
+ );
250
+ if (expectedRows.some((row) => row == null)) continue;
251
+ const completeRows = expectedRows;
252
+ const latest = completeRows[completeRows.length - 1];
253
+ hourlyRows.push({
254
+ symbol: latest.symbol,
255
+ interval: "1h",
256
+ ts: new Date(hourStart),
257
+ openInterest: latest.openInterest ?? null,
258
+ fundingRate: latest.fundingRate ?? null,
259
+ liqLong: sumAvailable(completeRows.map((row) => row.liqLong)),
260
+ liqShort: sumAvailable(completeRows.map((row) => row.liqShort)),
261
+ liqTotal: sumAvailable(completeRows.map(getLiquidationTotal)),
262
+ source: latest.source ?? null
263
+ });
264
+ }
265
+ return hourlyRows;
266
+ };
213
267
 
214
268
  // src/utils/derivativesContext.ts
215
269
  var HOUR_MS = 60 * 60 * 1e3;
@@ -11814,6 +11868,7 @@ export {
11814
11868
  buildReturnsFromCandles,
11815
11869
  calculatePearsonCorrelation,
11816
11870
  calculateCoinBtcCorrelation,
11871
+ getLastClosedDerivativesBarStartMs,
11817
11872
  normalizeCoinalyzeSymbols,
11818
11873
  normalizeDerivativesIntervals,
11819
11874
  toCoinalyzeTimestampMs,
@@ -11821,6 +11876,7 @@ export {
11821
11876
  toArrayData,
11822
11877
  mergeCoinalyzeMetrics,
11823
11878
  coinalyzePointsToRows,
11879
+ deriveCoinalyzeHourlyRowsFrom15m,
11824
11880
  buildDerivativesContext,
11825
11881
  buildMlCandleIndicators,
11826
11882
  registerIndicatorEntries,
@@ -37,6 +37,7 @@ type CoinalyzePoint = {
37
37
  liqShort?: number | null;
38
38
  liqTotal?: number | null;
39
39
  };
40
+ declare const getLastClosedDerivativesBarStartMs: (timestamp: number, interval: DerivativesInterval) => number;
40
41
  declare const normalizeCoinalyzeSymbols: (input: unknown) => string[];
41
42
  declare const normalizeDerivativesIntervals: (input: unknown) => DerivativesInterval[];
42
43
  declare const toCoinalyzeTimestampMs: (value: unknown) => number | null;
@@ -49,6 +50,7 @@ declare const mergeCoinalyzeMetrics: (params: {
49
50
  liqRaw: unknown;
50
51
  }) => CoinalyzePoint[];
51
52
  declare const coinalyzePointsToRows: (points: CoinalyzePoint[], interval: DerivativesInterval, source: string) => DerivativesRow[];
53
+ declare const deriveCoinalyzeHourlyRowsFrom15m: (rows: DerivativesRow[] | undefined) => DerivativesRow[];
52
54
 
53
55
  declare const buildDerivativesContext: (params: {
54
56
  symbol: string;
@@ -93,4 +95,4 @@ type TrendlineEngine = {
93
95
  };
94
96
  declare const createTrendlineEngine: (initialCandles: KLineData[], options: TrendLineOptions) => TrendlineEngine;
95
97
 
96
- export { type CoinalyzePoint, type IndicatorRendererDescriptor, type TrendlineEngine, alignSortedCandlesByTimestamp, buildDerivativesContext, buildReturnsFromCandles, calculateCoinBtcCorrelation, calculatePearsonCorrelation, coinalyzePointsToRows, createTrendlineEngine, detectRawSupportResistance, getPluginIndicatorCatalog, getPluginIndicatorRenderers, getRegisteredIndicatorEntries, getSupportResistanceLevels, mergeCoinalyzeMetrics, normalizeCoinalyzeSymbols, normalizeDerivativesIntervals, registerIndicatorEntries, resetIndicatorRegistryCache, toArrayData, toCoinalyzeTimestampMs, toFiniteNumber };
98
+ export { type CoinalyzePoint, type IndicatorRendererDescriptor, type TrendlineEngine, alignSortedCandlesByTimestamp, buildDerivativesContext, buildReturnsFromCandles, calculateCoinBtcCorrelation, calculatePearsonCorrelation, coinalyzePointsToRows, createTrendlineEngine, deriveCoinalyzeHourlyRowsFrom15m, detectRawSupportResistance, getLastClosedDerivativesBarStartMs, getPluginIndicatorCatalog, getPluginIndicatorRenderers, getRegisteredIndicatorEntries, getSupportResistanceLevels, mergeCoinalyzeMetrics, normalizeCoinalyzeSymbols, normalizeDerivativesIntervals, registerIndicatorEntries, resetIndicatorRegistryCache, toArrayData, toCoinalyzeTimestampMs, toFiniteNumber };
@@ -37,6 +37,7 @@ type CoinalyzePoint = {
37
37
  liqShort?: number | null;
38
38
  liqTotal?: number | null;
39
39
  };
40
+ declare const getLastClosedDerivativesBarStartMs: (timestamp: number, interval: DerivativesInterval) => number;
40
41
  declare const normalizeCoinalyzeSymbols: (input: unknown) => string[];
41
42
  declare const normalizeDerivativesIntervals: (input: unknown) => DerivativesInterval[];
42
43
  declare const toCoinalyzeTimestampMs: (value: unknown) => number | null;
@@ -49,6 +50,7 @@ declare const mergeCoinalyzeMetrics: (params: {
49
50
  liqRaw: unknown;
50
51
  }) => CoinalyzePoint[];
51
52
  declare const coinalyzePointsToRows: (points: CoinalyzePoint[], interval: DerivativesInterval, source: string) => DerivativesRow[];
53
+ declare const deriveCoinalyzeHourlyRowsFrom15m: (rows: DerivativesRow[] | undefined) => DerivativesRow[];
52
54
 
53
55
  declare const buildDerivativesContext: (params: {
54
56
  symbol: string;
@@ -93,4 +95,4 @@ type TrendlineEngine = {
93
95
  };
94
96
  declare const createTrendlineEngine: (initialCandles: KLineData[], options: TrendLineOptions) => TrendlineEngine;
95
97
 
96
- export { type CoinalyzePoint, type IndicatorRendererDescriptor, type TrendlineEngine, alignSortedCandlesByTimestamp, buildDerivativesContext, buildReturnsFromCandles, calculateCoinBtcCorrelation, calculatePearsonCorrelation, coinalyzePointsToRows, createTrendlineEngine, detectRawSupportResistance, getPluginIndicatorCatalog, getPluginIndicatorRenderers, getRegisteredIndicatorEntries, getSupportResistanceLevels, mergeCoinalyzeMetrics, normalizeCoinalyzeSymbols, normalizeDerivativesIntervals, registerIndicatorEntries, resetIndicatorRegistryCache, toArrayData, toCoinalyzeTimestampMs, toFiniteNumber };
98
+ export { type CoinalyzePoint, type IndicatorRendererDescriptor, type TrendlineEngine, alignSortedCandlesByTimestamp, buildDerivativesContext, buildReturnsFromCandles, calculateCoinBtcCorrelation, calculatePearsonCorrelation, coinalyzePointsToRows, createTrendlineEngine, deriveCoinalyzeHourlyRowsFrom15m, detectRawSupportResistance, getLastClosedDerivativesBarStartMs, getPluginIndicatorCatalog, getPluginIndicatorRenderers, getRegisteredIndicatorEntries, getSupportResistanceLevels, mergeCoinalyzeMetrics, normalizeCoinalyzeSymbols, normalizeDerivativesIntervals, registerIndicatorEntries, resetIndicatorRegistryCache, toArrayData, toCoinalyzeTimestampMs, toFiniteNumber };
@@ -47,7 +47,9 @@ __export(indicators_exports, {
47
47
  createSerializableSpreadSmoother: () => createSerializableSpreadSmoother,
48
48
  createSpreadSmoother: () => createSpreadSmoother,
49
49
  createTrendlineEngine: () => createTrendlineEngine,
50
+ deriveCoinalyzeHourlyRowsFrom15m: () => deriveCoinalyzeHourlyRowsFrom15m,
50
51
  detectRawSupportResistance: () => detectRawSupportResistance,
52
+ getLastClosedDerivativesBarStartMs: () => getLastClosedDerivativesBarStartMs,
51
53
  getPluginIndicatorCatalog: () => getPluginIndicatorCatalog,
52
54
  getPluginIndicatorRenderers: () => getPluginIndicatorRenderers,
53
55
  getRegisteredIndicatorEntries: () => getRegisteredIndicatorEntries,
@@ -188,6 +190,14 @@ var toFiniteNumber = (value, fallback = 0) => {
188
190
  };
189
191
 
190
192
  // src/utils/derivativesCoinalyze.ts
193
+ var DERIVATIVES_INTERVAL_MS = {
194
+ "15m": 15 * 60 * 1e3,
195
+ "1h": 60 * 60 * 1e3
196
+ };
197
+ var getLastClosedDerivativesBarStartMs = (timestamp, interval) => {
198
+ const intervalMs = DERIVATIVES_INTERVAL_MS[interval];
199
+ return Math.floor(timestamp / intervalMs) * intervalMs - intervalMs;
200
+ };
191
201
  var normalizeCoinalyzeSymbols = (input) => String(input ?? "").split(",").map((item) => item.trim().toUpperCase()).filter(Boolean);
192
202
  var normalizeDerivativesIntervals = (input) => parseDerivativesIntervals(input);
193
203
  var toCoinalyzeTimestampMs = (value) => {
@@ -268,6 +278,52 @@ var coinalyzePointsToRows = (points, interval, source) => points.map((point) =>
268
278
  liqTotal: point.liqTotal ?? null,
269
279
  source
270
280
  }));
281
+ var sumAvailable = (values) => {
282
+ const available = values.filter(
283
+ (value) => typeof value === "number" && Number.isFinite(value)
284
+ );
285
+ return available.length ? available.reduce((total, value) => total + value, 0) : null;
286
+ };
287
+ var getLiquidationTotal = (row) => typeof row.liqTotal === "number" && Number.isFinite(row.liqTotal) ? row.liqTotal : sumAvailable([row.liqLong, row.liqShort]);
288
+ var deriveCoinalyzeHourlyRowsFrom15m = (rows) => {
289
+ const quarterHourMs = DERIVATIVES_INTERVAL_MS["15m"];
290
+ const hourMs = DERIVATIVES_INTERVAL_MS["1h"];
291
+ const rowsByHour = /* @__PURE__ */ new Map();
292
+ for (const row of rows ?? []) {
293
+ if (row.interval !== "15m") continue;
294
+ const timestamp = row.ts.getTime();
295
+ if (!Number.isFinite(timestamp) || timestamp % quarterHourMs !== 0) {
296
+ continue;
297
+ }
298
+ const hourStart = Math.floor(timestamp / hourMs) * hourMs;
299
+ const hourRows = rowsByHour.get(hourStart) ?? /* @__PURE__ */ new Map();
300
+ hourRows.set(timestamp, row);
301
+ rowsByHour.set(hourStart, hourRows);
302
+ }
303
+ const hourlyRows = [];
304
+ for (const [hourStart, hourRows] of [...rowsByHour.entries()].sort(
305
+ ([left], [right]) => left - right
306
+ )) {
307
+ const expectedRows = [0, 1, 2, 3].map(
308
+ (offset) => hourRows.get(hourStart + offset * quarterHourMs)
309
+ );
310
+ if (expectedRows.some((row) => row == null)) continue;
311
+ const completeRows = expectedRows;
312
+ const latest = completeRows[completeRows.length - 1];
313
+ hourlyRows.push({
314
+ symbol: latest.symbol,
315
+ interval: "1h",
316
+ ts: new Date(hourStart),
317
+ openInterest: latest.openInterest ?? null,
318
+ fundingRate: latest.fundingRate ?? null,
319
+ liqLong: sumAvailable(completeRows.map((row) => row.liqLong)),
320
+ liqShort: sumAvailable(completeRows.map((row) => row.liqShort)),
321
+ liqTotal: sumAvailable(completeRows.map(getLiquidationTotal)),
322
+ source: latest.source ?? null
323
+ });
324
+ }
325
+ return hourlyRows;
326
+ };
271
327
 
272
328
  // src/utils/derivativesContext.ts
273
329
  var HOUR_MS = 60 * 60 * 1e3;
@@ -11942,7 +11998,9 @@ var createTrendlineEngine = (initialCandles, options) => {
11942
11998
  createSerializableSpreadSmoother,
11943
11999
  createSpreadSmoother,
11944
12000
  createTrendlineEngine,
12001
+ deriveCoinalyzeHourlyRowsFrom15m,
11945
12002
  detectRawSupportResistance,
12003
+ getLastClosedDerivativesBarStartMs,
11946
12004
  getPluginIndicatorCatalog,
11947
12005
  getPluginIndicatorRenderers,
11948
12006
  getRegisteredIndicatorEntries,
@@ -16,7 +16,9 @@ import {
16
16
  createSerializableSpreadSmoother,
17
17
  createSpreadSmoother,
18
18
  createTrendlineEngine,
19
+ deriveCoinalyzeHourlyRowsFrom15m,
19
20
  detectRawSupportResistance,
21
+ getLastClosedDerivativesBarStartMs,
20
22
  getPluginIndicatorCatalog,
21
23
  getPluginIndicatorRenderers,
22
24
  getRegisteredIndicatorEntries,
@@ -33,7 +35,7 @@ import {
33
35
  toArrayData,
34
36
  toCoinalyzeTimestampMs,
35
37
  toFiniteNumber
36
- } from "./chunk-EQEIRB6P.mjs";
38
+ } from "./chunk-2OUA2S6U.mjs";
37
39
  import "./chunk-AYC2QVKI.mjs";
38
40
  import "./chunk-M7QGVZ3J.mjs";
39
41
  import "./chunk-BOETNABM.mjs";
@@ -56,7 +58,9 @@ export {
56
58
  createSerializableSpreadSmoother,
57
59
  createSpreadSmoother,
58
60
  createTrendlineEngine,
61
+ deriveCoinalyzeHourlyRowsFrom15m,
59
62
  detectRawSupportResistance,
63
+ getLastClosedDerivativesBarStartMs,
60
64
  getPluginIndicatorCatalog,
61
65
  getPluginIndicatorRenderers,
62
66
  getRegisteredIndicatorEntries,
@@ -151,6 +151,12 @@ var calculateCoinBtcCorrelation = (coinCandles, btcCandles) => {
151
151
  };
152
152
  };
153
153
 
154
+ // src/utils/derivativesCoinalyze.ts
155
+ var DERIVATIVES_INTERVAL_MS = {
156
+ "15m": 15 * 60 * 1e3,
157
+ "1h": 60 * 60 * 1e3
158
+ };
159
+
154
160
  // src/utils/derivativesContext.ts
155
161
  var HOUR_MS = 60 * 60 * 1e3;
156
162
  var DEFAULT_STALE_AFTER_MS = {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createIndicators,
3
3
  getRequiredControllerSeedWindow
4
- } from "./chunk-EQEIRB6P.mjs";
4
+ } from "./chunk-2OUA2S6U.mjs";
5
5
  import "./chunk-AYC2QVKI.mjs";
6
6
  import "./chunk-M7QGVZ3J.mjs";
7
7
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "MIT-licensed browser-safe API for TradeJS config, strategy authoring, figures, and shared helpers.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -100,7 +100,7 @@
100
100
  }
101
101
  },
102
102
  "dependencies": {
103
- "@tradejs/types": "^2.0.0",
103
+ "@tradejs/types": "^2.0.1",
104
104
  "date-fns": "^3.3.1",
105
105
  "fast-technical-indicators": "^1.1.4",
106
106
  "klinecharts": "10.0.0-alpha9",