Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VER: Release 0.18.0 #29

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.18.0 - 2024-05-14

### Breaking changes
- Changed `FlagSet` to be more class-like:
- Added predicate methods and setters for each bit flag
- Improved string formatting
- Removed bitwise operators. Bitwise operations can be performed by first casting to a
`std::uint8_t` or calling the `Raw()` method
- Changed format of `display_factor` and `price_ratio` to a fixed-precision decimal for
`InstrumentDefMsg` and `InstrumentDefMsgV1` to match existing values and DBN crate
- Changed format of `unit_of_measure_qty` to a fixed-precision decimal for
`InstrumentDefMsgV1` to match `InstrumentDefMsg`

## 0.17.1 - 2024-04-08

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.14)
# Project details
#

project("databento" VERSION 0.17.1 LANGUAGES CXX)
project("databento" VERSION 0.18.0 LANGUAGES CXX)
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPERCASE)

#
Expand Down
33 changes: 17 additions & 16 deletions cmake/SourcesAndHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ set(headers
include/databento/dbn.hpp
include/databento/dbn_decoder.hpp
include/databento/dbn_file_store.hpp
include/databento/detail/file_stream.hpp
include/databento/detail/http_client.hpp
include/databento/detail/json_helpers.hpp
include/databento/detail/scoped_fd.hpp
include/databento/detail/scoped_thread.hpp
include/databento/detail/shared_channel.hpp
include/databento/detail/tcp_client.hpp
include/databento/detail/zstd_stream.hpp
include/databento/enums.hpp
include/databento/exceptions.hpp
include/databento/fixed_price.hpp
Expand All @@ -23,14 +31,6 @@ set(headers
include/databento/symbology.hpp
include/databento/timeseries.hpp
include/databento/with_ts_out.hpp
include/databento/detail/file_stream.hpp
include/databento/detail/http_client.hpp
include/databento/detail/json_helpers.hpp
include/databento/detail/scoped_fd.hpp
include/databento/detail/scoped_thread.hpp
include/databento/detail/shared_channel.hpp
include/databento/detail/tcp_client.hpp
include/databento/detail/zstd_stream.hpp
src/stream_op_helper.hpp
)

Expand All @@ -40,10 +40,18 @@ set(sources
src/datetime.cpp
src/dbn.cpp
src/dbn_decoder.cpp
src/dbn_file_store.cpp
src/detail/file_stream.cpp
src/detail/http_client.cpp
src/detail/json_helpers.cpp
src/detail/scoped_fd.cpp
src/detail/shared_channel.cpp
src/detail/tcp_client.cpp
src/detail/zstd_stream.cpp
src/enums.cpp
src/exceptions.cpp
src/dbn_file_store.cpp
src/fixed_price.cpp
src/flag_set.cpp
src/historical.cpp
src/live.cpp
src/live_blocking.cpp
Expand All @@ -54,11 +62,4 @@ set(sources
src/record.cpp
src/symbol_map.cpp
src/symbology.cpp
src/detail/file_stream.cpp
src/detail/http_client.cpp
src/detail/json_helpers.cpp
src/detail/scoped_fd.cpp
src/detail/shared_channel.cpp
src/detail/tcp_client.cpp
src/detail/zstd_stream.cpp
)
91 changes: 53 additions & 38 deletions include/databento/flag_set.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#pragma once

#include <bitset>
#include <cstdint>
#include <ostream>
#include <string>

namespace databento {
// Transparent wrapper around the bit flags used in several DBN record types.
class FlagSet {
public:
using Repr = std::uint8_t;
// Indicates it's the last message in the packet from the venue for a given
// Indicates it's the last message in the event from the venue for a given
// `instrument_id`.
static constexpr Repr kLast = 1 << 7;
// Indicates a top-of-book message, not an individual order.
Expand All @@ -27,61 +27,76 @@ class FlagSet {

friend std::ostream& operator<<(std::ostream&, FlagSet);

constexpr FlagSet() = default;
constexpr FlagSet() : repr_{0} {};

constexpr FlagSet( // cppcheck-suppress noExplicitConstructor
std::uint8_t repr)
: repr_{repr} {}
explicit constexpr FlagSet(Repr repr) : repr_{repr} {}

explicit constexpr operator std::uint8_t() const { return repr_; }

constexpr FlagSet operator~() const {
return FlagSet{static_cast<Repr>(~repr_)};
}
constexpr bool operator==(FlagSet rhs) const { return repr_ == rhs.repr_; }
constexpr bool operator!=(FlagSet rhs) const { return repr_ != rhs.repr_; }

constexpr FlagSet operator|(FlagSet rhs) const {
return FlagSet{static_cast<Repr>(repr_ | rhs.repr_)};
FlagSet Clear() {
repr_ = 0;
return *this;
}

constexpr FlagSet operator&(FlagSet rhs) const {
return FlagSet{static_cast<Repr>(repr_ & rhs.repr_)};
}
constexpr Repr Raw() const { return repr_; }
void SetRaw(Repr raw) { repr_ = raw; }

constexpr FlagSet operator^(FlagSet rhs) const {
return FlagSet{static_cast<Repr>(repr_ ^ rhs.repr_)};
// Checks if any flags are set.
constexpr bool Any() const { return repr_ != 0; }
constexpr bool IsEmpty() const { return repr_ == 0; }
constexpr bool IsLast() const { return bits_.last; }
FlagSet SetLast() {
bits_.last = true;
return *this;
}

FlagSet operator|=(FlagSet rhs) {
repr_ = repr_ | rhs.repr_;
constexpr bool IsTob() const { return bits_.tob; }
FlagSet SetTob() {
bits_.tob = true;
return *this;
}

FlagSet operator&=(FlagSet rhs) {
repr_ = repr_ & rhs.repr_;
constexpr bool IsSnapshot() const { return bits_.snapshot; }
FlagSet SetSnapshot() {
bits_.snapshot = true;
return *this;
}

FlagSet operator^=(FlagSet rhs) {
repr_ = repr_ ^ rhs.repr_;
constexpr bool IsMbp() const { return bits_.mbp; }
FlagSet SetMbp() {
bits_.mbp = true;
return *this;
}
constexpr bool IsBadTsRecv() const { return bits_.bad_ts_recv; }
FlagSet SetBadTsRecv() {
bits_.bad_ts_recv = true;
return *this;
}
constexpr bool IsMaybeBadBook() const { return bits_.maybe_bad_book; }
FlagSet SetMaybeBadBook() {
bits_.maybe_bad_book = true;
return *this;
}

constexpr bool operator==(FlagSet rhs) const { return repr_ == rhs.repr_; }

constexpr bool operator!=(FlagSet rhs) const { return repr_ != rhs.repr_; }

// Checks if any flags are set.
constexpr bool Any() const { return repr_ != 0; }

private:
Repr repr_{};
struct BitFlags {
bool reserved0 : 1;
bool reserved1 : 1;
bool maybe_bad_book : 1;
bool bad_ts_recv : 1;
bool mbp : 1;
bool snapshot : 1;
bool tob : 1;
bool last : 1;
};
union {
BitFlags bits_;
Repr repr_;
};
};

inline std::ostream& operator<<(std::ostream& stream, FlagSet flag) {
// print as binary
stream << "0b" << std::bitset<8>{flag.repr_};
return stream;
}
std::ostream& operator<<(std::ostream& stream, FlagSet flag_set);
std::string ToString(FlagSet flags);

static_assert(sizeof(FlagSet) == sizeof(std::uint8_t),
"FlagSet must be a transparent wrapper around std::uint8_t");
Expand Down
2 changes: 1 addition & 1 deletion pkg/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Databento <[email protected]>
_pkgname=databento-cpp
pkgname=databento-cpp-git
pkgver=0.17.1
pkgver=0.18.0
pkgrel=1
pkgdesc="Official C++ client for Databento"
arch=('any')
Expand Down
12 changes: 7 additions & 5 deletions src/compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ SymbolMappingMsgV2 SymbolMappingMsgV1::ToV2() const {
RecordHeader{sizeof(SymbolMappingMsgV2) / RecordHeader::kLengthMultiplier,
RType::SymbolMapping, hd.publisher_id, hd.instrument_id,
hd.ts_event},
// invalid
// Intentionally invalid
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
static_cast<SType>(std::numeric_limits<std::uint8_t>::max()),
{},
// invalid
// Intentionally invalid
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
static_cast<SType>(std::numeric_limits<std::uint8_t>::max()),
{},
start_ts,
Expand Down Expand Up @@ -205,18 +207,18 @@ std::ostream& operator<<(std::ostream& stream,
.AddField("hd", instr_def_msg.hd)
.AddField("ts_recv", instr_def_msg.ts_recv)
.AddField("min_price_increment", FixPx{instr_def_msg.min_price_increment})
.AddField("display_factor", instr_def_msg.display_factor)
.AddField("display_factor", FixPx{instr_def_msg.display_factor})
.AddField("expiration", instr_def_msg.expiration)
.AddField("activation", instr_def_msg.activation)
.AddField("high_limit_price", FixPx{instr_def_msg.high_limit_price})
.AddField("low_limit_price", FixPx{instr_def_msg.low_limit_price})
.AddField("max_price_variation", FixPx{instr_def_msg.max_price_variation})
.AddField("trading_reference_price",
FixPx{instr_def_msg.trading_reference_price})
.AddField("unit_of_measure_qty", instr_def_msg.unit_of_measure_qty)
.AddField("unit_of_measure_qty", FixPx{instr_def_msg.unit_of_measure_qty})
.AddField("min_price_increment_amount",
FixPx{instr_def_msg.min_price_increment_amount})
.AddField("price_ratio", instr_def_msg.price_ratio)
.AddField("price_ratio", FixPx{instr_def_msg.price_ratio})
.AddField("inst_attrib_value", instr_def_msg.inst_attrib_value)
.AddField("underlying_id", instr_def_msg.underlying_id)
.AddField("raw_instrument_id", instr_def_msg.raw_instrument_id)
Expand Down
48 changes: 48 additions & 0 deletions src/flag_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "databento/flag_set.hpp"

#include <array>

#include "stream_op_helper.hpp"

namespace databento {
constexpr FlagSet::Repr FlagSet::kLast;
constexpr FlagSet::Repr FlagSet::kTob;
constexpr FlagSet::Repr FlagSet::kSnapshot;
constexpr FlagSet::Repr FlagSet::kMbp;
constexpr FlagSet::Repr FlagSet::kBadTsRecv;
constexpr FlagSet::Repr FlagSet::kMaybeBadBook;

std::ostream& operator<<(std::ostream& stream, FlagSet flag_set) {
const std::array<std::pair<bool (FlagSet::*)() const, const char*>, 6>
kFlagsAndNames = {{
{&FlagSet::IsLast, "LAST"},
{&FlagSet::IsTob, "TOB"},
{&FlagSet::IsSnapshot, "SNAPSHOT"},
{&FlagSet::IsMbp, "MBP"},
{&FlagSet::IsBadTsRecv, "BAD_TS_RECV"},
{&FlagSet::IsMaybeBadBook, "MAYBE_BAD_BOOK"},
}};

bool has_written_flag = false;
for (const auto& pair : kFlagsAndNames) {
if ((flag_set.*pair.first)()) {
if (has_written_flag) {
stream << " | " << pair.second;
} else {
stream << pair.second;
has_written_flag = true;
}
}
}
// Cast to uint16_t to avoid being formatted as char
const auto raw = static_cast<std::uint16_t>(flag_set.Raw());
if (has_written_flag) {
stream << " (" << raw << ')';
} else {
stream << raw;
}
return stream;
}

std::string ToString(FlagSet flags) { return MakeString(flags); }
} // namespace databento
4 changes: 3 additions & 1 deletion src/live_threaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct LiveThreaded::Impl {
}

ILogReceiver* log_receiver;
std::atomic<std::thread::id> thread_id_{};
// Set to false when destructor is called
std::atomic<bool> keep_going{true};
KeepGoing last_cb_ret{KeepGoing::Continue};
Expand Down Expand Up @@ -114,7 +115,7 @@ void LiveThreaded::Start(MetadataCallback metadata_callback,
RecordCallback record_callback,
ExceptionCallback exception_callback) {
// Deadlock check
if (std::this_thread::get_id() == thread_.Id()) {
if (std::this_thread::get_id() == impl_->thread_id_) {
std::ostringstream log_ss;
log_ss << "[LiveThreaded::Start] Called Start from callback thread, which "
"would cause a deadlock. Ignoring.";
Expand Down Expand Up @@ -161,6 +162,7 @@ void LiveThreaded::ProcessingThread(Impl* impl,
static constexpr auto kMethodName = "LiveThreaded::ProcessingThread";
constexpr std::chrono::milliseconds kTimeout{50};

impl->thread_id_ = std::this_thread::get_id();
const auto metadata_cb{std::move(metadata_callback)};
const auto record_cb{std::move(record_callback)};
const auto exception_cb{std::move(exception_callback)};
Expand Down
4 changes: 2 additions & 2 deletions src/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ std::ostream& operator<<(std::ostream& stream,
.AddField("hd", instr_def_msg.hd)
.AddField("ts_recv", instr_def_msg.ts_recv)
.AddField("min_price_increment", FixPx{instr_def_msg.min_price_increment})
.AddField("display_factor", instr_def_msg.display_factor)
.AddField("display_factor", FixPx{instr_def_msg.display_factor})
.AddField("expiration", instr_def_msg.expiration)
.AddField("activation", instr_def_msg.activation)
.AddField("high_limit_price", FixPx{instr_def_msg.high_limit_price})
Expand All @@ -393,7 +393,7 @@ std::ostream& operator<<(std::ostream& stream,
.AddField("unit_of_measure_qty", FixPx{instr_def_msg.unit_of_measure_qty})
.AddField("min_price_increment_amount",
FixPx{instr_def_msg.min_price_increment_amount})
.AddField("price_ratio", instr_def_msg.price_ratio)
.AddField("price_ratio", FixPx{instr_def_msg.price_ratio})
.AddField("strike_price", FixPx{instr_def_msg.strike_price})
.AddField("inst_attrib_value", instr_def_msg.inst_attrib_value)
.AddField("underlying_id", instr_def_msg.underlying_id)
Expand Down
Loading