( candles: StockCandlePoint[], getGroupKey: (day: string) => string )
| 79 | }; |
| 80 | |
| 81 | const 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 | |
| 105 | export const getStockCandlesForInterval = ( |
| 106 | candles: StockCandlePoint[], |
no outgoing calls
no test coverage detected