Skip to content

Commit 6338f47

Browse files
authored
VER: Release 0.30.0
2 parents 0e000c5 + ee6f258 commit 6338f47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+333
-320
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 0.30.0 - 2025-02-11
4+
5+
### Enhancements
6+
- Added `Resubscribe()` methods to `LiveBlocking` and `LiveThreaded` to make it easier
7+
to resume a live session after losing the connection to the live gateway
8+
- Added `Subscriptions()` getter methods to `LiveBlocking` and `LiveThreaded` for
9+
getting all active subscriptions
10+
- Added `CommoditySpot` `InstrumentClass` variant
11+
312
## 0.29.0 - 2025-02-04
413

514
### Enhancements

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.14)
44
# Project details
55
#
66

7-
project("databento" VERSION 0.29.0 LANGUAGES CXX)
7+
project("databento" VERSION 0.30.0 LANGUAGES CXX)
88
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPERCASE)
99

1010
#

cmake/SourcesAndHeaders.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(headers
2323
include/databento/ireadable.hpp
2424
include/databento/live.hpp
2525
include/databento/live_blocking.hpp
26+
include/databento/live_subscription.hpp
2627
include/databento/live_threaded.hpp
2728
include/databento/log.hpp
2829
include/databento/metadata.hpp

examples/historical/metadata.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ int main() {
4949

5050
const auto all_unit_prices = client.MetadataListUnitPrices(kGlbxMdp3);
5151
std::cout << "Unit prices:\n";
52-
for (const auto& mode_and_prices : all_unit_prices) {
53-
const auto* mode_str = ToString(mode_and_prices.mode);
54-
for (const auto& schema_and_price : mode_and_prices.unit_prices) {
55-
std::cout << "- (" << mode_str << ", " << schema_and_price.first
56-
<< "): " << schema_and_price.second << '\n';
52+
for (const auto& [mode, unit_prices] : all_unit_prices) {
53+
const auto* mode_str = ToString(mode);
54+
for (const auto [schema, price] : unit_prices) {
55+
std::cout << "- (" << mode_str << ", " << schema << "): " << price
56+
<< '\n';
5757
}
5858
}
5959
std::cout << '\n';

examples/live/live_smoke_test.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <sstream>
1212
#include <stdexcept>
1313
#include <string>
14-
#include <unordered_map>
1514

1615
using namespace databento;
1716

@@ -28,7 +27,6 @@ std::vector<std::string> SplitSymbols(const std::string& symbols) {
2827
}
2928

3029
std::pair<bool, UnixNanos> TryConvertToUnixNanos(const char* start) {
31-
std::stringstream ss(start);
3230
std::size_t pos;
3331
const uint64_t result = std::stoul(start, &pos, 10);
3432
if (pos != std::strlen(start)) {
@@ -187,10 +185,10 @@ int main(int argc, char* argv[]) {
187185
if (use_snapshot) {
188186
client.SubscribeWithSnapshot(symbols, schema, stype);
189187
} else if (start) {
190-
const auto converted = TryConvertToUnixNanos(start);
191-
if (converted.first) {
192-
start_from_epoch = converted.second.time_since_epoch().count() == 0;
193-
client.Subscribe(symbols, schema, stype, converted.second);
188+
const auto [success, start_nanos] = TryConvertToUnixNanos(start);
189+
if (success) {
190+
start_from_epoch = start_nanos.time_since_epoch().count() == 0;
191+
client.Subscribe(symbols, schema, stype, start_nanos);
194192
} else {
195193
client.Subscribe(symbols, schema, stype, start);
196194
}

examples/live/simple.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static std::sig_atomic_t volatile gSignal;
1616

1717
int main() {
1818
databento::PitSymbolMap symbol_mappings;
19-
std::unique_ptr<databento::ILogReceiver> log_receiver{
20-
new databento::ConsoleLogReceiver{databento::LogLevel::Debug}};
19+
auto log_receiver = std::make_unique<databento::ConsoleLogReceiver>(
20+
databento::LogLevel::Debug);
2121

2222
auto client = databento::LiveBuilder{}
2323
.SetLogReceiver(log_receiver.get())

include/databento/detail/json_helpers.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ namespace httplib {
1515
using Params = std::multimap<std::string, std::string>;
1616
}
1717

18-
namespace databento {
19-
namespace detail {
18+
namespace databento::detail {
2019
void SetIfNotEmpty(httplib::Params* params, const std::string& key,
2120
const std::string& value);
2221
void SetIfNotEmpty(httplib::Params* params, const std::string& key,
@@ -95,5 +94,4 @@ date::year_month_day ParseAt(const std::string& endpoint,
9594
const nlohmann::json& json,
9695
const std::string& key);
9796

98-
} // namespace detail
99-
} // namespace databento
97+
} // namespace databento::detail

include/databento/detail/scoped_fd.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include <winsock2.h> // SOCKET
55
#endif
66

7-
namespace databento {
8-
namespace detail {
7+
namespace databento::detail {
98
#ifdef _WIN32
109
using Socket = SOCKET;
1110
#else
@@ -35,5 +34,4 @@ class ScopedFd {
3534
private:
3635
Socket fd_{kUnset};
3736
};
38-
} // namespace detail
39-
} // namespace databento
37+
} // namespace databento::detail

include/databento/detail/scoped_thread.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <thread>
44
#include <utility> // forward, move
55

6-
namespace databento {
7-
namespace detail {
6+
namespace databento::detail {
87
// An RAII thread that joins if necessary on destruction, like std::jthread in
98
// C++20.
109
class ScopedThread {
@@ -37,5 +36,4 @@ class ScopedThread {
3736
private:
3837
std::thread thread_;
3938
};
40-
} // namespace detail
41-
} // namespace databento
39+
} // namespace databento::detail

include/databento/detail/shared_channel.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include "databento/ireadable.hpp"
88

9-
namespace databento {
10-
namespace detail {
9+
namespace databento::detail {
1110
// Copyable, thread-safe, unidirectional channel.
1211
class SharedChannel : public IReadable {
1312
public:
@@ -28,5 +27,4 @@ class SharedChannel : public IReadable {
2827

2928
std::shared_ptr<Channel> channel_;
3029
};
31-
} // namespace detail
32-
} // namespace databento
30+
} // namespace databento::detail

include/databento/detail/tcp_client.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include "databento/detail/scoped_fd.hpp" // ScopedFd
88

9-
namespace databento {
10-
namespace detail {
9+
namespace databento::detail {
1110
class TcpClient {
1211
public:
1312
enum class Status : std::uint8_t {
@@ -47,5 +46,4 @@ class TcpClient {
4746

4847
ScopedFd socket_;
4948
};
50-
} // namespace detail
51-
} // namespace databento
49+
} // namespace databento::detail

include/databento/detail/zstd_stream.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include "databento/iwritable.hpp"
1212
#include "databento/log.hpp"
1313

14-
namespace databento {
15-
namespace detail {
14+
namespace databento::detail {
1615
class ZstdDecodeStream : public IReadable {
1716
public:
1817
explicit ZstdDecodeStream(std::unique_ptr<IReadable> input);
@@ -54,5 +53,4 @@ class ZstdCompressStream : public IWritable {
5453
std::size_t in_size_;
5554
std::vector<std::uint8_t> out_buffer_;
5655
};
57-
} // namespace detail
58-
} // namespace databento
56+
} // namespace databento::detail

include/databento/enums.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ enum InstrumentClass : char {
191191
FutureSpread = 'S',
192192
OptionSpread = 'T',
193193
FxSpot = 'X',
194+
CommoditySpot = 'Y',
194195
};
195196
} // namespace instrument_class
196197
using instrument_class::InstrumentClass;

include/databento/live_blocking.hpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include "databento/datetime.hpp" // UnixNanos
1111
#include "databento/dbn.hpp" // Metadata
1212
#include "databento/detail/tcp_client.hpp" // TcpClient
13-
#include "databento/enums.hpp" // Schema, SType, VersionUpgradePolicy
13+
#include "databento/enums.hpp" // Schema, SType, VersionUpgradePolicy
14+
#include "databento/live_subscription.hpp"
1415
#include "databento/record.hpp" // Record, RecordHeader
1516

1617
namespace databento {
@@ -44,6 +45,10 @@ class LiveBlocking {
4445
std::pair<bool, std::chrono::seconds> HeartbeatInterval() const {
4546
return {heartbeat_interval_.count() > 0, heartbeat_interval_};
4647
}
48+
const std::vector<LiveSubscription>& Subscriptions() const {
49+
return subscriptions_;
50+
}
51+
std::vector<LiveSubscription>& Subscriptions() { return subscriptions_; }
4752

4853
/*
4954
* Methods
@@ -80,6 +85,9 @@ class LiveBlocking {
8085
void Stop();
8186
// Closes the current connection and attempts to reconnect to the gateway.
8287
void Reconnect();
88+
// Resubscribes to all subscriptions, removing the original `start` time, if
89+
// any. Usually performed after a `Reconnect()`.
90+
void Resubscribe();
8391

8492
private:
8593
std::string DetermineGateway() const;
@@ -105,6 +113,7 @@ class LiveBlocking {
105113
VersionUpgradePolicy upgrade_policy_;
106114
std::chrono::seconds heartbeat_interval_;
107115
detail::TcpClient client_;
116+
std::vector<LiveSubscription> subscriptions_;
108117
// Must be 8-byte aligned for records
109118
alignas(RecordHeader) std::array<char, kMaxStrLen> read_buffer_{};
110119
std::size_t buffer_size_{};
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <variant>
5+
#include <vector>
6+
7+
#include "databento/datetime.hpp" // UnixNanos
8+
#include "databento/enums.hpp" // Schema, SType
9+
10+
namespace databento {
11+
struct LiveSubscription {
12+
struct Snapshot {};
13+
struct NoStart {};
14+
using Start = std::variant<Snapshot, UnixNanos, std::string, NoStart>;
15+
16+
std::vector<std::string> symbols;
17+
Schema schema;
18+
SType stype_in;
19+
Start start;
20+
};
21+
} // namespace databento

include/databento/live_threaded.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "databento/datetime.hpp" // UnixNanos
1111
#include "databento/detail/scoped_thread.hpp" // ScopedThread
1212
#include "databento/enums.hpp" // Schema, SType
13+
#include "databento/live_subscription.hpp"
1314
#include "databento/timeseries.hpp" // MetadataCallback, RecordCallback
1415

1516
namespace databento {
@@ -57,6 +58,8 @@ class LiveThreaded {
5758
// The the first member of the pair will be true, when the heartbeat interval
5859
// was overridden.
5960
std::pair<bool, std::chrono::seconds> HeartbeatInterval() const;
61+
const std::vector<LiveSubscription>& Subscriptions() const;
62+
std::vector<LiveSubscription>& Subscriptions();
6063

6164
/*
6265
* Methods
@@ -86,6 +89,7 @@ class LiveThreaded {
8689
ExceptionCallback exception_callback);
8790
// Closes the current connection, and attempts to reconnect to the gateway.
8891
void Reconnect();
92+
void Resubscribe();
8993
// Blocking wait with an optional timeout for the session to close when the
9094
// record_callback or the exception_callback return Stop.
9195
void BlockForStop();

include/databento/record.hpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,10 @@ struct RecordHeader {
4646
};
4747

4848
// Type trait helper for templated functions accepting DBN records.
49-
namespace detail {
50-
// std::void_t added in C++17
51-
template <typename... Ts>
52-
using void_t = void;
53-
} // namespace detail
54-
template <typename, typename = detail::void_t<>>
49+
template <typename, typename = std::void_t<>>
5550
struct has_header : std::false_type {};
5651
template <typename T>
57-
struct has_header<T, detail::void_t<decltype(std::declval<T>().hd)>>
52+
struct has_header<T, std::void_t<decltype(std::declval<T>().hd)>>
5853
: std::is_same<decltype(std::declval<T>().hd), RecordHeader> {};
5954

6055
class Record {

include/databento/v2.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include "databento/constants.hpp" // kSymbolCstrLen
44
#include "databento/record.hpp"
55

6-
namespace databento {
7-
namespace v2 {
6+
namespace databento::v2 {
87
static constexpr std::size_t kSymbolCstrLen = databento::kSymbolCstrLen;
98

109
using MboMsg = databento::MboMsg;
@@ -28,5 +27,4 @@ using StatMsg = databento::StatMsg;
2827
using ErrorMsg = databento::ErrorMsg;
2928
using SymbolMappingMsg = databento::SymbolMappingMsg;
3029
using SystemMsg = databento::SystemMsg;
31-
} // namespace v2
32-
} // namespace databento
30+
} // namespace databento::v2

include/databento/v3.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include "databento/enums.hpp" // InstrumentClass, MatchingAlgorithm, RType, SecurityUpdateAction, Side, UserDefinedInstrument
99
#include "databento/record.hpp" // RecordHeader
1010

11-
namespace databento {
12-
namespace v3 {
11+
namespace databento::v3 {
1312
static constexpr std::size_t kSymbolCstrLen = databento::kSymbolCstrLen;
1413

1514
using MboMsg = databento::MboMsg;
@@ -142,5 +141,4 @@ inline bool operator!=(const InstrumentDefMsg& lhs,
142141
std::string ToString(const InstrumentDefMsg& instr_def_msg);
143142
std::ostream& operator<<(std::ostream& stream,
144143
const InstrumentDefMsg& instr_def_msg);
145-
} // namespace v3
146-
} // namespace databento
144+
} // namespace databento::v3

pkg/PKGBUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Maintainer: Databento <support@databento.com>
22
_pkgname=databento-cpp
33
pkgname=databento-cpp-git
4-
pkgver=0.29.0
4+
pkgver=0.30.0
55
pkgrel=1
66
pkgdesc="Official C++ client for Databento"
77
arch=('any')

src/dbn_decoder.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ date::year_month_day DecodeIso8601Date(std::uint32_t yyyymmdd_int) {
6565
DbnDecoder::DbnDecoder(ILogReceiver* log_receiver,
6666
detail::SharedChannel channel)
6767
: DbnDecoder(log_receiver,
68-
std::unique_ptr<IReadable>{
69-
new detail::SharedChannel{std::move(channel)}}) {}
68+
std::make_unique<detail::SharedChannel>(std::move(channel))) {}
7069

7170
DbnDecoder::DbnDecoder(ILogReceiver* log_receiver, InFileStream file_stream)
72-
: DbnDecoder(log_receiver, std::unique_ptr<IReadable>{
73-
new InFileStream{std::move(file_stream)}}) {}
71+
: DbnDecoder(log_receiver,
72+
std::make_unique<InFileStream>(std::move(file_stream))) {}
7473

7574
DbnDecoder::DbnDecoder(ILogReceiver* log_receiver,
7675
std::unique_ptr<IReadable> input)
@@ -85,9 +84,8 @@ DbnDecoder::DbnDecoder(ILogReceiver* log_receiver,
8584
input_{std::move(input)} {
8685
read_buffer_.reserve(kBufferCapacity);
8786
if (DetectCompression()) {
88-
input_ =
89-
std::unique_ptr<detail::ZstdDecodeStream>(new detail::ZstdDecodeStream(
90-
std::move(input_), std::move(read_buffer_)));
87+
input_ = std::make_unique<detail::ZstdDecodeStream>(
88+
std::move(input_), std::move(read_buffer_));
9189
// Reinitialize buffer and get it into the same state as uncompressed input
9290
read_buffer_ = std::vector<std::uint8_t>();
9391
read_buffer_.reserve(kBufferCapacity);
@@ -192,10 +190,10 @@ databento::Metadata DbnDecoder::DecodeMetadata() {
192190
// already read first 4 bytes detecting compression
193191
read_buffer_.resize(kMetadataPreludeSize);
194192
input_->ReadExact(&read_buffer_[4], 4);
195-
const auto version_and_size = DbnDecoder::DecodeMetadataVersionAndSize(
193+
const auto [version, size] = DbnDecoder::DecodeMetadataVersionAndSize(
196194
read_buffer_.data(), kMetadataPreludeSize);
197-
version_ = version_and_size.first;
198-
read_buffer_.resize(version_and_size.second);
195+
version_ = version;
196+
read_buffer_.resize(size);
199197
input_->ReadExact(read_buffer_.data(), read_buffer_.size());
200198
buffer_idx_ = read_buffer_.size();
201199
auto metadata = DbnDecoder::DecodeMetadataFields(version_, read_buffer_);

0 commit comments

Comments
 (0)