forked from databento/databento-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive.hpp
More file actions
78 lines (65 loc) · 2.32 KB
/
live.hpp
File metadata and controls
78 lines (65 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include <chrono>
#include <cstddef>
#include <string>
#include "databento/enums.hpp" // VersionUpgradePolicy
#include "databento/live_blocking.hpp"
#include "databento/live_threaded.hpp"
#include "databento/publishers.hpp"
namespace databento {
// Forward declarations
class ILogReceiver;
// A helper class for constructing a Live client, either an instance of
// LiveBlocking or LiveThreaded.
class LiveBuilder {
public:
LiveBuilder();
/*
* Required settters
*/
// Sets `key_` based on the environment variable DATABENTO_API_KEY.
//
// NOTE: This is not thread-safe if `std::setenv` is used elsewhere in the
// program.
LiveBuilder& SetKeyFromEnv();
LiveBuilder& SetKey(std::string key);
LiveBuilder& SetDataset(Dataset dataset);
LiveBuilder& SetDataset(std::string dataset);
/*
* Optional settters
*/
// Whether to append the gateway send timestamp after each DBN message.
LiveBuilder& SetSendTsOut(bool send_ts_out);
// Set the version upgrade policy for when receiving DBN data from a prior
// version. Defaults to upgrading to DBNv2 (if not already).
LiveBuilder& SetUpgradePolicy(VersionUpgradePolicy upgrade_policy);
// Sets the receiver of the logs to be used by the client.
LiveBuilder& SetLogReceiver(ILogReceiver* log_receiver);
// Overrides the heartbeat interval.
LiveBuilder& SetHeartbeatInterval(std::chrono::seconds heartbeat_interval);
// Overrides the gateway and port. This is an advanced method.
LiveBuilder& SetAddress(std::string gateway, std::uint16_t port);
// Overrides the size of the buffer used for reading data from the TCP socket.
LiveBuilder& SetBufferSize(std::size_t size);
/*
* Build a live client instance
*/
// Attempts to construct an instance of a blocking live client or throws an
// exception.
LiveBlocking BuildBlocking();
// Attempts to construct an instance of a threaded live client or throws an
// exception.
LiveThreaded BuildThreaded();
private:
void Validate();
ILogReceiver* log_receiver_{};
std::string gateway_{};
std::uint16_t port_{};
std::string key_;
std::string dataset_;
bool send_ts_out_{false};
VersionUpgradePolicy upgrade_policy_{VersionUpgradePolicy::UpgradeToV3};
std::optional<std::chrono::seconds> heartbeat_interval_{};
std::size_t buffer_size_;
};
} // namespace databento