pinets 0.2.0 → 0.2.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.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![npm version](https://img.shields.io/npm/v/pinets.svg?style=flat-square)](https://www.npmjs.com/package/pinets)
2
+ [![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg?style=flat-square)](https://opensource.org/licenses/AGPL-3.0)
3
+ [![Documentation](https://img.shields.io/badge/docs-github--pages-blue?style=flat-square)](https://alaa-eddine.github.io/PineTS/)
4
+ [![Reddit](https://img.shields.io/reddit/subreddit-subscribers/PineTS?style=flat-square&logo=reddit)](https://www.reddit.com/r/PineTS/)
5
+
1
6
  This project aims to provide a Javascript/Typescript port for Tradingview's Pine Script.
2
7
  The current version does not run Pine Script directly, instead it runs a close Javascript equivalent called PineTS.
3
8
 
@@ -9191,7 +9191,7 @@
9191
9191
  type: "MemberExpression",
9192
9192
  object: {
9193
9193
  type: "Identifier",
9194
- name: "math"
9194
+ name: "$.math"
9195
9195
  },
9196
9196
  property: {
9197
9197
  type: "Identifier",
@@ -9240,7 +9240,7 @@
9240
9240
  __publicField$6(this, "_ready", false);
9241
9241
  this._readyPromise = new Promise((resolve) => {
9242
9242
  this.loadMarketData(source, tickerId, timeframe, limit, sDate, eDate).then((data) => {
9243
- const marketData = data.reverse().slice(0, MAX_PERIODS);
9243
+ const marketData = data.slice(0, MAX_PERIODS);
9244
9244
  this._periods = marketData.length;
9245
9245
  this.data = marketData;
9246
9246
  const _open = marketData.map((d) => d.open);
@@ -9299,19 +9299,28 @@
9299
9299
  context.useTACache = useTACache;
9300
9300
  const transformer = transpile.bind(this);
9301
9301
  let transpiledFn = transformer(pineTSCode);
9302
+ context.data.close = [];
9303
+ context.data.open = [];
9304
+ context.data.high = [];
9305
+ context.data.low = [];
9306
+ context.data.volume = [];
9307
+ context.data.hl2 = [];
9308
+ context.data.hlc3 = [];
9309
+ context.data.ohlc4 = [];
9310
+ context.data.openTime = [];
9311
+ context.data.closeTime = [];
9302
9312
  const contextVarNames = ["const", "var", "let", "params"];
9303
- for (let i = this._periods - n, idx = n - 1; i < this._periods; i++, idx--) {
9313
+ for (let i = this._periods - n; i < this._periods; i++) {
9304
9314
  context.idx = i;
9305
- context.data.close = this.close.slice(idx);
9306
- context.data.open = this.open.slice(idx);
9307
- context.data.high = this.high.slice(idx);
9308
- context.data.low = this.low.slice(idx);
9309
- context.data.volume = this.volume.slice(idx);
9310
- context.data.hl2 = this.hl2.slice(idx);
9311
- context.data.hlc3 = this.hlc3.slice(idx);
9312
- context.data.ohlc4 = this.ohlc4.slice(idx);
9313
- context.data.openTime = this.openTime.slice(idx);
9314
- context.data.closeTime = this.closeTime.slice(idx);
9315
+ context.data.close.unshift(this.close[i]);
9316
+ context.data.open.unshift(this.open[i]);
9317
+ context.data.high.unshift(this.high[i]);
9318
+ context.data.low.unshift(this.low[i]);
9319
+ context.data.volume.unshift(this.volume[i]);
9320
+ context.data.hl2.unshift(this.hl2[i]);
9321
+ context.data.hlc3.unshift(this.hlc3[i]);
9322
+ context.data.ohlc4.unshift(this.ohlc4[i]);
9323
+ context.data.openTime.unshift(this.openTime[i]);
9315
9324
  const result = await transpiledFn(context);
9316
9325
  if (typeof result === "object") {
9317
9326
  if (typeof context.result !== "object") {
@@ -9186,7 +9186,7 @@ function transformEqualityChecks(ast) {
9186
9186
  type: "MemberExpression",
9187
9187
  object: {
9188
9188
  type: "Identifier",
9189
- name: "math"
9189
+ name: "$.math"
9190
9190
  },
9191
9191
  property: {
9192
9192
  type: "Identifier",
@@ -9213,7 +9213,7 @@ class PineTS {
9213
9213
  this.eDate = eDate;
9214
9214
  this._readyPromise = new Promise((resolve) => {
9215
9215
  this.loadMarketData(source, tickerId, timeframe, limit, sDate, eDate).then((data) => {
9216
- const marketData = data.reverse().slice(0, MAX_PERIODS);
9216
+ const marketData = data.slice(0, MAX_PERIODS);
9217
9217
  this._periods = marketData.length;
9218
9218
  this.data = marketData;
9219
9219
  const _open = marketData.map((d) => d.open);
@@ -9291,19 +9291,28 @@ class PineTS {
9291
9291
  context.useTACache = useTACache;
9292
9292
  const transformer = transpile.bind(this);
9293
9293
  let transpiledFn = transformer(pineTSCode);
9294
+ context.data.close = [];
9295
+ context.data.open = [];
9296
+ context.data.high = [];
9297
+ context.data.low = [];
9298
+ context.data.volume = [];
9299
+ context.data.hl2 = [];
9300
+ context.data.hlc3 = [];
9301
+ context.data.ohlc4 = [];
9302
+ context.data.openTime = [];
9303
+ context.data.closeTime = [];
9294
9304
  const contextVarNames = ["const", "var", "let", "params"];
9295
- for (let i = this._periods - n, idx = n - 1; i < this._periods; i++, idx--) {
9305
+ for (let i = this._periods - n; i < this._periods; i++) {
9296
9306
  context.idx = i;
9297
- context.data.close = this.close.slice(idx);
9298
- context.data.open = this.open.slice(idx);
9299
- context.data.high = this.high.slice(idx);
9300
- context.data.low = this.low.slice(idx);
9301
- context.data.volume = this.volume.slice(idx);
9302
- context.data.hl2 = this.hl2.slice(idx);
9303
- context.data.hlc3 = this.hlc3.slice(idx);
9304
- context.data.ohlc4 = this.ohlc4.slice(idx);
9305
- context.data.openTime = this.openTime.slice(idx);
9306
- context.data.closeTime = this.closeTime.slice(idx);
9307
+ context.data.close.unshift(this.close[i]);
9308
+ context.data.open.unshift(this.open[i]);
9309
+ context.data.high.unshift(this.high[i]);
9310
+ context.data.low.unshift(this.low[i]);
9311
+ context.data.volume.unshift(this.volume[i]);
9312
+ context.data.hl2.unshift(this.hl2[i]);
9313
+ context.data.hlc3.unshift(this.hlc3[i]);
9314
+ context.data.ohlc4.unshift(this.ohlc4[i]);
9315
+ context.data.openTime.unshift(this.openTime[i]);
9307
9316
  const result = await transpiledFn(context);
9308
9317
  if (typeof result === "object") {
9309
9318
  if (typeof context.result !== "object") {