Skip to content

Commit 9d5edfa

Browse files
committed
MOD: Update databento-cpp for metadata API changes
1 parent 83e26d4 commit 9d5edfa

File tree

10 files changed

+249
-345
lines changed

10 files changed

+249
-345
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
# Changelog
22

3-
## 0.10.1 - TBD
3+
## 0.11.0 - TBD
44

55
#### Enhancements
66
- Added `raw_instrument_id` to definition schema
7+
- Added `operator==` and `operator!=` implementations for `DatasetConditionDetail` and
8+
`DatasetRange`
9+
10+
#### Breaking changes
11+
- Changed `MetadataListPublishers` to return a `vector<PublisherDetail>`
12+
- `MetadataListFields`:
13+
- Changed return type to `vector<FieldDetail>`
14+
- Made `encoding` and `schema` parameters required
15+
- Removed `dataset` parameter
16+
- `MetadataListUnitPrices`:
17+
- Changed return type to `vector<UnitPricesForMode>`
18+
- Made `dataset` parameter required
19+
- Removed `mode` and `schema` parameters
720

821
#### Bug fixes
922
- Fixed installation of `nlohmann_json` when using bundled version
23+
- Added missing `operator!=` implementations for `Metadata`, `MappingInterval`, and
24+
`SymbolMapping`
1025

1126
## 0.10.0 - 2023-07-20
1227

