tradingview-gex-flashalpha 0.0.0-stage → 1.1.0
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/CHANGELOG.md +300 -0
- package/LICENSE +21 -0
- package/README.md +1076 -2
- package/dist/tradingview-gex-flashalpha.cjs +3664 -0
- package/dist/tradingview-gex-flashalpha.css +2 -0
- package/dist/tradingview-gex-flashalpha.js +3638 -0
- package/dist/tradingview-gex-flashalpha.min.js +52 -0
- package/dist/tradingview-gex-flashalpha.mjs +3643 -0
- package/embed.js +116 -0
- package/package.json +97 -4
- package/types/index.d.ts +458 -0
package/embed.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* FlashAlpha chart embed: one script tag and a div, no build step.
|
|
3
|
+
*
|
|
4
|
+
* <div data-flashalpha-chart data-symbol="SPX" style="height: 480px"></div>
|
|
5
|
+
* <script async src="https://<chart host>/embed.js" data-key="YOUR_FLASHALPHA_API_KEY"></script>
|
|
6
|
+
*
|
|
7
|
+
* The script loads lightweight-charts (exactly LW_VERSION, served by its own host) and
|
|
8
|
+
* flashalpha-chart-core.js (same host) once, then the optional layer
|
|
9
|
+
* bundle (flashalpha-chart-layers.js, same host) if the host serves one, then mounts every [data-flashalpha-chart]
|
|
10
|
+
* element on the page, reading the chart API on the host it was loaded from. Without the layer bundle the chart works
|
|
11
|
+
* as is with the core layers (levels, maxpain).
|
|
12
|
+
* Attributes (all optional except data-symbol):
|
|
13
|
+
* data-key FlashAlpha API key for this chart, sent as X-Api-Key (default: data-key on the script tag, the
|
|
14
|
+
* page-wide key). Anyone can read it in the page source.
|
|
15
|
+
* data-resolution 1m 5m 15m 1h 1d 1w (default 5m; GEX levels need 1m to 1h)
|
|
16
|
+
* data-range days back, or 1D 5D 1M 6M 1Y (default: per resolution, 5 days on 5m)
|
|
17
|
+
* data-theme dark (default) | light | auto (follows the reader's system setting)
|
|
18
|
+
* data-upgrade-url where the Upgrade button and locked layers link (default flashalpha.com pricing)
|
|
19
|
+
* data-layers comma list, e.g. "levels,maxpain" (default: none, price and volume only; ids from the layer bundle work when it is loaded;
|
|
20
|
+
* the reader's picks are remembered in localStorage and win over it)
|
|
21
|
+
* data-session rth | eth
|
|
22
|
+
* data-controls "false" hides the toolbar
|
|
23
|
+
* data-background CSS colour of the chart background
|
|
24
|
+
* data-refresh seconds between refreshes (default 60, 0 = off)
|
|
25
|
+
* data-metric a per-minute metric column drawn in its own pane (intraday resolutions; needs the layer bundle)
|
|
26
|
+
* data-brand "false" keeps the TradingView logo instead of the FlashAlpha one
|
|
27
|
+
* data-base chart API root, when it is not the host of this script
|
|
28
|
+
* On the <script> tag itself: data-key (the key for every chart on the page), data-layer-bundle="false" skips the layer
|
|
29
|
+
* bundle, data-debug="true" shows load status in the toolbar.
|
|
30
|
+
* The plan of the key decides the layers: layers above it show a lock and an Upgrade link (the API sends the plan).
|
|
31
|
+
* Pages that add charts later (single-page apps) call FlashAlphaEmbed.scan().
|
|
32
|
+
* The core and the bundle are requested with ?v=VERSION, so a new deploy is not hidden by a cached copy: bump VERSION
|
|
33
|
+
* whenever either file changes.
|
|
34
|
+
* lightweight-charts: the host serves dist/vendor/lightweight-charts-<LW_VERSION>.standalone.production.js from this
|
|
35
|
+
* repository's build. To upgrade, change the devDependency, run npm install, set LW_VERSION, and run npm run check
|
|
36
|
+
* (test/lightweight-charts.test.js mounts the chart on the new version and fails until every pin matches).
|
|
37
|
+
*/
|
|
38
|
+
(function () {
|
|
39
|
+
'use strict';
|
|
40
|
+
if (window.FlashAlphaEmbed) { window.FlashAlphaEmbed.scan(); return; }
|
|
41
|
+
|
|
42
|
+
var VERSION = '1.1.0';
|
|
43
|
+
// The tested lightweight-charts, from the chart host (no CDN), like the core. No SRI hash: an integrity check needs a
|
|
44
|
+
// CORS (crossorigin) request, and the host's static files are served without Access-Control-Allow-Origin.
|
|
45
|
+
var LW_VERSION = '5.3.0';
|
|
46
|
+
var RANGES = { '1D': 1, '5D': 5, '1M': 31, '6M': 183, '1Y': 366 };
|
|
47
|
+
var me = document.currentScript;
|
|
48
|
+
var host = me ? me.src.replace(/\/[^\/]*(\?.*)?$/, '') : '';
|
|
49
|
+
var LW_URL = host + '/lightweight-charts-' + LW_VERSION + '.standalone.production.js';
|
|
50
|
+
var withLayers = !(me && me.getAttribute('data-layer-bundle') === 'false');
|
|
51
|
+
var pageKey = me ? me.getAttribute('data-key') : null;
|
|
52
|
+
var debug = !!(me && me.getAttribute('data-debug') === 'true');
|
|
53
|
+
|
|
54
|
+
function script(src, integrity) {
|
|
55
|
+
return new Promise(function (resolve, reject) {
|
|
56
|
+
var s = document.createElement('script');
|
|
57
|
+
s.src = src; s.async = true;
|
|
58
|
+
if (integrity) { s.integrity = integrity; s.crossOrigin = 'anonymous'; }
|
|
59
|
+
s.onload = resolve;
|
|
60
|
+
s.onerror = function () { reject(new Error('could not load ' + src)); };
|
|
61
|
+
document.head.appendChild(s);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The layer bundle registers its layers with FlashAlphaChart.registerLayers, so it loads after the core and before
|
|
66
|
+
// the first mount. A host without it (404) or a blocked request just leaves the core layers.
|
|
67
|
+
// A lightweight-charts the page already has is used only when it is LW_VERSION. Otherwise the pinned copy is loaded and
|
|
68
|
+
// handed to the charts (options.lightweightCharts); the page's own window.LightweightCharts is put back for its charts.
|
|
69
|
+
var lw = null;
|
|
70
|
+
function loadLightweightCharts() {
|
|
71
|
+
var pageLw = window.LightweightCharts;
|
|
72
|
+
var same = pageLw && typeof pageLw.version === 'function' && pageLw.version() === LW_VERSION;
|
|
73
|
+
if (same) { lw = pageLw; return Promise.resolve(); }
|
|
74
|
+
return script(LW_URL).then(function () {
|
|
75
|
+
lw = window.LightweightCharts;
|
|
76
|
+
if (pageLw) window.LightweightCharts = pageLw;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
var ready = loadLightweightCharts()
|
|
80
|
+
.then(function () { return window.FlashAlphaChart ? null : script(host + '/flashalpha-chart-core.js?v=' + VERSION); })
|
|
81
|
+
.then(function () {
|
|
82
|
+
if (!withLayers) return null;
|
|
83
|
+
return script(host + '/flashalpha-chart-layers.js?v=' + VERSION).catch(function () { return null; });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
function options(el) {
|
|
87
|
+
var d = el.dataset, o = { symbol: (d.symbol || '').toUpperCase() || null, apiKey: d.key || pageKey || null, baseUrl: d.base || host,
|
|
88
|
+
resolution: d.resolution || '5m', symbolButtons: false, debug: debug, lightweightCharts: lw };
|
|
89
|
+
if (d.range) { var days = RANGES[d.range.toUpperCase()] || +d.range; if (days > 0) o.days = days; }
|
|
90
|
+
if (d.theme) o.theme = d.theme;
|
|
91
|
+
if (d.upgradeUrl) o.upgradeUrl = d.upgradeUrl;
|
|
92
|
+
if (d.layers) o.layers = d.layers.split(',').map(function (x) { return x.trim(); }).filter(Boolean);
|
|
93
|
+
if (d.session) o.session = d.session;
|
|
94
|
+
if (d.controls === 'false') o.controls = false;
|
|
95
|
+
if (d.background) o.background = d.background;
|
|
96
|
+
if (d.refresh != null) o.refresh = +d.refresh;
|
|
97
|
+
if (d.metric) o.metric = d.metric;
|
|
98
|
+
if (d.brand !== 'false') o.brand = { logo: host + '/flashalpha-logo.png', href: 'https://flashalpha.com', name: 'FlashAlpha' };
|
|
99
|
+
return o;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function scan() {
|
|
103
|
+
return ready.then(function () {
|
|
104
|
+
var els = document.querySelectorAll('[data-flashalpha-chart]');
|
|
105
|
+
for (var i = 0; i < els.length; i++) {
|
|
106
|
+
var el = els[i];
|
|
107
|
+
if (el.__flashalphaChart) continue;
|
|
108
|
+
if (!el.clientHeight) el.style.height = '460px';
|
|
109
|
+
el.__flashalphaChart = window.FlashAlphaChart.mount(el, options(el));
|
|
110
|
+
}
|
|
111
|
+
}).catch(function (e) { if (window.console) console.error('[flashalpha-chart]', e); });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
window.FlashAlphaEmbed = { scan: scan };
|
|
115
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', scan); else scan();
|
|
116
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,99 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tradingview-gex-flashalpha",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "TradingView-style candlestick chart with options gamma exposure (GEX) levels: call wall, put wall, gamma flip, max pain, plus FlashAlpha indicators such as net GEX, the strike heatmap and the GEX profile. Built on TradingView Lightweight Charts, data from the FlashAlpha API.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"options",
|
|
7
|
+
"gamma-exposure",
|
|
8
|
+
"gex",
|
|
9
|
+
"dealer-positioning",
|
|
10
|
+
"call-wall",
|
|
11
|
+
"put-wall",
|
|
12
|
+
"gamma-flip",
|
|
13
|
+
"max-pain",
|
|
14
|
+
"candlestick-chart",
|
|
15
|
+
"lightweight-charts",
|
|
16
|
+
"embeddable-chart",
|
|
17
|
+
"stock-chart",
|
|
18
|
+
"trading",
|
|
19
|
+
"gex-chart",
|
|
20
|
+
"options-chart",
|
|
21
|
+
"options-analytics",
|
|
22
|
+
"charting-library",
|
|
23
|
+
"gamma-exposure-chart",
|
|
24
|
+
"dealer-gamma",
|
|
25
|
+
"tradingview",
|
|
26
|
+
"javascript-chart",
|
|
27
|
+
"0dte",
|
|
28
|
+
"tradingview-gex",
|
|
29
|
+
"flashalpha",
|
|
30
|
+
"flashalpha-api",
|
|
31
|
+
"net-gex",
|
|
32
|
+
"gex-heatmap"
|
|
33
|
+
],
|
|
34
|
+
"homepage": "https://flashalpha-lab.github.io/tradingview-gex-flashalpha/",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/FlashAlpha-lab/tradingview-gex-flashalpha.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/FlashAlpha-lab/tradingview-gex-flashalpha/issues"
|
|
41
|
+
},
|
|
42
|
+
"author": "FlashAlpha (https://flashalpha.com)",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"type": "module",
|
|
45
|
+
"main": "./dist/tradingview-gex-flashalpha.cjs",
|
|
46
|
+
"module": "./dist/tradingview-gex-flashalpha.mjs",
|
|
47
|
+
"types": "./types/index.d.ts",
|
|
48
|
+
"unpkg": "./dist/tradingview-gex-flashalpha.min.js",
|
|
49
|
+
"jsdelivr": "./dist/tradingview-gex-flashalpha.min.js",
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"types": "./types/index.d.ts",
|
|
53
|
+
"import": "./dist/tradingview-gex-flashalpha.mjs",
|
|
54
|
+
"require": "./dist/tradingview-gex-flashalpha.cjs"
|
|
55
|
+
},
|
|
56
|
+
"./style.css": "./dist/tradingview-gex-flashalpha.css",
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"dist",
|
|
61
|
+
"!dist/vendor",
|
|
62
|
+
"types",
|
|
63
|
+
"embed.js",
|
|
64
|
+
"README.md",
|
|
65
|
+
"CHANGELOG.md",
|
|
66
|
+
"LICENSE"
|
|
67
|
+
],
|
|
68
|
+
"sideEffects": [
|
|
69
|
+
"*.css",
|
|
70
|
+
"./dist/tradingview-gex-flashalpha.js",
|
|
71
|
+
"./dist/tradingview-gex-flashalpha.min.js"
|
|
72
|
+
],
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"lightweight-charts": "^5.0.0"
|
|
75
|
+
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=18"
|
|
78
|
+
},
|
|
79
|
+
"publishConfig": {
|
|
80
|
+
"access": "public",
|
|
81
|
+
"provenance": true
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "node scripts/build.mjs",
|
|
85
|
+
"test": "node --test test/*.test.js",
|
|
86
|
+
"lint:source": "node scripts/check-source.mjs",
|
|
87
|
+
"lint:types": "tsc --noEmit --strict --lib es2020,dom --module esnext --moduleResolution bundler types/index.d.ts test/types-usage.ts",
|
|
88
|
+
"check": "npm run lint:source && npm run lint:types && npm run build && npm test && npm pack --dry-run",
|
|
89
|
+
"prepublishOnly": "npm run check"
|
|
90
|
+
},
|
|
91
|
+
"devDependencies": {
|
|
92
|
+
"acorn": "^8.19.0",
|
|
93
|
+
"esbuild": "^0.28.2",
|
|
94
|
+
"jsdom": "^26.1.0",
|
|
95
|
+
"lightningcss": "^1.33.0",
|
|
96
|
+
"lightweight-charts": "5.3.0",
|
|
97
|
+
"typescript": "^5.9.3"
|
|
98
|
+
}
|
|
99
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import type { IChartApi, ISeriesApi } from 'lightweight-charts';
|
|
2
|
+
|
|
3
|
+
/** Bar resolutions. Gamma exposure levels are drawn on the intraday ones (`1m` to `1h`). */
|
|
4
|
+
export type Resolution = '1m' | '5m' | '15m' | '1h' | '1d' | '1w';
|
|
5
|
+
|
|
6
|
+
/** `rth` regular hours, `eth` with pre-market and after-hours. */
|
|
7
|
+
export type Session = 'rth' | 'eth';
|
|
8
|
+
|
|
9
|
+
/** `auto` follows the reader's `prefers-color-scheme`. */
|
|
10
|
+
export type Theme = 'dark' | 'light' | 'auto';
|
|
11
|
+
|
|
12
|
+
/** FlashAlpha plans, lowest first. */
|
|
13
|
+
export type Plan = 'free' | 'basic' | 'growth' | 'alpha' | 'enterprise';
|
|
14
|
+
|
|
15
|
+
/** The lightweight-charts 5 module (`import * as LightweightCharts from 'lightweight-charts'`). */
|
|
16
|
+
export type LightweightChartsModule = typeof import('lightweight-charts');
|
|
17
|
+
|
|
18
|
+
/** One OHLCV bar. Times are UTC ISO 8601 strings. */
|
|
19
|
+
export interface Bar {
|
|
20
|
+
ts: string;
|
|
21
|
+
open: number | null;
|
|
22
|
+
high: number | null;
|
|
23
|
+
low: number | null;
|
|
24
|
+
close: number | null;
|
|
25
|
+
volume?: number | null;
|
|
26
|
+
/**
|
|
27
|
+
* Where the bar comes from; `spot` marks candles built from exposure rows, `quotes` a bar built from quote mids (drawn
|
|
28
|
+
* muted, without volume, unless the symbol's `asset_class` is `index`).
|
|
29
|
+
*/
|
|
30
|
+
source?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Gamma exposure levels at one time. A `null` level is drawn as a gap. */
|
|
34
|
+
export interface ExposureRow {
|
|
35
|
+
ts: string;
|
|
36
|
+
call_wall?: number | null;
|
|
37
|
+
put_wall?: number | null;
|
|
38
|
+
/** Which walls the API sent: `oi` (most call / put open interest on each side of spot) or `gex` (gamma walls). */
|
|
39
|
+
walls?: 'oi' | 'gex' | null;
|
|
40
|
+
max_pain?: number | null;
|
|
41
|
+
/** A `status` other than `available` draws the flip in grey. */
|
|
42
|
+
gamma_flip?: { last: number | null; status?: string } | null;
|
|
43
|
+
/** Spot in the bucket: the chart draws muted candles from it after the last stored bar. */
|
|
44
|
+
spot?: { first: number | null; min: number | null; max: number | null; last: number | null } | null;
|
|
45
|
+
[column: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** An exposure row on a bar, as layer plugins see it (`ctx.exposure`). */
|
|
49
|
+
export interface ChartExposureRow extends ExposureRow {
|
|
50
|
+
/** The bar's chart time: ET wall-clock seconds written as UTC. */
|
|
51
|
+
time: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A session's close levels (`levels_daily`): drawn dashed over the next session. `ts` is the session date. */
|
|
55
|
+
export interface DailyLevelsRow {
|
|
56
|
+
ts: string;
|
|
57
|
+
call_wall?: number | null;
|
|
58
|
+
put_wall?: number | null;
|
|
59
|
+
/** As in `ExposureRow`. */
|
|
60
|
+
walls?: 'oi' | 'gex' | null;
|
|
61
|
+
gamma_flip?: number | null;
|
|
62
|
+
gamma_flip_status?: string | null;
|
|
63
|
+
max_pain?: number | null;
|
|
64
|
+
/** A status other than `ok` leaves a gap. */
|
|
65
|
+
status?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The `charts()` answer. */
|
|
69
|
+
export interface ChartsResponse {
|
|
70
|
+
exposure?: ExposureRow[];
|
|
71
|
+
levels_daily?: DailyLevelsRow[];
|
|
72
|
+
/** Per API layer: data, or `{ status: 'gated' }` when the plan does not include it. */
|
|
73
|
+
layers?: Record<string, { status?: string; [k: string]: unknown }>;
|
|
74
|
+
/** The key's plan: layers above it are locked. */
|
|
75
|
+
plan?: Plan | string | null;
|
|
76
|
+
/** An error code or message; the chart shows it instead of an empty chart. */
|
|
77
|
+
error?: string;
|
|
78
|
+
[k: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The `charts()` query: the API layers to read, the session, and parameters set by plugins (`ctx.setQuery`). */
|
|
82
|
+
export interface ChartsQuery {
|
|
83
|
+
layers: string[];
|
|
84
|
+
session: Session;
|
|
85
|
+
[param: string]: unknown;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
89
|
+
|
|
90
|
+
/** Where the chart reads its data. `chartEngineSource()` reads the FlashAlpha chart API; any backend with the same shapes works. */
|
|
91
|
+
export interface DataSource {
|
|
92
|
+
symbols(): MaybePromise<Array<{ symbol: string; last_bar?: string | null; first_bar?: string | null; asset_class?: string | null }>>;
|
|
93
|
+
/** `extra.sessions` (1D/5D intraday): the window is that many trading sessions ending at `toIso`; `fromIso` is an approximation. */
|
|
94
|
+
bars(symbol: string, resolution: Resolution, fromIso: string, toIso: string, session: Session, extra?: { sessions?: number }): MaybePromise<{ bars?: Bar[]; error?: string; message?: string }>;
|
|
95
|
+
charts(symbol: string, resolution: Resolution, fromIso: string, toIso: string, query: ChartsQuery): MaybePromise<ChartsResponse>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Your logo instead of the TradingView logo on the chart, with a "Charts by TradingView" link under the chart. */
|
|
99
|
+
export interface Brand {
|
|
100
|
+
logo: string;
|
|
101
|
+
href: string;
|
|
102
|
+
name?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface MountOptions {
|
|
106
|
+
/** Ticker. Default: the first symbol with data. */
|
|
107
|
+
symbol?: string | null;
|
|
108
|
+
/** Default `5m`. */
|
|
109
|
+
resolution?: Resolution;
|
|
110
|
+
/** Days to show; each resolution has a maximum. Default: per resolution. */
|
|
111
|
+
days?: number | null;
|
|
112
|
+
/** Default `rth`. */
|
|
113
|
+
session?: Session;
|
|
114
|
+
/**
|
|
115
|
+
* Layer ids: `levels`, `maxpain`, and ids of registered layer plugins. Default: none (price and volume only). The layers
|
|
116
|
+
* the reader picked last time (see `storage`) win over this.
|
|
117
|
+
*/
|
|
118
|
+
layers?: string[];
|
|
119
|
+
/** `false` does not remember the reader's layers in localStorage. Default `true`. */
|
|
120
|
+
storage?: boolean;
|
|
121
|
+
/** The localStorage key of the remembered layers, to keep charts apart. Default `'tradingview-gex-flashalpha:layers'`. */
|
|
122
|
+
storageKey?: string;
|
|
123
|
+
/** `true` shows the Upgrade box over the chart while a layer that is on needs a higher plan. Default `false` (hidden for now). */
|
|
124
|
+
upsell?: boolean;
|
|
125
|
+
/** `false` hides the toolbar (and the Layout menu: one chart). */
|
|
126
|
+
controls?: boolean;
|
|
127
|
+
/** The Layout menu next to Settings: one to four charts. `false` mounts one chart. Default `true`. */
|
|
128
|
+
layouts?: boolean;
|
|
129
|
+
/** The layout the chart opens with; the reader's last pick (remembered) wins. Default `'1'`. */
|
|
130
|
+
layout?: LayoutId;
|
|
131
|
+
/** `false` hides the symbol dropdown (with its search box). */
|
|
132
|
+
symbolButtons?: boolean;
|
|
133
|
+
/** `false` draws candles only. */
|
|
134
|
+
exposure?: boolean;
|
|
135
|
+
/** Your own data. Default: the FlashAlpha chart API at `baseUrl`. */
|
|
136
|
+
source?: DataSource | null;
|
|
137
|
+
/** Chart API root. Default: same origin. */
|
|
138
|
+
baseUrl?: string;
|
|
139
|
+
/** FlashAlpha API key, sent as `X-Api-Key`. Default: the `setLicenseKey` value. */
|
|
140
|
+
apiKey?: string | null;
|
|
141
|
+
/** Seconds between refreshes while the page is visible; `0` turns refresh off. Default 60. */
|
|
142
|
+
refresh?: number;
|
|
143
|
+
/**
|
|
144
|
+
* `true` draws 1m to 1h candles and levels live from the chart API's WebSocket (`/v1/live`), with the FlashAlpha chart
|
|
145
|
+
* API as the source; while it is connected the refresh runs every 5 minutes. Default `false`.
|
|
146
|
+
*/
|
|
147
|
+
live?: boolean;
|
|
148
|
+
/** Default `dark`. */
|
|
149
|
+
theme?: Theme;
|
|
150
|
+
/**
|
|
151
|
+
* Background colour. Default: per theme (CSS variable `--fac-bg`). A dark colour goes with the dark theme, a light one
|
|
152
|
+
* with the light theme (the other theme keeps its own); a colour that is not hex or rgb() goes with both.
|
|
153
|
+
*/
|
|
154
|
+
background?: string | null;
|
|
155
|
+
/** Where locked layers and the Upgrade box link. Default: FlashAlpha pricing. */
|
|
156
|
+
upgradeUrl?: string;
|
|
157
|
+
/** `false` hides the toolbar's account button: "Sign up" without a plan, the plan's name with one. Default `true`. */
|
|
158
|
+
account?: boolean;
|
|
159
|
+
/** Where the toolbar's "Sign up" button and the signed-out "Sign up free" box link. Default: FlashAlpha pricing. */
|
|
160
|
+
signupUrl?: string;
|
|
161
|
+
/** Shows load status in the toolbar; `'latency'` also the live lag (p50/p95, receive minus the newest print). */
|
|
162
|
+
debug?: boolean | 'latency';
|
|
163
|
+
/** The line under the chart next to the credit; `''` hides it. Default: the model-estimate note. */
|
|
164
|
+
note?: string;
|
|
165
|
+
brand?: Brand | null;
|
|
166
|
+
/** The lightweight-charts module, when you import it instead of loading the script. Default: `window.LightweightCharts`. */
|
|
167
|
+
lightweightCharts?: LightweightChartsModule;
|
|
168
|
+
/** `false` does not add the chart's `<style>` to the page; load `tradingview-gex-flashalpha/style.css` yourself. Default `true`. */
|
|
169
|
+
injectCss?: boolean;
|
|
170
|
+
/** Plot styles by plot id, over the plugins' defaults, e.g. `{ callWall: { color: '#00c853', lineWidth: 2 } }`. */
|
|
171
|
+
styles?: Record<string, Partial<PlotStyle>> | null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** How a plot (an indicator line) is drawn; its layer's options (Style tab) change it. */
|
|
175
|
+
export interface PlotStyle {
|
|
176
|
+
color: string;
|
|
177
|
+
lineWidth: 1 | 2 | 3 | 4 | number;
|
|
178
|
+
lineStyle: 'solid' | 'dotted' | 'dashed';
|
|
179
|
+
visible: boolean;
|
|
180
|
+
/** The dotted line at the latest value. */
|
|
181
|
+
priceLine: boolean;
|
|
182
|
+
/** The label on the price scale. */
|
|
183
|
+
axisLabel: boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** A line a layer plugin draws, listed in its indicator's Style tab. Defaults: width 1, solid, visible, price line, label. */
|
|
187
|
+
export interface PlotDef extends Partial<PlotStyle> {
|
|
188
|
+
id: string;
|
|
189
|
+
title: string;
|
|
190
|
+
/** The layer id the plot belongs to. */
|
|
191
|
+
layer?: string;
|
|
192
|
+
/** Its colour (a `toggle` may have none: a switch only). */
|
|
193
|
+
color?: string;
|
|
194
|
+
/** Only a colour in the Style tab (a colour the plugin uses, not a series of its own). */
|
|
195
|
+
colorOnly?: boolean;
|
|
196
|
+
/** Only a switch and a colour in the Style tab (something the plugin shows or not, e.g. markers; no line of its own). */
|
|
197
|
+
toggle?: boolean;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** A key-level item in the legend: label, value, the previous session's value, and a CSS class (`up`, `dn`). */
|
|
201
|
+
export interface LegendLevel {
|
|
202
|
+
label: string;
|
|
203
|
+
/** A number (with its change against `prev`), or a string shown as it is. */
|
|
204
|
+
value: number | string | null | undefined;
|
|
205
|
+
prev?: number | null;
|
|
206
|
+
cls?: string;
|
|
207
|
+
/** Writes a number and its change (default: two decimals), e.g. a compact 1.08B for net GEX. */
|
|
208
|
+
format?: (value: number) => string;
|
|
209
|
+
/** The plot it reads: the value takes the plot's colour, and the part is left out while the plot is hidden. */
|
|
210
|
+
plot?: string;
|
|
211
|
+
/** The layer it belongs to (default: its plot's): left out while that layer's values are off the status line. */
|
|
212
|
+
layer?: string;
|
|
213
|
+
/** A colour for the value, over the plot's. */
|
|
214
|
+
color?: string;
|
|
215
|
+
/** Shown in brackets after the value, e.g. `'broken'` → "Put wall 730.00 (broken)". */
|
|
216
|
+
note?: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** A colour scale in an indicator's legend line: `from`, a gradient through `ramp`, `to`; `title` shows on hover. */
|
|
220
|
+
export interface LegendRamp {
|
|
221
|
+
ramp: string[];
|
|
222
|
+
from?: string;
|
|
223
|
+
to?: string;
|
|
224
|
+
title?: string;
|
|
225
|
+
/** The layer it belongs to: left out while that layer's values are off the status line. */
|
|
226
|
+
layer?: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** An ⓘ in an indicator's legend line: `info` shows on hover or click. */
|
|
230
|
+
export interface LegendInfo {
|
|
231
|
+
info: string;
|
|
232
|
+
/** What it is about, for screen readers: the button reads "About <about>" (default "About"). */
|
|
233
|
+
about?: string;
|
|
234
|
+
/** The layer it belongs to: left out while that layer's values are off the status line. */
|
|
235
|
+
layer?: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A note in an indicator's legend line; `title` shows on hover. */
|
|
239
|
+
export interface LegendNote {
|
|
240
|
+
text: string;
|
|
241
|
+
title?: string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** A layout of the Layout menu: 1 to 4 charts. */
|
|
245
|
+
export type LayoutId = '1' | '2v' | '2h' | '3v' | '3h' | '3l' | '3r' | '3t' | '3b' | '4' | '4h' | '4v' | '4l' | '4r' | '4t' | '4b'
|
|
246
|
+
| '4lc' | '4rc' | '4tr';
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* What `mount` returns: the chart in focus's methods, plus the layout (one to four charts). `setSymbol`, `setTheme`,
|
|
250
|
+
* `reload` and `destroy` act on every chart. With `layouts: false`, one chart without the layout members.
|
|
251
|
+
*/
|
|
252
|
+
export interface ChartInstance {
|
|
253
|
+
setLayout?(id: LayoutId): void;
|
|
254
|
+
readonly layout?: LayoutId;
|
|
255
|
+
/** Every chart's methods, in layout order. */
|
|
256
|
+
readonly charts?: ChartInstance[];
|
|
257
|
+
/** The position of the chart in focus, from 0. */
|
|
258
|
+
readonly active?: number;
|
|
259
|
+
focus?(index: number): void;
|
|
260
|
+
readonly symbol: string | null;
|
|
261
|
+
readonly resolution: Resolution;
|
|
262
|
+
/** Days back from now. */
|
|
263
|
+
readonly range: number;
|
|
264
|
+
readonly session: Session;
|
|
265
|
+
setSymbol(symbol: string): Promise<void>;
|
|
266
|
+
setResolution(resolution: Resolution): Promise<void>;
|
|
267
|
+
/** Days back from now, capped per resolution. */
|
|
268
|
+
setRange(days: number): Promise<void>;
|
|
269
|
+
setSession(session: Session): Promise<void>;
|
|
270
|
+
setLayers(layers: string[]): Promise<void>;
|
|
271
|
+
setTheme(theme: Theme): void;
|
|
272
|
+
/** The key's plan from the last answer, or `null` before it or without auth. */
|
|
273
|
+
readonly plan: Plan | string | null;
|
|
274
|
+
readonly layers: string[];
|
|
275
|
+
/** Every plot's style by plot id (a copy). */
|
|
276
|
+
readonly styles: Record<string, PlotStyle>;
|
|
277
|
+
/** Changes a plot's style, as a layer's options do. */
|
|
278
|
+
setStyle(plotId: string, style: Partial<PlotStyle>): void;
|
|
279
|
+
reload(): Promise<void>;
|
|
280
|
+
destroy(): void;
|
|
281
|
+
/** The lightweight-charts instance, for your own series. */
|
|
282
|
+
readonly chart: IChartApi;
|
|
283
|
+
/** Methods added by layer plugins (`handle.methods`). */
|
|
284
|
+
[method: string]: unknown;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Helpers for layer plugins. */
|
|
288
|
+
export interface PluginUtil {
|
|
289
|
+
/** UTC ISO time → chart time (ET wall-clock seconds written as UTC). */
|
|
290
|
+
etTime(iso: string): number;
|
|
291
|
+
/** The ET date (`yyyy-mm-dd`) of a chart time. */
|
|
292
|
+
dayOf(time: number): string;
|
|
293
|
+
sessionOf(time: number): 'pre' | 'rth' | 'post';
|
|
294
|
+
/** Index of the last element of sorted `times` that is <= `t`, or -1. */
|
|
295
|
+
floorIndex(times: number[], t: number): number;
|
|
296
|
+
/** Escapes text for HTML. */
|
|
297
|
+
esc(value: unknown): string;
|
|
298
|
+
num(value: number | null | undefined, digits?: number): string;
|
|
299
|
+
/** 1.5B, 2.3M, 1.5K. */
|
|
300
|
+
big(value: number | null | undefined): string;
|
|
301
|
+
/**
|
|
302
|
+
* The points with each whitespace point kept a gap: Lightweight Charts 5 joins the points either side of it, so the
|
|
303
|
+
* point before the gap is made transparent (line and fill). `type`: the series type (default `'line'`).
|
|
304
|
+
*/
|
|
305
|
+
cutGaps<T extends { time: number; value?: number }>(points: T[], type?: 'line' | 'area' | 'baseline'): T[];
|
|
306
|
+
RES_SECONDS: Record<Resolution, number>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** What a layer plugin's `attach` receives, once per chart. */
|
|
310
|
+
export interface PluginContext {
|
|
311
|
+
LW: LightweightChartsModule;
|
|
312
|
+
chart: IChartApi;
|
|
313
|
+
/** The chart's root element (`.fac`). */
|
|
314
|
+
root: HTMLElement;
|
|
315
|
+
options: MountOptions;
|
|
316
|
+
colors: Record<'up' | 'down' | 'spotUp' | 'spotDown' | 'flip' | 'unverified' | 'maxpain', string>;
|
|
317
|
+
/** A level line: steps through the day and a dotted line at its latest value. */
|
|
318
|
+
/**
|
|
319
|
+
* With `plotId`, the line follows that plot's style (see `bindPlot`). `short`: its title on the price scale where the
|
|
320
|
+
* full one does not fit (phones, a plugin drawing at the pane's right edge), e.g. `'CW'`; without it, no title there.
|
|
321
|
+
*/
|
|
322
|
+
level(color: string, title: string, plotId?: string, short?: string): ISeriesApi<'Line'>;
|
|
323
|
+
/** Ties a series to one of the plugin's plots (`plots`): its layer's options restyle it. Returns the series. */
|
|
324
|
+
bindPlot<S extends ISeriesApi<any>>(plotId: string, series: S): S;
|
|
325
|
+
/** A plot's current style. */
|
|
326
|
+
styleOf(plotId: string): PlotStyle;
|
|
327
|
+
intraday(): boolean;
|
|
328
|
+
/** True when the layer is picked, the plan includes it and it is not hidden with the legend's 👁 (in apiLayers: not hidden ignored). */
|
|
329
|
+
on(layer: string): boolean;
|
|
330
|
+
/** True when the layer is on but hidden with the legend's 👁: not drawn (e.g. keep its pane, empty). */
|
|
331
|
+
hidden(layer: string): boolean;
|
|
332
|
+
/** True when the last answer gave API layer `apiLayer` as status "gated" (the key's plan does not include it). */
|
|
333
|
+
gated(apiLayer: string): boolean;
|
|
334
|
+
/** True when the key's plan is below `plan`. */
|
|
335
|
+
lockedPlan(plan: Plan | string): boolean;
|
|
336
|
+
/** The upgrade link, tagged with utm parameters. */
|
|
337
|
+
upgradeHref(what?: string): string;
|
|
338
|
+
readonly plan: Plan | string | null;
|
|
339
|
+
readonly candles: ISeriesApi<'Candlestick'> | null;
|
|
340
|
+
/** The drawn bars, each with its chart `time`. */
|
|
341
|
+
readonly bars: Array<Bar & { time: number }>;
|
|
342
|
+
/** The exposure rows of the last load on bar times. */
|
|
343
|
+
readonly exposure: ChartExposureRow[];
|
|
344
|
+
readonly symbol: string | null;
|
|
345
|
+
readonly resolution: Resolution;
|
|
346
|
+
readonly query: Record<string, unknown>;
|
|
347
|
+
/** Merged into the `charts()` request, then reloads; called from `attach` it only sets the first request. */
|
|
348
|
+
setQuery(params: Record<string, unknown>): Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* Adds a control: into an indicator's options (Inputs tab of each of its layers) under `el.title` (default), or the toolbar. The indicator is
|
|
351
|
+
* the plugin's own, or the one named by `indicator`. False when the toolbar is hidden.
|
|
352
|
+
*/
|
|
353
|
+
addControl(el: HTMLElement, where?: 'panel' | 'toolbar', indicator?: string): boolean;
|
|
354
|
+
/** A note in the legend when no exposure row is under the crosshair. */
|
|
355
|
+
note(text: string): void;
|
|
356
|
+
/**
|
|
357
|
+
* Keeps `px` free at the right edge of the price pane for what the plugin draws there (0 gives it back): room right of
|
|
358
|
+
* the latest bar, the level lines without their titles (axis labels stay), the edge labels left of it.
|
|
359
|
+
*/
|
|
360
|
+
reserveRight(px: number): void;
|
|
361
|
+
/** The width `reserveRight` keeps free (0 for none). */
|
|
362
|
+
readonly reservedRight: number;
|
|
363
|
+
/** Draws again from the last answer, no request: every plugin's draw(), then the legend. */
|
|
364
|
+
redraw(): void;
|
|
365
|
+
util: PluginUtil;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** What `attach` returns. Every member is optional. */
|
|
369
|
+
export interface PluginHandle {
|
|
370
|
+
/** Once, after the candles exist (series added here are drawn over them). */
|
|
371
|
+
ready?(): void;
|
|
372
|
+
/** After every load, with the `charts()` answer. */
|
|
373
|
+
draw?(response: ChartsResponse): void;
|
|
374
|
+
/** When a load failed. */
|
|
375
|
+
clear?(): void;
|
|
376
|
+
/**
|
|
377
|
+
* Lines for the legend at `time`. `{ gated: name }` names an indicator whose data the key's plan does not include: the
|
|
378
|
+
* legend puts every such name on one "Not in your plan" line with the Upgrade (or Sign up) link.
|
|
379
|
+
*/
|
|
380
|
+
legend?(time: number, y: number | null): Array<string | { gated: string } | null> | string | { gated: string } | null | undefined;
|
|
381
|
+
crosshair?(time: number | null, y: number | null): void;
|
|
382
|
+
destroy?(): void;
|
|
383
|
+
/**
|
|
384
|
+
* Parts of an indicator's line in the legend (after spot on the core one); insert or append in place. `{ label, value, prev, cls }`
|
|
385
|
+
* reads like a key level (change against `prev`); `{ text, title }` is a note with a tooltip; a string is text. `prev`:
|
|
386
|
+
* the previous session's last row, or null.
|
|
387
|
+
* Called once per indicator of the plugin that is on, at every bar; `indicator` is its name. At a bar without an
|
|
388
|
+
* exposure row `row` is `{ time }` and `prev` null. `at`: the bar and the crosshair's y in the price pane (null off the
|
|
389
|
+
* chart), for a part that follows the pointer. The line is one line: its parts never wrap.
|
|
390
|
+
*/
|
|
391
|
+
legendLevels?(row: ChartExposureRow | { time: number }, parts: Array<LegendLevel | LegendNote | LegendRamp | LegendInfo | string>, prev: ChartExposureRow | null, indicator: string, at: { time: number | null; y: number | null }): void;
|
|
392
|
+
/** The series of a pane of its own the indicator draws in: its legend line goes to the top left of that pane. */
|
|
393
|
+
paneOf?(indicator: string): ISeriesApi<any> | null;
|
|
394
|
+
/** Lines for panes that are no indicator of their own, at the top left of each `series`'s pane. */
|
|
395
|
+
paneLegends?(time: number): Array<{ series: ISeriesApi<any>; name: string; parts?: Array<LegendLevel | LegendNote | string>;
|
|
396
|
+
/** The indicator whose options the line's options button opens. */
|
|
397
|
+
indicator?: string;
|
|
398
|
+
/** Called by the line's remove button. */
|
|
399
|
+
remove?(): void }>;
|
|
400
|
+
/** Added to the object `mount` returns; core names win. */
|
|
401
|
+
methods?: Record<string, (...args: any[]) => unknown>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export interface LayerPlugin {
|
|
405
|
+
/** The indicator (Indicators menu group) the layers belong to; plugins with the same name share one. Default: `name`, else the first layer's label. */
|
|
406
|
+
indicator?: string;
|
|
407
|
+
/** An indicator per layer id, over `indicator`: one plugin can fill several indicators, e.g. `{ heatmap: 'Strike heatmap' }`. */
|
|
408
|
+
indicators?: Record<string, string>;
|
|
409
|
+
name?: string;
|
|
410
|
+
/** Lines the plugin draws, listed in the indicator's Style tab; tie each series with `ctx.bindPlot`. */
|
|
411
|
+
plots?: PlotDef[];
|
|
412
|
+
/** `[id, menu label]` pairs. */
|
|
413
|
+
layers: Array<[string, string]>;
|
|
414
|
+
/** @deprecated Not used: an indicator's switch turns all its layers on, or all off. */
|
|
415
|
+
defaults?: string[];
|
|
416
|
+
/** The lowest plan per layer id; a layer without one is never locked. */
|
|
417
|
+
plans?: Record<string, Plan>;
|
|
418
|
+
/** The API layers to request for the enabled ids. */
|
|
419
|
+
apiLayers?(ctx: PluginContext): string[];
|
|
420
|
+
/** Once per chart, before the candle series exists: series added here are drawn behind the candles. */
|
|
421
|
+
attach(ctx: PluginContext): PluginHandle | void;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** Mounts a chart that fills `container` and follows its size. */
|
|
425
|
+
export function mount(container: HTMLElement, options?: MountOptions): ChartInstance;
|
|
426
|
+
|
|
427
|
+
/** The FlashAlpha chart API (`/v1/symbols`, `/v1/bars`, `/v1/charts`) under `baseUrl`, the key sent as `X-Api-Key`. */
|
|
428
|
+
export function chartEngineSource(baseUrl?: string, apiKey?: string | null): DataSource;
|
|
429
|
+
|
|
430
|
+
/** Adds layers to every chart mounted after this call. */
|
|
431
|
+
export function registerLayers(plugin: LayerPlugin): void;
|
|
432
|
+
|
|
433
|
+
/** The key for every chart mounted after this call when `options.apiKey` is not given. */
|
|
434
|
+
export function setLicenseKey(key: string | null): void;
|
|
435
|
+
|
|
436
|
+
export const plans: Plan[];
|
|
437
|
+
export const version: string;
|
|
438
|
+
|
|
439
|
+
declare const FlashAlphaChart: {
|
|
440
|
+
mount: typeof mount;
|
|
441
|
+
chartEngineSource: typeof chartEngineSource;
|
|
442
|
+
registerLayers: typeof registerLayers;
|
|
443
|
+
setLicenseKey: typeof setLicenseKey;
|
|
444
|
+
plans: Plan[];
|
|
445
|
+
/** Every layer id a chart mounted now would offer. */
|
|
446
|
+
readonly layers: string[];
|
|
447
|
+
version: string;
|
|
448
|
+
};
|
|
449
|
+
export default FlashAlphaChart;
|
|
450
|
+
|
|
451
|
+
declare global {
|
|
452
|
+
interface Window {
|
|
453
|
+
/** Set by the script build (`dist/tradingview-gex-flashalpha.js`). */
|
|
454
|
+
FlashAlphaChart?: typeof FlashAlphaChart;
|
|
455
|
+
LightweightCharts?: LightweightChartsModule;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|