Available languages: [Python](https://databento.com/docs/api-live/client/live-blocking-next-record.python.md) · [C++](https://databento.com/docs/api-live/client/live-blocking-next-record.cpp.md) · [Rust](https://databento.com/docs/api-live/client/live-blocking-next-record.rust.md) · [Raw](https://databento.com/docs/api-live/client/live-blocking-next-record.raw.md)

Source: https://databento.com/docs/api-live/client/live-blocking-next-record


### 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](https://databento.com/docs/api-live/client/live-blocking-start.md).

#### API method

```cpp
const Record& NextRecord();
const Record* NextRecord(std::chrono::milliseconds timeout);
```

#### 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](https://databento.com/docs/schemas/whats-a-schema.md) or the struct definitions in
`<databento/record.hpp>`.

#### Example usage

```cpp
#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

```plaintext
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
}
```
