INNER CODE UNIT · TypeScript
randomChange
alexanderwanyoike/the0 · example-bots/typescript-price-alerts/main.ts:186
const randomChange = (Math.random() - 0.5) * 2 * volatility;
const reversion =
((basePrice - state.lastPrice) / basePrice) * meanReversion;
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,
};