Skip to content

@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

ParameterTypeDefault valueDescription
barsreadonly Bar[]undefinedSource OHLCV bars in chronological order.
fieldBarField'close'Which OHLCV field to extract. Defaults to 'close'.

Returns

Series

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');

Released under the MIT License.