fetchData
Fetches historical market data (klines/candlesticks) from a data provider and populates a time series.Function Signature
Parameters
Data source provider:
Source.yfinance or Source.binanceBase time series object to populate with fetched kline data
Symbol/ticker to fetch (e.g., “BTCUSDT” for Binance, “AAPL” for Yahoo Finance)
Timeframe object specifying the interval (e.g., 1m, 5m, 1h, 1d)
Timezone string for time calculations (e.g., “America/New_York”, “UTC”)
Starting timestamp in milliseconds. If not provided, defaults to
limit periods back from now.Maximum number of klines to fetch. If not provided, defaults to provider-specific limits.
Return Value
Returns a promise that resolves to the timestamp of the latest kline fetched, or
undefined if no data was fetched.Example Usage
Data Processing
- Fetches klines from the specified provider
- Sorts klines chronologically by open time
- Removes any duplicate klines
- Creates
Klineobjects and adds them tobaseSerusingKVAR_NAME(“kline”) - Returns the timestamp of the latest kline
Fallback Behavior
If the provider fetch fails or returns no data, the function attempts to load data from a local./klines.json file.
Source: DataFecther.ts:13-35
fetchSymbolList
Fetches a list of available symbols/tickers from a data provider, filtered by search text.Function Signature
Parameters
Data source provider:
Source.yfinance or Source.binanceSearch/filter text to match against symbol names (e.g., “BTC”, “AAPL”)
Fetch API initialization options (for request cancellation, headers, etc.)
Return Value
Returns a promise that resolves to an array of objects, each containing a
ticker property with the symbol name.Example Usage
Use Cases
- Symbol search/autocomplete in trading interfaces
- Building watchlists
- Symbol validation before fetching data
DataFecther.ts:120-139
Source Enum
Enumeration of supported data providers.Values
Yahoo Finance - supports stocks, ETFs, indices, forex, cryptocurrencies
Binance - cryptocurrency exchange data
Example
DataFecther.ts:8-11
Kline Class
Represents a single candlestick/kline with OHLCV (Open-High-Low-Close-Volume) data.Constructor
Properties
Primary timestamp for this kline (milliseconds)
Opening price
Highest price during the period
Lowest price during the period
Closing price
Trading volume during the period
Timestamp when the kline period opened (milliseconds)
Timestamp when the kline period closed (milliseconds)
Whether this kline is complete (closed) or still forming (real-time)
Getter that returns the close price (for compatibility with TVal)
Methods
Updates a real-time kline with a new price tick and volume.
- Updates
highif the new value is higher - Updates
lowif the new value is lower - Sets
closeto the new value - Adds
amountto cumulativevolume
this (for method chaining)Source: Kline.ts:43-50Marks the kline as closed/completed.Returns:
this (for method chaining)Source: Kline.ts:52-56Serializes the kline to a JSON object.Returns: Object with properties:
time, open, high, low, close, volume, isClosedSource: Kline.ts:58-68Example Usage
Constant
The variable name used to store klines in time series:
"kline"Source: Kline.ts:4Kline.ts:6-71
Provider-Specific Notes
Binance Provider
- Uses the
pinetslibrary’s Binance provider - Supports cryptocurrency pairs (e.g., BTCUSDT, ETHUSDT)
- Timeframe conversion: VibeTrader timeframes are mapped to Binance/pinets equivalents
- Data includes: open, high, low, close, volume, openTime, closeTime
DataFecther.ts:49-86
Yahoo Finance Provider
- Supports stocks, ETFs, indices, forex, and cryptocurrencies
- Ticker format: Standard Yahoo Finance symbols (e.g., “AAPL”, “^GSPC”)
- Timestamps are converted to Unix seconds for the Yahoo Finance API
- Data includes: time, open, high, low, close, volume
DataFecther.ts:88-117
Timeframe Handling
Both providers automatically calculate the start time based on:- The specified
limit(number of klines) - The
tframe(timeframe interval) - The
tzone(timezone)
startTime is provided, it overrides the calculated value.
Error Handling
If the remote provider fetch fails, the system attempts to load data from a local./klines.json file as a fallback. This is useful for development and offline testing.
Source: DataFecther.ts:37-47