@metamask-previews/advanced-chart-core 0.0.0-preview-e58fe0640 → 0.0.0-preview-238cb7063
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/dist/core/bootstrap.cjs +185 -0
- package/dist/core/bootstrap.cjs.map +1 -0
- package/dist/core/bootstrap.d.cts +10 -0
- package/dist/core/bootstrap.d.cts.map +1 -0
- package/dist/core/bootstrap.d.mts +10 -0
- package/dist/core/bootstrap.d.mts.map +1 -0
- package/dist/core/bootstrap.mjs +181 -0
- package/dist/core/bootstrap.mjs.map +1 -0
- package/dist/core/bridge.cjs +115 -0
- package/dist/core/bridge.cjs.map +1 -0
- package/dist/core/bridge.d.cts +37 -0
- package/dist/core/bridge.d.cts.map +1 -0
- package/dist/core/bridge.d.mts +37 -0
- package/dist/core/bridge.d.mts.map +1 -0
- package/dist/core/bridge.mjs +108 -0
- package/dist/core/bridge.mjs.map +1 -0
- package/dist/core/dataLifecycle.cjs +52 -0
- package/dist/core/dataLifecycle.cjs.map +1 -0
- package/dist/core/dataLifecycle.d.cts +8 -0
- package/dist/core/dataLifecycle.d.cts.map +1 -0
- package/dist/core/dataLifecycle.d.mts +8 -0
- package/dist/core/dataLifecycle.d.mts.map +1 -0
- package/dist/core/dataLifecycle.mjs +46 -0
- package/dist/core/dataLifecycle.mjs.map +1 -0
- package/dist/core/loadLibrary.cjs +63 -0
- package/dist/core/loadLibrary.cjs.map +1 -0
- package/dist/core/loadLibrary.d.cts +16 -0
- package/dist/core/loadLibrary.d.cts.map +1 -0
- package/dist/core/loadLibrary.d.mts +16 -0
- package/dist/core/loadLibrary.d.mts.map +1 -0
- package/dist/core/loadLibrary.mjs +58 -0
- package/dist/core/loadLibrary.mjs.map +1 -0
- package/dist/core/resolution.cjs +58 -0
- package/dist/core/resolution.cjs.map +1 -0
- package/dist/core/resolution.d.cts +15 -0
- package/dist/core/resolution.d.cts.map +1 -0
- package/dist/core/resolution.d.mts +15 -0
- package/dist/core/resolution.d.mts.map +1 -0
- package/dist/core/resolution.mjs +54 -0
- package/dist/core/resolution.mjs.map +1 -0
- package/dist/core/state.cjs +343 -0
- package/dist/core/state.cjs.map +1 -0
- package/dist/core/state.d.cts +67 -0
- package/dist/core/state.d.cts.map +1 -0
- package/dist/core/state.d.mts +67 -0
- package/dist/core/state.d.mts.map +1 -0
- package/dist/core/state.mjs +283 -0
- package/dist/core/state.mjs.map +1 -0
- package/dist/core/timeUtils.cjs +72 -0
- package/dist/core/timeUtils.cjs.map +1 -0
- package/dist/core/timeUtils.d.cts +32 -0
- package/dist/core/timeUtils.d.cts.map +1 -0
- package/dist/core/timeUtils.d.mts +32 -0
- package/dist/core/timeUtils.d.mts.map +1 -0
- package/dist/core/timeUtils.mjs +66 -0
- package/dist/core/timeUtils.mjs.map +1 -0
- package/dist/core/timezone.cjs +135 -0
- package/dist/core/timezone.cjs.map +1 -0
- package/dist/core/timezone.d.cts +16 -0
- package/dist/core/timezone.d.cts.map +1 -0
- package/dist/core/timezone.d.mts +16 -0
- package/dist/core/timezone.d.mts.map +1 -0
- package/dist/core/timezone.mjs +131 -0
- package/dist/core/timezone.mjs.map +1 -0
- package/dist/core/types.cjs +20 -0
- package/dist/core/types.cjs.map +1 -0
- package/dist/core/types.d.cts +323 -0
- package/dist/core/types.d.cts.map +1 -0
- package/dist/core/types.d.mts +323 -0
- package/dist/core/types.d.mts.map +1 -0
- package/dist/core/types.mjs +17 -0
- package/dist/core/types.mjs.map +1 -0
- package/dist/features/indicators/index.cjs +183 -0
- package/dist/features/indicators/index.cjs.map +1 -0
- package/dist/features/indicators/index.d.cts +6 -0
- package/dist/features/indicators/index.d.cts.map +1 -0
- package/dist/features/indicators/index.d.mts +6 -0
- package/dist/features/indicators/index.d.mts.map +1 -0
- package/dist/features/indicators/index.mjs +177 -0
- package/dist/features/indicators/index.mjs.map +1 -0
- package/dist/features/indicators/legend.cjs +575 -0
- package/dist/features/indicators/legend.cjs.map +1 -0
- package/dist/features/indicators/legend.d.cts +40 -0
- package/dist/features/indicators/legend.d.cts.map +1 -0
- package/dist/features/indicators/legend.d.mts +40 -0
- package/dist/features/indicators/legend.d.mts.map +1 -0
- package/dist/features/indicators/legend.mjs +564 -0
- package/dist/features/indicators/legend.mjs.map +1 -0
- package/dist/features/indicators/resize.cjs +34 -0
- package/dist/features/indicators/resize.cjs.map +1 -0
- package/dist/features/indicators/resize.d.cts +2 -0
- package/dist/features/indicators/resize.d.cts.map +1 -0
- package/dist/features/indicators/resize.d.mts +2 -0
- package/dist/features/indicators/resize.d.mts.map +1 -0
- package/dist/features/indicators/resize.mjs +30 -0
- package/dist/features/indicators/resize.mjs.map +1 -0
- package/dist/features/indicators/studies.cjs +147 -0
- package/dist/features/indicators/studies.cjs.map +1 -0
- package/dist/features/indicators/studies.d.cts +36 -0
- package/dist/features/indicators/studies.d.cts.map +1 -0
- package/dist/features/indicators/studies.d.mts +36 -0
- package/dist/features/indicators/studies.d.mts.map +1 -0
- package/dist/features/indicators/studies.mjs +140 -0
- package/dist/features/indicators/studies.mjs.map +1 -0
- package/dist/features/indicators/subPane.cjs +78 -0
- package/dist/features/indicators/subPane.cjs.map +1 -0
- package/dist/features/indicators/subPane.d.cts +6 -0
- package/dist/features/indicators/subPane.d.cts.map +1 -0
- package/dist/features/indicators/subPane.d.mts +6 -0
- package/dist/features/indicators/subPane.d.mts.map +1 -0
- package/dist/features/indicators/subPane.mjs +72 -0
- package/dist/features/indicators/subPane.mjs.map +1 -0
- package/dist/features/volume/index.cjs +145 -0
- package/dist/features/volume/index.cjs.map +1 -0
- package/dist/features/volume/index.d.cts +4 -0
- package/dist/features/volume/index.d.cts.map +1 -0
- package/dist/features/volume/index.d.mts +4 -0
- package/dist/features/volume/index.d.mts.map +1 -0
- package/dist/features/volume/index.mjs +140 -0
- package/dist/features/volume/index.mjs.map +1 -0
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +18 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interaction/crosshair.cjs +147 -0
- package/dist/interaction/crosshair.cjs.map +1 -0
- package/dist/interaction/crosshair.d.cts +21 -0
- package/dist/interaction/crosshair.d.cts.map +1 -0
- package/dist/interaction/crosshair.d.mts +21 -0
- package/dist/interaction/crosshair.d.mts.map +1 -0
- package/dist/interaction/crosshair.mjs +141 -0
- package/dist/interaction/crosshair.mjs.map +1 -0
- package/dist/interaction/visibleRange.cjs +102 -0
- package/dist/interaction/visibleRange.cjs.map +1 -0
- package/dist/interaction/visibleRange.d.cts +11 -0
- package/dist/interaction/visibleRange.d.cts.map +1 -0
- package/dist/interaction/visibleRange.d.mts +11 -0
- package/dist/interaction/visibleRange.d.mts.map +1 -0
- package/dist/interaction/visibleRange.mjs +97 -0
- package/dist/interaction/visibleRange.mjs.map +1 -0
- package/dist/messages/contract.cjs +27 -0
- package/dist/messages/contract.cjs.map +1 -0
- package/dist/messages/contract.d.cts +262 -0
- package/dist/messages/contract.d.cts.map +1 -0
- package/dist/messages/contract.d.mts +262 -0
- package/dist/messages/contract.d.mts.map +1 -0
- package/dist/messages/contract.mjs +26 -0
- package/dist/messages/contract.mjs.map +1 -0
- package/dist/messages/handler.cjs +54 -0
- package/dist/messages/handler.cjs.map +1 -0
- package/dist/messages/handler.d.cts +25 -0
- package/dist/messages/handler.d.cts.map +1 -0
- package/dist/messages/handler.d.mts +25 -0
- package/dist/messages/handler.d.mts.map +1 -0
- package/dist/messages/handler.mjs +48 -0
- package/dist/messages/handler.mjs.map +1 -0
- package/dist/overlays/focusTime/index.cjs +161 -0
- package/dist/overlays/focusTime/index.cjs.map +1 -0
- package/dist/overlays/focusTime/index.d.cts +6 -0
- package/dist/overlays/focusTime/index.d.cts.map +1 -0
- package/dist/overlays/focusTime/index.d.mts +6 -0
- package/dist/overlays/focusTime/index.d.mts.map +1 -0
- package/dist/overlays/focusTime/index.mjs +155 -0
- package/dist/overlays/focusTime/index.mjs.map +1 -0
- package/dist/overlays/positionLines/index.cjs +188 -0
- package/dist/overlays/positionLines/index.cjs.map +1 -0
- package/dist/overlays/positionLines/index.d.cts +4 -0
- package/dist/overlays/positionLines/index.d.cts.map +1 -0
- package/dist/overlays/positionLines/index.d.mts +4 -0
- package/dist/overlays/positionLines/index.d.mts.map +1 -0
- package/dist/overlays/positionLines/index.mjs +183 -0
- package/dist/overlays/positionLines/index.mjs.map +1 -0
- package/dist/overlays/positionLines/state.cjs +35 -0
- package/dist/overlays/positionLines/state.cjs.map +1 -0
- package/dist/overlays/positionLines/state.d.cts +8 -0
- package/dist/overlays/positionLines/state.d.cts.map +1 -0
- package/dist/overlays/positionLines/state.d.mts +8 -0
- package/dist/overlays/positionLines/state.d.mts.map +1 -0
- package/dist/overlays/positionLines/state.mjs +26 -0
- package/dist/overlays/positionLines/state.mjs.map +1 -0
- package/dist/overlays/socialLeaderboard/index.cjs +229 -0
- package/dist/overlays/socialLeaderboard/index.cjs.map +1 -0
- package/dist/overlays/socialLeaderboard/index.d.cts +48 -0
- package/dist/overlays/socialLeaderboard/index.d.cts.map +1 -0
- package/dist/overlays/socialLeaderboard/index.d.mts +48 -0
- package/dist/overlays/socialLeaderboard/index.d.mts.map +1 -0
- package/dist/overlays/socialLeaderboard/index.mjs +222 -0
- package/dist/overlays/socialLeaderboard/index.mjs.map +1 -0
- package/dist/overlays/tradeMarkers/animation.cjs +123 -0
- package/dist/overlays/tradeMarkers/animation.cjs.map +1 -0
- package/dist/overlays/tradeMarkers/animation.d.cts +5 -0
- package/dist/overlays/tradeMarkers/animation.d.cts.map +1 -0
- package/dist/overlays/tradeMarkers/animation.d.mts +5 -0
- package/dist/overlays/tradeMarkers/animation.d.mts.map +1 -0
- package/dist/overlays/tradeMarkers/animation.mjs +118 -0
- package/dist/overlays/tradeMarkers/animation.mjs.map +1 -0
- package/dist/overlays/tradeMarkers/index.cjs +334 -0
- package/dist/overlays/tradeMarkers/index.cjs.map +1 -0
- package/dist/overlays/tradeMarkers/index.d.cts +35 -0
- package/dist/overlays/tradeMarkers/index.d.cts.map +1 -0
- package/dist/overlays/tradeMarkers/index.d.mts +35 -0
- package/dist/overlays/tradeMarkers/index.d.mts.map +1 -0
- package/dist/overlays/tradeMarkers/index.mjs +324 -0
- package/dist/overlays/tradeMarkers/index.mjs.map +1 -0
- package/dist/overlays/tradeMarkers/markerHitTest.cjs +337 -0
- package/dist/overlays/tradeMarkers/markerHitTest.cjs.map +1 -0
- package/dist/overlays/tradeMarkers/markerHitTest.d.cts +15 -0
- package/dist/overlays/tradeMarkers/markerHitTest.d.cts.map +1 -0
- package/dist/overlays/tradeMarkers/markerHitTest.d.mts +15 -0
- package/dist/overlays/tradeMarkers/markerHitTest.d.mts.map +1 -0
- package/dist/overlays/tradeMarkers/markerHitTest.mjs +331 -0
- package/dist/overlays/tradeMarkers/markerHitTest.mjs.map +1 -0
- package/dist/overlays/tradeMarkers/state.cjs +75 -0
- package/dist/overlays/tradeMarkers/state.cjs.map +1 -0
- package/dist/overlays/tradeMarkers/state.d.cts +20 -0
- package/dist/overlays/tradeMarkers/state.d.cts.map +1 -0
- package/dist/overlays/tradeMarkers/state.d.mts +20 -0
- package/dist/overlays/tradeMarkers/state.d.mts.map +1 -0
- package/dist/overlays/tradeMarkers/state.mjs +60 -0
- package/dist/overlays/tradeMarkers/state.mjs.map +1 -0
- package/dist/pagination/priceApi.cjs +102 -0
- package/dist/pagination/priceApi.cjs.map +1 -0
- package/dist/pagination/priceApi.d.cts +43 -0
- package/dist/pagination/priceApi.d.cts.map +1 -0
- package/dist/pagination/priceApi.d.mts +43 -0
- package/dist/pagination/priceApi.d.mts.map +1 -0
- package/dist/pagination/priceApi.mjs +97 -0
- package/dist/pagination/priceApi.mjs.map +1 -0
- package/dist/pagination/rnBacked.cjs +108 -0
- package/dist/pagination/rnBacked.cjs.map +1 -0
- package/dist/pagination/rnBacked.d.cts +15 -0
- package/dist/pagination/rnBacked.d.cts.map +1 -0
- package/dist/pagination/rnBacked.d.mts +15 -0
- package/dist/pagination/rnBacked.d.mts.map +1 -0
- package/dist/pagination/rnBacked.mjs +100 -0
- package/dist/pagination/rnBacked.mjs.map +1 -0
- package/dist/widget/chartType.cjs +39 -0
- package/dist/widget/chartType.cjs.map +1 -0
- package/dist/widget/chartType.d.cts +4 -0
- package/dist/widget/chartType.d.cts.map +1 -0
- package/dist/widget/chartType.d.mts +4 -0
- package/dist/widget/chartType.d.mts.map +1 -0
- package/dist/widget/chartType.mjs +34 -0
- package/dist/widget/chartType.mjs.map +1 -0
- package/dist/widget/datafeed.cjs +228 -0
- package/dist/widget/datafeed.cjs.map +1 -0
- package/dist/widget/datafeed.d.cts +22 -0
- package/dist/widget/datafeed.d.cts.map +1 -0
- package/dist/widget/datafeed.d.mts +22 -0
- package/dist/widget/datafeed.d.mts.map +1 -0
- package/dist/widget/datafeed.mjs +223 -0
- package/dist/widget/datafeed.mjs.map +1 -0
- package/dist/widget/externalLinkBridge.cjs +134 -0
- package/dist/widget/externalLinkBridge.cjs.map +1 -0
- package/dist/widget/externalLinkBridge.d.cts +14 -0
- package/dist/widget/externalLinkBridge.d.cts.map +1 -0
- package/dist/widget/externalLinkBridge.d.mts +14 -0
- package/dist/widget/externalLinkBridge.d.mts.map +1 -0
- package/dist/widget/externalLinkBridge.mjs +127 -0
- package/dist/widget/externalLinkBridge.mjs.map +1 -0
- package/dist/widget/initChart.cjs +242 -0
- package/dist/widget/initChart.cjs.map +1 -0
- package/dist/widget/initChart.d.cts +53 -0
- package/dist/widget/initChart.d.cts.map +1 -0
- package/dist/widget/initChart.d.mts +53 -0
- package/dist/widget/initChart.d.mts.map +1 -0
- package/dist/widget/initChart.mjs +235 -0
- package/dist/widget/initChart.mjs.map +1 -0
- package/dist/widget/ohlcvIngestion.cjs +240 -0
- package/dist/widget/ohlcvIngestion.cjs.map +1 -0
- package/dist/widget/ohlcvIngestion.d.cts +16 -0
- package/dist/widget/ohlcvIngestion.d.cts.map +1 -0
- package/dist/widget/ohlcvIngestion.d.mts +16 -0
- package/dist/widget/ohlcvIngestion.d.mts.map +1 -0
- package/dist/widget/ohlcvIngestion.mjs +233 -0
- package/dist/widget/ohlcvIngestion.mjs.map +1 -0
- package/dist/widget/priceFormatter.cjs +142 -0
- package/dist/widget/priceFormatter.cjs.map +1 -0
- package/dist/widget/priceFormatter.d.cts +38 -0
- package/dist/widget/priceFormatter.d.cts.map +1 -0
- package/dist/widget/priceFormatter.d.mts +38 -0
- package/dist/widget/priceFormatter.d.mts.map +1 -0
- package/dist/widget/priceFormatter.mjs +134 -0
- package/dist/widget/priceFormatter.mjs.map +1 -0
- package/dist/widget/scaleLayout.cjs +89 -0
- package/dist/widget/scaleLayout.cjs.map +1 -0
- package/dist/widget/scaleLayout.d.cts +9 -0
- package/dist/widget/scaleLayout.d.cts.map +1 -0
- package/dist/widget/scaleLayout.d.mts +9 -0
- package/dist/widget/scaleLayout.d.mts.map +1 -0
- package/dist/widget/scaleLayout.mjs +85 -0
- package/dist/widget/scaleLayout.mjs.map +1 -0
- package/dist/widget/theme.cjs +286 -0
- package/dist/widget/theme.cjs.map +1 -0
- package/dist/widget/theme.d.cts +99 -0
- package/dist/widget/theme.d.cts.map +1 -0
- package/dist/widget/theme.d.mts +99 -0
- package/dist/widget/theme.d.mts.map +1 -0
- package/dist/widget/theme.mjs +270 -0
- package/dist/widget/theme.mjs.map +1 -0
- package/dist/widget/tvDomHelpers.cjs +65 -0
- package/dist/widget/tvDomHelpers.cjs.map +1 -0
- package/dist/widget/tvDomHelpers.d.cts +19 -0
- package/dist/widget/tvDomHelpers.d.cts.map +1 -0
- package/dist/widget/tvDomHelpers.d.mts +19 -0
- package/dist/widget/tvDomHelpers.d.mts.map +1 -0
- package/dist/widget/tvDomHelpers.mjs +60 -0
- package/dist/widget/tvDomHelpers.mjs.map +1 -0
- package/dist/widget/visualOverrides.cjs +63 -0
- package/dist/widget/visualOverrides.cjs.map +1 -0
- package/dist/widget/visualOverrides.d.cts +27 -0
- package/dist/widget/visualOverrides.d.cts.map +1 -0
- package/dist/widget/visualOverrides.d.mts +27 -0
- package/dist/widget/visualOverrides.d.mts.map +1 -0
- package/dist/widget/visualOverrides.mjs +58 -0
- package/dist/widget/visualOverrides.mjs.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SET_CHART_TYPE handler — switches between candle (1) and line (2) types.
|
|
3
|
+
//
|
|
4
|
+
// Ported from chartLogic.js handleSetChartType (~line 2457). After
|
|
5
|
+
// setChartType, the legacy code calls applyChartScaleLayout to re-apply
|
|
6
|
+
// pane margins + right-scale binding; without it the line chart auto-fits
|
|
7
|
+
// to close-only and looks "zoomed in" vs the candle chart's high/low range.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ChartType = exports.handleSetChartType = void 0;
|
|
10
|
+
const bridge_js_1 = require("../core/bridge.cjs");
|
|
11
|
+
const state_js_1 = require("../core/state.cjs");
|
|
12
|
+
const scaleLayout_js_1 = require("./scaleLayout.cjs");
|
|
13
|
+
function handleSetChartType(payload) {
|
|
14
|
+
const widget = (0, state_js_1.getWidget)();
|
|
15
|
+
if (!widget) {
|
|
16
|
+
// Widget not built yet; persist the desired type so initChart picks it up.
|
|
17
|
+
(0, state_js_1.setCurrentChartType)(payload.type);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
(0, state_js_1.setCurrentChartType)(payload.type);
|
|
21
|
+
if (!(0, state_js_1.isChartReady)()) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
widget.activeChart().setChartType(payload.type);
|
|
26
|
+
(0, scaleLayout_js_1.applyScaleLayout)(payload.type);
|
|
27
|
+
// TradingView may rebind scales asynchronously after a type switch; the
|
|
28
|
+
// legacy code re-applies on the next animation frame for the line chart.
|
|
29
|
+
// Doing it for both types is safe.
|
|
30
|
+
requestAnimationFrame(() => (0, scaleLayout_js_1.applyScaleLayout)(payload.type));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
(0, bridge_js_1.reportErrorToRN)(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.handleSetChartType = handleSetChartType;
|
|
37
|
+
var types_js_1 = require("../core/types.cjs");
|
|
38
|
+
Object.defineProperty(exports, "ChartType", { enumerable: true, get: function () { return types_js_1.ChartType; } });
|
|
39
|
+
//# sourceMappingURL=chartType.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartType.cjs","sourceRoot":"","sources":["../../src/widget/chartType.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,EAAE;AACF,mEAAmE;AACnE,wEAAwE;AACxE,0EAA0E;AAC1E,4EAA4E;;;AAE5E,kDAAoD;AACpD,gDAAgF;AAEhF,sDAAoD;AAEpD,SAAgB,kBAAkB,CAChC,OAAuC;IAEvC,MAAM,MAAM,GAAG,IAAA,oBAAS,GAAE,CAAC;IAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,2EAA2E;QAC3E,IAAA,8BAAmB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO;IACT,CAAC;IAED,IAAA,8BAAmB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC,IAAI,CAAC,IAAA,uBAAY,GAAE,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,MAAM,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChD,IAAA,iCAAgB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,wEAAwE;QACxE,yEAAyE;QACzE,mCAAmC;QACnC,qBAAqB,CAAC,GAAG,EAAE,CAAC,IAAA,iCAAgB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,2BAAe,EAAC,KAAK,CAAC,CAAC;IACzB,CAAC;AACH,CAAC;AA1BD,gDA0BC;AAED,8CAA6C;AAApC,qGAAA,SAAS,OAAA","sourcesContent":["// SET_CHART_TYPE handler — switches between candle (1) and line (2) types.\n//\n// Ported from chartLogic.js handleSetChartType (~line 2457). After\n// setChartType, the legacy code calls applyChartScaleLayout to re-apply\n// pane margins + right-scale binding; without it the line chart auto-fits\n// to close-only and looks \"zoomed in\" vs the candle chart's high/low range.\n\nimport { reportErrorToRN } from '../core/bridge.js';\nimport { getWidget, isChartReady, setCurrentChartType } from '../core/state.js';\nimport type { SetChartTypeMessage } from '../messages/contract.js';\nimport { applyScaleLayout } from './scaleLayout.js';\n\nexport function handleSetChartType(\n payload: SetChartTypeMessage['payload'],\n): void {\n const widget = getWidget();\n if (!widget) {\n // Widget not built yet; persist the desired type so initChart picks it up.\n setCurrentChartType(payload.type);\n return;\n }\n\n setCurrentChartType(payload.type);\n\n if (!isChartReady()) {\n return;\n }\n\n try {\n widget.activeChart().setChartType(payload.type);\n applyScaleLayout(payload.type);\n // TradingView may rebind scales asynchronously after a type switch; the\n // legacy code re-applies on the next animation frame for the line chart.\n // Doing it for both types is safe.\n requestAnimationFrame(() => applyScaleLayout(payload.type));\n } catch (error) {\n reportErrorToRN(error);\n }\n}\n\nexport { ChartType } from '../core/types.js';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartType.d.cts","sourceRoot":"","sources":["../../src/widget/chartType.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAAgC;AAGnE,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,GACtC,IAAI,CAwBN;AAED,OAAO,EAAE,SAAS,EAAE,0BAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartType.d.mts","sourceRoot":"","sources":["../../src/widget/chartType.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAAgC;AAGnE,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,GACtC,IAAI,CAwBN;AAED,OAAO,EAAE,SAAS,EAAE,0BAAyB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SET_CHART_TYPE handler — switches between candle (1) and line (2) types.
|
|
2
|
+
//
|
|
3
|
+
// Ported from chartLogic.js handleSetChartType (~line 2457). After
|
|
4
|
+
// setChartType, the legacy code calls applyChartScaleLayout to re-apply
|
|
5
|
+
// pane margins + right-scale binding; without it the line chart auto-fits
|
|
6
|
+
// to close-only and looks "zoomed in" vs the candle chart's high/low range.
|
|
7
|
+
import { reportErrorToRN } from "../core/bridge.mjs";
|
|
8
|
+
import { getWidget, isChartReady, setCurrentChartType } from "../core/state.mjs";
|
|
9
|
+
import { applyScaleLayout } from "./scaleLayout.mjs";
|
|
10
|
+
export function handleSetChartType(payload) {
|
|
11
|
+
const widget = getWidget();
|
|
12
|
+
if (!widget) {
|
|
13
|
+
// Widget not built yet; persist the desired type so initChart picks it up.
|
|
14
|
+
setCurrentChartType(payload.type);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
setCurrentChartType(payload.type);
|
|
18
|
+
if (!isChartReady()) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
widget.activeChart().setChartType(payload.type);
|
|
23
|
+
applyScaleLayout(payload.type);
|
|
24
|
+
// TradingView may rebind scales asynchronously after a type switch; the
|
|
25
|
+
// legacy code re-applies on the next animation frame for the line chart.
|
|
26
|
+
// Doing it for both types is safe.
|
|
27
|
+
requestAnimationFrame(() => applyScaleLayout(payload.type));
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
reportErrorToRN(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export { ChartType } from "../core/types.mjs";
|
|
34
|
+
//# sourceMappingURL=chartType.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartType.mjs","sourceRoot":"","sources":["../../src/widget/chartType.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,mEAAmE;AACnE,wEAAwE;AACxE,0EAA0E;AAC1E,4EAA4E;AAE5E,OAAO,EAAE,eAAe,EAAE,2BAA0B;AACpD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,EAAE,0BAAyB;AAEhF,OAAO,EAAE,gBAAgB,EAAE,0BAAyB;AAEpD,MAAM,UAAU,kBAAkB,CAChC,OAAuC;IAEvC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,2EAA2E;QAC3E,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO;IACT,CAAC;IAED,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,MAAM,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChD,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,wEAAwE;QACxE,yEAAyE;QACzE,mCAAmC;QACnC,qBAAqB,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAe,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;AACH,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,0BAAyB","sourcesContent":["// SET_CHART_TYPE handler — switches between candle (1) and line (2) types.\n//\n// Ported from chartLogic.js handleSetChartType (~line 2457). After\n// setChartType, the legacy code calls applyChartScaleLayout to re-apply\n// pane margins + right-scale binding; without it the line chart auto-fits\n// to close-only and looks \"zoomed in\" vs the candle chart's high/low range.\n\nimport { reportErrorToRN } from '../core/bridge.js';\nimport { getWidget, isChartReady, setCurrentChartType } from '../core/state.js';\nimport type { SetChartTypeMessage } from '../messages/contract.js';\nimport { applyScaleLayout } from './scaleLayout.js';\n\nexport function handleSetChartType(\n payload: SetChartTypeMessage['payload'],\n): void {\n const widget = getWidget();\n if (!widget) {\n // Widget not built yet; persist the desired type so initChart picks it up.\n setCurrentChartType(payload.type);\n return;\n }\n\n setCurrentChartType(payload.type);\n\n if (!isChartReady()) {\n return;\n }\n\n try {\n widget.activeChart().setChartType(payload.type);\n applyScaleLayout(payload.type);\n // TradingView may rebind scales asynchronously after a type switch; the\n // legacy code re-applies on the next animation frame for the line chart.\n // Doing it for both types is safe.\n requestAnimationFrame(() => applyScaleLayout(payload.type));\n } catch (error) {\n reportErrorToRN(error);\n }\n}\n\nexport { ChartType } from '../core/types.js';\n"]}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TradingView UDF datafeed object passed into the widget constructor.
|
|
3
|
+
//
|
|
4
|
+
// Ported from chartLogic.js `customDatafeed` (lines ~5074-5203) and its
|
|
5
|
+
// helpers `filterBarsForRange` (~4944), `fetchOlderBars` (~4991).
|
|
6
|
+
// Phase 2 wires the default Price API paginator; Phase 6 swaps in
|
|
7
|
+
// pagination/rnBacked.ts when consumers opt into the custom strategy.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.forwardRealtimeTick = exports.customDatafeed = exports.filterBarsForRange = void 0;
|
|
10
|
+
const bridge_js_1 = require("../core/bridge.cjs");
|
|
11
|
+
const state_js_1 = require("../core/state.cjs");
|
|
12
|
+
const index_js_1 = require("../overlays/socialLeaderboard/index.cjs");
|
|
13
|
+
const priceApi_js_1 = require("../pagination/priceApi.cjs");
|
|
14
|
+
const rnBacked_js_1 = require("../pagination/rnBacked.cjs");
|
|
15
|
+
const priceFormatter_js_1 = require("./priceFormatter.cjs");
|
|
16
|
+
const SUPPORTED_RESOLUTIONS = [
|
|
17
|
+
'1',
|
|
18
|
+
'3',
|
|
19
|
+
'5',
|
|
20
|
+
'15',
|
|
21
|
+
'30',
|
|
22
|
+
'60',
|
|
23
|
+
'120',
|
|
24
|
+
'240',
|
|
25
|
+
'480',
|
|
26
|
+
'720',
|
|
27
|
+
'1D',
|
|
28
|
+
'3D',
|
|
29
|
+
'1W',
|
|
30
|
+
'1M',
|
|
31
|
+
];
|
|
32
|
+
const DEFAULT_VARIABLE_TICK_SIZE = [
|
|
33
|
+
'0.0000000001',
|
|
34
|
+
'0.000001',
|
|
35
|
+
'0.00000001',
|
|
36
|
+
'0.0001',
|
|
37
|
+
'0.000001',
|
|
38
|
+
'0.01',
|
|
39
|
+
'0.0001',
|
|
40
|
+
'1',
|
|
41
|
+
'0.01',
|
|
42
|
+
'10000',
|
|
43
|
+
'0.1',
|
|
44
|
+
].join(' ');
|
|
45
|
+
const PERPS_VARIABLE_TICK_SIZE = [
|
|
46
|
+
'0.0000000001',
|
|
47
|
+
'0.000001',
|
|
48
|
+
'0.00000001',
|
|
49
|
+
'0.0001',
|
|
50
|
+
'0.000001',
|
|
51
|
+
'0.01',
|
|
52
|
+
'0.0001',
|
|
53
|
+
'10000',
|
|
54
|
+
'1',
|
|
55
|
+
].join(' ');
|
|
56
|
+
function getVariableTickSize() {
|
|
57
|
+
return (0, priceFormatter_js_1.getConfiguredPriceDecimals)() === null
|
|
58
|
+
? DEFAULT_VARIABLE_TICK_SIZE
|
|
59
|
+
: PERPS_VARIABLE_TICK_SIZE;
|
|
60
|
+
}
|
|
61
|
+
function getPriceScale() {
|
|
62
|
+
return (0, priceFormatter_js_1.getConfiguredPriceDecimals)() === null ? 100 : 10000000000;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Strips internal fields from an OHLCVBar to the shape TV expects.
|
|
66
|
+
*
|
|
67
|
+
* @param bar - The internal OHLCV bar.
|
|
68
|
+
* @returns The bar in the shape TradingView expects.
|
|
69
|
+
*/
|
|
70
|
+
function toTVBar(bar) {
|
|
71
|
+
return {
|
|
72
|
+
time: bar.time,
|
|
73
|
+
open: bar.open,
|
|
74
|
+
high: bar.high,
|
|
75
|
+
low: bar.low,
|
|
76
|
+
close: bar.close,
|
|
77
|
+
volume: bar.volume,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Filters the in-memory OHLCV array to the requested time window.
|
|
82
|
+
* Mirrors legacy `filterBarsForRange`: returns bars in [fromMs, toMs); if
|
|
83
|
+
* fewer than countBack bars match, falls back to the last countBack bars
|
|
84
|
+
* before toMs.
|
|
85
|
+
*
|
|
86
|
+
* @param fromMs - Inclusive start of the window, in milliseconds.
|
|
87
|
+
* @param toMs - Exclusive end of the window, in milliseconds.
|
|
88
|
+
* @param countBack - Minimum number of bars TradingView expects.
|
|
89
|
+
* @returns The matching bars in the requested window.
|
|
90
|
+
*/
|
|
91
|
+
function filterBarsForRange(fromMs, toMs, countBack) {
|
|
92
|
+
const all = (0, state_js_1.getOhlcvData)();
|
|
93
|
+
const inRange = [];
|
|
94
|
+
for (const bar of all) {
|
|
95
|
+
if (bar.time >= fromMs && bar.time < toMs) {
|
|
96
|
+
inRange.push(toTVBar(bar));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (inRange.length >= countBack) {
|
|
100
|
+
return inRange;
|
|
101
|
+
}
|
|
102
|
+
const beforeTo = all.filter((b) => b.time < toMs);
|
|
103
|
+
const startIdx = Math.max(0, beforeTo.length - countBack);
|
|
104
|
+
return beforeTo.slice(startIdx).map(toTVBar);
|
|
105
|
+
}
|
|
106
|
+
exports.filterBarsForRange = filterBarsForRange;
|
|
107
|
+
exports.customDatafeed = {
|
|
108
|
+
onReady(callback) {
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
callback({
|
|
111
|
+
supported_resolutions: SUPPORTED_RESOLUTIONS,
|
|
112
|
+
supports_marks: false,
|
|
113
|
+
supports_timescale_marks: false,
|
|
114
|
+
supports_time: true,
|
|
115
|
+
});
|
|
116
|
+
}, 0);
|
|
117
|
+
},
|
|
118
|
+
searchSymbols(_userInput, _exchange, _symbolType, onResult) {
|
|
119
|
+
onResult([]);
|
|
120
|
+
},
|
|
121
|
+
resolveSymbol(symbolName, onResolve, _onError) {
|
|
122
|
+
const info = {
|
|
123
|
+
name: symbolName,
|
|
124
|
+
ticker: symbolName,
|
|
125
|
+
description: symbolName,
|
|
126
|
+
type: 'crypto',
|
|
127
|
+
session: '24x7',
|
|
128
|
+
timezone: 'Etc/UTC',
|
|
129
|
+
exchange: '',
|
|
130
|
+
minmov: 1,
|
|
131
|
+
pricescale: getPriceScale(),
|
|
132
|
+
variable_tick_size: getVariableTickSize(),
|
|
133
|
+
has_intraday: true,
|
|
134
|
+
has_daily: true,
|
|
135
|
+
has_weekly_and_monthly: true,
|
|
136
|
+
supported_resolutions: SUPPORTED_RESOLUTIONS,
|
|
137
|
+
volume_precision: 0,
|
|
138
|
+
data_status: 'endofday',
|
|
139
|
+
};
|
|
140
|
+
setTimeout(() => onResolve(info), 0);
|
|
141
|
+
},
|
|
142
|
+
getBars(_symbolInfo, resolution, periodParams, onResult, onError) {
|
|
143
|
+
try {
|
|
144
|
+
const fromMs = periodParams.from * 1000;
|
|
145
|
+
const toMs = periodParams.to * 1000;
|
|
146
|
+
const { countBack, firstDataRequest } = periodParams;
|
|
147
|
+
const bars = filterBarsForRange(fromMs, toMs, countBack);
|
|
148
|
+
if (bars.length > 0) {
|
|
149
|
+
onResult(bars, { noData: false });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const all = (0, state_js_1.getOhlcvData)();
|
|
153
|
+
if (firstDataRequest || all.length === 0) {
|
|
154
|
+
onResult([], { noData: true });
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const oldestAtDefer = all[0].time;
|
|
158
|
+
const pag = (0, state_js_1.getOhlcvPagination)();
|
|
159
|
+
// Strategy C (SLB): all data is pre-loaded by RN — no pagination.
|
|
160
|
+
if ((0, index_js_1.slbHandleGetBars)(onResult)) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
// Strategy A (Price API / Token Details):
|
|
164
|
+
if (pag.assetId) {
|
|
165
|
+
(0, priceApi_js_1.fetchOlderBarsFromPriceApi)({ oldestAtDefer })
|
|
166
|
+
.then(({ olderBars, noData }) => {
|
|
167
|
+
onResult(olderBars, { noData });
|
|
168
|
+
return undefined;
|
|
169
|
+
})
|
|
170
|
+
.catch((error) => {
|
|
171
|
+
(0, bridge_js_1.reportErrorToRN)(error);
|
|
172
|
+
onResult([], { noData: true });
|
|
173
|
+
});
|
|
174
|
+
// Strategy B (RN-backed / Perps):
|
|
175
|
+
}
|
|
176
|
+
else if ((0, state_js_1.getRnBackedPagination)().enabled) {
|
|
177
|
+
(0, rnBacked_js_1.requestOlderBarsFromRN)({
|
|
178
|
+
resolution,
|
|
179
|
+
fromSec: periodParams.from,
|
|
180
|
+
toSec: periodParams.to,
|
|
181
|
+
countBack: periodParams.countBack,
|
|
182
|
+
onResult,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
onResult([], { noData: true });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
let errMsg;
|
|
191
|
+
if (error instanceof Error) {
|
|
192
|
+
errMsg = error.message;
|
|
193
|
+
}
|
|
194
|
+
else if (typeof error === 'string') {
|
|
195
|
+
errMsg = error;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
errMsg = (0, bridge_js_1.safeStringify)(error);
|
|
199
|
+
}
|
|
200
|
+
onError(errMsg);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
subscribeBars(_symbolInfo, _resolution, onTick, listenerGuid) {
|
|
204
|
+
(0, state_js_1.registerRealtimeCallback)(listenerGuid, onTick);
|
|
205
|
+
},
|
|
206
|
+
unsubscribeBars(listenerGuid) {
|
|
207
|
+
(0, state_js_1.unregisterRealtimeCallback)(listenerGuid);
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Forward a realtime tick to every TradingView subscribeBars listener.
|
|
212
|
+
* Called from widget/ohlcvIngestion.ts on REALTIME_UPDATE.
|
|
213
|
+
*
|
|
214
|
+
* @param tick - The realtime bar to forward to listeners.
|
|
215
|
+
*/
|
|
216
|
+
function forwardRealtimeTick(tick) {
|
|
217
|
+
const callbacks = (0, state_js_1.getRealtimeCallbacks)();
|
|
218
|
+
for (const guid of Object.keys(callbacks)) {
|
|
219
|
+
try {
|
|
220
|
+
callbacks[guid](tick);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
(0, bridge_js_1.reportErrorToRN)(error);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.forwardRealtimeTick = forwardRealtimeTick;
|
|
228
|
+
//# sourceMappingURL=datafeed.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datafeed.cjs","sourceRoot":"","sources":["../../src/widget/datafeed.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,EAAE;AACF,wEAAwE;AACxE,kEAAkE;AAClE,kEAAkE;AAClE,sEAAsE;;;AAEtE,kDAAmE;AACnE,gDAO0B;AAY1B,sEAA0E;AAC1E,4DAAuE;AACvE,4DAAmE;AACnE,4DAAiE;AAEjE,MAAM,qBAAqB,GAAmB;IAC5C,GAAG;IACH,GAAG;IACH,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;CACL,CAAC;AAEF,MAAM,0BAA0B,GAAG;IACjC,cAAc;IACd,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,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AE,MAAM,CAAC,CAAC;IACjD,CAAC;IAED,eAAe,CAAC,YAAoB;QAClC,IAAA,qCAA0B,EAAC,YAAY,CAAC,CAAC;IAC3C,CAAC;CACF,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,IAAW;IAC7C,MAAM,SAAS,GAAG,IAAA,+BAAoB,GAAE,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAC;YACH,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAA,2BAAe,EAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC;AATD,kDASC","sourcesContent":["// TradingView UDF datafeed object passed into the widget constructor.\n//\n// Ported from chartLogic.js `customDatafeed` (lines ~5074-5203) and its\n// helpers `filterBarsForRange` (~4944), `fetchOlderBars` (~4991).\n// Phase 2 wires the default Price API paginator; Phase 6 swaps in\n// pagination/rnBacked.ts when consumers opt into the custom strategy.\n\nimport { reportErrorToRN, safeStringify } from '../core/bridge.js';\nimport {\n getOhlcvData,\n getOhlcvPagination,\n getRealtimeCallbacks,\n getRnBackedPagination,\n registerRealtimeCallback,\n unregisterRealtimeCallback,\n} from '../core/state.js';\nimport type {\n GetBarsCallback,\n GetBarsErrorCallback,\n OHLCVBar,\n PeriodParams,\n RealtimeTickCallback,\n SymbolInfo,\n TVBar,\n TVDatafeed,\n TVResolution,\n} from '../core/types.js';\nimport { slbHandleGetBars } from '../overlays/socialLeaderboard/index.js';\nimport { fetchOlderBarsFromPriceApi } from '../pagination/priceApi.js';\nimport { requestOlderBarsFromRN } from '../pagination/rnBacked.js';\nimport { getConfiguredPriceDecimals } from './priceFormatter.js';\n\nconst SUPPORTED_RESOLUTIONS: TVResolution[] = [\n '1',\n '3',\n '5',\n '15',\n '30',\n '60',\n '120',\n '240',\n '480',\n '720',\n '1D',\n '3D',\n '1W',\n '1M',\n];\n\nconst DEFAULT_VARIABLE_TICK_SIZE = [\n '0.0000000001',\n '0.000001',\n '0.00000001',\n '0.0001',\n '0.000001',\n '0.01',\n '0.0001',\n '1',\n '0.01',\n '10000',\n '0.1',\n].join(' ');\n\nconst PERPS_VARIABLE_TICK_SIZE = [\n '0.0000000001',\n '0.000001',\n '0.00000001',\n '0.0001',\n '0.000001',\n '0.01',\n '0.0001',\n '10000',\n '1',\n].join(' ');\n\nfunction getVariableTickSize(): string {\n return getConfiguredPriceDecimals() === null\n ? DEFAULT_VARIABLE_TICK_SIZE\n : PERPS_VARIABLE_TICK_SIZE;\n}\n\nfunction getPriceScale(): number {\n return getConfiguredPriceDecimals() === null ? 100 : 10000000000;\n}\n\n/**\n * Strips internal fields from an OHLCVBar to the shape TV expects.\n *\n * @param bar - The internal OHLCV bar.\n * @returns The bar in the shape TradingView expects.\n */\nfunction toTVBar(bar: OHLCVBar): TVBar {\n return {\n time: bar.time,\n open: bar.open,\n high: bar.high,\n low: bar.low,\n close: bar.close,\n volume: bar.volume,\n };\n}\n\n/**\n * Filters the in-memory OHLCV array to the requested time window.\n * Mirrors legacy `filterBarsForRange`: returns bars in [fromMs, toMs); if\n * fewer than countBack bars match, falls back to the last countBack bars\n * before toMs.\n *\n * @param fromMs - Inclusive start of the window, in milliseconds.\n * @param toMs - Exclusive end of the window, in milliseconds.\n * @param countBack - Minimum number of bars TradingView expects.\n * @returns The matching bars in the requested window.\n */\nexport function filterBarsForRange(\n fromMs: number,\n toMs: number,\n countBack: number,\n): TVBar[] {\n const all = getOhlcvData();\n const inRange: TVBar[] = [];\n for (const bar of all) {\n if (bar.time >= fromMs && bar.time < toMs) {\n inRange.push(toTVBar(bar));\n }\n }\n if (inRange.length >= countBack) {\n return inRange;\n }\n\n const beforeTo: OHLCVBar[] = all.filter((b) => b.time < toMs);\n const startIdx = Math.max(0, beforeTo.length - countBack);\n return beforeTo.slice(startIdx).map(toTVBar);\n}\n\nexport const customDatafeed: TVDatafeed = {\n onReady(callback) {\n setTimeout(() => {\n callback({\n supported_resolutions: SUPPORTED_RESOLUTIONS,\n supports_marks: false,\n supports_timescale_marks: false,\n supports_time: true,\n });\n }, 0);\n },\n\n searchSymbols(_userInput, _exchange, _symbolType, onResult) {\n onResult([]);\n },\n\n resolveSymbol(symbolName, onResolve, _onError) {\n const info: SymbolInfo = {\n name: symbolName,\n ticker: symbolName,\n description: symbolName,\n type: 'crypto',\n session: '24x7',\n timezone: 'Etc/UTC',\n exchange: '',\n minmov: 1,\n pricescale: getPriceScale(),\n variable_tick_size: getVariableTickSize(),\n has_intraday: true,\n has_daily: true,\n has_weekly_and_monthly: true,\n supported_resolutions: SUPPORTED_RESOLUTIONS,\n volume_precision: 0,\n data_status: 'endofday',\n };\n setTimeout(() => onResolve(info), 0);\n },\n\n getBars(\n _symbolInfo: SymbolInfo,\n resolution: TVResolution,\n periodParams: PeriodParams,\n onResult: GetBarsCallback,\n onError: GetBarsErrorCallback,\n ) {\n try {\n const fromMs = periodParams.from * 1000;\n const toMs = periodParams.to * 1000;\n const { countBack, firstDataRequest } = periodParams;\n\n const bars = filterBarsForRange(fromMs, toMs, countBack);\n if (bars.length > 0) {\n onResult(bars, { noData: false });\n return;\n }\n\n const all = getOhlcvData();\n if (firstDataRequest || all.length === 0) {\n onResult([], { noData: true });\n return;\n }\n\n const oldestAtDefer = all[0].time;\n const pag = getOhlcvPagination();\n\n // Strategy C (SLB): all data is pre-loaded by RN — no pagination.\n if (slbHandleGetBars(onResult)) {\n return;\n }\n\n // Strategy A (Price API / Token Details):\n if (pag.assetId) {\n fetchOlderBarsFromPriceApi({ oldestAtDefer })\n .then(({ olderBars, noData }) => {\n onResult(olderBars, { noData });\n return undefined;\n })\n .catch((error) => {\n reportErrorToRN(error);\n onResult([], { noData: true });\n });\n // Strategy B (RN-backed / Perps):\n } else if (getRnBackedPagination().enabled) {\n requestOlderBarsFromRN({\n resolution,\n fromSec: periodParams.from,\n toSec: periodParams.to,\n countBack: periodParams.countBack,\n onResult,\n });\n } else {\n onResult([], { noData: true });\n }\n } catch (error) {\n let errMsg: string;\n if (error instanceof Error) {\n errMsg = error.message;\n } else if (typeof error === 'string') {\n errMsg = error;\n } else {\n errMsg = safeStringify(error);\n }\n onError(errMsg);\n }\n },\n\n subscribeBars(\n _symbolInfo: SymbolInfo,\n _resolution: TVResolution,\n onTick: RealtimeTickCallback,\n listenerGuid: string,\n ) {\n registerRealtimeCallback(listenerGuid, onTick);\n },\n\n unsubscribeBars(listenerGuid: string) {\n unregisterRealtimeCallback(listenerGuid);\n },\n};\n\n/**\n * Forward a realtime tick to every TradingView subscribeBars listener.\n * Called from widget/ohlcvIngestion.ts on REALTIME_UPDATE.\n *\n * @param tick - The realtime bar to forward to listeners.\n */\nexport function forwardRealtimeTick(tick: TVBar): void {\n const callbacks = getRealtimeCallbacks();\n for (const guid of Object.keys(callbacks)) {\n try {\n callbacks[guid](tick);\n } catch (error) {\n reportErrorToRN(error);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TVBar, TVDatafeed } from "../core/types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Filters the in-memory OHLCV array to the requested time window.
|
|
4
|
+
* Mirrors legacy `filterBarsForRange`: returns bars in [fromMs, toMs); if
|
|
5
|
+
* fewer than countBack bars match, falls back to the last countBack bars
|
|
6
|
+
* before toMs.
|
|
7
|
+
*
|
|
8
|
+
* @param fromMs - Inclusive start of the window, in milliseconds.
|
|
9
|
+
* @param toMs - Exclusive end of the window, in milliseconds.
|
|
10
|
+
* @param countBack - Minimum number of bars TradingView expects.
|
|
11
|
+
* @returns The matching bars in the requested window.
|
|
12
|
+
*/
|
|
13
|
+
export declare function filterBarsForRange(fromMs: number, toMs: number, countBack: number): TVBar[];
|
|
14
|
+
export declare const customDatafeed: TVDatafeed;
|
|
15
|
+
/**
|
|
16
|
+
* Forward a realtime tick to every TradingView subscribeBars listener.
|
|
17
|
+
* Called from widget/ohlcvIngestion.ts on REALTIME_UPDATE.
|
|
18
|
+
*
|
|
19
|
+
* @param tick - The realtime bar to forward to listeners.
|
|
20
|
+
*/
|
|
21
|
+
export declare function forwardRealtimeTick(tick: TVBar): void;
|
|
22
|
+
//# sourceMappingURL=datafeed.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datafeed.d.cts","sourceRoot":"","sources":["../../src/widget/datafeed.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAOV,KAAK,EACL,UAAU,EAEX,0BAAyB;AA4E1B;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,KAAK,EAAE,CAeT;AAED,eAAO,MAAM,cAAc,EAAE,UAsH5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CASrD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TVBar, TVDatafeed } from "../core/types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Filters the in-memory OHLCV array to the requested time window.
|
|
4
|
+
* Mirrors legacy `filterBarsForRange`: returns bars in [fromMs, toMs); if
|
|
5
|
+
* fewer than countBack bars match, falls back to the last countBack bars
|
|
6
|
+
* before toMs.
|
|
7
|
+
*
|
|
8
|
+
* @param fromMs - Inclusive start of the window, in milliseconds.
|
|
9
|
+
* @param toMs - Exclusive end of the window, in milliseconds.
|
|
10
|
+
* @param countBack - Minimum number of bars TradingView expects.
|
|
11
|
+
* @returns The matching bars in the requested window.
|
|
12
|
+
*/
|
|
13
|
+
export declare function filterBarsForRange(fromMs: number, toMs: number, countBack: number): TVBar[];
|
|
14
|
+
export declare const customDatafeed: TVDatafeed;
|
|
15
|
+
/**
|
|
16
|
+
* Forward a realtime tick to every TradingView subscribeBars listener.
|
|
17
|
+
* Called from widget/ohlcvIngestion.ts on REALTIME_UPDATE.
|
|
18
|
+
*
|
|
19
|
+
* @param tick - The realtime bar to forward to listeners.
|
|
20
|
+
*/
|
|
21
|
+
export declare function forwardRealtimeTick(tick: TVBar): void;
|
|
22
|
+
//# sourceMappingURL=datafeed.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datafeed.d.mts","sourceRoot":"","sources":["../../src/widget/datafeed.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAOV,KAAK,EACL,UAAU,EAEX,0BAAyB;AA4E1B;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,KAAK,EAAE,CAeT;AAED,eAAO,MAAM,cAAc,EAAE,UAsH5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CASrD"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// TradingView UDF datafeed object passed into the widget constructor.
|
|
2
|
+
//
|
|
3
|
+
// Ported from chartLogic.js `customDatafeed` (lines ~5074-5203) and its
|
|
4
|
+
// helpers `filterBarsForRange` (~4944), `fetchOlderBars` (~4991).
|
|
5
|
+
// Phase 2 wires the default Price API paginator; Phase 6 swaps in
|
|
6
|
+
// pagination/rnBacked.ts when consumers opt into the custom strategy.
|
|
7
|
+
import { reportErrorToRN, safeStringify } from "../core/bridge.mjs";
|
|
8
|
+
import { getOhlcvData, getOhlcvPagination, getRealtimeCallbacks, getRnBackedPagination, registerRealtimeCallback, unregisterRealtimeCallback } from "../core/state.mjs";
|
|
9
|
+
import { slbHandleGetBars } from "../overlays/socialLeaderboard/index.mjs";
|
|
10
|
+
import { fetchOlderBarsFromPriceApi } from "../pagination/priceApi.mjs";
|
|
11
|
+
import { requestOlderBarsFromRN } from "../pagination/rnBacked.mjs";
|
|
12
|
+
import { getConfiguredPriceDecimals } from "./priceFormatter.mjs";
|
|
13
|
+
const SUPPORTED_RESOLUTIONS = [
|
|
14
|
+
'1',
|
|
15
|
+
'3',
|
|
16
|
+
'5',
|
|
17
|
+
'15',
|
|
18
|
+
'30',
|
|
19
|
+
'60',
|
|
20
|
+
'120',
|
|
21
|
+
'240',
|
|
22
|
+
'480',
|
|
23
|
+
'720',
|
|
24
|
+
'1D',
|
|
25
|
+
'3D',
|
|
26
|
+
'1W',
|
|
27
|
+
'1M',
|
|
28
|
+
];
|
|
29
|
+
const DEFAULT_VARIABLE_TICK_SIZE = [
|
|
30
|
+
'0.0000000001',
|
|
31
|
+
'0.000001',
|
|
32
|
+
'0.00000001',
|
|
33
|
+
'0.0001',
|
|
34
|
+
'0.000001',
|
|
35
|
+
'0.01',
|
|
36
|
+
'0.0001',
|
|
37
|
+
'1',
|
|
38
|
+
'0.01',
|
|
39
|
+
'10000',
|
|
40
|
+
'0.1',
|
|
41
|
+
].join(' ');
|
|
42
|
+
const PERPS_VARIABLE_TICK_SIZE = [
|
|
43
|
+
'0.0000000001',
|
|
44
|
+
'0.000001',
|
|
45
|
+
'0.00000001',
|
|
46
|
+
'0.0001',
|
|
47
|
+
'0.000001',
|
|
48
|
+
'0.01',
|
|
49
|
+
'0.0001',
|
|
50
|
+
'10000',
|
|
51
|
+
'1',
|
|
52
|
+
].join(' ');
|
|
53
|
+
function getVariableTickSize() {
|
|
54
|
+
return getConfiguredPriceDecimals() === null
|
|
55
|
+
? DEFAULT_VARIABLE_TICK_SIZE
|
|
56
|
+
: PERPS_VARIABLE_TICK_SIZE;
|
|
57
|
+
}
|
|
58
|
+
function getPriceScale() {
|
|
59
|
+
return getConfiguredPriceDecimals() === null ? 100 : 10000000000;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Strips internal fields from an OHLCVBar to the shape TV expects.
|
|
63
|
+
*
|
|
64
|
+
* @param bar - The internal OHLCV bar.
|
|
65
|
+
* @returns The bar in the shape TradingView expects.
|
|
66
|
+
*/
|
|
67
|
+
function toTVBar(bar) {
|
|
68
|
+
return {
|
|
69
|
+
time: bar.time,
|
|
70
|
+
open: bar.open,
|
|
71
|
+
high: bar.high,
|
|
72
|
+
low: bar.low,
|
|
73
|
+
close: bar.close,
|
|
74
|
+
volume: bar.volume,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Filters the in-memory OHLCV array to the requested time window.
|
|
79
|
+
* Mirrors legacy `filterBarsForRange`: returns bars in [fromMs, toMs); if
|
|
80
|
+
* fewer than countBack bars match, falls back to the last countBack bars
|
|
81
|
+
* before toMs.
|
|
82
|
+
*
|
|
83
|
+
* @param fromMs - Inclusive start of the window, in milliseconds.
|
|
84
|
+
* @param toMs - Exclusive end of the window, in milliseconds.
|
|
85
|
+
* @param countBack - Minimum number of bars TradingView expects.
|
|
86
|
+
* @returns The matching bars in the requested window.
|
|
87
|
+
*/
|
|
88
|
+
export function filterBarsForRange(fromMs, toMs, countBack) {
|
|
89
|
+
const all = getOhlcvData();
|
|
90
|
+
const inRange = [];
|
|
91
|
+
for (const bar of all) {
|
|
92
|
+
if (bar.time >= fromMs && bar.time < toMs) {
|
|
93
|
+
inRange.push(toTVBar(bar));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (inRange.length >= countBack) {
|
|
97
|
+
return inRange;
|
|
98
|
+
}
|
|
99
|
+
const beforeTo = all.filter((b) => b.time < toMs);
|
|
100
|
+
const startIdx = Math.max(0, beforeTo.length - countBack);
|
|
101
|
+
return beforeTo.slice(startIdx).map(toTVBar);
|
|
102
|
+
}
|
|
103
|
+
export const customDatafeed = {
|
|
104
|
+
onReady(callback) {
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
callback({
|
|
107
|
+
supported_resolutions: SUPPORTED_RESOLUTIONS,
|
|
108
|
+
supports_marks: false,
|
|
109
|
+
supports_timescale_marks: false,
|
|
110
|
+
supports_time: true,
|
|
111
|
+
});
|
|
112
|
+
}, 0);
|
|
113
|
+
},
|
|
114
|
+
searchSymbols(_userInput, _exchange, _symbolType, onResult) {
|
|
115
|
+
onResult([]);
|
|
116
|
+
},
|
|
117
|
+
resolveSymbol(symbolName, onResolve, _onError) {
|
|
118
|
+
const info = {
|
|
119
|
+
name: symbolName,
|
|
120
|
+
ticker: symbolName,
|
|
121
|
+
description: symbolName,
|
|
122
|
+
type: 'crypto',
|
|
123
|
+
session: '24x7',
|
|
124
|
+
timezone: 'Etc/UTC',
|
|
125
|
+
exchange: '',
|
|
126
|
+
minmov: 1,
|
|
127
|
+
pricescale: getPriceScale(),
|
|
128
|
+
variable_tick_size: getVariableTickSize(),
|
|
129
|
+
has_intraday: true,
|
|
130
|
+
has_daily: true,
|
|
131
|
+
has_weekly_and_monthly: true,
|
|
132
|
+
supported_resolutions: SUPPORTED_RESOLUTIONS,
|
|
133
|
+
volume_precision: 0,
|
|
134
|
+
data_status: 'endofday',
|
|
135
|
+
};
|
|
136
|
+
setTimeout(() => onResolve(info), 0);
|
|
137
|
+
},
|
|
138
|
+
getBars(_symbolInfo, resolution, periodParams, onResult, onError) {
|
|
139
|
+
try {
|
|
140
|
+
const fromMs = periodParams.from * 1000;
|
|
141
|
+
const toMs = periodParams.to * 1000;
|
|
142
|
+
const { countBack, firstDataRequest } = periodParams;
|
|
143
|
+
const bars = filterBarsForRange(fromMs, toMs, countBack);
|
|
144
|
+
if (bars.length > 0) {
|
|
145
|
+
onResult(bars, { noData: false });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const all = getOhlcvData();
|
|
149
|
+
if (firstDataRequest || all.length === 0) {
|
|
150
|
+
onResult([], { noData: true });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const oldestAtDefer = all[0].time;
|
|
154
|
+
const pag = getOhlcvPagination();
|
|
155
|
+
// Strategy C (SLB): all data is pre-loaded by RN — no pagination.
|
|
156
|
+
if (slbHandleGetBars(onResult)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// Strategy A (Price API / Token Details):
|
|
160
|
+
if (pag.assetId) {
|
|
161
|
+
fetchOlderBarsFromPriceApi({ oldestAtDefer })
|
|
162
|
+
.then(({ olderBars, noData }) => {
|
|
163
|
+
onResult(olderBars, { noData });
|
|
164
|
+
return undefined;
|
|
165
|
+
})
|
|
166
|
+
.catch((error) => {
|
|
167
|
+
reportErrorToRN(error);
|
|
168
|
+
onResult([], { noData: true });
|
|
169
|
+
});
|
|
170
|
+
// Strategy B (RN-backed / Perps):
|
|
171
|
+
}
|
|
172
|
+
else if (getRnBackedPagination().enabled) {
|
|
173
|
+
requestOlderBarsFromRN({
|
|
174
|
+
resolution,
|
|
175
|
+
fromSec: periodParams.from,
|
|
176
|
+
toSec: periodParams.to,
|
|
177
|
+
countBack: periodParams.countBack,
|
|
178
|
+
onResult,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
onResult([], { noData: true });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
let errMsg;
|
|
187
|
+
if (error instanceof Error) {
|
|
188
|
+
errMsg = error.message;
|
|
189
|
+
}
|
|
190
|
+
else if (typeof error === 'string') {
|
|
191
|
+
errMsg = error;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
errMsg = safeStringify(error);
|
|
195
|
+
}
|
|
196
|
+
onError(errMsg);
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
subscribeBars(_symbolInfo, _resolution, onTick, listenerGuid) {
|
|
200
|
+
registerRealtimeCallback(listenerGuid, onTick);
|
|
201
|
+
},
|
|
202
|
+
unsubscribeBars(listenerGuid) {
|
|
203
|
+
unregisterRealtimeCallback(listenerGuid);
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Forward a realtime tick to every TradingView subscribeBars listener.
|
|
208
|
+
* Called from widget/ohlcvIngestion.ts on REALTIME_UPDATE.
|
|
209
|
+
*
|
|
210
|
+
* @param tick - The realtime bar to forward to listeners.
|
|
211
|
+
*/
|
|
212
|
+
export function forwardRealtimeTick(tick) {
|
|
213
|
+
const callbacks = getRealtimeCallbacks();
|
|
214
|
+
for (const guid of Object.keys(callbacks)) {
|
|
215
|
+
try {
|
|
216
|
+
callbacks[guid](tick);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
reportErrorToRN(error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=datafeed.mjs.map
|