@mathieuc/tradingview 3.4.1 → 3.4.2
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 +1 -0
- package/README.md +7 -1
- package/examples/AllPrivateIndicators.js +5 -4
- package/examples/BuiltInIndicator.js +3 -4
- package/examples/CustomChartType.js +4 -6
- package/examples/CustomTimeframe.js +3 -4
- package/examples/Errors.js +3 -3
- package/examples/FakeReplayMode.js +4 -5
- package/examples/FromToData.js +4 -5
- package/examples/GetDrawings.js +3 -4
- package/examples/GraphicIndicator.js +4 -5
- package/examples/MultipleSyncFetch.js +3 -4
- package/examples/PinePermManage.js +7 -7
- package/examples/ReplayMode.js +4 -5
- package/examples/Search.js +4 -5
- package/examples/SimpleChart.js +3 -3
- package/examples/UserLogin.js +4 -4
- package/package.json +6 -3
- package/src/chart/session.js +1 -1
- package/src/classes/PinePermManager.js +89 -74
- package/src/miscRequests.js +163 -187
- package/vite.config.js +6 -0
- package/src/FormData.js +0 -36
- package/src/request.js +0 -37
- package/test.js +0 -70
- package/tests/01. Search.js +0 -17
- package/tests/02. QuoteSession.js +0 -51
- package/tests/03. SimpleChart.js +0 -59
- package/tests/04. Indicators.js +0 -96
- package/tests/05. BuiltInIndicator.js +0 -39
- package/tests/06. FakeReplayMode.js +0 -57
- package/tests/07. ReplayMode.js +0 -49
- package/tests/08. CustomChartTypes.js +0 -113
- package/tests/09. AllErrors.js +0 -184
- package/tests/10. Authenticated.js +0 -101
package/.eslintrc.js
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TradingView API [](https://GitHub.com/Mathieu2301/TradingView-API/stargazers/)
|
|
2
2
|
|
|
3
|
-
[](https://github.com/Mathieu2301/TradingView-API/actions/workflows/tests.yml)
|
|
4
4
|
[](https://www.codefactor.io/repository/github/mathieu2301/tradingview-api/overview/main)
|
|
5
5
|
[](https://GitHub.com/Mathieu2301/TradingView-API/commit/)
|
|
6
6
|
[](https://npmjs.com/@mathieuc/tradingview)
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
Get realtime market prices and indicator values from Tradingview !
|
|
11
11
|
|
|
12
|
+
## 🔵 New Telegram group
|
|
13
|
+
|
|
14
|
+
👉 To get help, exchange tips, find collaborators, developers, missions, etc...
|
|
15
|
+
|
|
16
|
+
Here is the Telegram group of the library: https://t.me/tradingview_api
|
|
17
|
+
|
|
12
18
|
## Features
|
|
13
19
|
|
|
14
20
|
- [x] Premium features
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
const TradingView = require('../main');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
package/examples/Errors.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const { Client } = require('../main');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
package/examples/FromToData.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const TradingView = require('../main');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
package/examples/GetDrawings.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
const TradingView = require('../main');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
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());
|
package/examples/ReplayMode.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const TradingView = require('../main');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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',
|
package/examples/Search.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const TradingView = require('../main');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
package/examples/SimpleChart.js
CHANGED
package/examples/UserLogin.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
const TradingView = require('../main');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"description": "Tradingview instant stocks API, indicator alerts, trading bot, and more !",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"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
|
}
|
package/src/chart/session.js
CHANGED
|
@@ -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 {
|
|
32
|
+
* @prop {number} [range] Range range
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
/** @typedef {Object<string, Function[]>} StudyListeners */
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
|