@backtest-kit/pinets 0.0.2 → 0.0.3

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 CHANGED
@@ -442,6 +442,27 @@ class PineConnectionService {
442
442
  }
443
443
  }
444
444
 
445
+ const TABLE_ROWS_LIMIT = 48;
446
+ const GET_METHOD_CONTEXT_FN = () => {
447
+ if (backtestKit.MethodContextService.hasContext()) {
448
+ const { exchangeName, frameName, strategyName } = backtestKit.lib.methodContextService.context;
449
+ return { exchangeName, frameName, strategyName };
450
+ }
451
+ return {
452
+ strategyName: "",
453
+ exchangeName: "",
454
+ frameName: "",
455
+ };
456
+ };
457
+ const GET_EXECUTION_CONTEXT_FN = () => {
458
+ if (backtestKit.ExecutionContextService.hasContext()) {
459
+ const { when } = backtestKit.lib.executionContextService.context;
460
+ return { when: when.toISOString() };
461
+ }
462
+ return {
463
+ when: "",
464
+ };
465
+ };
445
466
  const DEFAULT_FORMAT = (v) => v !== null ? Number(v).toFixed(4) : "N/A";
446
467
  function isUnsafe(value) {
447
468
  if (value === null)
@@ -488,8 +509,13 @@ function isRowWarmedUp(row, keys) {
488
509
  }
489
510
  function generateMarkdownTable(rows, keys, signalId) {
490
511
  let markdown = "";
512
+ const { when: createdAt } = GET_EXECUTION_CONTEXT_FN();
491
513
  markdown += `# PineScript Technical Analysis Dump\n\n`;
492
- markdown += `**Signal ID**: ${String(signalId)}\n\n`;
514
+ markdown += `**Signal ID**: ${String(signalId)}\n`;
515
+ if (createdAt) {
516
+ markdown += `**Current datetime**: ${String(createdAt)}\n`;
517
+ }
518
+ markdown += "\n";
493
519
  const header = `| Timestamp | ${keys.join(" | ")} |\n`;
494
520
  const separator = `| --- | ${keys.map(() => "---").join(" | ")} |\n`;
495
521
  markdown += header;
@@ -533,7 +559,7 @@ class PineMarkdownService {
533
559
  }
534
560
  rows.push(row);
535
561
  }
536
- return rows;
562
+ return rows.slice(-TABLE_ROWS_LIMIT);
537
563
  };
538
564
  this.getReport = (signalId, plots) => {
539
565
  this.loggerService.log("pineMarkdownService getReport", {
@@ -551,14 +577,15 @@ class PineMarkdownService {
551
577
  outputDir,
552
578
  });
553
579
  const content = this.getReport(signalId, plots);
580
+ const { exchangeName, frameName, strategyName } = GET_METHOD_CONTEXT_FN();
554
581
  await backtestKit.Markdown.writeData(taName, content, {
555
582
  path: outputDir,
556
583
  file: `${String(signalId)}.md`,
557
584
  symbol: "",
558
585
  signalId: String(signalId),
559
- strategyName: "",
560
- exchangeName: "",
561
- frameName: "",
586
+ strategyName,
587
+ exchangeName,
588
+ frameName,
562
589
  });
563
590
  };
564
591
  }
package/build/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { join } from 'path';
2
- import { getDate, getRawCandles, Markdown } from 'backtest-kit';
2
+ import { getDate, getRawCandles, Markdown, MethodContextService, lib, ExecutionContextService } from 'backtest-kit';
3
3
  import { createActivator } from 'di-kit';
4
4
  import { singleshot, memoize, randomString } from 'functools-kit';
5
5
  import fs from 'fs/promises';
@@ -439,6 +439,27 @@ class PineConnectionService {
439
439
  }
440
440
  }
441
441
 
442
+ const TABLE_ROWS_LIMIT = 48;
443
+ const GET_METHOD_CONTEXT_FN = () => {
444
+ if (MethodContextService.hasContext()) {
445
+ const { exchangeName, frameName, strategyName } = lib.methodContextService.context;
446
+ return { exchangeName, frameName, strategyName };
447
+ }
448
+ return {
449
+ strategyName: "",
450
+ exchangeName: "",
451
+ frameName: "",
452
+ };
453
+ };
454
+ const GET_EXECUTION_CONTEXT_FN = () => {
455
+ if (ExecutionContextService.hasContext()) {
456
+ const { when } = lib.executionContextService.context;
457
+ return { when: when.toISOString() };
458
+ }
459
+ return {
460
+ when: "",
461
+ };
462
+ };
442
463
  const DEFAULT_FORMAT = (v) => v !== null ? Number(v).toFixed(4) : "N/A";
443
464
  function isUnsafe(value) {
444
465
  if (value === null)
@@ -485,8 +506,13 @@ function isRowWarmedUp(row, keys) {
485
506
  }
486
507
  function generateMarkdownTable(rows, keys, signalId) {
487
508
  let markdown = "";
509
+ const { when: createdAt } = GET_EXECUTION_CONTEXT_FN();
488
510
  markdown += `# PineScript Technical Analysis Dump\n\n`;
489
- markdown += `**Signal ID**: ${String(signalId)}\n\n`;
511
+ markdown += `**Signal ID**: ${String(signalId)}\n`;
512
+ if (createdAt) {
513
+ markdown += `**Current datetime**: ${String(createdAt)}\n`;
514
+ }
515
+ markdown += "\n";
490
516
  const header = `| Timestamp | ${keys.join(" | ")} |\n`;
491
517
  const separator = `| --- | ${keys.map(() => "---").join(" | ")} |\n`;
492
518
  markdown += header;
@@ -530,7 +556,7 @@ class PineMarkdownService {
530
556
  }
531
557
  rows.push(row);
532
558
  }
533
- return rows;
559
+ return rows.slice(-TABLE_ROWS_LIMIT);
534
560
  };
535
561
  this.getReport = (signalId, plots) => {
536
562
  this.loggerService.log("pineMarkdownService getReport", {
@@ -548,14 +574,15 @@ class PineMarkdownService {
548
574
  outputDir,
549
575
  });
550
576
  const content = this.getReport(signalId, plots);
577
+ const { exchangeName, frameName, strategyName } = GET_METHOD_CONTEXT_FN();
551
578
  await Markdown.writeData(taName, content, {
552
579
  path: outputDir,
553
580
  file: `${String(signalId)}.md`,
554
581
  symbol: "",
555
582
  signalId: String(signalId),
556
- strategyName: "",
557
- exchangeName: "",
558
- frameName: "",
583
+ strategyName,
584
+ exchangeName,
585
+ frameName,
559
586
  });
560
587
  };
561
588
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtest-kit/pinets",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
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",