Historical::TimeseriesGetRangeToFile
Make a streaming request for time series data from Databento.
Primary method for getting historical intraday and daily market data, instrument definitions, and market status data directly into your application.
Data is streamed directly to the file at file_path.
If the file at file_path already exists, it will be overwritten.
Parameters
| Parameter | Type | Description |
|---|---|---|
dataset | std::string | The dataset code (string identifier). Must be one of the values from MetadataListDatasets. Constants are provided in the databento::dataset namespace in <databento/constants.hpp>. |
datetime_range | databento::DateTimeRange<UnixNanos> or databento::DateTimeRange<std::string> | The request range with an inclusive start and an optional exclusive end. Filters on ts_recv if it exists in the schema, otherwise ts_event. Takes an ISO 8601 string or a UNIX timestamp in nanoseconds. Assumes UTC as timezone unless otherwise specified. If not specified, end defaults to the forward filled value of start based on the resolution provided. |
symbols | std::vector<std::string> | The product symbols to filter for. Takes up to 2,000 symbols per request. Use databento::kAllSymbols from <databento/symbology.hpp> to request all symbols. |
schema | databento::Schema | The data record schema. Must be one of the values from MetadataListSchemas. |
stype_in | databento::SType | |
stype_out | databento::SType | The symbology type of output symbols. Defaults to InstrumentId. Must be a valid symbology combination with stype_in. See symbology combinations. |
limit | std::uint64_t | The maximum number of records to return. Use 0 or {} for no limit. Defaults to no limit. |
file_path | std::filesystem::path | The path of the file where the data should be saved. If the file already exists, it will be overwritten. It is recommended to use the ".dbn.zst" suffix. |
Returns
A DbnStore object.
A full list of fields for the records read through NextRecord
or Replay for each schema is available through
Historical.MetadataListFields
or the struct definitions in <databento/record.hpp>.
API method
DbnStore TimeseriesGetRangeToFile(
const std::string& dataset,
const DateTimeRange<UnixNanos>& datetime_range,
const std::vector<std::string>& symbols, Schema schema,
const std::filesystem::path& file_path);
DbnStore TimeseriesGetRangeToFile(
const std::string& dataset,
const DateTimeRange<std::string>& datetime_range,
const std::vector<std::string>& symbols, Schema schema,
const std::filesystem::path& file_path);
DbnStore TimeseriesGetRangeToFile(
const std::string& dataset,
const DateTimeRange<UnixNanos>& datetime_range,
const std::vector<std::string>& symbols, Schema schema,
SType stype_in, SType stype_out, std::uint64_t limit,
const std::filesystem::path& file_path);
DbnStore TimeseriesGetRangeToFile(
const std::string& dataset,
const DateTimeRange<std::string>& datetime_range,
const std::vector<std::string>& symbols, Schema schema,
SType stype_in, SType stype_out, std::uint64_t limit,
const std::filesystem::path& file_path); Example usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <databento/historical.hpp>
#include <iostream>
using namespace databento;
auto client =
Historical::Builder().SetKey("$YOUR_API_KEY").Build();
auto file_bento = client.TimeseriesGetRangeToFile(
"GLBX.MDP3", {"2022-06-06T00:00", "2022-06-10T00:10"},
{"ESM2"}, Schema::Trades, SType::RawSymbol,
SType::InstrumentId, 1, "ESM2_20220606-20220610.dbn.zst");
file_bento.Replay([](const Record& record) {
// Convert the generic `Record` to a `TradeMsg`, the
// record type associated with `Schema::Trades`
const auto& trade_msg = record.Get<TradeMsg>();
std::cout << trade_msg << '\n';
return KeepGoing::Continue;
}); Example response
1 2 3 4 5 6 7 8 9 10 11 12
TradeMsg {
hd = RecordHeader { length = 12, rtype = mbp-0, publisher_id = 1, instrument_id = 3403, ts_event = 2022-06-06T00:00:00.070033767Z },
price = 4108.500000000,
size = 1,
action = Trade,
side = Ask,
flags = 0,
depth = 0,
ts_recv = 2022-06-06T00:00:00.070314216Z,
ts_in_delta = 18681,
sequence = 157862
}