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

Source: https://databento.com/docs/api-live/client/live-threaded


### LiveThreaded

To access Databento's live threaded API, first create an instance of the `LiveThreaded` client through the `LiveBuilder` class.
The entire API is exposed through methods of the client.
Note that each instance of the live client is associated with a single dataset.

Note that the API key can be passed as an argument to `SetKey()`, which is [not recommended for production applications](https://databento.com/docs/portal/api-keys.md#securing-your-api-keys).
Instead, you can use the `SetKeyFromEnv()` method which reads from the `DATABENTO_API_KEY` environment variable.
When you've finished configuring the client, call `BuildThreaded()` to obtain an instance of `LiveClient` from the builder.

#### API method

```cpp
class LiveBuilder {
 public:
  // Required
  LiveBuilder& SetKeyFromEnv();
  LiveBuilder& SetKey(std::string key);
  LiveBuilder& SetDataset(Dataset dataset);
  LiveBuilder& SetDataset(std::string dataset);

  // Optional
  LiveBuilder& SetSendTsOut(bool send_ts_out);
  LiveBuilder& SetUpgradePolicy(
      VersionUpgradePolicy upgrade_policy);
  LiveBuilder& SetLogReceiver(ILogReceiver* log_receiver);
  LiveBuilder& SetHeartbeatInterval(
      std::chrono::seconds heartbeat_interval);
  LiveBuilder& SetBufferSize(std::size_t size);
  LiveBuilder& SetCompression(Compression compression);
  LiveBuilder& SetSlowReaderBehavior(
      SlowReaderBehavior slow_reader_behavior);
  LiveBuilder& SetTimeoutConf(TimeoutConf timeout_conf);

  LiveThreaded BuildThreaded();
};
```

#### Parameters

| Parameter | Type | Description |
| `key` | std::string | 32-character API key. Found on your [API keys]($PLATFORM_HOSTNAME/portal/keys) page. |
| `dataset` | Dataset or std::string | The [dataset](https://databento.com/docs/api-historical/basics/datasets.md) code (string identifier). Must be one of the values from [MetadataListDatasets](https://databento.com/docs/api-historical/metadata/metadata-list-datasets.md). Constants are provided in the `databento::dataset` namespace in ``. |
| `send_ts_out` | bool | Whether the gateway should append the send timestamp (`ts_out`) to each record. Use with the `WithTsOut` struct. Disabled by default. |
| `upgrade_policy` | VersionUpgradePolicy | How to handle records from previous DBN versions. By default, records from DBN versions 1 and 2 are upgraded to version 3. |
| `log_receiver` | ILogReceiver\* | Non-null, non-owning pointer to a [log receiver](https://databento.com/docs/api-historical/helpers/ilog-receiver.md). If you wish to disable logging, pass a `NullLogReceiver`. By default it will use `ILogReceiver::Default()` which will log Info level and above messages to standard error. |
| `heartbeat_interval` | std::chrono::seconds | Overrides the interval at which [heartbeats records](https://databento.com/docs/api-live/basics/system-messages.md) will be sent. If the default-constructed value is passed, the gateway's default heartbeat interval will be used. Must be between 5 and 1800 seconds. |
| `buffer_size` | std::size_t | Sets the size of the buffer used for reading data from the TCP socket. |
| `compression` | Compression | Sets the [compression](https://databento.com/docs/api-live/basics/compression.md) mode for the read stream. Uncompressed by default. |
| `slow_reader_behavior` | SlowReaderBehavior | How the gateway should handle a connection unable to keep up with realtime. |
| `timeout_conf` | TimeoutConf | Timeouts for connecting and authenticating with the gateway. `connect` defaults to 10 seconds, `auth` defaults to 30 seconds. |

#### Example usage

```cpp
#include <databento/enums.hpp>
#include <databento/live.hpp>
#include <databento/log.hpp>

using namespace databento;

// Pass as an argument
auto client1 = LiveThreaded::Builder()
                   .SetKey("$YOUR_API_KEY")
                   .SetDataset(Dataset::EqusMini)
                   .BuildThreaded();
// Or, pass as `DATABENTO_API_KEY` environment variable
auto client2 = LiveThreaded::Builder()
                   .SetKeyFromEnv()
                   .SetDataset(Dataset::EqusMini)
                   .BuildThreaded();
```
