MCPcopy Create free account
hub / github.com/chart-kit/react-native-chart-kit-example / aggregateCandles

Function aggregateCandles

src/fixtures/v2Finance.ts:81–103  ·  view source on GitHub ↗
(
  candles: StockCandlePoint[],
  getGroupKey: (day: string) => string
)

Source from the content-addressed store, hash-verified

79};
80
81const aggregateCandles = (
82 candles: StockCandlePoint[],
83 getGroupKey: (day: string) => string
84) => {
85 const groups: StockCandlePoint[] = [];
86
87 candles.forEach((candle) => {
88 const key = getGroupKey(candle.day);
89 const last = groups[groups.length - 1];
90
91 if (!last || getGroupKey(last.day) !== key) {
92 groups.push({ ...candle, day: key });
93 return;
94 }
95
96 last.close = candle.close;
97 last.high = Math.max(last.high, candle.high);
98 last.low = Math.min(last.low, candle.low);
99 last.volume += candle.volume;
100 });
101
102 return groups;
103};
104
105export const getStockCandlesForInterval = (
106 candles: StockCandlePoint[],

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected