INNER CODE UNIT · TypeScript

changePercent

alexanderwanyoike/the0 · example-bots/typescript-price-alerts/main.ts:189

  const changePercent = randomChange + reversion;

  const newPrice = state.lastPrice * (1 + changePercent);
  const changePct = ((newPrice - state.lastPrice) / state.lastPrice) * 100;

  const high24h = Math.max(...state.priceHistory, newPrice);
  const low24h = Math.min(...state.priceHistory, newPrice);

  return {
    symbol,
    value: Math.round(newPrice * 100) / 100,
    change_pct: Math.round(changePct * 1000) / 1000,
    high_24h: Math.round(high24h * 100) / 100,
    low_24h: Math.round(low24h * 100) / 100,
  };
}

/**

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…