Skip to content

Commit a3ad023

Browse files
authored
VER: Release 0.2.0
2 parents 027aa8e + bf544c8 commit a3ad023

27 files changed

+800
-138
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## 0.2.0 - 2022-12-01
4+
- Add dataset condition endpoint
5+
- Improve Zstd CMake integration
6+
- Fix requesting all symbols for a dataset
7+
8+
## 0.1.0 - 2022-11-07
9+
- Initial release with support for historical data

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ cmake_minimum_required(VERSION 3.14)
44
# Project details
55
#
66

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

1010
#
1111
# Set project options
1212
#
1313

14+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1415
include(cmake/StandardSettings.cmake)
1516
include(cmake/StaticAnalyzers.cmake)
1617
include(cmake/Utils.cmake)
@@ -146,18 +147,18 @@ find_package(OpenSSL REQUIRED)
146147
if(OPENSSL_FOUND)
147148
set(HTTPLIB_IS_USING_OPENSSL TRUE)
148149
endif()
149-
find_library(zstd zstd REQUIRED)
150+
find_package(Zstd REQUIRED)
150151
find_package(Threads REQUIRED)
151152

152153
target_link_libraries(
153154
${PROJECT_NAME}
154155
PUBLIC
155-
httplib
156+
httplib::httplib
156157
nlohmann_json::nlohmann_json
157158
OpenSSL::Crypto
158159
OpenSSL::SSL
159160
Threads::Threads
160-
zstd
161+
zstd::zstd
161162
)
162163

