@mathieuc/tradingview 3.5.2 → 4.0.0-beta.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.
Files changed (120) hide show
  1. package/README.md +112 -51
  2. package/dist/chart/chart-session.d.ts +114 -0
  3. package/dist/chart/chart-session.js +339 -0
  4. package/dist/chart/graphics.d.ts +129 -0
  5. package/dist/chart/graphics.js +153 -0
  6. package/dist/chart/index.d.ts +11 -0
  7. package/dist/chart/index.js +6 -0
  8. package/dist/chart/strategy.d.ts +113 -0
  9. package/dist/chart/strategy.js +78 -0
  10. package/dist/chart/study.d.ts +60 -0
  11. package/dist/chart/study.js +179 -0
  12. package/dist/chart/timeframes.d.ts +7 -0
  13. package/dist/chart/timeframes.js +22 -0
  14. package/dist/chart/types.d.ts +105 -0
  15. package/dist/chart/types.js +9 -0
  16. package/dist/client/client.d.ts +89 -0
  17. package/dist/client/client.js +254 -0
  18. package/dist/client/index.d.ts +4 -0
  19. package/dist/client/index.js +2 -0
  20. package/dist/client/transport.d.ts +27 -0
  21. package/dist/client/transport.js +38 -0
  22. package/dist/data/candles.d.ts +40 -0
  23. package/dist/data/candles.js +101 -0
  24. package/dist/data/history.d.ts +61 -0
  25. package/dist/data/history.js +101 -0
  26. package/dist/data/index.d.ts +30 -0
  27. package/dist/data/index.js +16 -0
  28. package/dist/data/indicators.d.ts +54 -0
  29. package/dist/data/indicators.js +139 -0
  30. package/dist/data/operation.d.ts +71 -0
  31. package/dist/data/operation.js +205 -0
  32. package/dist/data/provider.d.ts +23 -0
  33. package/dist/data/provider.js +11 -0
  34. package/dist/data/quotes.d.ts +33 -0
  35. package/dist/data/quotes.js +117 -0
  36. package/dist/data/symbols.d.ts +9 -0
  37. package/dist/data/symbols.js +19 -0
  38. package/dist/errors.d.ts +53 -0
  39. package/dist/errors.js +24 -0
  40. package/dist/events.d.ts +36 -0
  41. package/dist/events.js +70 -0
  42. package/dist/http/account.d.ts +47 -0
  43. package/dist/http/account.js +127 -0
  44. package/dist/http/index.d.ts +11 -0
  45. package/dist/http/index.js +5 -0
  46. package/dist/http/indicators.d.ts +37 -0
  47. package/dist/http/indicators.js +144 -0
  48. package/dist/http/layouts.d.ts +36 -0
  49. package/dist/http/layouts.js +24 -0
  50. package/dist/http/market.d.ts +45 -0
  51. package/dist/http/market.js +59 -0
  52. package/dist/http/pine-permissions.d.ts +29 -0
  53. package/dist/http/pine-permissions.js +56 -0
  54. package/dist/http/request.d.ts +44 -0
  55. package/dist/http/request.js +83 -0
  56. package/dist/index.d.ts +21 -0
  57. package/dist/index.js +19 -0
  58. package/dist/indicators/builtin-indicator.d.ts +17 -0
  59. package/dist/indicators/builtin-indicator.js +75 -0
  60. package/dist/indicators/index.d.ts +8 -0
  61. package/dist/indicators/index.js +2 -0
  62. package/dist/indicators/pine-indicator.d.ts +63 -0
  63. package/dist/indicators/pine-indicator.js +101 -0
  64. package/dist/protocol/compression.d.ts +12 -0
  65. package/dist/protocol/compression.js +83 -0
  66. package/dist/protocol/framing.d.ts +59 -0
  67. package/dist/protocol/framing.js +68 -0
  68. package/dist/protocol/ids.d.ts +2 -0
  69. package/dist/protocol/ids.js +10 -0
  70. package/dist/protocol/index.d.ts +4 -0
  71. package/dist/protocol/index.js +3 -0
  72. package/dist/quote/fields.d.ts +35 -0
  73. package/dist/quote/fields.js +21 -0
  74. package/dist/quote/index.d.ts +4 -0
  75. package/dist/quote/index.js +2 -0
  76. package/dist/quote/quote-session.d.ts +73 -0
  77. package/dist/quote/quote-session.js +205 -0
  78. package/docs/README.es.md +58 -0
  79. package/docs/README.fr.md +58 -0
  80. package/docs/README.pt.md +58 -0
  81. package/docs/data-api.md +285 -0
  82. package/docs/low-level-api.md +213 -0
  83. package/docs/migration-v4.md +128 -0
  84. package/docs/release-4.0.0-beta.1.md +39 -0
  85. package/docs/v4-coverage.md +213 -0
  86. package/package.json +53 -20
  87. package/.env.sample +0 -2
  88. package/.eslintrc.js +0 -28
  89. package/.gitattributes +0 -2
  90. package/docs/DOCS.md +0 -3
  91. package/examples/AllPrivateIndicators.js +0 -44
  92. package/examples/BuiltInIndicator.js +0 -51
  93. package/examples/CustomChartType.js +0 -123
  94. package/examples/CustomTimeframe.js +0 -31
  95. package/examples/Errors.js +0 -155
  96. package/examples/FakeReplayMode.js +0 -40
  97. package/examples/FromToData.js +0 -35
  98. package/examples/GetDrawings.js +0 -27
  99. package/examples/GraphicIndicator.js +0 -42
  100. package/examples/MultipleSyncFetch.js +0 -44
  101. package/examples/PinePermManage.js +0 -67
  102. package/examples/ReplayMode.js +0 -103
  103. package/examples/Search.js +0 -14
  104. package/examples/SimpleChart.js +0 -63
  105. package/examples/UserLogin.js +0 -16
  106. package/main.js +0 -11
  107. package/src/chart/graphicParser.js +0 -308
  108. package/src/chart/session.js +0 -553
  109. package/src/chart/study.js +0 -435
  110. package/src/classes/BuiltInIndicator.js +0 -137
  111. package/src/classes/PineIndicator.js +0 -132
  112. package/src/classes/PinePermManager.js +0 -159
  113. package/src/client.js +0 -298
  114. package/src/miscRequests.js +0 -609
  115. package/src/protocol.js +0 -60
  116. package/src/quote/market.js +0 -132
  117. package/src/quote/session.js +0 -125
  118. package/src/types.js +0 -36
  119. package/src/utils.js +0 -20
  120. package/vite.config.js +0 -7
