@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.
- package/README.md +112 -51
- package/dist/chart/chart-session.d.ts +114 -0
- package/dist/chart/chart-session.js +339 -0
- package/dist/chart/graphics.d.ts +129 -0
- package/dist/chart/graphics.js +153 -0
- package/dist/chart/index.d.ts +11 -0
- package/dist/chart/index.js +6 -0
- package/dist/chart/strategy.d.ts +113 -0
- package/dist/chart/strategy.js +78 -0
- package/dist/chart/study.d.ts +60 -0
- package/dist/chart/study.js +179 -0
- package/dist/chart/timeframes.d.ts +7 -0
- package/dist/chart/timeframes.js +22 -0
- package/dist/chart/types.d.ts +105 -0
- package/dist/chart/types.js +9 -0
- package/dist/client/client.d.ts +89 -0
- package/dist/client/client.js +254 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.js +2 -0
- package/dist/client/transport.d.ts +27 -0
- package/dist/client/transport.js +38 -0
- package/dist/data/candles.d.ts +40 -0
- package/dist/data/candles.js +101 -0
- package/dist/data/history.d.ts +61 -0
- package/dist/data/history.js +101 -0
- package/dist/data/index.d.ts +30 -0
- package/dist/data/index.js +16 -0
- package/dist/data/indicators.d.ts +54 -0
- package/dist/data/indicators.js +139 -0
- package/dist/data/operation.d.ts +71 -0
- package/dist/data/operation.js +205 -0
- package/dist/data/provider.d.ts +23 -0
- package/dist/data/provider.js +11 -0
- package/dist/data/quotes.d.ts +33 -0
- package/dist/data/quotes.js +117 -0
- package/dist/data/symbols.d.ts +9 -0
- package/dist/data/symbols.js +19 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.js +24 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.js +70 -0
- package/dist/http/account.d.ts +47 -0
- package/dist/http/account.js +127 -0
- package/dist/http/index.d.ts +11 -0
- package/dist/http/index.js +5 -0
- package/dist/http/indicators.d.ts +37 -0
- package/dist/http/indicators.js +144 -0
- package/dist/http/layouts.d.ts +36 -0
- package/dist/http/layouts.js +24 -0
- package/dist/http/market.d.ts +45 -0
- package/dist/http/market.js +59 -0
- package/dist/http/pine-permissions.d.ts +29 -0
- package/dist/http/pine-permissions.js +56 -0
- package/dist/http/request.d.ts +44 -0
- package/dist/http/request.js +83 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +19 -0
- package/dist/indicators/builtin-indicator.d.ts +17 -0
- package/dist/indicators/builtin-indicator.js +75 -0
- package/dist/indicators/index.d.ts +8 -0
- package/dist/indicators/index.js +2 -0
- package/dist/indicators/pine-indicator.d.ts +63 -0
- package/dist/indicators/pine-indicator.js +101 -0
- package/dist/protocol/compression.d.ts +12 -0
- package/dist/protocol/compression.js +83 -0
- package/dist/protocol/framing.d.ts +59 -0
- package/dist/protocol/framing.js +68 -0
- package/dist/protocol/ids.d.ts +2 -0
- package/dist/protocol/ids.js +10 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +3 -0
- package/dist/quote/fields.d.ts +35 -0
- package/dist/quote/fields.js +21 -0
- package/dist/quote/index.d.ts +4 -0
- package/dist/quote/index.js +2 -0
- package/dist/quote/quote-session.d.ts +73 -0
- package/dist/quote/quote-session.js +205 -0
- package/docs/README.es.md +58 -0
- package/docs/README.fr.md +58 -0
- package/docs/README.pt.md +58 -0
- package/docs/data-api.md +285 -0
- package/docs/low-level-api.md +213 -0
- package/docs/migration-v4.md +128 -0
- package/docs/release-4.0.0-beta.1.md +39 -0
- package/docs/v4-coverage.md +213 -0
- package/package.json +53 -20
- package/.env.sample +0 -2
- package/.eslintrc.js +0 -28
- package/.gitattributes +0 -2
- package/docs/DOCS.md +0 -3
- package/examples/AllPrivateIndicators.js +0 -44
- package/examples/BuiltInIndicator.js +0 -51
- package/examples/CustomChartType.js +0 -123
- package/examples/CustomTimeframe.js +0 -31
- package/examples/Errors.js +0 -155
- package/examples/FakeReplayMode.js +0 -40
- package/examples/FromToData.js +0 -35
- package/examples/GetDrawings.js +0 -27
- package/examples/GraphicIndicator.js +0 -42
- package/examples/MultipleSyncFetch.js +0 -44
- package/examples/PinePermManage.js +0 -67
- package/examples/ReplayMode.js +0 -103
- package/examples/Search.js +0 -14
- package/examples/SimpleChart.js +0 -63
- package/examples/UserLogin.js +0 -16
- package/main.js +0 -11
- package/src/chart/graphicParser.js +0 -308
- package/src/chart/session.js +0 -553
- package/src/chart/study.js +0 -435
- package/src/classes/BuiltInIndicator.js +0 -137
- package/src/classes/PineIndicator.js +0 -132
- package/src/classes/PinePermManager.js +0 -159
- package/src/client.js +0 -298
- package/src/miscRequests.js +0 -609
- package/src/protocol.js +0 -60
- package/src/quote/market.js +0 -132
- package/src/quote/session.js +0 -125
- package/src/types.js +0 -36
- package/src/utils.js +0 -20
- package/vite.config.js +0 -7
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# v4 coverage matrix
|
|
2
|
+
|
|
3
|
+
[Migration guide](migration-v4.md) · [Data API](data-api.md) · [Low-level API](low-level-api.md)
|
|
4
|
+
|
|
5
|
+
This matrix lists every capability of v3 (`main.js`, `src/`, examples, tests) and of the `agent.ts` preview, with its v4 replacement and the evidence that it works.
|
|
6
|
+
|
|
7
|
+
**Evidence columns**
|
|
8
|
+
|
|
9
|
+
- **Unit**: deterministic test in `tests/unit/` (`npm test` with Vitest on Node, `npm run test:bun` with Bun's runner; 115 tests, both green). Websocket tests use a scripted fake server (`tests/helpers/fake-server.ts`) or packets captured from TradingView (`tests/fixtures/live-session.json`); HTTP tests use a mocked `fetch`.
|
|
10
|
+
- **Live**: result of `npm run test:live` (`tests/live/`) and examples against TradingView on **2 October 2026**: 16 anonymous tests locally and 21 tests (including five authenticated) in the [manual GitHub Actions run](https://github.com/Mathieu2301/TradingView-API/actions/runs/37075296707):
|
|
11
|
+
- ✅ verified live anonymously;
|
|
12
|
+
- 🔒 path or variant not exercised live (often requires a specific account asset); deterministic tests only;
|
|
13
|
+
- ➖ not applicable (no network involved).
|
|
14
|
+
|
|
15
|
+
Test names are abbreviated as `file › test`.
|
|
16
|
+
|
|
17
|
+
## Package and tooling
|
|
18
|
+
|
|
19
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
20
|
+
| --- | --- | --- | --- |
|
|
21
|
+
| CommonJS entry `require('@mathieuc/tradingview')` (`main.js`) | ESM entry `@mathieuc/tradingview` with `.d.ts`; `require()` works on Node ≥ 20.19/22.12 (require(esm)) | `exports › root entry...`; `scripts/smoke.mjs` (packs the tarball, imports under Node and Bun, `require()` check, strict TS consumer without `@types/node`) | ➖ |
|
|
22
|
+
| `agent.js` / `agent.d.ts` preview entry | `@mathieuc/tradingview/data` subpath | `exports › data entry only exposes...`; smoke test | ➖ |
|
|
23
|
+
| JSDoc types (`src/types.js`: `Timezone`, `TimeFrame`, `MarketSymbol`) | TypeScript types `Timezone`, `Timeframe`, `MarketSymbol` (`src/chart/types.ts`) | `npm run typecheck`; smoke consumer | ➖ |
|
|
24
|
+
| `build:agent`, `lint:agent`, `prepack` scripts | `build`, `typecheck`, `lint`, `test`, `test:bun`, `test:live`, `smoke`, `check`, `prepack` | CI workflow | ➖ |
|
|
25
|
+
| CI: Node 14/18/19 live tests on every push + nightly; agent job | CI: typecheck, lint, unit tests (Vitest), build and smoke on Node 20/22/24; unit tests with Bun's test runner and smoke on Bun; live tests only nightly/manual, non-blocking | `.github/workflows/tests.yml` | ➖ |
|
|
26
|
+
| `docs/DOCS.md` (pointer to JSDoc) | `docs/data-api.md`, `docs/low-level-api.md`, `docs/migration-v4.md`, this matrix | n/a | ➖ |
|
|
27
|
+
|
|
28
|
+
## Protocol and transport
|
|
29
|
+
|
|
30
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
31
|
+
| --- | --- | --- | --- |
|
|
32
|
+
| `protocol.parseWSPacket` (frame split, heartbeat as number, invalid JSON warning) | `protocol.decodeFrames` (length-based, UTF-16 lengths, typed frames, lenient fallback, invalid frames reported) | `protocol › decodes several frames...`, `keeps payloads containing frame markers intact`, `reports invalid JSON...`, `falls back to splitting malformed input`, `decodes every message of a captured live session` | ✅ (fixture captured live; UTF-16 lengths checked on Japanese/Korean descriptions) |
|
|
33
|
+
| `protocol.formatWSPacket` | `protocol.encodeFrame`, `encodePacket`, `encodeHeartbeat` | `protocol › encodes packets with UTF-16 lengths` | ✅ |
|
|
34
|
+
| `protocol.parseCompressed` (ZIP via jszip, base64 normalisation, zlib/raw/gzip fallbacks) | `protocol.decodeCompressed` (built-in ZIP reader: stored, deflated, data descriptors, empty entry names; zlib, raw deflate, gzip, plain JSON) and `normaliseBase64`, `readFirstZipEntry` | `protocol › compressed payloads › *` (ZIP fixtures generated independently with Python `zipfile`) | ✅ private compressed browser capture replayed through compiled parser (3 October 2026); plain report verified |
|
|
35
|
+
| `utils.genSessionID` | `protocol.createSessionId` (crypto-random) | `protocol › ids` | ➖ |
|
|
36
|
+
| `utils.genAuthCookies` | Internal cookie builder used by every HTTP call | `http › * with credentials` (cookie headers asserted) | ➖ |
|
|
37
|
+
| Websocket URL `wss://<server>.tradingview.com/socket.io/websocket?from=chart&type=chart`, Origin and browser headers | Same, in `TradingViewClient`; transport is pluggable (`transport` option, default `ws`) | `client › connects with browser-like headers...` | ✅ Node and Bun (Bun needed the Origin header fix) |
|
|
38
|
+
| Heartbeat (`~h~`) echo, `onPing` | Automatic echo, `heartbeat` event | `client › answers heartbeats...` | ✅ |
|
|
39
|
+
| `protocol_error` → error + close | `PROTOCOL_ERROR` error + close | `client › turns protocol_error into an error event and closes` | ✅ (observed during probes) |
|
|
40
|
+
| Send queue until open and authenticated; `sendQueue()` | Automatic queue and flush | `client › connects ... then flushes queued packets` | ✅ |
|
|
41
|
+
| Packet routing to sessions by ID | Same (`registerSession`) | `client › routes packets to registered sessions`, `routes a captured live session...` | ✅ |
|
|
42
|
+
| `global.TW_DEBUG` / `DEBUG` option | Per-client `debug: true | (...args) => void` | `client › logs traffic through a debug function` | ✅ |
|
|
43
|
+
|
|
44
|
+
## Client, authentication and events
|
|
45
|
+
|
|
46
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| `new Client()` anonymous (`unauthorized_user_token`) | `new TradingViewClient()` | `client › connects with ... an anonymous token` | ✅ |
|
|
49
|
+
| `token` + `signature` options → `getUser` → `set_auth_token` | `credentials: { session, signature }` (and new `authToken`) | `client › loads the auth token from credentials...`, `uses an explicit auth token` | ✅ (`authenticated › gets the account`, `opens an authenticated connection`) |
|
|
50
|
+
| `location` option | `location` | `client › loads the auth token...` (asserts the regional URL) | 🔒 |
|
|
51
|
+
| `server` option (`data`, `prodata`, `widgetdata`) | `server` | `client › connects with browser-like headers...` (`prodata` URL) | ✅ `data`; 🔒 `prodata` |
|
|
52
|
+
| `headers` option | `headers` | `client › connects with browser-like headers...` | ✅ |
|
|
53
|
+
| Credentials error reported through `onError` | `AUTH_ERROR` (rejects `ready`, `error` event, connection closed, cause passed to sessions) | `client › fails, emits AUTH_ERROR...`, `rejects ready without logging...` | ✅ (fake cookie rejected live in `examples/errors.js`) |
|
|
54
|
+
| `onConnected`, `onDisconnected`, `onLogged`, `onPing`, `onData`, `onError`, `onEvent` | `open`, `close`, `ready`/`hello`, `heartbeat`, `packet`, `error` events and `onAny` | `client › answers heartbeats and emits hello, heartbeat and unrouted packets`, `events › *` | ✅ |
|
|
55
|
+
| `isLogged`, `isOpen` | `isAuthenticated`, `isOpen`, `isClosed`, `serverInfo` | `client › connects ...` | ✅ |
|
|
56
|
+
| `client.send(t, p)` raw packets | `client.send(method, params)` | `client › accepts a raw frame string through send()` | ✅ |
|
|
57
|
+
| `client.end()` | `client.close()` (resolves when closed, idempotent, sessions released silently) | `client › close() is idempotent...`, `chart › intentional close` | ✅ |
|
|
58
|
+
| Disconnection handling | `DISCONNECTED` to charts, studies, quote subscriptions and pending calls | `client › notifies sessions...`, `chart › reports DISCONNECTED...`, `quote › reports DISCONNECTED...`, `data › rejects with DISCONNECTED...` | ➖ (simulated) |
|
|
59
|
+
| (new) Connection timeout | `connectTimeoutMs`, `TIMEOUT` | `client › times out if the connection never opens` | ➖ |
|
|
60
|
+
|
|
61
|
+
## Charts
|
|
62
|
+
|
|
63
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
64
|
+
| --- | --- | --- | --- |
|
|
65
|
+
| `new client.Session.Chart()` / `chart_create_session` | `client.createChart()` | `chart › creates a session, resolves the symbol...` | ✅ |
|
|
66
|
+
| `setMarket(symbol, { timeframe, range })` | `setMarket(symbol, { timeframe, count })` | `chart › creates a session...`; `data › getCandles › *` | ✅ |
|
|
67
|
+
| Candles `chart.periods` (newest first, `max`/`min`) | `chart.candles` (oldest first, `high`/`low`), `lastCandle` | `chart › creates a session...`, `parses a captured live chart session` | ✅ |
|
|
68
|
+
| `to` reference (`['bar_count', to, range]`) | `to` option; `getCandles({ to })` | `chart › encodes market options...`, `data › loads a from/to range...` | ✅ recent past reference with account (`authenticated › uses an account timeframe...`); older history remains server-limited |
|
|
69
|
+
| Negative `range` (bars after `to`), "fake replay" | Negative `count` + `fetchMore(-n)` | `chart › encodes market options...` | ✅ (`sessions › loads bars after a past reference...`, `examples/fake-replay.js`) |
|
|
70
|
+
| `fetchMore(n)` / deep history | `chart.fetchMore(n)`; automatic batching in `getCandles` (`count` or `from`), stops on `data_completed` | `chart › fetches more history...`, `data › loads deep history in batches...`, `stops when the server has no more history` | ✅ (3 000 hourly and 6 600 hourly bars; anonymous cap observed as `data_completed: "limit"`) |
|
|
71
|
+
| (new) From/to date ranges | `getCandles({ from, to, maxCount })` | `data › loads a from/to range...` | ✅ (`from` anonymously, recent past `to` with account) |
|
|
72
|
+
| `adjustment` (`splits`/`dividends`) | `adjustment` | `chart › encodes market options...` | ✅ default; ➖ dividends |
|
|
73
|
+
| `backadjustment` | `backAdjustment` | `chart › encodes market options...`, `data › passes chart options...` | ➖ (encoding only) |
|
|
74
|
+
| `session` (`regular`/`extended`) | `session` | same | ➖ (encoding only) |
|
|
75
|
+
| `currency` (`currency-id`) | `currency` | same | ➖ (encoding only) |
|
|
76
|
+
| Custom chart types: HeikinAshi, Renko, LineBreak, Kagi, PointAndFigure, Range + `inputs` | `type` + `inputs`; `getCandles({ chartType, chartInputs })` | `chart › encodes market options...`, `modifies the series...` | ✅ all six (`data › gets custom chart types`, `examples/custom-chart-types.js`) |
|
|
77
|
+
| `setSeries(timeframe)` | `setTimeframe(timeframe)` | `chart › modifies the series on later setMarket/setTimeframe calls...` | ✅ (D → 15) |
|
|
78
|
+
| `setSeries` before market → error | `INVALID_STATE` thrown | `chart › modifies the series...` | ✅ (`examples/errors.js`) |
|
|
79
|
+
| `setTimezone(tz)` | `setTimezone(tz)`; `getCandles({ timezone })` | `chart › fetches more history and switches timezone` | ✅ |
|
|
80
|
+
| Custom timeframes (`1S`, `20`...) | Any `Timeframe` string | `data › passes chart options...` | ✅ account timeframe `240`; 🔒 `1S`/`20` not exercised |
|
|
81
|
+
| `onSymbolLoaded`, `chart.infos` | `symbolLoaded` event, `symbolInfo`; `getSymbolInfo()` | `chart › creates a session...`, `data › getSymbolInfo` | ✅ |
|
|
82
|
+
| `onUpdate(changes)` | `update` event | `chart › creates a session...` | ✅ |
|
|
83
|
+
| (new) `series_loading` / `series_completed` | `seriesLoading`, `seriesCompleted` (`dataCompleted: end|limit`) | `chart › fetches more history...` | ✅ |
|
|
84
|
+
| `symbol_error`, `series_error`, `critical_error` → `onError` | `SYMBOL_ERROR`, `SERIES_ERROR`, `CRITICAL_ERROR` | `chart › emits typed errors...` | ✅ (`sessions › reports server errors as typed errors`) |
|
|
85
|
+
| `delete()` | `delete()` (idempotent; also deletes the replay session) | `chart › rejects pending replay requests when deleted...` | ✅ |
|
|
86
|
+
|
|
87
|
+
## Replay
|
|
88
|
+
|
|
89
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
90
|
+
| --- | --- | --- | --- |
|
|
91
|
+
| `setMarket(symbol, { replay })` (replay session, add series, reset) | Same option | `chart › runs replay mode...` | ✅ |
|
|
92
|
+
| `replayStep(n)`, `replayStart(interval)`, `replayStop()` resolved by `replay_ok` | Same; reject with `INVALID_STATE` outside replay and on delete | `chart › runs replay mode...`, `rejects pending replay requests...` | ✅ step (`sessions › replays history step by step`); ✅ start/stop acknowledgments and advancing bars on Basic (3 October 2026) |
|
|
93
|
+
| `onReplayLoaded`, `onReplayPoint`, `onReplayResolution`, `onReplayEnd` | `replayLoaded`, `replayPoint`, `replayResolution`, `replayEnd` events | `chart › runs replay mode...` | ✅ |
|
|
94
|
+
| Replay `critical_error` | `CRITICAL_ERROR` on the chart; pending replay requests rejected | (code path shared with chart errors) | ➖ |
|
|
95
|
+
|
|
96
|
+
## Studies, indicators and strategies
|
|
97
|
+
|
|
98
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
99
|
+
| --- | --- | --- | --- |
|
|
100
|
+
| `new chart.Study(indicator)` with instance check | `chart.createStudy(indicator)` (`INVALID_ARGUMENT` otherwise) | `study › creates a Pine study...`, `modifies and removes a study` | ✅ built-in and public Pine RSI with account |
|
|
101
|
+
| Pine inputs serialisation (`text`, `pineId`, `pineVersion`, `{ v, f, t }`, colours by index) | `PineIndicator.toStudyInputs()` | `indicators › serialises inputs for create_study...` | ✅ public Pine RSI inputs; colour variant unit-tested |
|
|
102
|
+
| `study.periods` with plot names, `plot_N` fallback for unnamed/duplicate plots | `study.values` (oldest first) | `study › creates a Pine study, names plots...`, `chart › parses a captured live chart session` | ✅ (built-in volume rows) |
|
|
103
|
+
| `study.graphic` (labels, lines, boxes, tables + cells, polygons, horizLines, horizHists, raw) and `graphicsCmds` erase/create | `study.graphics` (`cells` array, `raw` object) | `study › reads graphics commands...`, `applies erase commands` | ✅ horizontal histograms (volume profile); 🔒 Pine drawings |
|
|
104
|
+
| Bars-back translation of graphic X indexes | Same | `study › reads graphics commands...` | ✅ |
|
|
105
|
+
| `study.strategyReport` (plain `data.report` and compressed `dataCompressed`; trades, performance, history, currency, settings) | Same | `study › decodes plain and compressed strategy reports`, `reports undecodable strategy reports as PARSE_ERROR` | ✅ Supertrend strategy report with account; compressed variant also validated using a private browser capture |
|
|
106
|
+
| `study.setIndicator()` (`modify_study`) | Same | `study › modifies and removes a study` | 🔒 |
|
|
107
|
+
| `study.remove()` | Same (idempotent) | same | ✅ |
|
|
108
|
+
| `onReady`, `onUpdate`, `onError`, `study_error` | `ready`, `loading`, `update`, `error` (`STUDY_ERROR`, message formatted with server context) | `study › formats study errors with their context` | ✅ (anonymous Pine refusal reported as `STUDY_ERROR`) |
|
|
109
|
+
| `PineIndicator` getters (`pineId`, `pineVersion`, description, inputs, plots, script, type) and `setType` | `id`, `version`, same others; `setType`, `clone` | `indicators › clones independently...` | ✅ (`sessions › loads Pine indicator definitions`) |
|
|
110
|
+
| `PineIndicator.setOption` (by `in_N`, number, inline name, internal ID; type and option checks) | `setInput`, `setInputs`, `findInput` | `indicators › finds inputs by ID...` | ✅ (definition-level) |
|
|
111
|
+
| `BuiltInIndicator(type)`, defaults for Volume and volume profiles, `setOption(key, value, FORCE)` | Same (+ initial options; time defaults computed per instance instead of at import) | `indicators › BuiltInIndicator › *` | ✅ (`Volume`, `VbPFixed@tv-basicstudies-241!`) |
|
|
112
|
+
| `getIndicator(id, version, session, signature)` (pine-facade translate, input/plot naming) | `getIndicator(id, { version, credentials })`, `parseIndicatorDefinition` | `indicators › parseIndicatorDefinition...`, `http › loads an indicator definition...`, `throws NOT_FOUND...` | ✅ public scripts; 🔒 private/invite-only |
|
|
113
|
+
| (new) One-shot / streaming indicator values | `getIndicatorData`, `watchIndicator` | `data › indicator data › *` | ✅ built-in and one-shot Pine RSI with account; Pine stream unit-tested |
|
|
114
|
+
|
|
115
|
+
## Quotes
|
|
116
|
+
|
|
117
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
118
|
+
| --- | --- | --- | --- |
|
|
119
|
+
| `new client.Session.Quote({ fields: 'all' | 'price', customFields })` | `client.createQuoteSession({ fields: 'all' | 'price' | [...] })`; `setFields()` | `quote › quote fields`, `creates a session with fields...` | ✅ |
|
|
120
|
+
| `new quoteSession.Market(symbol, session)` | `quoteSession.subscribe(symbol, { session })` | `quote › creates a session...` | ✅ |
|
|
121
|
+
| Merged quote data, `onData`, `onLoaded`, `onEvent` | `data` (quote, changes), `loaded`, `onAny`; `subscription.data` | `quote › creates a session...` | ✅ (`sessions › streams quotes through a quote session`) |
|
|
122
|
+
| Quote symbol errors → `onError` | `QUOTE_ERROR` | `quote › reports symbol errors...` | ✅ |
|
|
123
|
+
| Removal of symbols nobody listens to | Same | `quote › reports symbol errors and removes symbols nobody listens to` | ➖ |
|
|
124
|
+
| `market.close()` (shared per symbol) | `subscription.close()` with correct reference counting (v3 never decreased its count) | `quote › shares one server subscription...` | ➖ |
|
|
125
|
+
| `quoteSession.delete()` | Same (idempotent) | same | ✅ |
|
|
126
|
+
| (new) One-shot and streaming quotes | `getQuote`, `getQuotes`, `watchQuotes` | `data › quotes › *` | ✅ |
|
|
127
|
+
|
|
128
|
+
## HTTP: search, technical analysis, accounts, layouts, permissions
|
|
129
|
+
|
|
130
|
+
| v3 capability | v4 | Unit evidence | Live |
|
|
131
|
+
| --- | --- | --- | --- |
|
|
132
|
+
| `searchMarketV3(text, filter, offset)` (exchange prefix split) | `searchMarkets(text, { type, offset, exchange })` | `http › queries symbol search v3...` | ✅ (`BINANCE:`, `nasdaq apple` → `NASDAQ:AAPL`) |
|
|
133
|
+
| `searchMarket(text, filter)` (deprecated v1 endpoint) | Replaced by `searchMarkets` (same results, maintained endpoint) | same | ✅ |
|
|
134
|
+
| `result.getTA()` | `getTechnicalAnalysis(result.id)` | `http › requests every period and scales ratings` | ✅ |
|
|
135
|
+
| `getTA(symbol)` (8 periods × All/MA/Other, scaled) | `getTechnicalAnalysis(symbol)` (`null` instead of `false` without data) | `http › getTechnicalAnalysis › *` | ✅ |
|
|
136
|
+
| `searchIndicator(text)` (built-in lists cached + community suggestions, access mapping) | `searchIndicators(text)`, `clearIndicatorCache()` | `http › searches built-in and community indicators` | ✅ |
|
|
137
|
+
| `result.get()` on indicator results | `getIndicator(result.id, { version: result.version })` | `http › loads an indicator definition...` | ✅ |
|
|
138
|
+
| `getPrivateIndicators(session, signature)` | `getPrivateIndicators(credentials)` | `http › lists private indicators with credentials` | ✅ authenticated listing endpoint; actual private item not available |
|
|
139
|
+
| `loginUser(username, password, remember, UA)` | `loginUser({ username, password, remember, userAgent })` (form now URL-encoded) | `http › loginUser posts an encoded form and reads cookies` | 🔒 |
|
|
140
|
+
| `getUser(session, signature, location)` with redirect-loop protection | `getUser(credentials, { location, maxRedirects })` (relative redirects resolved) | `http › getUser parses the account page...`, `getUser stops redirect loops...` | ✅ authenticated success and wrong-cookie rejection |
|
|
141
|
+
| `getChartToken(layout, credentials)` | `getChartToken(layoutId, { userId, credentials })` | `http › gets a chart token...` | 🔒 (needs a layout ID) |
|
|
142
|
+
| `getDrawings(layout, symbol, credentials, chartID)` | `getDrawings(layoutId, { symbol, chartId, userId, credentials })` | `http › lists drawings with merged state` | 🔒 |
|
|
143
|
+
| `PinePermManager(session, signature, pineId)`: `getUsers`, `addUser`, `modifyExpiration`, `removeUser` | `PinePermissionManager(pineId, { credentials })`, same methods | `http › PinePermissionManager › *` | 🔒 (needs an owned invite-only script) |
|
|
144
|
+
| 5xx responses throw; HTTP errors | `HTTP_ERROR` (also wraps network failures) | `http › throws HTTP_ERROR...`, `wraps network failures` | ➖ |
|
|
145
|
+
|
|
146
|
+
## High-level data API (agent preview)
|
|
147
|
+
|
|
148
|
+
| Preview capability | v4 | Unit evidence | Live |
|
|
149
|
+
| --- | --- | --- | --- |
|
|
150
|
+
| `fetchCandles({ symbol, timeframe, limit })`, oldest first, `high`/`low` | `getCandles({ symbol, timeframe, count })` (+ deep history, ranges, chart options) | `data › getCandles › *` | ✅ |
|
|
151
|
+
| `watchCandles(query, { onData, onError })`, `worker.latest`, idempotent `stop()` | Same names + `closed`, `isActive`, `symbolInfo` | `data › watchCandles › *` | ✅ |
|
|
152
|
+
| `timeoutMs` (15 s default), `AbortSignal` | Same, for every data function | `data › times out...`, `aborts in flight and before starting`, `stops on abort after start-up` | ✅ |
|
|
153
|
+
| Cleanup of chart and connection on success, failure, timeout, abort and disconnect | Same, plus shared `client` support | `data › returns ... and closes everything`, `shares a client without closing it`, `rejects when a provided client is already closed` | ✅ |
|
|
154
|
+
| Validation before connecting | Same (`INVALID_ARGUMENT`) | `data › rejects invalid queries before connecting` | ➖ |
|
|
155
|
+
| `MarketDataProvider` / `TradingViewProvider` injection | Same provider-neutral candle contract; `getCandles(query, provider)` and `watchCandles(query, handlers, provider)`, plus shared `client` and custom `clientOptions.transport` for TradingView | `data › accepts an alternate candle provider...`; other data tests use an injected transport | ➖ |
|
|
156
|
+
|
|
157
|
+
## Examples
|
|
158
|
+
|
|
159
|
+
| v3 example | v4 example |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| `SimpleChart.js` | `simple-chart.js` (✅ live) |
|
|
162
|
+
| `CustomChartType.js` | `custom-chart-types.js` (✅ live) |
|
|
163
|
+
| `CustomTimeframe.js` | `custom-timeframe.js` (🔒) |
|
|
164
|
+
| `Errors.js` | `errors.js` (✅ live for anonymous cases) |
|
|
165
|
+
| `FakeReplayMode.js` | `fake-replay.js` (✅ live) |
|
|
166
|
+
| `FromToData.js` | `from-to.js` (🔒) |
|
|
167
|
+
| `GetDrawings.js` | `drawings.js` (🔒) |
|
|
168
|
+
| `GraphicIndicator.js` | `graphic-indicator.js` (🔒) |
|
|
169
|
+
| `MultipleSyncFetch.js` | `multiple-indicators.js` (🔒) |
|
|
170
|
+
| `PinePermManage.js` | `pine-permissions.js` (🔒) |
|
|
171
|
+
| `ReplayMode.js` | `replay.js` (✅ live without Pine studies) |
|
|
172
|
+
| `Search.js` | `search.js` (✅ live) |
|
|
173
|
+
| `UserLogin.js` | `user-login.js` (🔒) |
|
|
174
|
+
| `AllPrivateIndicators.js` | `private-indicators.js` (🔒) |
|
|
175
|
+
| `BuiltInIndicator.js` | `builtin-indicator.js` (✅ live) |
|
|
176
|
+
| (new) | `candles.js` (✅), `watch-candles.js`, `quotes.js`, `indicator-data.js`, `quote-session.js` |
|
|
177
|
+
|
|
178
|
+
## Intentional changes
|
|
179
|
+
|
|
180
|
+
These v3 behaviours were changed on purpose; none removes a capability.
|
|
181
|
+
|
|
182
|
+
- Bars and study rows are oldest first; candles use `high`/`low`; volume is no longer rounded to two decimals.
|
|
183
|
+
- `setMarket('')` throws instead of silently loading `BTCEUR`; the default timeframe is `D` instead of `240`.
|
|
184
|
+
- `setTimezone` no longer clears loaded bars (the server does not resend them).
|
|
185
|
+
- Replay methods reject instead of never resolving outside replay mode.
|
|
186
|
+
- Errors are `TradingViewError` objects instead of string lists; unhandled `error` events are still printed, except connection failures that already reject `client.ready`.
|
|
187
|
+
- `searchMarket` (deprecated v1 endpoint) is folded into `searchMarkets`.
|
|
188
|
+
- `result.getTA()` / `result.get()` methods on search results became plain data plus `getTechnicalAnalysis()` / `getIndicator()`.
|
|
189
|
+
|
|
190
|
+
## Not verified live for this release
|
|
191
|
+
|
|
192
|
+
The 21-test manual live workflow verified authenticated connection, account lookup, a public Pine RSI, a Supertrend strategy report, the private-indicators listing endpoint, and recent historical `to` with an account. It did **not** verify password login, actual private/invite-only scripts, older history beyond server limits, second-based/custom timeframes, the `prodata` server, owned layouts/drawings, or Pine permission changes. Those paths have deterministic tests but need the corresponding account assets to verify live. Run `SESSION=... SIGNATURE=... npm run test:live` to repeat the authenticated subset.
|
|
193
|
+
|
|
194
|
+
## Basic account follow-up — 3 October 2026
|
|
195
|
+
|
|
196
|
+
A fresh authenticated library client loaded `BINANCE:BTCEUR` daily Replay at a
|
|
197
|
+
reference 30 days before the probe. Loading returned five bars; three step
|
|
198
|
+
requests were acknowledged; automatic playback produced advancing bar timestamps;
|
|
199
|
+
start and stop were both acknowledged. The client was closed after the bounded
|
|
200
|
+
probe. This verifies the library protocol for that symbol/timeframe/reference,
|
|
201
|
+
not intraday Replay, every exchange, unlimited history, or simulated order entry.
|
|
202
|
+
The existing browser chart and its settings were not changed.
|
|
203
|
+
|
|
204
|
+
`examples/strategy-report.js` was executed with the same Basic account against
|
|
205
|
+
the public Supertrend strategy on `BINANCE:BTCEUR`, timeframe `60`, count `300`.
|
|
206
|
+
It returned trade records, closed/open aggregate counts and PnL, and buy-and-hold
|
|
207
|
+
history. No private payloads or credentials are included in this repository.
|
|
208
|
+
The strategy may compute over more history than the requested candle count;
|
|
209
|
+
`count` is not an exact backtest-window guarantee.
|
|
210
|
+
|
|
211
|
+
UI CSV and XLSX exports remain plan-blocked (Essential offered), and Deep
|
|
212
|
+
Backtesting remains plan-blocked (Premium offered). The library report example
|
|
213
|
+
is not an implementation of those UI exports and does not enable Deep Backtesting.
|
package/package.json
CHANGED
|
@@ -1,44 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mathieuc/tradingview",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
|
+
"description": "TradingView market data for JavaScript and TypeScript: candles, quotes, indicators and strategies, with a simple data API and full low-level access.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./data": {
|
|
15
|
+
"types": "./dist/data/index.d.ts",
|
|
16
|
+
"import": "./dist/data/index.js",
|
|
17
|
+
"default": "./dist/data/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"docs"
|
|
25
|
+
],
|
|
26
|
+
"sideEffects": false,
|
|
6
27
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
28
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
29
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:bun": "bun test tests/unit",
|
|
33
|
+
"test:watch": "vitest",
|
|
34
|
+
"test:live": "vitest run --config vitest.live.config.ts",
|
|
35
|
+
"smoke": "node scripts/smoke.mjs",
|
|
36
|
+
"check": "npm run typecheck && npm run lint && npm test && npm run build && npm run smoke",
|
|
37
|
+
"prepack": "npm run build"
|
|
10
38
|
},
|
|
11
39
|
"repository": {
|
|
12
40
|
"type": "git",
|
|
13
41
|
"url": "git+https://github.com/Mathieu2301/TradingView-API.git"
|
|
14
42
|
},
|
|
15
43
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
44
|
+
"node": ">=20.0.0"
|
|
17
45
|
},
|
|
18
46
|
"keywords": [
|
|
19
|
-
"
|
|
20
|
-
"market",
|
|
47
|
+
"tradingview",
|
|
48
|
+
"market-data",
|
|
49
|
+
"candles",
|
|
50
|
+
"quotes",
|
|
21
51
|
"stocks",
|
|
22
52
|
"crypto",
|
|
23
53
|
"forex",
|
|
24
54
|
"indicator",
|
|
25
|
-
"
|
|
55
|
+
"pine",
|
|
56
|
+
"websocket",
|
|
26
57
|
"api"
|
|
27
58
|
],
|
|
28
59
|
"author": "Mathieu Colmon",
|
|
29
60
|
"license": "ISC",
|
|
30
61
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"jszip": "^3.7.1",
|
|
33
|
-
"ws": "^7.4.3"
|
|
62
|
+
"ws": "^8.18.0"
|
|
34
63
|
},
|
|
35
64
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"
|
|
41
|
-
"eslint
|
|
42
|
-
"vitest": "^
|
|
65
|
+
"@eslint/js": "^9.39.0",
|
|
66
|
+
"@types/node": "^22.20.5",
|
|
67
|
+
"@types/ws": "^8.18.1",
|
|
68
|
+
"eslint": "^9.39.0",
|
|
69
|
+
"typescript": "~5.9.3",
|
|
70
|
+
"typescript-eslint": "^8.46.0",
|
|
71
|
+
"vitest": "^3.2.4"
|
|
72
|
+
},
|
|
73
|
+
"homepage": "https://github.com/Mathieu2301/TradingView-API#readme",
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/Mathieu2301/TradingView-API/issues"
|
|
43
76
|
}
|
|
44
77
|
}
|
package/.env.sample
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
commonjs: true,
|
|
4
|
-
es2021: true,
|
|
5
|
-
node: true,
|
|
6
|
-
},
|
|
7
|
-
extends: [
|
|
8
|
-
'airbnb-base',
|
|
9
|
-
],
|
|
10
|
-
parser: '@babel/eslint-parser',
|
|
11
|
-
parserOptions: {
|
|
12
|
-
ecmaVersion: 12,
|
|
13
|
-
requireConfigFile: false,
|
|
14
|
-
},
|
|
15
|
-
rules: {
|
|
16
|
-
'no-console': 'off',
|
|
17
|
-
'import/no-extraneous-dependencies': [
|
|
18
|
-
'error',
|
|
19
|
-
{
|
|
20
|
-
devDependencies: ['./test.js', './tests/**'],
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
'no-restricted-syntax': 'off',
|
|
24
|
-
'no-await-in-loop': 'off',
|
|
25
|
-
'no-continue': 'off',
|
|
26
|
-
'guard-for-in': 'off',
|
|
27
|
-
},
|
|
28
|
-
};
|
package/.gitattributes
DELETED
package/docs/DOCS.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example creates a chart with all user's private indicators
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
8
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const client = new TradingView.Client({
|
|
12
|
-
token: process.env.SESSION,
|
|
13
|
-
signature: process.env.SIGNATURE,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const chart = new client.Session.Chart();
|
|
17
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
18
|
-
timeframe: 'D',
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
(async () => {
|
|
22
|
-
const indicList = await TradingView.getPrivateIndicators(process.argv[2]);
|
|
23
|
-
|
|
24
|
-
if (!indicList.length) {
|
|
25
|
-
console.error('Your account has no private indicators');
|
|
26
|
-
process.exit(0);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
for (const indic of indicList) {
|
|
30
|
-
const privateIndic = await indic.get();
|
|
31
|
-
console.log('Loading indicator', indic.name, '...');
|
|
32
|
-
|
|
33
|
-
const indicator = new chart.Study(privateIndic);
|
|
34
|
-
|
|
35
|
-
indicator.onReady(() => {
|
|
36
|
-
console.log('Indicator', indic.name, 'loaded !');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
indicator.onUpdate(() => {
|
|
40
|
-
console.log('Plot values', indicator.periods);
|
|
41
|
-
console.log('Strategy report', indicator.strategyReport);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
})();
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests built-in indicators like volume-based indicators
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const volumeProfile = new TradingView.BuiltInIndicator('VbPFixed@tv-basicstudies-241!');
|
|
8
|
-
|
|
9
|
-
const needAuth = ![
|
|
10
|
-
'VbPFixed@tv-basicstudies-241',
|
|
11
|
-
'VbPFixed@tv-basicstudies-241!',
|
|
12
|
-
'Volume@tv-basicstudies-241',
|
|
13
|
-
].includes(volumeProfile.type);
|
|
14
|
-
|
|
15
|
-
if (needAuth && (!process.env.SESSION || !process.env.SIGNATURE)) {
|
|
16
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const client = new TradingView.Client(
|
|
20
|
-
needAuth
|
|
21
|
-
? {
|
|
22
|
-
token: process.env.SESSION,
|
|
23
|
-
signature: process.env.SIGNATURE,
|
|
24
|
-
}
|
|
25
|
-
: {},
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const chart = new client.Session.Chart();
|
|
29
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
30
|
-
timeframe: '60',
|
|
31
|
-
range: 1,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
/* Required or not, depending on the indicator */
|
|
35
|
-
volumeProfile.setOption('first_bar_time', Date.now() - 10 ** 8);
|
|
36
|
-
// volumeProfile.setOption('first_visible_bar_time', Date.now() - 10 ** 8);
|
|
37
|
-
|
|
38
|
-
const VOL = new chart.Study(volumeProfile);
|
|
39
|
-
VOL.onUpdate(() => {
|
|
40
|
-
VOL.graphic.horizHists
|
|
41
|
-
.filter((h) => h.lastBarTime === 0) // We only keep recent volume infos
|
|
42
|
-
.sort((a, b) => b.priceHigh - a.priceHigh)
|
|
43
|
-
.forEach((h) => {
|
|
44
|
-
console.log(
|
|
45
|
-
`~ ${Math.round((h.priceHigh + h.priceLow) / 2)} € :`,
|
|
46
|
-
`${'_'.repeat(h.rate[0] / 3)}${'_'.repeat(h.rate[1] / 3)}`,
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
client.end();
|
|
51
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example creates charts of custom types such as 'HeikinAshi', 'Renko',
|
|
5
|
-
* 'LineBreak', 'Kagi', 'PointAndFigure', and 'Range' with default settings.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const client = new TradingView.Client({
|
|
9
|
-
/*
|
|
10
|
-
Token and signature are only required if you want to use
|
|
11
|
-
intraday timeframes (if you have a paid TradingView account)
|
|
12
|
-
*/
|
|
13
|
-
token: process.env.SESSION,
|
|
14
|
-
signature: process.env.SIGNATURE,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const chart = new client.Session.Chart();
|
|
18
|
-
|
|
19
|
-
chart.onError((...err) => {
|
|
20
|
-
console.log('Chart error:', ...err);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
chart.onUpdate(() => {
|
|
25
|
-
if (!chart.periods[0]) return;
|
|
26
|
-
console.log('Last period', chart.periods[0]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
/* (0s) Heikin Ashi chart */
|
|
30
|
-
setTimeout(() => {
|
|
31
|
-
console.log('\nSetting chart type to: HeikinAshi');
|
|
32
|
-
|
|
33
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
34
|
-
type: 'HeikinAshi',
|
|
35
|
-
timeframe: 'D',
|
|
36
|
-
});
|
|
37
|
-
}, 0);
|
|
38
|
-
|
|
39
|
-
/* (5s) Renko chart */
|
|
40
|
-
setTimeout(() => {
|
|
41
|
-
console.log('\nSetting chart type to: Renko');
|
|
42
|
-
|
|
43
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
44
|
-
type: 'Renko',
|
|
45
|
-
timeframe: 'D',
|
|
46
|
-
inputs: {
|
|
47
|
-
source: 'close',
|
|
48
|
-
sources: 'Close',
|
|
49
|
-
boxSize: 3,
|
|
50
|
-
style: 'ATR',
|
|
51
|
-
atrLength: 14,
|
|
52
|
-
wicks: true,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
}, 5000);
|
|
56
|
-
|
|
57
|
-
/* (10s) Line Break chart */
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
console.log('\nSetting chart type to: LineBreak');
|
|
60
|
-
|
|
61
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
62
|
-
type: 'LineBreak',
|
|
63
|
-
timeframe: 'D',
|
|
64
|
-
inputs: {
|
|
65
|
-
source: 'close',
|
|
66
|
-
lb: 3,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}, 10000);
|
|
70
|
-
|
|
71
|
-
/* (15s) Kagi chart */
|
|
72
|
-
setTimeout(() => {
|
|
73
|
-
console.log('\nSetting chart type to: Kagi');
|
|
74
|
-
|
|
75
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
76
|
-
type: 'Kagi',
|
|
77
|
-
timeframe: 'D',
|
|
78
|
-
inputs: {
|
|
79
|
-
source: 'close',
|
|
80
|
-
style: 'ATR',
|
|
81
|
-
atrLength: 14,
|
|
82
|
-
reversalAmount: 1,
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
}, 15000);
|
|
86
|
-
|
|
87
|
-
/* (20s) Point & Figure chart */
|
|
88
|
-
setTimeout(() => {
|
|
89
|
-
console.log('\nSetting chart type to: PointAndFigure');
|
|
90
|
-
|
|
91
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
92
|
-
type: 'PointAndFigure',
|
|
93
|
-
timeframe: 'D',
|
|
94
|
-
inputs: {
|
|
95
|
-
sources: 'Close',
|
|
96
|
-
reversalAmount: 3,
|
|
97
|
-
boxSize: 1,
|
|
98
|
-
style: 'ATR',
|
|
99
|
-
atrLength: 14,
|
|
100
|
-
oneStepBackBuilding: false,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
}, 20000);
|
|
104
|
-
|
|
105
|
-
/* (25s) Range chart */
|
|
106
|
-
setTimeout(() => {
|
|
107
|
-
console.log('\nSetting chart type to: Range');
|
|
108
|
-
|
|
109
|
-
chart.setMarket('BINANCE:BTCEUR', {
|
|
110
|
-
type: 'Range',
|
|
111
|
-
timeframe: 'D',
|
|
112
|
-
inputs: {
|
|
113
|
-
range: 1,
|
|
114
|
-
phantomBars: false,
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
}, 25000);
|
|
118
|
-
|
|
119
|
-
/* (30s) Delete chart, close client */
|
|
120
|
-
setTimeout(() => {
|
|
121
|
-
console.log('\nClosing client...');
|
|
122
|
-
client.end();
|
|
123
|
-
}, 30000);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const TradingView = require('../main');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This example tests custom timeframes like 1 second
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
if (!process.env.SESSION || !process.env.SIGNATURE) {
|
|
8
|
-
throw Error('Please set your sessionid and signature cookies');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const client = new TradingView.Client({
|
|
12
|
-
token: process.env.SESSION,
|
|
13
|
-
signature: process.env.SIGNATURE,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const chart = new client.Session.Chart();
|
|
17
|
-
chart.setTimezone('Europe/Paris');
|
|
18
|
-
|
|
19
|
-
chart.setMarket('CAPITALCOM:US100', {
|
|
20
|
-
timeframe: '1S',
|
|
21
|
-
range: 10,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
chart.onSymbolLoaded(() => {
|
|
25
|
-
console.log(chart.infos.name, 'loaded !');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
chart.onUpdate(() => {
|
|
29
|
-
console.log('OK', chart.periods);
|
|
30
|
-
client.end();
|
|
31
|
-
});
|