1010#include " databento/datetime.hpp" // DateRange, DateTimeRange, UnixNanos
1111#include " databento/dbn_file_store.hpp"
1212#include " databento/detail/http_client.hpp" // HttpClient
13- #include " databento/enums.hpp" // BatchState, Delivery, DurationInterval, Schema, SType
13+ #include " databento/enums.hpp" // BatchState, Delivery, DurationInterval, Schema, SType, VersionUpgradePolicy
1414#include " databento/metadata.hpp" // DatasetConditionDetail, DatasetRange, FieldDetail, PublisherDetail, UnitPricesForMode
1515#include " databento/symbology.hpp" // SymbologyResolution
1616#include " databento/timeseries.hpp" // KeepGoing, MetadataCallback, RecordCallback
1717
1818namespace databento {
19+ // Forward declarations
20+ class HistoricalBuilder ;
1921class ILogReceiver ;
2022
2123// A client for interfacing with Databento's historical market data API.
2224class Historical {
2325 public:
26+ // WARNING: Will be deprecated in the future in favor of the builder
2427 Historical (ILogReceiver* log_receiver, std::string key,
2528 HistoricalGateway gateway);
26- // Primarily for unit tests
27- Historical (ILogReceiver* log_receiver, std::string key, std::string gateway,
28- std::uint16_t port);
2929
3030 /*
3131 * Getters
@@ -227,8 +227,17 @@ class Historical {
227227 const std::filesystem::path& file_path);
228228
229229 private:
230+ friend HistoricalBuilder;
231+
230232 using HttplibParams = std::multimap<std::string, std::string>;
231233
234+ Historical (ILogReceiver* log_receiver, std::string key,
235+ HistoricalGateway gateway, VersionUpgradePolicy upgrade_policy,
236+ std::string user_agent_ext);
237+ Historical (ILogReceiver* log_receiver, std::string key, std::string gateway,
238+ std::uint16_t port, VersionUpgradePolicy upgrade_policy,
239+ std::string user_agent_ext);
240+
232241 BatchJob BatchSubmitJob (const HttplibParams& params);
233242 void DownloadFile (const std::string& url,
234243 const std::filesystem::path& output_path);
@@ -247,6 +256,8 @@ class Historical {
247256 ILogReceiver* log_receiver_;
248257 const std::string key_;
249258 const std::string gateway_;
259+ const std::string user_agent_ext_;
260+ const VersionUpgradePolicy upgrade_policy_;
250261 detail::HttpClient client_;
251262};
252263
@@ -255,22 +266,43 @@ class HistoricalBuilder {
255266 public:
256267 HistoricalBuilder () = default ;
257268
269+ /*
270+ * Required setters
271+ */
272+
258273 // Sets `key_` based on the environment variable DATABENTO_API_KEY.
259274 //
260275 // NOTE: This is not thread-safe if `std::setenv` is used elsewhere in the
261276 // program.
262277 HistoricalBuilder& SetKeyFromEnv ();
263278 HistoricalBuilder& SetKey (std::string key);
264- HistoricalBuilder& SetGateway (HistoricalGateway gateway);
279+
280+ /*
281+ * Optional setters
282+ */
283+
284+ // Set the version upgrade policy for when streaming DBN data from a prior
285+ // version. Defaults to upgrading to DBNv3 (if not already).
286+ HistoricalBuilder& SetUpgradePolicy (VersionUpgradePolicy upgrade_policy);
265287 // Sets the receiver of the logs to be used by the client.
266288 HistoricalBuilder& SetLogReceiver (ILogReceiver* log_receiver);
289+ HistoricalBuilder& SetGateway (HistoricalGateway gateway);
290+ // Overrides the gateway and port. This is an advanced method.
291+ HistoricalBuilder& SetAddress (std::string gateway, std::uint16_t port);
292+ // Appends to the default user agent.
293+ HistoricalBuilder& ExtendUserAgent (std::string extension);
294+
267295 // Attempts to construct an instance of Historical or throws an exception if
268296 // no key has been set.
269297 Historical Build ();
270298
271299 private:
272300 ILogReceiver* log_receiver_{};
273- std::string key_;
274301 HistoricalGateway gateway_{HistoricalGateway::Bo1};
302+ std::string gateway_override_{};
303+ std::uint16_t port_{};
304+ std::string key_;
305+ VersionUpgradePolicy upgrade_policy_{VersionUpgradePolicy::UpgradeToV3};
306+ std::string user_agent_ext_;
275307};
276308} // namespace databento
0 commit comments