@forgecharts/sdk 1.5.53 → 1.5.55

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/internal.js CHANGED
@@ -483,9 +483,17 @@ var TimeScale = class {
483
483
  const toIdx = this.timeToIndex(this._visibleRange.to);
484
484
  const idxSpan = toIdx - fromIdx;
485
485
  const idxStep = Math.max(1, Math.round(idxSpan / approxTicks));
486
- const span = this._visibleRange.to - this._visibleRange.from;
487
- const step = this._niceTimeStep(span / approxTicks);
488
486
  const startIdx = Math.ceil(fromIdx / idxStep) * idxStep;
487
+ const _tickDeltas = [];
488
+ for (let i = Math.max(0, startIdx); i + idxStep <= Math.min(toIdx, this._barTimes.length - 1); i += idxStep) {
489
+ const a = this._barTimes[Math.round(i)];
490
+ const b = this._barTimes[Math.round(i + idxStep)];
491
+ if (a != null && b != null && b > a) _tickDeltas.push(b - a);
492
+ if (_tickDeltas.length >= 12) break;
493
+ }
494
+ _tickDeltas.sort((p, q) => p - q);
495
+ const _perTick = _tickDeltas.length > 0 ? _tickDeltas[Math.floor(_tickDeltas.length / 2)] : (this._visibleRange.to - this._visibleRange.from) / approxTicks;
496
+ const step = this._niceTimeStep(_perTick);
489
497
  for (let i = startIdx; i <= toIdx; i += idxStep) {
490
498
  const bIdx = Math.round(i);
491
499
  if (bIdx < 0) continue;
@@ -5795,8 +5803,16 @@ var PixiGridRenderer = class {
5795
5803
  const idxStep = Math.max(1, Math.round(rawIdxStep));
5796
5804
  const barTimes = this._timeScale.barTimes;
5797
5805
  const startIdx = Math.ceil(fromIdx / idxStep) * idxStep;
5798
- const span = timeTo - timeFrom;
5799
- const step = this._niceTimeStep(span / approxTicks);
5806
+ const _tickDeltas = [];
5807
+ for (let i = Math.max(0, startIdx); i + idxStep <= Math.min(toIdx, barTimes.length - 1); i += idxStep) {
5808
+ const a = barTimes[Math.round(i)];
5809
+ const b = barTimes[Math.round(i + idxStep)];
5810
+ if (a != null && b != null && b > a) _tickDeltas.push(b - a);
5811
+ if (_tickDeltas.length >= 12) break;
5812
+ }
5813
+ _tickDeltas.sort((p, q) => p - q);
5814
+ const _perTick = _tickDeltas.length > 0 ? _tickDeltas[Math.floor(_tickDeltas.length / 2)] : (timeTo - timeFrom) / approxTicks;
5815
+ const step = this._niceTimeStep(_perTick);
5800
5816
  for (let i = startIdx; i <= toIdx; i += idxStep) {
5801
5817
  const bIdx = Math.round(i);
5802
5818
  if (bIdx < 0) continue;
@@ -10354,6 +10370,29 @@ function _historyWindow(tf) {
10354
10370
  return 500 * (parseTfSeconds(tf) ?? 3600);
10355
10371
  }
10356
10372
  var BATCH_SUPPRESSION_MS = 1e4;
10373
+ var TF_SECONDS = {
10374
+ "1s": 1,
10375
+ "5s": 5,
10376
+ "10s": 10,
10377
+ "15s": 15,
10378
+ "30s": 30,
10379
+ "1m": 60,
10380
+ "3m": 180,
10381
+ "5m": 300,
10382
+ "15m": 900,
10383
+ "30m": 1800,
10384
+ "1h": 3600,
10385
+ "2h": 7200,
10386
+ "4h": 14400,
10387
+ "6h": 21600,
10388
+ "8h": 28800,
10389
+ "12h": 43200,
10390
+ "1D": 86400,
10391
+ "3D": 259200,
10392
+ "1W": 604800,
10393
+ "1M": 2592e3
10394
+ };
10395
+ var LIVE_GAP_REPAIR_DELAY_MS = 3e3;
10357
10396
  function _pageSize(tf) {
10358
10397
  return 500 * (parseTfSeconds(tf) ?? 3600);
10359
10398
  }
@@ -10481,15 +10520,36 @@ var DatafeedConnector = class {
10481
10520
  this._batchSafetyTimer = null;
10482
10521
  }, BATCH_SUPPRESSION_MS);
10483
10522
  }
10523
+ const tfSec = TF_SECONDS[timeframe] ?? 0;
10524
+ let lastSeenBarTime = lastBarTime ?? 0;
10525
+ let repairTimer = null;
10526
+ const repairGap = (fromTime, toTime) => {
10527
+ if (repairTimer) clearTimeout(repairTimer);
10528
+ repairTimer = setTimeout(() => {
10529
+ repairTimer = null;
10530
+ if (this._activeUID !== uid || this._destroyed) return;
10531
+ void this._datafeed.getHistoricalBars(symbol, timeframe, fromTime, toTime).then(({ bars: filled }) => {
10532
+ if (this._activeUID !== uid || filled.length === 0) return;
10533
+ engine.backfillGap(filled);
10534
+ }).catch(() => {
10535
+ });
10536
+ }, LIVE_GAP_REPAIR_DELAY_MS);
10537
+ };
10484
10538
  this._datafeed.subscribeBars(symbol, timeframe, (bar) => {
10485
- if (this._activeUID === uid) {
10486
- engine.applyLiveUpdate(bar);
10539
+ if (this._activeUID !== uid) return;
10540
+ const t = bar.time;
10541
+ if (tfSec > 0 && lastSeenBarTime > 0 && t > lastSeenBarTime + tfSec) {
10542
+ repairGap(lastSeenBarTime, t);
10487
10543
  }
10544
+ if (t > lastSeenBarTime) lastSeenBarTime = t;
10545
+ engine.applyLiveUpdate(bar);
10488
10546
  }, uid, lastBarTime, (bars) => {
10489
10547
  this._clearBatchTimer();
10490
10548
  batchPending = false;
10491
10549
  if (this._activeUID === uid) {
10492
10550
  engine.backfillGap(bars);
10551
+ const newest = bars.length > 0 ? bars[bars.length - 1].time : 0;
10552
+ if (newest > lastSeenBarTime) lastSeenBarTime = newest;
10493
10553
  }
10494
10554
  fireLoaded();
10495
10555
  });
@@ -25526,7 +25586,7 @@ var demonstrationTool = {
25526
25586
  };
25527
25587
 
25528
25588
  // src/version.ts
25529
- var FORGECHARTS_VERSION = "1.5.53" ;
25589
+ var FORGECHARTS_VERSION = "1.5.55" ;
25530
25590
 
25531
25591
  // src/compatibility.ts
25532
25592
  var MIN_KIT_API = 1;