@livefolio/sdk / barsToSeries
Function: barsToSeries()
barsToSeries(
bars,field?):Series
Defined in: features/series-utils.ts:60
Converts an array of OHLCV bars into a Series by extracting a single numeric field from each bar.
The resulting Series is a readonly array of { t: Date; v: number } points in the same order as bars. The timestamp t is taken directly from bar.t, and v is the value of field for that bar.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
bars | readonly Bar[] | undefined | Source OHLCV bars in chronological order. |
field | BarField | 'close' | Which OHLCV field to extract. Defaults to 'close'. |
Returns
A Series of the same length as bars. Returns an empty array when bars is empty.
Example
ts
import { collectBars, barsToSeries } from '@livefolio/sdk';
const bars = await collectBars(dataFeed.bars(asset, range, '1d'));
const closeSeries = barsToSeries(bars); // default: 'close'
const volumeSeries = barsToSeries(bars, 'volume');