data.local
data.local
Local file loading and saving (parquet, csv, …) plus raw trade aggregation from cached files.
Functions
| Name | Description |
|---|---|
| load | Load a local data file into a DataFrame. |
| load_ohlc_timeseries_range | Load daily trade CSV files and aggregate them into OHLC bars. |
| save | Save a DataFrame to a local file. |
load
data.local.load(path, index=None)Load a local data file into a DataFrame.
Dispatches on the file suffix: .parquet is read via DuckDB (see :func:~qrt.data.sources._util.cached for why), .csv via pandas.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| path | str | Path | File to load. | required |
| index | str | None | Column to set as the index, if any. | None |
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | The loaded DataFrame. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the file suffix isn’t .parquet or .csv. |
load_ohlc_timeseries_range
data.local.load_ohlc_timeseries_range(
sym,
time_interval,
start_date,
end_date,
data_path='./cache',
)Load daily trade CSV files and aggregate them into OHLC bars.
Expects daily files named like {sym}-trades-YYYY-MM-DD.csv, e.g. BTCUSDT-trades-2025-09-22.csv, containing at least a datetime and a price column. A qty column, if present, is summed into a volume column.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| sym | str | Symbol prefix (e.g. "BTCUSDT"). |
required |
| time_interval | str | Pandas offset alias (e.g. "1h", "5min"). |
required |
| start_date | datetime | Start datetime (inclusive). | required |
| end_date | datetime | End datetime (inclusive). | required |
| data_path | str | Path | Directory containing the cached trade CSV files. | './cache' |
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | DataFrame indexed by datetime with columns |
|
| pd.DataFrame | open, high, low, close (and volume if available). |
save
data.local.save(df, path, index=False)Save a DataFrame to a local file.
Dispatches on the file suffix: .parquet is written via DuckDB, .csv via pandas.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| df | pd.DataFrame | DataFrame to save. | required |
| path | str | Path | Destination file. Parent directories are created if needed. | required |
| index | bool | Whether to keep the DataFrame index as a leading column. | False |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the file suffix isn’t .parquet or .csv. |