Code Monkey home page Code Monkey logo

databento-cpp's Introduction

databento-cpp

test license Slack

The official C++ client library for Databento. The client supports both streaming real-time and historical market data through similar interfaces.

Usage

The minimum C++ standard is C++11 and the minimum CMake version is 3.14.

Integration

The easiest way to use our library is by embedding it with CMake FetchContent. Your CMakeLists.txt should look something like the following:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.14)

project(databento_example)
include(FetchContent)

FetchContent_Declare(
  databento
  GIT_REPOSITORY https://github.com/databento/databento-cpp
  GIT_TAG HEAD
)
FetchContent_MakeAvailable(databento)

add_executable(example main.cpp)
target_link_libraries(example PRIVATE databento::databento)

Alternatively, you can clone the source code from GitHub here.

To install the library to /usr, build and install it with the following:

git clone https://github.com/databento/databento-cpp
cd databento-cpp
cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DCMAKE_INSTALL_PREFIX='/usr'
cmake --build build --target databento --parallel
cmake --install build

In your project's CMakeLists.txt, add the following:

# CMakeLists.txt
find_package(databento REQUIRED)
target_link_libraries(example PRIVATE databento::databento)

Dependencies

You'll need to ensure the following dependencies are installed:

By default, cpp-httplib and nlohmann_json are downloaded by CMake as part of the build process. If you would like to use a local version of these libraries, enable the CMake flag DATABENTO_ENABLE_EXTERNAL_HTTPLIB or DATABENTO_ENABLE_EXTERNAL_JSON.

Ubuntu

Run the following commands to install the dependencies on Ubuntu:

$ sudo apt update
$ sudo apt install libssl-dev libzstd-dev

macOS

On macOS, you can install the dependencies with Homebrew by running the following:

$ brew install openssl@3 zstd

Live

Real-time and intraday replay is provided through the Live clients. Here is a simple program that fetches 10 seconds of trades for all ES mini futures:

#include <chrono>
#include <databento/live.hpp>
#include <databento/symbol_map.hpp>
#include <iostream>
#include <string>
#include <thread>

using namespace databento;

int main() {
  PitSymbolMap symbol_mappings;

  auto client =
      LiveBuilder{}.SetKeyFromEnv().SetDataset("GLBX.MDP3").BuildThreaded();

  auto handler = [&symbol_mappings](const Record& rec) {
    symbol_mappings.OnRecord(rec);
    if (const auto* trade = rec.GetIf<TradeMsg>()) {
      std::cout << "Received trade for "
                << symbol_mappings[trade->hd.instrument_id] << ':' << *trade
                << '\n';
    }
    return KeepGoing::Continue;
  };

  client.Subscribe({"ES.FUT"}, Schema::Trades, SType::Parent);
  client.Start(handler);
  std::this_thread::sleep_for(std::chrono::seconds{10});
  return 0;
}

To run this program, set the DATABENTO_API_KEY environment variable with an actual API key.

Historical

Here is a simple program that fetches 10 minutes worth of historical trades for the entire CME Globex market:

#include <databento/constants.hpp>
#include <databento/historical.hpp>
#include <iostream>

using namespace databento;

int main() {
  auto client = HistoricalBuilder{}.SetKeyFromEnv().Build();
  auto print_trades = [](const Record& record) {
    const auto& trade_msg = record.Get<TradeMsg>();
    std::cout << trade_msg << '\n';
    return KeepGoing::Continue;
  };
  client.TimeseriesGetRange("GLBX.MDP3",
                            {"2022-06-10T14:30", "2022-06-10T14:40"},
                            kAllSymbols, Schema::Trades, SType::RawSymbol,
                            SType::InstrumentId, {}, {}, print_trades);
}

To run this program, set the DATABENTO_API_KEY environment variable with an actual API key.

Additional example standalone executables are provided in the example directory. These examples can be compiled by enabling the cmake option DATABENTO_ENABLE_EXAMPLES with -DDATABENTO_ENABLE_EXAMPLES=1 during the configure step.

Documentation

You can find more detailed examples and the full API documentation on the Databento doc site.

License

Distributed under the Apache 2.0 License.

databento-cpp's People

Contributors

threecgreen avatar cjdsellers avatar nmacholl avatar renan-databento avatar hailios avatar akovachev avatar camrongodbout avatar naomi-danielle avatar zcqian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.