@backtest-kit/pinets 6.2.0 → 6.5.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/build/index.cjs +25 -1
- package/build/index.mjs +26 -2
- package/package.json +3 -3
package/build/index.cjs
CHANGED
|
@@ -244,6 +244,22 @@ const ExchangeContextService = diScoped.scoped(class {
|
|
|
244
244
|
}
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
+
const PINE_TF_MAP = {
|
|
248
|
+
"1": "1m",
|
|
249
|
+
"3": "3m",
|
|
250
|
+
"5": "5m",
|
|
251
|
+
"15": "15m",
|
|
252
|
+
"30": "30m",
|
|
253
|
+
"60": "1h",
|
|
254
|
+
"120": "2h",
|
|
255
|
+
"240": "4h",
|
|
256
|
+
"360": "6h",
|
|
257
|
+
"480": "8h",
|
|
258
|
+
"1D": "1d",
|
|
259
|
+
D: "1d",
|
|
260
|
+
"1W": "1w",
|
|
261
|
+
W: "1w",
|
|
262
|
+
};
|
|
247
263
|
const GET_RAW_CANDLES_FN = async (self, symbol, interval, limit, sDate, eDate) => {
|
|
248
264
|
if (ExchangeContextService.hasContext()) {
|
|
249
265
|
return await backtestKit.Exchange.getRawCandles(symbol, interval, self.exchangeContextService.context, limit, sDate, eDate);
|
|
@@ -272,7 +288,15 @@ class CandleProviderService {
|
|
|
272
288
|
const symbol = tickerId
|
|
273
289
|
.toUpperCase()
|
|
274
290
|
.replace(/^BINANCE:|^BYBIT:|^OKX:/, "");
|
|
275
|
-
const
|
|
291
|
+
const normalizedTimeframe = PINE_TF_MAP[timeframe] ?? timeframe;
|
|
292
|
+
let clampedEDate = eDate;
|
|
293
|
+
if (backtestKit.ExecutionContextService.hasContext()) {
|
|
294
|
+
const whenMs = backtestKit.lib.executionContextService.context.when.getTime();
|
|
295
|
+
if (clampedEDate === undefined || clampedEDate > whenMs) {
|
|
296
|
+
clampedEDate = whenMs;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const rawCandles = await GET_RAW_CANDLES_FN(this, symbol, normalizedTimeframe, limit, sDate, clampedEDate);
|
|
276
300
|
const candles = rawCandles.map((c) => ({
|
|
277
301
|
openTime: c.timestamp,
|
|
278
302
|
open: c.open,
|
package/build/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
-
import { getDate, Exchange, MethodContextService,
|
|
2
|
+
import { getDate, ExecutionContextService, lib, Exchange, MethodContextService, getRawCandles, Markdown } from 'backtest-kit';
|
|
3
3
|
import { createActivator } from 'di-kit';
|
|
4
4
|
import { scoped } from 'di-scoped';
|
|
5
5
|
import { singleshot, memoize, str, randomString } from 'functools-kit';
|
|
@@ -241,6 +241,22 @@ const ExchangeContextService = scoped(class {
|
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
+
const PINE_TF_MAP = {
|
|
245
|
+
"1": "1m",
|
|
246
|
+
"3": "3m",
|
|
247
|
+
"5": "5m",
|
|
248
|
+
"15": "15m",
|
|
249
|
+
"30": "30m",
|
|
250
|
+
"60": "1h",
|
|
251
|
+
"120": "2h",
|
|
252
|
+
"240": "4h",
|
|
253
|
+
"360": "6h",
|
|
254
|
+
"480": "8h",
|
|
255
|
+
"1D": "1d",
|
|
256
|
+
D: "1d",
|
|
257
|
+
"1W": "1w",
|
|
258
|
+
W: "1w",
|
|
259
|
+
};
|
|
244
260
|
const GET_RAW_CANDLES_FN = async (self, symbol, interval, limit, sDate, eDate) => {
|
|
245
261
|
if (ExchangeContextService.hasContext()) {
|
|
246
262
|
return await Exchange.getRawCandles(symbol, interval, self.exchangeContextService.context, limit, sDate, eDate);
|
|
@@ -269,7 +285,15 @@ class CandleProviderService {
|
|
|
269
285
|
const symbol = tickerId
|
|
270
286
|
.toUpperCase()
|
|
271
287
|
.replace(/^BINANCE:|^BYBIT:|^OKX:/, "");
|
|
272
|
-
const
|
|
288
|
+
const normalizedTimeframe = PINE_TF_MAP[timeframe] ?? timeframe;
|
|
289
|
+
let clampedEDate = eDate;
|
|
290
|
+
if (ExecutionContextService.hasContext()) {
|
|
291
|
+
const whenMs = lib.executionContextService.context.when.getTime();
|
|
292
|
+
if (clampedEDate === undefined || clampedEDate > whenMs) {
|
|
293
|
+
clampedEDate = whenMs;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const rawCandles = await GET_RAW_CANDLES_FN(this, symbol, normalizedTimeframe, limit, sDate, clampedEDate);
|
|
273
297
|
const candles = rawCandles.map((c) => ({
|
|
274
298
|
openTime: c.timestamp,
|
|
275
299
|
open: c.open,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backtest-kit/pinets",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "Run TradingView Pine Script strategies in Node.js self hosted environment. Execute existing Pine Script indicators and generate trading signals with 1:1 syntax compatibility via PineTS runtime.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Petr Tripolsky",
|
|
@@ -69,11 +69,11 @@
|
|
|
69
69
|
"ts-morph": "27.0.2",
|
|
70
70
|
"tslib": "2.7.0",
|
|
71
71
|
"typedoc": "0.27.9",
|
|
72
|
-
"backtest-kit": "6.
|
|
72
|
+
"backtest-kit": "6.5.0",
|
|
73
73
|
"worker-testbed": "1.0.12"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"backtest-kit": "^6.
|
|
76
|
+
"backtest-kit": "^6.5.0",
|
|
77
77
|
"pinets": "^0.9.9",
|
|
78
78
|
"typescript": "^5.0.0"
|
|
79
79
|
},
|