LiveBlocking::NextRecord
Blocks until the next record is received or the optional timeout is reached. It's an error to call this method before Start.
Parameters
| Parameter | Type | Description |
|---|---|---|
timeout | std::chrono::milliseconds | The maximum time to wait for a record. |
Returns
A reference to the Record or a pointer if a timeout was specified.
nullptr indicates the timeout was reached and no record was received.
Warning
The returned reference or pointer is only valid until the next call to NextRecord.
Copy the record or relevant fields to persist data across calls to NextRecord.
A full list of fields returned for each schema is available in the
list of fields by schema or the struct definitions in
<databento/record.hpp>.
API method
const Record& NextRecord();
const Record* NextRecord(std::chrono::milliseconds timeout); Example usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <chrono>
#include <databento/live.hpp>
#include <iostream>
using namespace databento;
auto client = LiveBlocking::Builder()
.SetKey("$YOUR_API_KEY")
.SetDataset("IFEU.IMPACT")
.BuildBlocking();
client.Subscribe({"BRN.FUT"}, Schema::Trades, SType::Parent);
client.Start();
while (true) {
auto* record = client.NextRecord(std::chrono::seconds{5});
if (record == nullptr) {
std::cout << "Timed out waiting for trade\n";
break;
}
if (auto* trade = record->GetIf<TradeMsg>()) {
std::cout << *trade << '\n';
break;
}
} Example response
1 2 3 4 5 6 7 8 9 10 11 12
TradeMsg {
hd = RecordHeader { length = 12, rtype = Mbp0, publisher_id = 57, instrument_id = 5884689, ts_event = 2025-02-07T15:41:12.826163003Z },
price = 74.820000000,
size = 1,
action = Trade,
side = Bid,
flags = MAYBE_BAD_BOOK (4),
depth = 0,
ts_recv = 2025-02-07T15:41:12.826833855Z,
ts_in_delta = 321855,
sequence = 40335981
}