163164
target_compile_definitions(

cmake/FindZstd.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
include(FindPackageHandleStandardArgs)
2+
3+
find_library(ZSTD_LIBRARY NAMES zstd)
4+
find_path(ZSTD_INCLUDE_DIR NAMES zstd.h)
5+
6+
#
7+
# Detect version
8+
#
9+
if(ZSTD_INCLUDE_DIR)
10+
file(
11+
STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h"
12+
version-file
13+
REGEX "^#define[ \t]ZSTD_VERSION_(MAJOR|MINOR|RELEASE).*$"
14+
)
15+
if(NOT version-file)
16+
message(AUTHOR_WARNING "ZSTD_INCLUDE_DIR found, but missing version info")
17+
endif()
18+
list(GET version-file 0 major-line)
19+
list(GET version-file 1 minor-line)
20+
list(GET version-file 2 patch-line)
21+
string(REGEX MATCH "[0-9]+$" ZSTD_VERSION_MAJOR ${major-line})
22+
string(REGEX MATCH "[0-9]+$" ZSTD_VERSION_MINOR ${minor-line})
23+
string(REGEX MATCH "[0-9]+$" ZSTD_VERSION_PATCH ${patch-line})
24+
set(ZSTD_VERSION ${ZSTD_VERSION_MAJOR}.${ZSTD_VERSION_MINOR}.${ZSTD_VERSION_PATCH} CACHE STRING "Zstd version")
25+
endif()
26+
27+
find_package_handle_standard_args(
28+
Zstd
29+
REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR
30+
VERSION_VAR ZSTD_VERSION
31+
)
32+
33+
if(ZSTD_FOUND)
34+
mark_as_advanced(ZSTD_LIBRARY)
35+
mark_as_advanced(ZSTD_INCLUDE_DIR)
36+
mark_as_advanced(ZSTD_VERSION)
37+
endif()
38+
39+
#
40+
# Create namespaced target
41+
#
42+
if(ZSTD_FOUND AND NOT TARGET zstd::zstd)
43+
add_library(zstd::zstd UNKNOWN IMPORTED)
44+
set_target_properties(
45+
zstd::zstd
46+
PROPERTIES
47+
IMPORTED_LOCATION ${ZSTD_LIBRARY}
48+
# target_include_directories doesn't work with unknown imported libraries in older
49+
# cmake versions
50+
INTERFACE_INCLUDE_DIRECTORIES ${ZSTD_INCLUDE_DIR}
51+
)
52+
endif()

cmake/SourcesAndHeaders.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ set(headers
1515
include/databento/detail/file_stream.hpp
1616
include/databento/detail/http_client.hpp
1717
include/databento/detail/shared_channel.hpp
18+
include/databento/detail/socket.hpp
19+
include/databento/detail/tcp_client.hpp
1820
src/scoped_thread.hpp
1921
src/stream_op_helper.hpp
2022
)
@@ -28,9 +30,12 @@ set(sources
2830
src/exceptions.cpp
2931
src/file_bento.cpp
3032
src/historical.cpp
33+
src/metadata.cpp
3134
src/record.cpp
3235
src/symbology.cpp
3336
src/detail/file_stream.cpp
3437
src/detail/http_client.cpp
3538
src/detail/shared_channel.cpp
39+
src/detail/socket.cpp
40+
src/detail/tcp_client.cpp
3641
)

example/metadata.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ int main() {
5050
}
5151
std::cout << '\n';
5252

53+
const auto dataset_condition = client.MetadataGetDatasetCondition(
54+
"GLBX.MDP3", "2019-06-01", "2019-08-01");
55+
std::cout << dataset_condition << "\n\n";
56+
5357
const auto compressions = client.MetadataListCompressions();
5458
std::cout << "Compressions:\n";
5559
for (const auto compression : compressions) {

example/symbology_resolve.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "databento/symbology.hpp"
99

1010
int main(int argc, char* argv[]) {
11-
if (argc < 6) {
11+
if (argc < 7) {
1212
std::cerr << "USAGE: symbology-resolve <DATASET> <STYPE_IN> <STYPE_OUT> "
1313
"<START_DATE> <END_DATE> <SYMBOLS...>\n";
1414
return EX_USAGE;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <string>
5+
namespace databento {
6+
namespace detail {
7+
// RAII wrapper around a socket.
8+
class Socket {
9+
public:
10+
Socket(const std::string& addr, std::uint16_t port);
11+
Socket(const Socket&) = delete;
12+
Socket& operator=(const Socket&) = delete;
13+
Socket(Socket&& other) noexcept;
14+
Socket& operator=(Socket&& other) noexcept;
15+
~Socket();
16+
17+
int Get() const { return fd_; }
18+
19+
private:
20+
int fd_;
21+
};
22+
} // namespace detail
23+
} // namespace databento
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include <cstdint>
5+
#include <string>
6+
7+
#include "databento/detail/socket.hpp"
8+
9+
namespace databento {
10+
namespace detail {
11+
class TcpClient {
12+
public:
13+
TcpClient(const std::string& gateway, std::uint16_t port);
14+
15+
void WriteAll(const char* buffer, std::size_t size);
16+
// returns bytes read
17+
std::size_t Read(char* buffer, std::size_t max_size);
18+
void ReadExact(char* buffer, std::size_t size);
19+
20+
private:
21+
Socket socket_;
22+
};
23+
} // namespace detail
24+
} // namespace databento

include/databento/enums.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
namespace databento {
88
// Represents a historical data center gateway location.
99
enum class HistoricalGateway : std::uint8_t {
10-
Nearest = 0,
1110
Bo1,
1211
};
1312

1413
// Represents a live data center gateway location.
1514
enum class LiveGateway : std::uint8_t {
1615
Origin = 0,
17-
Nearest,
1816
Ny4,
1917
Dc3,
2018
};
@@ -101,6 +99,12 @@ enum class JobState : std::uint8_t {
10199
Expired,
102100
};
103101

102+
// The condition of a dataset at a point in time.
103+
enum class DatasetCondition : std::uint8_t {
104+
Available,
105+
Bad,
106+
};
107+
104108
// Convert a HistoricalGateway to a URL.
105109
const char* UrlFromGateway(HistoricalGateway gateway);
106110

@@ -113,6 +117,7 @@ const char* ToString(SplitDuration duration_interval);
113117
const char* ToString(Packaging packaging);
114118
const char* ToString(Delivery delivery);
115119
const char* ToString(JobState state);
120+
const char* ToString(DatasetCondition condition);
116121

117122
std::ostream& operator<<(std::ostream& out, Schema schema);
118123
std::ostream& operator<<(std::ostream& out, Encoding encoding);
@@ -123,6 +128,7 @@ std::ostream& operator<<(std::ostream& out, SplitDuration duration_interval);
123128
std::ostream& operator<<(std::ostream& out, Packaging packaging);
124129
std::ostream& operator<<(std::ostream& out, Delivery delivery);
125130
std::ostream& operator<<(std::ostream& out, JobState state);
131+
std::ostream& operator<<(std::ostream& out, DatasetCondition condition);
126132

127133
template <typename T>
128134
T FromString(const std::string& str);
@@ -144,4 +150,6 @@ template <>
144150
Delivery FromString(const std::string& str);
145151
template <>
146152
JobState FromString(const std::string& str);
153+
template <>
154+
DatasetCondition FromString(const std::string& str);
147155
} // namespace databento

include/databento/exceptions.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ class HttpResponseError : public Exception {
6565
const std::string response_body_;
6666
};
6767

68+
// Exception indicating an issue with the TCP connection.
69+
class TcpError : public Exception {
70+
public:
71+
explicit TcpError(int err_num, std::string message)
72+
: Exception{BuildMessage(err_num, std::move(message))},
73+
err_num_{err_num} {};
74+
75+
int err_num() const { return err_num_; }
76+
77+
private:
78+
static std::string BuildMessage(int err_num, std::string message);
79+
80+
int err_num_;
81+
};
82+
6883
// Exception indicating an argument to a callable is invalid.
6984
class InvalidArgumentError : public Exception {
7085
public:

0 commit comments

Comments
 (0)