Загрузка данных


public setState(state: unknown): void {
  if (!state || typeof state !== 'object') {
    return;
  }

  const next = state as Partial<SliderPositionState>;
  const {
    hidden = this.hidden,
    mode = this.mode,
    startTime = this.startTime,
    endTime = this.endTime,
    entryPrice = this.entryPrice,
  } = next;

  this.hidden = hidden;
  this.mode = mode;
  this.startTime = startTime;
  this.endTime = endTime;
  this.entryPrice = entryPrice;

  if (next.stopPrice !== undefined) {
    this.stopPrice =
      next.stopPrice === null || entryPrice === null
        ? next.stopPrice
        : this.normalizeStop(entryPrice, next.stopPrice);
  }

  if (next.targetPrice !== undefined) {
    this.targetPrice =
      next.targetPrice === null || entryPrice === null
        ? next.targetPrice
        : this.normalizeTarget(entryPrice, next.targetPrice);
  } else if (
    entryPrice !== null &&
    this.stopPrice !== null &&
    typeof next.riskRewardRatio === 'number' &&
    next.riskRewardRatio >= 0
  ) {
    const risk = Math.abs(entryPrice - this.stopPrice);
    const direction = this.side === 'long' ? 1 : -1;

    this.targetPrice = this.normalizeTarget(
      entryPrice,
      entryPrice + risk * next.riskRewardRatio * direction,
    );
  }

  if (next.settings) {
    this.settings = {
      ...createDefaultSettings(),
      ...next.settings,
    };
  }

  if (typeof next.amount === 'number' && next.amount >= 0) {
    this.settings.accountSize = next.amount;
  }

  this.render();
}