@mathieuc/tradingview 3.4.1 → 3.4.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/.eslintrc.js CHANGED
@@ -22,5 +22,6 @@ module.exports = {
22
22
  ],
23
23
  'no-restricted-syntax': 'off',
24
24
  'no-await-in-loop': 'off',
25
+ 'no-continue': 'off',
25
26
  },
26
27
  };
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TradingView API [![GitHub stars](https://img.shields.io/github/stars/Mathieu2301/TradingView-API.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/Mathieu2301/TradingView-API/stargazers/)
2
2
 
3
- [![Tests](https://github.com/Mathieu2301/TradingView-API/actions/workflows/node.js.yml/badge.svg)](https://github.com/Mathieu2301/TradingView-API/actions/workflows/node.js.yml)
3
+ [![Tests](https://github.com/Mathieu2301/TradingView-API/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/Mathieu2301/TradingView-API/actions/workflows/tests.yml)
4
4
  [![CodeFactor](https://www.codefactor.io/repository/github/mathieu2301/tradingview-api/badge/main)](https://www.codefactor.io/repository/github/mathieu2301/tradingview-api/overview/main)
5
5
  [![GitHub latest commit](https://img.shields.io/github/last-commit/Mathieu2301/TradingView-API)](https://GitHub.com/Mathieu2301/TradingView-API/commit/)
6
6
  [![Npm package yearly downloads](https://badgen.net/npm/dt/@mathieuc/tradingview)](https://npmjs.com/@mathieuc/tradingview)
@@ -9,6 +9,16 @@
9
9
 
10
10
  Get realtime market prices and indicator values from Tradingview !
11
11
 
12
+ ## 🟢 Need help with your project?
13
+
14
+ 🚀 Click [here](https://forms.gle/qPp5RKo8L55C5oJE7) for personalized assistance on your project.
15
+
16
+ ## 🔵 Telegram group
17
+
18
+ 👉 To get help, exchange tips, find collaborators, developers, missions, etc...
19
+
20
+ Join the Telegram group of the TradingView-API Community: [t.me/tradingview_api](https://t.me/tradingview_api)
21
+
12
22
  ## Features
13
23
 
14
24
  - [x] Premium features
@@ -1,14 +1,15 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example creates a chart with
5
- all user's private indicators
6
- */
3
+ /**
4
+ * This example creates a chart with all user's private indicators
5
+ */
7
6
 
8
7
  if (!process.argv[2]) throw Error('Please specify your \'sessionid\' cookie');
8
+ if (!process.argv[3]) throw Error('Please specify your \'signature\' cookie');
9
9
 
10
10
  const client = new TradingView.Client({
11
11
  token: process.argv[2],
12
+ signature: process.argv[3],
12
13
  });
13
14
 
14
15
  const chart = new client.Session.Chart();
@@ -1,9 +1,8 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests built-in indicators
5
- like volume-based indicators
6
- */
3
+ /**
4
+ * This example tests built-in indicators like volume-based indicators
5
+ */
7
6
 
8
7
  const volumeProfile = new TradingView.BuiltInIndicator('VbPFixed@tv-basicstudies-139!');
9
8
 
@@ -1,11 +1,9 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example creates charts of custom
5
- types such as 'HeikinAshi', 'Renko',
6
- 'LineBreak', 'Kagi', 'PointAndFigure',
7
- and 'Range' with default settings
8
- */
3
+ /**
4
+ * This example creates charts of custom types such as 'HeikinAshi', 'Renko',
5
+ * 'LineBreak', 'Kagi', 'PointAndFigure', and 'Range' with default settings.
6
+ */
9
7
 
10
8
  const client = new TradingView.Client({
11
9
  /* Token is only required if you want to use intraday
@@ -1,9 +1,8 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests custom
5
- timeframes like 1 second
6
- */
3
+ /**
4
+ * This example tests custom timeframes like 1 second
5
+ */
7
6
 
8
7
  if (!process.argv[2]) throw Error('Please specify your \'sessionid\' cookie');
9
8
 
@@ -1,8 +1,8 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests many types of errors
5
- */
3
+ /**
4
+ * This example tests many types of errors
5
+ */
6
6
 
7
7
  const client = new TradingView.Client(); // Creates a websocket client
8
8
 
@@ -1,10 +1,9 @@
1
1
  const { Client } = require('../main');
2
2
 
3
- /*
4
- This example tests the fake
5
- replay mode which works in
6
- intraday even with free plan
7
- */
3
+ /**
4
+ * This example tests the fake replay mode which
5
+ * works in intraday even with free plan
6
+ */
8
7
 
9
8
  console.log('----- Testing FakeReplayMode: -----');
10
9
 
@@ -1,10 +1,9 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests fetching chart
5
- data of a number of candles before
6
- or after a timestamp
7
- */
3
+ /**
4
+ * This example tests fetching chart data of a number
5
+ * of candles before or after a timestamp
6
+ */
8
7
 
9
8
  const client = new TradingView.Client();
10
9
 
@@ -1,9 +1,8 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests the
5
- getDrawings function
6
- */
3
+ /**
4
+ * This example tests the getDrawings function
5
+ */
7
6
 
8
7
  // First parameter must be the layoutID
9
8
  // (if the layout is private) Second parameter must be the sessionid cookie
@@ -1,10 +1,9 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests an indicator that sends
5
- graphic data such as 'lines', 'labels',
6
- 'boxes', 'tables', 'polygons', etc...
7
- */
3
+ /**
4
+ * This example tests an indicator that sends graphic data such
5
+ * as 'lines', 'labels', 'boxes', 'tables', 'polygons', etc...
6
+ */
8
7
 
9
8
  const client = new TradingView.Client();
10
9
 
@@ -1,9 +1,8 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This examples synchronously
5
- fetches data from 3 indicators
6
- */
3
+ /**
4
+ * This examples synchronously fetches data from 3 indicators
5
+ */
7
6
 
8
7
  const client = new TradingView.Client();
9
8
  const chart = new client.Session.Chart();
@@ -1,15 +1,15 @@
1
1
  const { PinePermManager } = require('../main');
2
2
 
3
- /*
4
- This example creates a pine
5
- permission manager and tests
6
- all the available functions
7
- */
3
+ /**
4
+ * This example creates a pine permission manager
5
+ * and tests all the available functions
6
+ */
8
7
 
9
8
  const sessionid = process.argv[2];
10
- const pineid = process.argv[3];
9
+ const signature = process.argv[3];
10
+ const pineid = process.argv[4];
11
11
 
12
- const manager = new PinePermManager(sessionid, pineid);
12
+ const manager = new PinePermManager(sessionid, signature, pineid);
13
13
 
14
14
  (async () => {
15
15
  console.log('Users:', await manager.getUsers());
@@ -1,10 +1,9 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests the real replay
5
- mode by fetching indicator data and
6
- stores it in a 'periods' variable
7
- */
3
+ /**
4
+ * This example tests the real replay mode by fetching
5
+ * indicator data and stores it in a 'periods' variable
6
+ */
8
7
 
9
8
  const config = {
10
9
  symbol: 'BINANCE:BTCEUR',
@@ -1,10 +1,9 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests the searching
5
- functions such as 'searchMarket'
6
- and 'searchIndicator'
7
- */
3
+ /**
4
+ * This example tests the searching functions such
5
+ * as 'searchMarket' and 'searchIndicator'
6
+ */
8
7
 
9
8
  TradingView.searchMarket('BINANCE:').then((rs) => {
10
9
  console.log('Found Markets:', rs);
@@ -1,8 +1,8 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example creates a BTCEUR daily chart
5
- */
3
+ /**
4
+ * This example creates a BTCEUR daily chart
5
+ */
6
6
 
7
7
  const client = new TradingView.Client(); // Creates a websocket client
8
8
 
@@ -1,9 +1,8 @@
1
1
  const TradingView = require('../main');
2
2
 
3
- /*
4
- This example tests the
5
- user login function
6
- */
3
+ /**
4
+ * This example tests the user login function
5
+ */
7
6
 
8
7
  if (!process.argv[2]) throw Error('Please specify your username/email');
9
8
  if (!process.argv[3]) throw Error('Please specify your password');
@@ -11,6 +10,7 @@ if (!process.argv[3]) throw Error('Please specify your password');
11
10
  TradingView.loginUser(process.argv[2], process.argv[3], false).then((user) => {
12
11
  console.log('User:', user);
13
12
  console.log('Sessionid:', user.session);
13
+ console.log('Signature:', user.signature);
14
14
  }).catch((err) => {
15
15
  console.error('Login error:', err.message);
16
16
  });
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mathieuc/tradingview",
3
- "version": "3.4.1",
3
+ "version": "3.4.3",
4
4
  "description": "Tradingview instant stocks API, indicator alerts, trading bot, and more !",
5
5
  "main": "main.js",
6
6
  "scripts": {
7
- "test": "node test"
7
+ "test": "vitest"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -26,14 +26,17 @@
26
26
  "author": "Mathieu Colmon",
27
27
  "license": "ISC",
28
28
  "dependencies": {
29
+ "axios": "^1.5.0",
29
30
  "jszip": "^3.7.1",
30
31
  "ws": "^7.4.3"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@babel/eslint-parser": "^7.15.7",
34
35
  "@mathieuc/console": "^1.0.1",
36
+ "dotenv": "^16.3.1",
35
37
  "eslint": "^7.25.0",
36
38
  "eslint-config-airbnb-base": "^14.2.1",
37
- "eslint-plugin-import": "^2.22.1"
39
+ "eslint-plugin-import": "^2.22.1",
40
+ "vitest": "^0.31.1"
38
41
  }
39
42
  }
@@ -29,7 +29,7 @@ const ChartTypes = {
29
29
  * @prop {number} [lb] LineBreak Line break
30
30
  * @prop {boolean} [oneStepBackBuilding] PointAndFigure oneStepBackBuilding
31
31
  * @prop {boolean} [phantomBars] Range phantom bars
32
- * @prop {boolean} [range] Range range
32
+ * @prop {number} [range] Range range
33
33
  */
34
34
 
35
35
  /** @typedef {Object<string, Function[]>} StudyListeners */
@@ -1,5 +1,4 @@
1
- const request = require('../request');
2
- const FormData = require('../FormData');
1
+ const axios = require('axios');
3
2
 
4
3
  /**
5
4
  * @typedef {Object} AuthorizationUser
@@ -18,14 +17,17 @@ class PinePermManager {
18
17
 
19
18
  /**
20
19
  * Creates a PinePermManager instance
21
- * @param {string} sessionId Token from sessionid cookie
20
+ * @param {string} sessionId Token from `sessionid` cookie
21
+ * @param {string} signature Signature cookie
22
22
  * @param {string} pineId Indicator ID (Like: PUB;XXXXXXXXXXXXXXXXXXXXX)
23
23
  */
24
- constructor(sessionId, pineId) {
24
+ constructor(sessionId, signature, pineId) {
25
25
  if (!sessionId) throw new Error('Please provide a SessionID');
26
+ if (!signature) throw new Error('Please provide a Signature');
26
27
  if (!pineId) throw new Error('Please provide a PineID');
27
- this.pineId = pineId;
28
28
  this.sessionId = sessionId;
29
+ this.signature = signature;
30
+ this.pineId = pineId;
29
31
  }
30
32
 
31
33
  /**
@@ -40,20 +42,23 @@ class PinePermManager {
40
42
  * @returns {AuthorizationUser[]}
41
43
  */
42
44
  async getUsers(limit = 10, order = '-created') {
43
- const { data } = await request({
44
- method: 'POST',
45
- host: 'www.tradingview.com',
46
- path: `/pine_perm/list_users/?limit=${limit}&order_by=${order}`,
47
- headers: {
48
- origin: 'https://www.tradingview.com',
49
- 'Content-Type': 'application/x-www-form-urlencoded',
50
- cookie: `sessionid=${this.sessionId}`,
51
- },
52
- }, false, `pine_id=${this.pineId.replace(/;/g, '%3B')}`);
53
-
54
- if (!data.results) throw new Error('Wrong sessionId or pineId');
55
-
56
- return data.results;
45
+ try {
46
+ const { data } = await axios.post(
47
+ `https://www.tradingview.com/pine_perm/list_users/?limit=${limit}&order_by=${order}`,
48
+ `pine_id=${this.pineId.replace(/;/g, '%3B')}`,
49
+ {
50
+ headers: {
51
+ origin: 'https://www.tradingview.com',
52
+ 'Content-Type': 'application/x-www-form-urlencoded',
53
+ cookie: `sessionid=${this.sessionId};sessionid_sign=${this.signature};`,
54
+ },
55
+ },
56
+ );
57
+
58
+ return data.results;
59
+ } catch (e) {
60
+ throw new Error(e.response.data.detail || 'Wrong credentials or pineId');
61
+ }
57
62
  }
58
63
 
59
64
  /**
@@ -63,26 +68,31 @@ class PinePermManager {
63
68
  * @returns {'ok' | 'exists' | null}
64
69
  */
65
70
  async addUser(username, expiration = null) {
66
- const formData = new FormData();
67
- formData.append('pine_id', this.pineId);
68
- formData.append('username_recip', username);
69
- if (expiration && expiration instanceof Date) {
70
- formData.append('expiration', expiration.toString());
71
+ try {
72
+ const { data } = await axios.post(
73
+ 'https://www.tradingview.com/pine_perm/add/',
74
+ `pine_id=${
75
+ this.pineId.replace(/;/g, '%3B')
76
+ }&username_recip=${
77
+ username
78
+ }${
79
+ expiration && expiration instanceof Date
80
+ ? `&expiration=${expiration.toISOString()}`
81
+ : ''
82
+ }`,
83
+ {
84
+ headers: {
85
+ origin: 'https://www.tradingview.com',
86
+ 'Content-Type': 'application/x-www-form-urlencoded',
87
+ cookie: `sessionid=${this.sessionId};sessionid_sign=${this.signature};`,
88
+ },
89
+ },
90
+ );
91
+
92
+ return data.status;
93
+ } catch (e) {
94
+ throw new Error(e.response.data.detail || 'Wrong credentials or pineId');
71
95
  }
72
-
73
- const { data } = await request({
74
- method: 'POST',
75
- host: 'www.tradingview.com',
76
- path: '/pine_perm/add/',
77
- headers: {
78
- origin: 'https://www.tradingview.com',
79
- 'Content-Type': `multipart/form-data; boundary=${formData.boundary}`,
80
- cookie: `sessionid=${this.sessionId}`,
81
- },
82
- }, false, formData.toString());
83
-
84
- if (!data.status) throw new Error('Wrong sessionId or pineId');
85
- return data.status;
86
96
  }
87
97
 
88
98
  /**
@@ -92,26 +102,31 @@ class PinePermManager {
92
102
  * @returns {'ok' | null}
93
103
  */
94
104
  async modifyExpiration(username, expiration = null) {
95
- const formData = new FormData();
96
- formData.append('pine_id', this.pineId);
97
- formData.append('username_recip', username);
98
- if (expiration && expiration instanceof Date) {
99
- formData.append('expiration', expiration.toISOString());
105
+ try {
106
+ const { data } = await axios.post(
107
+ 'https://www.tradingview.com/pine_perm/modify_user_expiration/',
108
+ `pine_id=${
109
+ this.pineId.replace(/;/g, '%3B')
110
+ }&username_recip=${
111
+ username
112
+ }${
113
+ expiration && expiration instanceof Date
114
+ ? `&expiration=${expiration.toISOString()}`
115
+ : ''
116
+ }`,
117
+ {
118
+ headers: {
119
+ origin: 'https://www.tradingview.com',
120
+ 'Content-Type': 'application/x-www-form-urlencoded',
121
+ cookie: `sessionid=${this.sessionId};sessionid_sign=${this.signature};`,
122
+ },
123
+ },
124
+ );
125
+
126
+ return data.status;
127
+ } catch (e) {
128
+ throw new Error(e.response.data.detail || 'Wrong credentials or pineId');
100
129
  }
101
-
102
- const { data } = await request({
103
- method: 'POST',
104
- host: 'www.tradingview.com',
105
- path: '/pine_perm/modify_user_expiration/',
106
- headers: {
107
- origin: 'https://www.tradingview.com',
108
- 'Content-Type': `multipart/form-data; boundary=${formData.boundary}`,
109
- cookie: `sessionid=${this.sessionId}`,
110
- },
111
- }, false, formData.toString());
112
-
113
- if (!data.status) throw new Error('Wrong sessionId or pineId');
114
- return data.status;
115
130
  }
116
131
 
117
132
  /**
@@ -120,23 +135,23 @@ class PinePermManager {
120
135
  * @returns {'ok' | null}
121
136
  */
122
137
  async removeUser(username) {
123
- const formData = new FormData();
124
- formData.append('pine_id', this.pineId);
125
- formData.append('username_recip', username);
126
-
127
- const { data } = await request({
128
- method: 'POST',
129
- host: 'www.tradingview.com',
130
- path: '/pine_perm/remove/',
131
- headers: {
132
- origin: 'https://www.tradingview.com',
133
- 'Content-Type': `multipart/form-data; boundary=${formData.boundary}`,
134
- cookie: `sessionid=${this.sessionId}`,
135
- },
136
- }, false, formData.toString());
137
-
138
- if (!data.status) throw new Error('Wrong sessionId or pineId');
139
- return data.status;
138
+ try {
139
+ const { data } = await axios.post(
140
+ 'https://www.tradingview.com/pine_perm/remove/',
141
+ `pine_id=${this.pineId.replace(/;/g, '%3B')}&username_recip=${username}`,
142
+ {
143
+ headers: {
144
+ origin: 'https://www.tradingview.com',
145
+ 'Content-Type': 'application/x-www-form-urlencoded',
146
+ cookie: `sessionid=${this.sessionId};sessionid_sign=${this.signature};`,
147
+ },
148
+ },
149
+ );
150
+
151
+ return data.status;
152
+ } catch (e) {
153
+ throw new Error(e.response.data.detail || 'Wrong credentials or pineId');
154
+ }
140
155
  }
141
156
  }
142
157