@@ -1,132 +0,0 @@
1
- /**
2
- * @typedef {'loaded' | 'data' | 'error'} MarketEvent
3
- */
4
-
5
- /**
6
- * @param {import('./session').QuoteSessionBridge} quoteSession
7
- */
8
-
9
- module.exports = (quoteSession) => class QuoteMarket {
10
- #symbolListeners = quoteSession.symbolListeners;
11
-
12
- #symbol;
13
-
14
- #session;
15
-
16
- #symbolKey;
17
-
18
- #symbolListenerID = 0;
19
-
20
- #lastData = {};
21
-
22
- #callbacks = {
23
- loaded: [],
24
- data: [],
25
-
26
- event: [],
27
- error: [],
28
- };
29
-
30
- /**
31
- * @param {MarketEvent} ev Client event
32
- * @param {...{}} data Packet data
33
- */
34
- #handleEvent(ev, ...data) {
35
- this.#callbacks[ev].forEach((e) => e(...data));
36
- this.#callbacks.event.forEach((e) => e(ev, ...data));
37
- }
38
-
39
- #handleError(...msgs) {
40
- if (this.#callbacks.error.length === 0) console.error(...msgs);
41
- else this.#handleEvent('error', ...msgs);
42
- }
43
-
44
- /**
45
- * @param {string} symbol Market symbol (like: 'BTCEUR' or 'KRAKEN:BTCEUR')
46
- * @param {string} session Market session (like: 'regular' or 'extended')
47
- */
48
- constructor(symbol, session = 'regular') {
49
- this.#symbol = symbol;
50
- this.#session = session;
51
- this.#symbolKey = `=${JSON.stringify({ session, symbol })}`;
52
-
53
- if (!this.#symbolListeners[this.#symbolKey]) {
54
- this.#symbolListeners[this.#symbolKey] = [];
55
- quoteSession.send('quote_add_symbols', [
56
- quoteSession.sessionID,
57
- this.#symbolKey,
58
- ]);
59
- }
60
-
61
- this.#symbolListenerID = this.#symbolListeners[this.#symbolKey].length;
62
-
63
- this.#symbolListeners[this.#symbolKey][this.#symbolListenerID] = (packet) => {
64
- if (global.TW_DEBUG) console.log('§90§30§105 MARKET §0 DATA', packet);
65
-
66
- if (packet.type === 'qsd' && packet.data[1].s === 'ok') {
67
- this.#lastData = {
68
- ...this.#lastData,
69
- ...packet.data[1].v,
70
- };
71
- this.#handleEvent('data', this.#lastData);
72
- return;
73
- }
74
-
75
- if (packet.type === 'quote_completed') {
76
- this.#handleEvent('loaded');
77
- return;
78
- }
79
-
80
- if (packet.type === 'qsd' && packet.data[1].s === 'error') {
81
- this.#handleError('Market error', packet.data);
82
- }
83
- };
84
- }
85
-
86
- /**
87
- * When quote market is loaded
88
- * @param {() => void} cb Callback
89
- * @event
90
- */
91
- onLoaded(cb) {
92
- this.#callbacks.loaded.push(cb);
93
- }
94
-
95
- /**
96
- * When quote data is received
97
- * @param {(data: {}) => void} cb Callback
98
- * @event
99
- */
100
- onData(cb) {
101
- this.#callbacks.data.push(cb);
102
- }
103
-
104
- /**
105
- * When quote event happens
106
- * @param {(...any) => void} cb Callback
107
- * @event
108
- */
109
- onEvent(cb) {
110
- this.#callbacks.event.push(cb);
111
- }
112
-
113
- /**
114
- * When quote error happens
115
- * @param {(...any) => void} cb Callback
116
- * @event
117
- */
118
- onError(cb) {
119
- this.#callbacks.error.push(cb);
120
- }
121
-
122
- /** Close this listener */
123
- close() {
124
- if (this.#symbolListeners[this.#symbolKey].length <= 1) {
125
- quoteSession.send('quote_remove_symbols', [
126
- quoteSession.sessionID,
127
- this.#symbolKey,
128
- ]);
129
- }
130
- delete this.#symbolListeners[this.#symbolKey][this.#symbolListenerID];
131
- }
132
- };
@@ -1,125 +0,0 @@
1
- const { genSessionID } = require('../utils');
2
-
3
- const quoteMarketConstructor = require('./market');
4
-
5
- /** @typedef {Object<string, Function[]>} SymbolListeners */
6
-
7
- /**
8
- * @typedef {Object} QuoteSessionBridge
9
- * @prop {string} sessionID
10
- * @prop {SymbolListeners} symbolListeners
11
- * @prop {import('../client').SendPacket} send
12
- */
13
-
14
- /**
15
- * @typedef {'base-currency-logoid'
16
- * | 'ch' | 'chp' | 'currency-logoid' | 'provider_id'
17
- * | 'currency_code' | 'current_session' | 'description'
18
- * | 'exchange' | 'format' | 'fractional' | 'is_tradable'
19
- * | 'language' | 'local_description' | 'logoid' | 'lp'
20
- * | 'lp_time' | 'minmov' | 'minmove2' | 'original_name'
21
- * | 'pricescale' | 'pro_name' | 'short_name' | 'type'
22
- * | 'update_mode' | 'volume' | 'ask' | 'bid' | 'fundamentals'
23
- * | 'high_price' | 'low_price' | 'open_price' | 'prev_close_price'
24
- * | 'rch' | 'rchp' | 'rtc' | 'rtc_time' | 'status' | 'industry'
25
- * | 'basic_eps_net_income' | 'beta_1_year' | 'market_cap_basic'
26
- * | 'earnings_per_share_basic_ttm' | 'price_earnings_ttm'
27
- * | 'sector' | 'dividends_yield' | 'timezone' | 'country_code'
28
- * } quoteField Quote data field
29
- */
30
-
31
- /** @param {'all' | 'price'} fieldsType */
32
- function getQuoteFields(fieldsType) {
33
- if (fieldsType === 'price') {
34
- return ['lp'];
35
- }
36
-
37
- return [
38
- 'base-currency-logoid', 'ch', 'chp', 'currency-logoid',
39
- 'currency_code', 'current_session', 'description',
40
- 'exchange', 'format', 'fractional', 'is_tradable',
41
- 'language', 'local_description', 'logoid', 'lp',
42
- 'lp_time', 'minmov', 'minmove2', 'original_name',
43
- 'pricescale', 'pro_name', 'short_name', 'type',
44
- 'update_mode', 'volume', 'ask', 'bid', 'fundamentals',
45
- 'high_price', 'low_price', 'open_price', 'prev_close_price',
46
- 'rch', 'rchp', 'rtc', 'rtc_time', 'status', 'industry',
47
- 'basic_eps_net_income', 'beta_1_year', 'market_cap_basic',
48
- 'earnings_per_share_basic_ttm', 'price_earnings_ttm',
49
- 'sector', 'dividends_yield', 'timezone', 'country_code',
50
- 'provider_id',
51
- ];
52
- }
53
-
54
- /**
55
- * @param {import('../client').ClientBridge} client
56
- */
57
- module.exports = (client) => class QuoteSession {
58
- #sessionID = genSessionID('qs');
59
-
60
- /** Parent client */
61
- #client = client;
62
-
63
- /** @type {SymbolListeners} */
64
- #symbolListeners = {};
65
-
66
- /**
67
- * @typedef {Object} quoteSessionOptions Quote Session options
68
- * @prop {'all' | 'price'} [fields] Asked quote fields
69
- * @prop {quoteField[]} [customFields] List of asked quote fields
70
- */
71
-
72
- /**
73
- * @param {quoteSessionOptions} options Quote settings options
74
- */
75
- constructor(options = {}) {
76
- this.#client.sessions[this.#sessionID] = {
77
- type: 'quote',
78
- onData: (packet) => {
79
- if (global.TW_DEBUG) console.log('§90§30§102 QUOTE SESSION §0 DATA', packet);
80
-
81
- if (packet.type === 'quote_completed') {
82
- const symbolKey = packet.data[1];
83
- if (!this.#symbolListeners[symbolKey]) {
84
- this.#client.send('quote_remove_symbols', [this.#sessionID, symbolKey]);
85
- return;
86
- }
87
- this.#symbolListeners[symbolKey].forEach((h) => h(packet));
88
- }
89
-
90
- if (packet.type === 'qsd') {
91
- const symbolKey = packet.data[1].n;
92
- if (!this.#symbolListeners[symbolKey]) {
93
- this.#client.send('quote_remove_symbols', [this.#sessionID, symbolKey]);
94
- return;
95
- }
96
- this.#symbolListeners[symbolKey].forEach((h) => h(packet));
97
- }
98
- },
99
- };
100
-
101
- const fields = (options.customFields && options.customFields.length > 0
102
- ? options.customFields
103
- : getQuoteFields(options.fields)
104
- );
105
-
106
- this.#client.send('quote_create_session', [this.#sessionID]);
107
- this.#client.send('quote_set_fields', [this.#sessionID, ...fields]);
108
- }
109
-
110
- /** @type {QuoteSessionBridge} */
111
- #quoteSession = {
112
- sessionID: this.#sessionID,
113
- symbolListeners: this.#symbolListeners,
114
- send: (t, p) => this.#client.send(t, p),
115
- };
116
-
117
- /** @constructor */
118
- Market = quoteMarketConstructor(this.#quoteSession);
119
-
120
- /** Delete the quote session */
121
- delete() {
122
- this.#client.send('quote_delete_session', [this.#sessionID]);
123
- delete this.#client.sessions[this.#sessionID];
124
- }
125
- };
package/src/types.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * @typedef {string} MarketSymbol Market symbol (like: 'BTCEUR' or 'KRAKEN:BTCEUR')
3
- */
4
-
5
- /**
6
- * @typedef {'Etc/UTC' | 'exchange'
7
- * | 'Pacific/Honolulu' | 'America/Juneau' | 'America/Los_Angeles'
8
- * | 'America/Phoenix' | 'America/Vancouver' | 'US/Mountain'
9
- * | 'America/El_Salvador' | 'America/Bogota' | 'America/Chicago'
10
- * | 'America/Lima' | 'America/Mexico_City' | 'America/Caracas'
11
- * | 'America/New_York' | 'America/Toronto' | 'America/Argentina/Buenos_Aires'
12
- * | 'America/Santiago' | 'America/Sao_Paulo' | 'Atlantic/Reykjavik'
13
- * | 'Europe/Dublin' | 'Africa/Lagos' | 'Europe/Lisbon' | 'Europe/London'
14
- * | 'Europe/Amsterdam' | 'Europe/Belgrade' | 'Europe/Berlin'
15
- * | 'Europe/Brussels' | 'Europe/Copenhagen' | 'Africa/Johannesburg'
16
- * | 'Africa/Cairo' | 'Europe/Luxembourg' | 'Europe/Madrid' | 'Europe/Malta'
17
- * | 'Europe/Oslo' | 'Europe/Paris' | 'Europe/Rome' | 'Europe/Stockholm'
18
- * | 'Europe/Warsaw' | 'Europe/Zurich' | 'Europe/Athens' | 'Asia/Bahrain'
19
- * | 'Europe/Helsinki' | 'Europe/Istanbul' | 'Asia/Jerusalem' | 'Asia/Kuwait'
20
- * | 'Europe/Moscow' | 'Asia/Qatar' | 'Europe/Riga' | 'Asia/Riyadh'
21
- * | 'Europe/Tallinn' | 'Europe/Vilnius' | 'Asia/Tehran' | 'Asia/Dubai'
22
- * | 'Asia/Muscat' | 'Asia/Ashkhabad' | 'Asia/Kolkata' | 'Asia/Almaty'
23
- * | 'Asia/Bangkok' | 'Asia/Jakarta' | 'Asia/Ho_Chi_Minh' | 'Asia/Chongqing'
24
- * | 'Asia/Hong_Kong' | 'Australia/Perth' | 'Asia/Shanghai' | 'Asia/Singapore'
25
- * | 'Asia/Taipei' | 'Asia/Seoul' | 'Asia/Tokyo' | 'Australia/Brisbane'
26
- * | 'Australia/Adelaide' | 'Australia/Sydney' | 'Pacific/Norfolk'
27
- * | 'Pacific/Auckland' | 'Pacific/Fakaofo' | 'Pacific/Chatham'} Timezone (Chart) timezone
28
- */
29
-
30
- /**
31
- * @typedef {'1' | '3' | '5' | '15' | '30'
32
- * | '45' | '60' | '120' | '180' | '240'
33
- * | '1D' | '1W' | '1M' | 'D' | 'W' | 'M'} TimeFrame
34
- */
35
-
36
- module.exports = {};
package/src/utils.js DELETED
@@ -1,20 +0,0 @@
1
- module.exports = {
2
- /**
3
- * Generates a session id
4
- * @function genSessionID
5
- * @param {String} type Session type
6
- * @returns {string}
7
- */
8
- genSessionID(type = 'xs') {
9
- let r = '';
10
- const c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
11
- for (let i = 0; i < 12; i += 1) r += c.charAt(Math.floor(Math.random() * c.length));
12
- return `${type}_${r}`;
13
- },
14
-
15
- genAuthCookies(sessionId = '', signature = '') {
16
- if (!sessionId) return '';
17
- if (!signature) return `sessionid=${sessionId}`;
18
- return `sessionid=${sessionId};sessionid_sign=${signature}`;
19
- },
20
- };
package/vite.config.js DELETED
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- test: {
3
- testTimeout: 10000,
4
- retry: 3,
5
- setupFiles: 'dotenv/config',
6
- },
7
- };