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. 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.

Parameters

Parameter
Type
Description
key
std::string
32-character API key. Found on your API keys page.
dataset
Dataset or 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>.
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. 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 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 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.
API method
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();
};
Example usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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();