@orderly.network/ui-tradingview 2.8.10-alpha.0 → 2.8.11-alpha.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/dist/index.js +164 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +164 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -1078,16 +1078,37 @@ var _HistoryProvider = class _HistoryProvider {
|
|
|
1078
1078
|
countBack
|
|
1079
1079
|
);
|
|
1080
1080
|
if (needsFallback) {
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1081
|
+
const earliestTime = this._getEarliestTime(result.bars);
|
|
1082
|
+
if (earliestTime !== null) {
|
|
1083
|
+
const remainingCountBack = Math.max(
|
|
1084
|
+
0,
|
|
1085
|
+
countBack - result.bars.length
|
|
1086
|
+
);
|
|
1087
|
+
const mergedResult = await this._tryKlineFallbackWithMerge(
|
|
1088
|
+
requestParams,
|
|
1089
|
+
remainingCountBack,
|
|
1090
|
+
earliestTime,
|
|
1091
|
+
result
|
|
1092
|
+
);
|
|
1093
|
+
if (mergedResult !== null) {
|
|
1094
|
+
result = mergedResult;
|
|
1095
|
+
usedHistoryResult = false;
|
|
1096
|
+
this._klinePreference.set(preferenceKey, true);
|
|
1097
|
+
} else {
|
|
1098
|
+
this._klinePreference.set(preferenceKey, false);
|
|
1099
|
+
}
|
|
1089
1100
|
} else {
|
|
1090
|
-
this.
|
|
1101
|
+
const klineResult = await this._tryKlineFallback(
|
|
1102
|
+
requestParams,
|
|
1103
|
+
countBack
|
|
1104
|
+
);
|
|
1105
|
+
if (klineResult !== null) {
|
|
1106
|
+
result = klineResult;
|
|
1107
|
+
usedHistoryResult = false;
|
|
1108
|
+
this._klinePreference.set(preferenceKey, true);
|
|
1109
|
+
} else {
|
|
1110
|
+
this._klinePreference.set(preferenceKey, false);
|
|
1111
|
+
}
|
|
1091
1112
|
}
|
|
1092
1113
|
} else {
|
|
1093
1114
|
this._klinePreference.set(preferenceKey, false);
|
|
@@ -1302,6 +1323,106 @@ var _HistoryProvider = class _HistoryProvider {
|
|
|
1302
1323
|
}
|
|
1303
1324
|
return params;
|
|
1304
1325
|
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Get the earliest time from bars array
|
|
1328
|
+
* @param bars - Array of bars
|
|
1329
|
+
* @returns Earliest timestamp in seconds, or null if bars array is empty
|
|
1330
|
+
*/
|
|
1331
|
+
_getEarliestTime(bars) {
|
|
1332
|
+
if (bars.length === 0) {
|
|
1333
|
+
return null;
|
|
1334
|
+
}
|
|
1335
|
+
return bars[0].time / 1e3;
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Try kline fallback with merge logic
|
|
1339
|
+
* Requests kline data from the earliest time in history result to the original end time,
|
|
1340
|
+
* then merges the kline data with history data
|
|
1341
|
+
* @param requestParams - Original request parameters
|
|
1342
|
+
* @param countBack - Count back value
|
|
1343
|
+
* @param earliestTime - Earliest time from history result (in seconds)
|
|
1344
|
+
* @param historyResult - History result to merge with
|
|
1345
|
+
* @returns Merged result or null if kline request fails
|
|
1346
|
+
*/
|
|
1347
|
+
async _tryKlineFallbackWithMerge(requestParams, countBack, earliestTime, historyResult) {
|
|
1348
|
+
try {
|
|
1349
|
+
const klineParams = {
|
|
1350
|
+
...requestParams,
|
|
1351
|
+
from: requestParams.from,
|
|
1352
|
+
to: earliestTime
|
|
1353
|
+
};
|
|
1354
|
+
const klineResult = await this._requestKlineHistory(
|
|
1355
|
+
this._buildKlineParams(klineParams, countBack)
|
|
1356
|
+
);
|
|
1357
|
+
if (klineResult.bars.length === 0) {
|
|
1358
|
+
return null;
|
|
1359
|
+
}
|
|
1360
|
+
return this._mergeBars(historyResult, klineResult);
|
|
1361
|
+
} catch {
|
|
1362
|
+
return null;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Merge history bars with kline bars
|
|
1367
|
+
* Optimized for the case where klineBars are earlier data than historyBars
|
|
1368
|
+
* Uses direct concatenation when no overlap, otherwise uses two-pointer merge
|
|
1369
|
+
* Assumes both arrays are sorted by time (ascending, earliest first)
|
|
1370
|
+
* Kline data takes precedence when timestamps match
|
|
1371
|
+
* @param historyResult - History result (later time range)
|
|
1372
|
+
* @param klineResult - Kline result (earlier time range)
|
|
1373
|
+
* @returns Merged result with sorted bars
|
|
1374
|
+
*/
|
|
1375
|
+
_mergeBars(historyResult, klineResult) {
|
|
1376
|
+
const historyBars = historyResult.bars;
|
|
1377
|
+
const klineBars = klineResult.bars;
|
|
1378
|
+
if (historyBars.length === 0) {
|
|
1379
|
+
return klineResult;
|
|
1380
|
+
}
|
|
1381
|
+
if (klineBars.length === 0) {
|
|
1382
|
+
return historyResult;
|
|
1383
|
+
}
|
|
1384
|
+
const latestKlineTime = klineBars[klineBars.length - 1].time;
|
|
1385
|
+
const earliestHistoryTime = historyBars[0].time;
|
|
1386
|
+
let mergedBars;
|
|
1387
|
+
if (latestKlineTime < earliestHistoryTime) {
|
|
1388
|
+
mergedBars = [...klineBars, ...historyBars];
|
|
1389
|
+
} else if (latestKlineTime === earliestHistoryTime) {
|
|
1390
|
+
mergedBars = [...klineBars, ...historyBars.slice(1)];
|
|
1391
|
+
} else {
|
|
1392
|
+
mergedBars = [];
|
|
1393
|
+
let historyIdx = 0;
|
|
1394
|
+
let klineIdx = 0;
|
|
1395
|
+
while (historyIdx < historyBars.length && klineIdx < klineBars.length) {
|
|
1396
|
+
const historyBar = historyBars[historyIdx];
|
|
1397
|
+
const klineBar = klineBars[klineIdx];
|
|
1398
|
+
if (historyBar.time < klineBar.time) {
|
|
1399
|
+
mergedBars.push(historyBar);
|
|
1400
|
+
historyIdx++;
|
|
1401
|
+
} else if (historyBar.time > klineBar.time) {
|
|
1402
|
+
mergedBars.push(klineBar);
|
|
1403
|
+
klineIdx++;
|
|
1404
|
+
} else {
|
|
1405
|
+
mergedBars.push(klineBar);
|
|
1406
|
+
historyIdx++;
|
|
1407
|
+
klineIdx++;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
while (historyIdx < historyBars.length) {
|
|
1411
|
+
mergedBars.push(historyBars[historyIdx++]);
|
|
1412
|
+
}
|
|
1413
|
+
while (klineIdx < klineBars.length) {
|
|
1414
|
+
mergedBars.push(klineBars[klineIdx++]);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
const meta = {
|
|
1418
|
+
noData: klineResult.meta.noData && historyResult.meta.noData,
|
|
1419
|
+
nextTime: klineResult.meta.nextTime ?? historyResult.meta.nextTime
|
|
1420
|
+
};
|
|
1421
|
+
return {
|
|
1422
|
+
bars: mergedBars,
|
|
1423
|
+
meta
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1305
1426
|
async _tryKlineFallback(requestParams, countBack) {
|
|
1306
1427
|
try {
|
|
1307
1428
|
const result = await this._requestKlineHistory(
|
|
@@ -2467,6 +2588,8 @@ var limitOrdersByInterval = (orders, interval) => {
|
|
|
2467
2588
|
});
|
|
2468
2589
|
return res;
|
|
2469
2590
|
};
|
|
2591
|
+
|
|
2592
|
+
// src/tradingviewAdapter/renderer/execution.service.ts
|
|
2470
2593
|
var ExecutionService = class _ExecutionService {
|
|
2471
2594
|
constructor(instance, broker) {
|
|
2472
2595
|
this.interval = "1D";
|
|
@@ -2525,7 +2648,8 @@ var ExecutionService = class _ExecutionService {
|
|
|
2525
2648
|
try {
|
|
2526
2649
|
this.instance.activeChart().onIntervalChanged().unsubscribe(null, changeInterval);
|
|
2527
2650
|
} catch (e) {
|
|
2528
|
-
|
|
2651
|
+
const errorString = e?.toString() || String(e);
|
|
2652
|
+
if (errorString.includes("tradingViewApi") || errorString.includes("Cannot read properties of null") || errorString.includes("Cannot read property") || e instanceof TypeError && errorString.includes("null")) ;
|
|
2529
2653
|
}
|
|
2530
2654
|
}
|
|
2531
2655
|
destroy() {
|
|
@@ -2648,9 +2772,31 @@ var _OrderLineService = class _OrderLineService {
|
|
|
2648
2772
|
orderLine.remove();
|
|
2649
2773
|
}
|
|
2650
2774
|
}
|
|
2775
|
+
/**
|
|
2776
|
+
* Creates a base order line with default styling.
|
|
2777
|
+
* Returns null if the chart is not ready (e.g., during initialization, hot reload, or chart switching).
|
|
2778
|
+
*
|
|
2779
|
+
* @returns IOrderLineAdapter instance or null if chart is not available
|
|
2780
|
+
*/
|
|
2651
2781
|
getBaseOrderLine() {
|
|
2652
|
-
|
|
2653
|
-
|
|
2782
|
+
try {
|
|
2783
|
+
const activeChart = this.instance.activeChart();
|
|
2784
|
+
if (!activeChart) {
|
|
2785
|
+
return null;
|
|
2786
|
+
}
|
|
2787
|
+
const colorConfig = this.broker.colorConfig;
|
|
2788
|
+
const orderLine = activeChart.createOrderLine();
|
|
2789
|
+
if (!orderLine) {
|
|
2790
|
+
return null;
|
|
2791
|
+
}
|
|
2792
|
+
return orderLine.setCancelTooltip(i18n.i18n.t("orders.cancelOrder")).setQuantityTextColor(colorConfig.qtyTextColor).setQuantityBackgroundColor(colorConfig.chartBG).setBodyBackgroundColor(colorConfig.chartBG).setCancelButtonBackgroundColor(colorConfig.chartBG).setLineStyle(1).setBodyFont(colorConfig.font).setQuantityFont(colorConfig.font);
|
|
2793
|
+
} catch (e) {
|
|
2794
|
+
const errorString = e?.toString() || String(e);
|
|
2795
|
+
if (errorString.includes("Value is null") || errorString.includes("tradingViewApi") || errorString.includes("Cannot read properties of null") || errorString.includes("Cannot read property") || e instanceof TypeError && errorString.includes("null")) {
|
|
2796
|
+
return null;
|
|
2797
|
+
}
|
|
2798
|
+
throw e;
|
|
2799
|
+
}
|
|
2654
2800
|
}
|
|
2655
2801
|
static getCombinationType(order) {
|
|
2656
2802
|
const { algo_type: algoType, type } = order;
|
|
@@ -2732,7 +2878,11 @@ var _OrderLineService = class _OrderLineService {
|
|
|
2732
2878
|
return null;
|
|
2733
2879
|
}
|
|
2734
2880
|
const colorConfig = this.broker.colorConfig;
|
|
2735
|
-
const
|
|
2881
|
+
const existingOrderLine = this.pendingOrderLineMap.get(orderId);
|
|
2882
|
+
const orderLine = existingOrderLine ?? this.getBaseOrderLine();
|
|
2883
|
+
if (!orderLine) {
|
|
2884
|
+
return null;
|
|
2885
|
+
}
|
|
2736
2886
|
const color = pendingOrder.side === "BUY" /* BUY */ ? colorConfig.upColor : colorConfig.downColor;
|
|
2737
2887
|
pendingOrder.side === "BUY" /* BUY */ ? colorConfig.pnlUpColor : colorConfig.pnlDownColor;
|
|
2738
2888
|
const price = _OrderLineService.getOrderPrice(pendingOrder);
|
|
@@ -4370,5 +4520,5 @@ var TradingviewWidget = React3.forwardRef((props, ref) => {
|
|
|
4370
4520
|
exports.TradingviewUI = TradingviewUI;
|
|
4371
4521
|
exports.TradingviewWidget = TradingviewWidget;
|
|
4372
4522
|
exports.useTradingviewScript = useTradingviewScript;
|
|
4373
|
-
//# sourceMappingURL=
|
|
4523
|
+
//# sourceMappingURL=index.js.map
|
|
4374
4524
|
//# sourceMappingURL=index.js.map
|