example/historical/metadata.cpp

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main() {
1313
const auto publishers = client.MetadataListPublishers();
1414
std::cout << "Publishers:\n";
1515
for (const auto& publisher : publishers) {
16-
std::cout << "- " << publisher.first << ": " << publisher.second << '\n';
16+
std::cout << "- " << publisher << '\n';
1717
}
1818
std::cout << '\n';
1919

@@ -31,15 +31,11 @@ int main() {
3131
}
3232
std::cout << '\n';
3333

34-
const auto fields = client.MetadataListFields(
35-
kGlbxMdp3, databento::Encoding::Dbn, databento::Schema::Trades);
34+
const auto fields = client.MetadataListFields(databento::Encoding::Dbn,
35+
databento::Schema::Trades);
3636
std::cout << "Fields:\n";
37-
const auto& dbn_trades_fields = fields.at("GLBX.MDP3")
38-
.at(databento::Encoding::Dbn)
39-
.at(databento::Schema::Trades);
40-
for (const auto& field_and_type : dbn_trades_fields) {
41-
std::cout << "- " << field_and_type.first << ": " << field_and_type.second
42-
<< '\n';
37+
for (const auto& field_detail : fields) {
38+
std::cout << "- " << field_detail << '\n';
4339
}
4440
std::cout << '\n';
4541

@@ -54,8 +50,8 @@ int main() {
5450
const auto all_unit_prices = client.MetadataListUnitPrices(kGlbxMdp3);
5551
std::cout << "Unit prices:\n";
5652
for (const auto& mode_and_prices : all_unit_prices) {
57-
const auto* mode_str = ToString(mode_and_prices.first);
58-
for (const auto& schema_and_price : mode_and_prices.second) {
53+
const auto* mode_str = ToString(mode_and_prices.mode);
54+
for (const auto& schema_and_price : mode_and_prices.unit_prices) {
5955
std::cout << "- (" << mode_str << ", " << schema_and_price.first
6056
<< "): " << schema_and_price.second << '\n';
6157
}
@@ -67,29 +63,6 @@ int main() {
6763
{"ESH1"}, databento::Schema::Mbo);
6864
std::cout << "Record count: " << record_count << "\n\n";
6965

70-
const auto live_unit_prices =
71-
client.MetadataListUnitPrices(kGlbxMdp3, databento::FeedMode::Live);
72-
std::cout << "Unit prices (live):\n";
73-
for (const auto& schema_and_price : live_unit_prices) {
74-
std::cout << "- (" << schema_and_price.first
75-
<< "): " << schema_and_price.second << '\n';
76-
}
77-
std::cout << '\n';
78-
79-
const auto trades_unit_prices =
80-
client.MetadataListUnitPrices(kGlbxMdp3, databento::Schema::Trades);
81-
std::cout << "Unit prices (trades):\n";
82-
for (const auto& mode_and_price : trades_unit_prices) {
83-
std::cout << "- (" << mode_and_price.first << "): " << mode_and_price.second
84-
<< '\n';
85-
}
86-
std::cout << '\n';
87-
88-
const auto unit_price = client.MetadataListUnitPrices(
89-
kGlbxMdp3, databento::FeedMode::Historical, databento::Schema::Trades);
90-
std::cout << "Unit price (GLBX.MDP3, Historical, Trades): " << unit_price
91-
<< "\n\n";
92-
9366
const std::size_t billable_size = client.MetadataGetBillableSize(
9467
kGlbxMdp3, {"2020-12-28", "2020-12-29"}, {"ESH1"}, databento::Schema::Mbo,
9568
databento::SType::RawSymbol, {});

include/databento/dbn.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ inline bool operator==(const MappingInterval& lhs, const MappingInterval& rhs) {
7171
return lhs.start_date == rhs.start_date && lhs.end_date == rhs.end_date &&
7272
lhs.symbol == rhs.symbol;
7373
}
74+
inline bool operator!=(const MappingInterval& lhs, const MappingInterval& rhs) {
75+
return !(lhs == rhs);
76+
}
7477

7578
inline bool operator==(const SymbolMapping& lhs, const SymbolMapping& rhs) {
7679
return lhs.raw_symbol == rhs.raw_symbol && lhs.intervals == rhs.intervals;
7780
}
81+
inline bool operator!=(const SymbolMapping& lhs, const SymbolMapping& rhs) {
82+
return !(lhs == rhs);
83+
}
7884

7985
inline bool operator==(const Metadata& lhs, const Metadata& rhs) {
8086
return lhs.version == rhs.version && lhs.dataset == rhs.dataset &&
@@ -88,6 +94,9 @@ inline bool operator==(const Metadata& lhs, const Metadata& rhs) {
8894
lhs.symbols == rhs.symbols && lhs.partial == rhs.partial &&
8995
lhs.not_found == rhs.not_found && lhs.mappings == rhs.mappings;
9096
}
97+
inline bool operator!=(const Metadata& lhs, const Metadata& rhs) {
98+
return !(lhs == rhs);
99+
}
91100

92101
std::string ToString(const Metadata& metadata);
93102
std::ostream& operator<<(std::ostream& stream, const Metadata& metadata);

include/databento/detail/json_helpers.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ template <>
8080
std::uint64_t ParseAt(const std::string& endpoint, const nlohmann::json& json,
8181
const std::string& key);
8282
template <>
83+
std::uint16_t ParseAt(const std::string& endpoint, const nlohmann::json& json,
84+
const std::string& key);
85+
template <>
8386
double ParseAt(const std::string& endpoint, const nlohmann::json& json,
8487
const std::string& key);
8588
template <>

include/databento/historical.hpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include <cstdint>
4-
#include <map> // map, multimap
4+
#include <map> // multimap
55
#include <string>
66
#include <vector>
77

@@ -10,7 +10,7 @@
1010
#include "databento/dbn_file_store.hpp"
1111
#include "databento/detail/http_client.hpp" // HttpClient
1212
#include "databento/enums.hpp" // BatchState, Delivery, DurationInterval, Packaging, Schema, SType
13-
#include "databento/metadata.hpp" // DatasetConditionDetail, DatasetRange, FieldsByDatasetEncodingAndSchema, PriceByFeedMode, PriceByFeedModeAndSchema, PriceBySchema
13+
#include "databento/metadata.hpp" // DatasetConditionDetail, DatasetRange, FieldDetail, PublisherDetail, UnitPricesForMode
1414
#include "databento/symbology.hpp" // SymbologyResolution
1515
#include "databento/timeseries.hpp" // KeepGoing, MetadataCallback, RecordCallback
1616

@@ -80,22 +80,13 @@ class Historical {
8080
*/
8181

8282
// Retrievs a mapping of publisher name to publisher ID.
83-
std::map<std::string, std::int32_t> MetadataListPublishers();
83+
std::vector<PublisherDetail> MetadataListPublishers();
8484
std::vector<std::string> MetadataListDatasets();
8585
std::vector<std::string> MetadataListDatasets(const DateRange& date_range);
8686
std::vector<Schema> MetadataListSchemas(const std::string& dataset);
87-
FieldsByDatasetEncodingAndSchema MetadataListFields();
88-
FieldsByDatasetEncodingAndSchema MetadataListFields(
87+
std::vector<FieldDetail> MetadataListFields(Encoding encoding, Schema schema);
88+
std::vector<UnitPricesForMode> MetadataListUnitPrices(
8989
const std::string& dataset);
90-
FieldsByDatasetEncodingAndSchema MetadataListFields(
91-
const std::string& dataset, Encoding encoding, Schema schema);
92-
PriceByFeedModeAndSchema MetadataListUnitPrices(const std::string& dataset);
93-
PriceBySchema MetadataListUnitPrices(const std::string& dataset,
94-
FeedMode mode);
95-
PriceByFeedMode MetadataListUnitPrices(const std::string& dataset,
96-
Schema schema);
97-
double MetadataListUnitPrices(const std::string& dataset, FeedMode mode,
98-
Schema schema);
9990
std::vector<DatasetConditionDetail> MetadataGetDatasetCondition(
10091
const std::string& dataset);
10192
std::vector<DatasetConditionDetail> MetadataGetDatasetCondition(
@@ -245,8 +236,6 @@ class Historical {
245236
std::uint64_t MetadataGetRecordCount(const HttplibParams& params);
246237
std::uint64_t MetadataGetBillableSize(const HttplibParams& params);
247238
double MetadataGetCost(const HttplibParams& params);
248-
FieldsByDatasetEncodingAndSchema MetadataListFields(
249-
const HttplibParams& params);
250239
void TimeseriesGetRange(const HttplibParams& params,
251240
const MetadataCallback& metadata_callback,
252241
const RecordCallback& record_callback);

include/databento/metadata.hpp

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <map>
45
#include <ostream>
56
#include <string>
@@ -8,15 +9,22 @@
89
#include "databento/enums.hpp" // FeedMode, DatasetCondition, Schema
910

1011
namespace databento {
11-
// mapping of field name to type name
12-
using FieldDefinition = std::map<std::string, std::string>;
13-
using FieldsByEncodingAndSchema =
14-
std::map<Encoding, std::map<Schema, FieldDefinition>>;
15-
using FieldsByDatasetEncodingAndSchema =
16-
std::map<std::string, FieldsByEncodingAndSchema>;
17-
using PriceBySchema = std::map<Schema, double>;
18-
using PriceByFeedModeAndSchema = std::map<FeedMode, PriceBySchema>;
19-
using PriceByFeedMode = std::map<FeedMode, double>;
12+
struct PublisherDetail {
13+
std::uint16_t publisher_id;
14+
std::string dataset;
15+
std::string venue;
16+
std::string description;
17+
};
18+
19+
struct FieldDetail {
20+
std::string name;
21+
std::string type;
22+
};
23+
24+
struct UnitPricesForMode {
25+
FeedMode mode;
26+
std::map<Schema, double> unit_prices;
27+
};
2028

2129
struct DatasetConditionDetail {
2230
std::string date;
@@ -29,6 +37,52 @@ struct DatasetRange {
2937
std::string end_date;
3038
};
3139

40+
inline bool operator==(const PublisherDetail& lhs, const PublisherDetail& rhs) {
41+
return lhs.publisher_id == rhs.publisher_id && lhs.dataset == rhs.dataset &&
42+
lhs.venue == rhs.venue && lhs.description == rhs.description;
43+
}
44+
inline bool operator!=(const PublisherDetail& lhs, const PublisherDetail& rhs) {
45+
return !(lhs == rhs);
46+
}
47+
48+
inline bool operator==(const FieldDetail& lhs, const FieldDetail& rhs) {
49+
return lhs.name == rhs.name && lhs.type == rhs.type;
50+
}
51+
inline bool operator!=(const FieldDetail& lhs, const FieldDetail& rhs) {
52+
return !(lhs == rhs);
53+
}
54+
55+
inline bool operator==(const UnitPricesForMode& lhs,
56+
const UnitPricesForMode& rhs) {
57+
return lhs.mode == rhs.mode && lhs.unit_prices == rhs.unit_prices;
58+
}
59+
inline bool operator!=(const UnitPricesForMode& lhs,
60+
const UnitPricesForMode& rhs) {
61+
return !(lhs == rhs);
62+
}
63+
64+
inline bool operator==(const DatasetConditionDetail& lhs,
65+
const DatasetConditionDetail& rhs) {
66+
return lhs.date == rhs.date && lhs.condition == rhs.condition &&
67+
lhs.last_modified_date == rhs.last_modified_date;
68+
}
69+
inline bool operator!=(const DatasetConditionDetail& lhs,
70+
const DatasetConditionDetail& rhs) {
71+
return !(lhs == rhs);
72+
}
73+
74+
inline bool operator==(const DatasetRange& lhs, const DatasetRange& rhs) {
75+
return lhs.start_date == rhs.start_date && lhs.end_date == rhs.end_date;
76+
}
77+
inline bool operator!=(const DatasetRange& lhs, const DatasetRange& rhs) {
78+
return !(lhs == rhs);
79+
}
80+
81+
std::string ToString(const PublisherDetail& publisher_detail);
82+
std::ostream& operator<<(std::ostream& stream,
83+
const PublisherDetail& publisher_detail);
84+
std::string ToString(const FieldDetail& field_detail);
85+
std::ostream& operator<<(std::ostream& stream, const FieldDetail& field_detail);
3286
std::string ToString(const DatasetConditionDetail& condition_detail);
3387
std::ostream& operator<<(std::ostream& stream,
3488
const DatasetConditionDetail& condition_detail);

src/detail/json_helpers.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ std::uint64_t ParseAt(const std::string& endpoint, const nlohmann::json& json,
7171
return val_json;
7272
}
7373

74+
template <>
75+
std::uint16_t ParseAt(const std::string& endpoint, const nlohmann::json& json,
76+
const std::string& key) {
77+
const auto& val_json = CheckedAt(endpoint, json, key);
78+
if (val_json.is_null()) {
79+
return 0;
80+
}
81+
if (!val_json.is_number_unsigned()) {
82+
throw JsonResponseError::TypeMismatch(endpoint, key + " unsigned number",
83+
val_json);
84+
}
85+
return val_json;
86+
}
87+
7488
template <>
7589
double ParseAt(const std::string& endpoint, const nlohmann::json& json,
7690
const std::string& key) {

0 commit comments

Comments
 (0)