Source: https://databento.com/docs/quickstart


# Quickstart



## Set up Databento

You need an API key to request data from Databento.
[Sign up]($PLATFORM_HOSTNAME/signup) and you will automatically
receive an API key. Each API key is a 32-character
string starting with `db-`, that can be found on the
[API keys]($PLATFORM_HOSTNAME/portal/keys) page on your portal.

> **Info**
>
> Every new account receives [$125 in free data credits](https://databento.com/docs/faqs/usage-pricing-and-data-credits.md).
> These credits allow you to start receiving actual historical data immediately
> and verify your integration at no cost.


## Choose a service

Databento provides two data services: historical and live. These two
services are nearly identical, but we separate them due to licensing fees
and the differences between request-response and real-time streaming
APIs. You can choose to integrate just one or both services.

|  | Historical | Live | Reference |
| Coverage | Historical and delayed intraday data within the exchange's live data restrictions. | Intraday data from within the last 24 hours and real-time data. | Historical with intraday updates. |
| Pricing | Usage-based or flat-rate. No monthly license fees. | Flat-rate. Monthly license fees apply. | Dataset license fees apply. |
| Access | Client libraries (C++, Python, and Rust) and API (HTTP). | Client libraries (C++, Python, and Rust) and API (Raw). | Client libraries (Python and Rust) and API (HTTP). |


## Build your first application

Historical

Live

Reference


## Getting historical data

Select how you will be integrating Databento below to see
installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our historical service through its HTTP API.

The easiest way of using our library is by embedding it with [CMake FetchContent](https://cmake.org/cmake/help/v3.11/module/FetchContent.html).
The minimum required CMake version is 3.24.
Create a `CMakeLists.txt` that looks like the following:

```cmake
# CMakeLists.txt
cmake_minimum_required(VERSION 3.24)

project(databento_historical_example)
include(FetchContent)

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

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

You'll also need to ensure the following dependencies are installed:
- [OpenSSL](https://www.openssl.org/) (minimum version 3.0)
- [Libcrypto](https://www.openssl.org/docs/man3.0/man7/crypto.html)
- [Zstandard (zstd)](https://github.com/facebook/zstd)

CMake downloads libdbn\_c, the C interface to the [DBN library](https://github.com/databento/dbn), as a prebuilt library.
Platforms without a prebuilt build it from source, which requires a [Rust toolchain](https://rustup.rs).

A simple Databento application looks like this:

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

using namespace databento;

int main() {
  auto client =
      Historical::Builder().SetKey("$YOUR_API_KEY").Build();
  auto store = client.TimeseriesGetRange(
      "GLBX.MDP3", {"2022-06-10T14:30", "2022-06-10T14:40"},
      kAllSymbols, Schema::Trades, SType::RawSymbol,
      SType::InstrumentId, {});
  while (const auto* record = store.NextRecord()) {
    const auto& trade_msg = record->Get<TradeMsg>();
    std::cout << trade_msg << '\n';
  }
}
```

Copy this to a file named `main.cpp` in the same directory as the `CMakeLists.txt`, then compile and run the application.

```sh
cmake -S . -B build            # configure
cmake --build build --parallel # build
./build/example                # run
```

This replays 10 minutes of trades of the entire CME Globex market event-by-event.
You can modify this application to specify particular
[instruments](https://databento.com/docs/faqs/instruments-and-products.md),
and [schemas](https://databento.com/docs/schemas/whats-a-schema.md).

Let's get `ESM2` and `NQZ2` data in 1-second OHLCV bars:

```cpp
#include <databento/dbn.hpp>
#include <databento/historical.hpp>
#include <databento/symbol_map.hpp>
#include <iostream>

using namespace databento;

int main() {
  auto client =
      Historical::Builder().SetKey("$YOUR_API_KEY").Build();
  auto store = client.TimeseriesGetRange(
      "GLBX.MDP3", {"2022-06-10T14:30", "2022-06-10T14:40"},
      {"ESM2", "NQZ2"}, Schema::Trades, SType::RawSymbol,
      SType::InstrumentId, {});
  auto symbol_map = store.GetMetadata().CreateSymbolMap();
  while (const auto* record = store.NextRecord()) {
    const auto& trade_msg = record->Get<TradeMsg>();
    std::cout << "Received trade for "
              << symbol_map.At(trade_msg) << ": " << trade_msg
              << '\n';
  }
}
```
Rebuild and run the application with:
```sh
cmake --build build --parallel
./build/example
```

You have successfully written your first historical data application
with Databento! Here are shortcuts to some of the next steps you can
take:

- To download a large amount of data to disk, see how to do
  a [batch download](https://databento.com/docs/faqs/streaming-vs-batch-download.md)
  of data files.
- To get another dataset, just swap the dataset. You can get a list of
  datasets and their names from our [metadata](https://databento.com/docs/api-historical/metadata.md).
- You can use our [symbology](https://databento.com/docs/api-historical/symbology.md)
  API to find other instrument IDs.
- You can also find dataset names and instrument IDs interactively from
  our [search]($PLATFORM_HOSTNAME).

To learn more, read the full documentation for our historical service
under [API reference - Historical](https://databento.com/docs/api-historical.md).


## Getting historical data

Select how you will be integrating Databento below to see
installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our historical service through its HTTP API.

You can use our HTTP API with any client that can send HTTP requests.
We will demonstrate this with both curl and your web browser.

A simple historical data request looks like this:

```sh
curl -G 'https://hist.databento.com/v0/timeseries.get_range' \
 -u $YOUR_API_KEY: \
 -d dataset=GLBX.MDP3 \
 -d start=2022-06-06T14:30 \
 -d end=2022-06-06T14:40
```

Copy this command to your shell and run the command. Keep the colon after your
API key, which indicates to curl that no password is required.

You can also [make this request on your web browser](https://hist.databento.com/v0/timeseries.get_range?dataset=GLBX.MDP3&start=2022-06-06T14:30&end=2022-06-06T14:40).
When prompted, provide your API key as the username and leave the password
blank.

This request fetches the full order book data of the entire CME Globex
market. You can modify this request to specify the [symbols](https://databento.com/docs/faqs/instruments-and-products.md),
[schema](https://databento.com/docs/schemas/whats-a-schema.md), and
[encoding](https://databento.com/docs/api-historical/basics/encodings.md) you want to use. Let's get
`ESM2` data in 1 second OHLCV bars and JSON encoding:

```sh
curl -G 'https://hist.databento.com/v0/timeseries.get_range' \
 -u $YOUR_API_KEY: \
 -d dataset=GLBX.MDP3 \
 -d symbols=ESM2 \
 -d schema=ohlcv-1s \
 -d start=2022-06-06T14:30 \
 -d end=2022-06-06T14:40 \
 -d encoding=json
```
If you're doing this on a web browser, [try this](https://hist.databento.com/v0/timeseries.get_range?dataset=GLBX.MDP3&symbols=ESM2&schema=OHLCV-1s&encoding=json&start=2022-06-06T14:30&end=2022-06-06T14:40).

You have successfully made your first historical data request
with Databento! Here are shortcuts to some next steps you can take:

- To download a large amount of data to disk, see how to do
  a [batch download](https://databento.com/docs/faqs/streaming-vs-batch-download.md)
  of data files.
- To get another dataset, just swap the dataset. You can get a list of
  datasets and their names from our [metadata](https://databento.com/docs/api-historical/metadata.md).
- You can use our [symbology](https://databento.com/docs/api-historical/symbology.md)
  API to find other instrument IDs.
- You can also find dataset names and symbols interactively from
  the [search]($PLATFORM_HOSTNAME) feature on our site.

To learn more, read the full documentation for our historical service
under [API reference - Historical](https://databento.com/docs/api-historical.md).


## Getting historical data

Select how you will be integrating Databento below to see
installation instructions.
By default, Python has been selected for you.

If you don't see an official client library for your preferred
language, you can still integrate our historical service through its HTTP API.

Install our Python client library with pip.
Python 3.10+ is required.
```sh
$ pip install databento
```

A simple Databento historical application looks like this.

This replays 10 minutes of trades of the entire CME Globex market event-by-event.

Copy this to a file `main.py`. Then, run the file with `python main.py`.

```python
import databento as db

client = db.Historical("$YOUR_API_KEY")
data = client.timeseries.get_range(
    dataset="GLBX.MDP3",
    symbols="ALL_SYMBOLS",
    start="2022-06-02T14:20:00",
    end="2022-06-02T14:30:00",
)

data.replay(print)
```

You can modify this application to specify particular
[instruments](https://databento.com/docs/faqs/instruments-and-products.md),
and [schemas](https://databento.com/docs/schemas/whats-a-schema.md).

Let's get `ESM2` and `NQZ2` data in 1-second OHLCV bars.

```python
import databento as db

client = db.Historical("$YOUR_API_KEY")
data = client.timeseries.get_range(
    dataset="GLBX.MDP3",
    symbols=["ESM2", "NQZ2"],
    schema="ohlcv-1s",
    start="2022-06-06T14:30:00",
    end="2022-06-06T14:40:00",
)

data.replay(print)
```

You have successfully written your first historical data application
with Databento! Here are shortcuts to some of the next steps you can
take:

- To download a large amount of data to disk, see how to do
  a [batch download](https://databento.com/docs/faqs/streaming-vs-batch-download.md)
  of data files.
- To get another dataset, just swap the dataset. You can get a list of
  datasets and their names from our [metadata](https://databento.com/docs/api-historical/metadata.md).
- You can use our [symbology](https://databento.com/docs/api-historical/symbology.md)
  API to find other instrument IDs.
- You can also find dataset names and instrument IDs interactively from
  our [search]($PLATFORM_HOSTNAME).

To learn more, read the full documentation for our historical service
under [API reference - Historical](https://databento.com/docs/api-historical.md).


## Getting historical data

Select how you will be integrating Databento below to see
installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our historical service through its HTTP API.

Add our Rust client to your project's dependencies with `cargo`.
```sh
$ cargo add databento
```

A simple Databento application looks like this.

This replays 10 minutes of trades of the entire CME Globex market event-by-event.

Copy this to a file named `main.rs`, then compile and run the application.

```rust
use databento::{
    HistoricalClient, Symbols,
    dbn::{Schema, TradeMsg},
    historical::timeseries::GetRangeParams,
};
use time::macros::datetime;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut client = HistoricalClient::builder()
        .key("$YOUR_API_KEY")?
        .build()?;
    let mut decoder = client
        .timeseries()
        .get_range(
            &GetRangeParams::builder()
                .dataset("GLBX.MDP3")
                .date_time_range(
                    datetime!(2022-06-10 14:30 UTC)
                        ..datetime!(2022-06-10 14:40 UTC),
                )
                .symbols(Symbols::All)
                .schema(Schema::Trades)
                .build(),
        )
        .await?;
    while let Some(trade) =
        decoder.decode_record::<TradeMsg>().await?
    {
        println!("{trade:?}");
    }
    Ok(())
}
```

You can modify this application to specify particular
[instruments](https://databento.com/docs/faqs/instruments-and-products.md),
and [schemas](https://databento.com/docs/schemas/whats-a-schema.md),

Let's get `ESM2` and `NQZ2` data in 1-second OHLCV bars.

```rust
use databento::{
    HistoricalClient,
    dbn::{OhlcvMsg, Schema},
    historical::timeseries::GetRangeParams,
};
use time::macros::datetime;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut client = HistoricalClient::builder()
        .key("$YOUR_API_KEY")?
        .build()?;
    let mut decoder = client
        .timeseries()
        .get_range(
            &GetRangeParams::builder()
                .dataset("GLBX.MDP3")
                .date_time_range(
                    datetime!(2022-06-10 14:30 UTC)
                        ..datetime!(2022-06-10 14:40 UTC),
                )
                .symbols(vec!["ESM2", "NQZ2"])
                .schema(Schema::Ohlcv1S)
                .build(),
        )
        .await?;
    while let Some(bar) =
        decoder.decode_record::<OhlcvMsg>().await?
    {
        println!("{bar:?}");
    }
    Ok(())
}
```

You have successfully written your first historical data application
with Databento! Here are shortcuts to some of the next steps you can
take:

- To download a large amount of data to disk, see how to do
  a [batch download](https://databento.com/docs/faqs/streaming-vs-batch-download.md)
  of data files.
- To get another dataset, just swap the dataset. You can get a list of
  datasets and their names from our [metadata](https://databento.com/docs/api-historical/metadata.md).
- You can use our [symbology](https://databento.com/docs/api-historical/symbology.md)
  API to find other instrument IDs.
- You can also find dataset names and instrument IDs interactively from
  our [search]($PLATFORM_HOSTNAME).

To learn more, read the full documentation for our historical service
under [API reference - Historical](https://databento.com/docs/api-historical.md).


## Getting live data

Select how you will be integrating Databento below to see installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our service via the Raw API.

The easiest way of using our library is by embedding it with [CMake FetchContent](https://cmake.org/cmake/help/v3.11/module/FetchContent.html).
The minimum required CMake version is 3.24.
Create a `CMakeLists.txt` that looks like the following:

```cmake
# CMakeLists.txt
cmake_minimum_required(VERSION 3.24)

project(databento_live_example)
include(FetchContent)

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

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

You'll also need to ensure the following dependencies are installed:
- [OpenSSL](https://www.openssl.org/) (minimum version 3.0)
- [Libcrypto](https://www.openssl.org/docs/man3.0/man7/crypto.html)
- [Zstandard (zstd)](https://github.com/facebook/zstd)

CMake downloads libdbn\_c, the C interface to the [DBN library](https://github.com/databento/dbn), as a prebuilt library.
Platforms without a prebuilt build it from source, which requires a [Rust toolchain](https://rustup.rs).

A simple Databento live application looks like this:

```cpp
#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 = LiveThreaded::Builder()
                    .SetKey("$YOUR_API_KEY")
                    .SetDataset("GLBX.MDP3")
                    .BuildThreaded();

  auto handler = [&symbol_mappings](const Record& rec) {
    symbol_mappings.OnRecord(rec);
    if (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;
}
```
Copy this to a file named `main.cpp` in the same directory as the `CMakeLists.txt`, then compile and run the application.

```sh
cmake -S . -B build            # configure
cmake --build build --parallel # build
./build/example                # run
```

This will stream and print trades for E-mini S&P 500 futures contracts, event-by-event, for 10 seconds.
You can modify this application to specify other [instruments](https://databento.com/docs/faqs/instruments-and-products.md)
 and [schemas](https://databento.com/docs/schemas/whats-a-schema.md).

Let's get `ESZ5` and `ESZ5 C6000` data in 1-second OHLCV bars.
We'll also handle unexpected messages and [errors](https://databento.com/docs/api-live/basics/errors.md) in case something goes wrong.
Since we're handling more messages, it makes sense to change to a `switch` statement based on
the [rtype](https://databento.com/docs/conventions/common-fields-enums-types.md#rtype) or record type field in the header of each record.

```cpp
#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 = LiveThreaded::Builder()
                    .SetKey("$YOUR_API_KEY")
                    .SetDataset("GLBX.MDP3")
                    .BuildThreaded();

  auto handler = [&symbol_mappings](const Record& rec) {
    if (auto* trade = rec.GetIf<TradeMsg>()) {
      std::cout << "Received trade for "
                << symbol_mappings[trade->hd.instrument_id]
                << ':' << *trade << '\n';
    } else if (auto* mapping = rec.GetIf<SymbolMappingMsg>()) {
      std::cout << "Received symbol mapping: " << *mapping
                << '\n';
      symbol_mappings.OnSymbolMapping(*mapping);
    } else if (!rec.Holds<SystemMsg>() &&
               !rec.Holds<ErrorMsg>()) {
      std::cerr << "Received unknown record with rtype "
                << std::hex
                << static_cast<std::uint16_t>(rec.RType())
                << '\n';
    }
    return KeepGoing::Continue;
  };

  client.Subscribe({"ESZ5", "ESZ5 C6000"}, Schema::Trades,
                   SType::RawSymbol);
  client.Start(handler);
  std::this_thread::sleep_for(std::chrono::seconds{10});
  return 0;
}
```
Rebuild and run the application with:
```sh
cmake --build build --parallel
./build/example
```

You have successfully written your first live data application with Databento!
To learn more, read the full documentation for our live service under
[API reference - Live](https://databento.com/docs/api-live.md).


## Getting live data

Select how you will be integrating Databento below to see installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our service via the Raw API.

Install our Python client library with pip.
Python 3.10+ is required.
```sh
$ pip install -U databento
```

A simple Databento live application looks like this.

This prints 10 seconds of trades for all ES futures contracts event-by-event.

Copy this to a file `main.py`. Then, run the file with `python main.py`.

```python
import databento as db

client = db.Live(key="$YOUR_API_KEY")

client.subscribe(
    dataset="GLBX.MDP3",
    schema="trades",
    stype_in="parent",
    symbols="ES.FUT",
)

client.add_callback(print)

client.start()

client.block_for_close(timeout=10)
```

You can modify this application to specify particular
[instruments](https://databento.com/docs/faqs/instruments-and-products.md),
and [schemas](https://databento.com/docs/schemas/whats-a-schema.md).

Let's get `ES.FUT` and `NQ.FUT` data in 1-second OHLCV bars.

```python
import databento as db

client = db.Live(key="$YOUR_API_KEY")

client.subscribe(
    dataset="GLBX.MDP3",
    schema="ohlcv-1s",
    stype_in="parent",
    symbols=["ES.FUT", "NQ.FUT"],
)

client.add_callback(print)

client.start()

client.block_for_close(timeout=10)
```

You have successfully written your first live data application with Databento!
To learn more, read the full documentation for our live service
under [API reference - Live](https://databento.com/docs/api-live.md).


# Getting live data

Select how you will be integrating Databento below to see installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our service via the Raw API.

As an example, we're going to implement a rudimentary Raw API client with bash.

A simple Databento Raw API client looks like this:

```sh
#!/usr/bin/env bash
set -e

KEY=$YOUR_API_KEY

cram_response() {
    local cram=${1#cram=}
    local hash=$(echo -n "$cram|$KEY" | sha256sum | head -c 64)
    local resp=$hash-${KEY: -5}
    echo "auth=$resp|dataset=GLBX.MDP3|encoding=json|ts_out=1"
}

exec 3<>/dev/tcp/glbx-mdp3.lsg.databento.com/13000
trap 'exec 3>&-' EXIT

read version_str <&3
read cram <&3

response=$(cram_response $cram)

echo $response >&3
read success <&3

if ! [[ $success =~ "success=1" ]]; then
    echo "Authentication failed" >&2
    exit 2
fi

echo "schema=trades|stype_in=parent|symbols=ES.FUT" >&3
echo "start_session=1" >&3

timeout 20s cat <&3
```

Copy this to a file `client.sh`. Then, run the file with `sh client.sh`.

This script opens a TCP connection to `glbx-mdp3.lsg.databento.com:13000`,
which is the entry point for `GLBX.MDP3` live data, [authenticates](https://databento.com/docs/api-live/message-flows/authentication.md),
and [subscribes](https://databento.com/docs/api-live/message-flows/subscription.md) to trades for all ES futures contracts (`ES.FUT`).
Then it will [start the session](https://databento.com/docs/api-live/message-flows/start-session.md) and print 10 seconds of events,
event-by-event in JSON format.

You can modify this script to specify particular
[instruments](https://databento.com/docs/faqs/instruments-and-products.md),
and [schemas](https://databento.com/docs/schemas/whats-a-schema.md).

Let's get `ES.FUT` and `NQ.FUT` data in 1-second OHLCV bars:

```sh
#!/usr/bin/env bash
set -e

KEY=$YOUR_API_KEY

cram_response() {
    local cram=${1#cram=}
    local hash=$(echo -n "$cram|$KEY" | sha256sum | head -c 64)
    local resp=$hash-${KEY: -5}
    echo "auth=$resp|dataset=GLBX.MDP3|encoding=json|ts_out=1"
}

exec 3<>/dev/tcp/glbx-mdp3.lsg.databento.com/13000
trap 'exec 3>&-' EXIT

read version_str <&3
read cram <&3

response=$(cram_response $cram)

echo $response >&3
read success <&3

if ! [[ $success =~ "success=1" ]]; then
    echo "Authentication failed" >&2
    exit 2
fi

echo "schema=ohlcv-1s|stype_in=parent|symbols=ES.FUT,NQ.FUT" >&3
echo "start_session=1" >&3

timeout 10s cat <&3
```

You have successfully written your first live data application with Databento!
To learn more, read the full documentation for our live service
under [API reference - Live](https://databento.com/docs/api-live.md).


## Getting live data

Select how you will be integrating Databento below to see installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our service via the Raw API.

Add our Rust client to your project's dependencies with `cargo`.
```sh
$ cargo add databento
```

A simple Databento live application looks like this.

This will stream and print trades for E-mini S&P 500 futures contracts, event-by-event, for 10 seconds.

Copy this to a file named `main.rs`, then compile and run the application.

```rust
use std::time::{Duration, Instant};

use databento::{
    LiveClient,
    dbn::{PitSymbolMap, SType, Schema, TradeMsg},
    live::Subscription,
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut client = LiveClient::builder()
        .key("$YOUR_API_KEY")?
        .dataset("GLBX.MDP3")
        .build()
        .await?;
    client
        .subscribe(
            Subscription::builder()
                .symbols("ES.FUT")
                .schema(Schema::Trades)
                .stype_in(SType::Parent)
                .build(),
        )
        .await?;
    client.start().await?;
    let mut symbol_map = PitSymbolMap::new();
    let now = Instant::now();
    while let Some(rec) = client.next_record().await? {
        if let Some(trade) = rec.get::<TradeMsg>() {
            let symbol = &symbol_map[trade.hd.instrument_id];
            println!("Received trade for {symbol}: {trade:?}");
        } else {
            symbol_map.on_record(rec)?;
        }
        if now.elapsed() > Duration::from_secs(10) {
            break;
        }
    }
    Ok(())
}
```

You can modify this application to specify other [instruments](https://databento.com/docs/faqs/instruments-and-products.md)
 and [schemas](https://databento.com/docs/schemas/whats-a-schema.md).

Let's get `ESZ4` and `ESZ4 C4000` data in 1-second OHLCV bars.
We'll also handle unexpected messages and [errors](https://databento.com/docs/api-live/basics/errors.md) in case something goes wrong.
Since we're handling more messages, it makes sense to change to a `match` expression based on
the `rtype` or record type field in the header of each record.

```rust
use std::time::{Duration, Instant};

use databento::{
    LiveClient,
    dbn::{OhlcvMsg, PitSymbolMap, RType, Record, Schema},
    live::Subscription,
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut client = LiveClient::builder()
        .key_from_env()?
        .dataset("GLBX.MDP3")
        .build()
        .await?;
    client
        .subscribe(
            Subscription::builder()
                .symbols(vec!["ESZ5", "ESZ5 C6000"])
                .schema(Schema::Ohlcv1S)
                .start(time::OffsetDateTime::UNIX_EPOCH)
                .build(),
        )
        .await?;
    client.start().await?;
    let mut symbol_map = PitSymbolMap::new();
    let now = Instant::now();
    while let Some(rec) = client.next_record().await? {
        match rec.rtype()? {
            RType::Ohlcv1S => {
                let bar = rec.get::<OhlcvMsg>().unwrap();
                println!(
                    "Received bar for {}: {bar:?}",
                    symbol_map[bar.hd.instrument_id]
                );
            }
            RType::SymbolMapping => {
                symbol_map.on_record(rec)?;
            }
            RType::System | RType::Error => {}
            rtype => {
                eprintln!(
                    "Received record with unexpected rtype {rtype:?}"
                );
            }
        }
        if now.elapsed() > Duration::from_secs(10) {
            break;
        }
    }
    Ok(())
}
```

You have successfully written your first live data application with Databento!
To learn more, read the full documentation for our live service under
[API reference - Live](https://databento.com/docs/api-live.md).


## Getting reference data

Select how you will be integrating Databento below to see
installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our reference service through its HTTP API.

You can use our HTTP API with any client that can send HTTP requests.
We will demonstrate this with both curl and your web browser.

This request fetches all dividend event records for Microsoft from 1st January 2019 to 30th June 2024.
You can modify this request to specify particular [symbols](https://databento.com/docs/faqs/instruments-and-products.md),
and [events](https://databento.com/docs/datasets/corporate-actions.md#events).

```sh
curl -G 'https://hist.databento.com/v0/corporate_actions.get_range' \
 -u $YOUR_API_KEY: \
 -d start=2019 \
 -d end=2024-06 \
 -d symbols=MSFT \
 -d events=DIV \
 -d countries=US
```

You have successfully written your first reference data application
with Databento! Here are shortcuts to some of the next steps you can
take:

- Read the corporate actions [dataset guide](https://databento.com/docs/datasets/corporate-actions.md).
- Become familiar with the reference data [enum lookup tables](https://databento.com/docs/conventions/reference-data-enums.md).
- Go through the corporate actions [examples](https://databento.com/docs/examples/corporate-actions.md).

To learn more, read the full documentation for our reference service
under [Reference API](https://databento.com/docs/api-reference-data.md).


## Getting reference data

Select how you will be integrating Databento below to see
installation instructions.
By default, Python has been selected for you.

If you don't see an official client library for your preferred
language, you can still integrate our reference service through its HTTP API.

Install our Python client library with pip.
Python 3.10+ is required.
```sh
$ pip install databento
```

A simple Databento reference application looks like this.

This request fetches all dividend event records for Microsoft from January 2019 until June 2024.
You can modify this request to specify particular [symbols](https://databento.com/docs/faqs/instruments-and-products.md),
and [events](https://databento.com/docs/datasets/corporate-actions.md#events).

Copy this to a file `main.py`. Then, run the file with `python main.py`.

```python
import databento as db

client = db.Reference("$YOUR_API_KEY")
df = client.corporate_actions.get_range(
    start="2019",
    end="2024-07",
    symbols=["MSFT"],
    events=["DIV"],
    countries=["US"],
)

print(df)
```

You have successfully written your first reference data application
with Databento! Here are shortcuts to some of the next steps you can
take:

- Read the corporate actions [dataset guide](https://databento.com/docs/datasets/corporate-actions.md).
- Become familiar with the reference data [enum lookup tables](https://databento.com/docs/conventions/reference-data-enums.md).
- Go through the corporate actions [examples](https://databento.com/docs/examples/corporate-actions.md).

To learn more, read the full documentation for our reference service
under [Reference API](https://databento.com/docs/api-reference-data.md).


## Getting reference data

Select how you will be integrating Databento below to see installation instructions.

If you don't see an official client library for your preferred
language, you can still integrate our reference service through its HTTP API.

Add our Rust client to your project's dependencies with `cargo`.
```sh
$ cargo add databento
```

A simple Databento reference application looks like this.

This request fetches all dividend event records for Microsoft from January 2019 until June 2024.
You can modify this request to specify particular [symbols](https://databento.com/docs/faqs/instruments-and-products.md),
and [events](https://databento.com/docs/datasets/corporate-actions.md#events).

Copy this to a file named `main.rs`, then compile and run the application.

```rust
use databento::{
    ReferenceClient,
    reference::{Country, Event, corporate::GetRangeParams},
};
use time::macros::date;

let mut client =
    ReferenceClient::builder().key("$YOUR_API_KEY")?.build()?;
let corporate_actions = client
    .corporate_actions()
    .get_range(
        &GetRangeParams::builder()
            .symbols("MSFT")
            .start(date!(2019 - 01 - 01))
            .end(date!(2024 - 08 - 01))
            .events([Event::Div])
            .countries([Country::Us])
            .build(),
    )
    .await?;
println!("{corporate_actions:#?}");
```

You have successfully written your first reference data application
with Databento! Here are shortcuts to some of the next steps you can
take:

- Read the corporate actions [dataset guide](https://databento.com/docs/datasets/corporate-actions.md).
- Become familiar with the reference data [enum lookup tables](https://databento.com/docs/conventions/reference-data-enums.md).
- Go through the corporate actions [examples](https://databento.com/docs/examples/corporate-actions.md).

To learn more, read the full documentation for our reference service
under [Reference API](https://databento.com/docs/api-reference-data.md).


## New user guides

**[What's a schema?](https://databento.com/docs/schemas/whats-a-schema.md)**

See fields and columns included with each schema.

![Supported Schemas](https://databento.com/docs/supported-chemas.svg.md)

**[Symbology](https://databento.com/docs/conventions/symbology.md)**

How to interpret instrument IDs, symbols, and definitions.

![Symbology](https://databento.com/docs/quickstart-symbology.svg.md)

**[Normalization format](https://databento.com/docs/conventions/normalization.md)**

Learn more about our data normalization.

![Normalization Format](https://databento.com/docs/normalization-format.svg.md)

**[DBN files and encoding](https://databento.com/docs/conventions/databento-binary-encoding.md)**

Save and read our data in DBN, our lightning-fast binary format.

![DBN Encoding](https://databento.com/docs/files-and-encoding.svg.md)

**[Equities](https://databento.com/docs/examples/equities/equities-introduction.md)**

Get started on equities data like Nasdaq TotalView-ITCH.

![Equities](https://databento.com/docs/equities.svg.md)

**[Equity options](https://databento.com/docs/examples/options/equity-options-introduction.md)**

Get started on equity options data like OPRA.

![Equity Options](https://databento.com/docs/equity-options.svg.md)

**[Futures](https://databento.com/docs/examples/futures/futures-introduction.md)**

Get started on futures data like CME Globex MDP 3.0.

![Futures](https://databento.com/docs/futures.svg.md)

**[Options on futures](https://databento.com/docs/examples/options/options-on-futures-introduction.md)**

Get started on options on futures data.

![Futures Options](https://databento.com/docs/futures-options.svg.md)


## New user guides

**[What's a schema?](https://databento.com/docs/schemas/whats-a-schema.md)**

See fields and columns included with each schema.

![Supported Schemas](https://databento.com/docs/supported-chemas.svg.md)

**[Symbology](https://databento.com/docs/conventions/symbology.md)**

How to interpret instrument IDs, symbols, and definitions.

![Symbology](https://databento.com/docs/quickstart-symbology.svg.md)

**[Normalization format](https://databento.com/docs/conventions/normalization.md)**

Learn more about our data normalization.

![Normalization Format](https://databento.com/docs/normalization-format.svg.md)

**[DBN files and encoding](https://databento.com/docs/conventions/databento-binary-encoding.md)**

Save and read our data in DBN, our lightning-fast binary format.

![DBN Encoding](https://databento.com/docs/files-and-encoding.svg.md)

**[Equities](https://databento.com/docs/examples/equities/equities-introduction.md)**

Get started on equities data like Nasdaq TotalView-ITCH.

![Equities](https://databento.com/docs/equities.svg.md)

**[Equity options](https://databento.com/docs/examples/options/equity-options-introduction.md)**

Get started on equity options data like OPRA.

![Equity Options](https://databento.com/docs/equity-options.svg.md)

**[Futures](https://databento.com/docs/examples/futures/futures-introduction.md)**

Get started on futures data like CME Globex MDP 3.0.

![Futures](https://databento.com/docs/futures.svg.md)

**[Options on futures](https://databento.com/docs/examples/options/options-on-futures-introduction.md)**

Get started on options on futures data.

![Futures Options](https://databento.com/docs/futures-options.svg.md)


## New user guides

**[What's a schema?](https://databento.com/docs/schemas/whats-a-schema.md)**

See fields and columns included with each schema.

![Supported Schemas](https://databento.com/docs/supported-chemas.svg.md)

**[Symbology](https://databento.com/docs/conventions/symbology.md)**

How to interpret instrument IDs, symbols, and definitions.

![Symbology](https://databento.com/docs/quickstart-symbology.svg.md)

**[Normalization format](https://databento.com/docs/conventions/normalization.md)**

Learn more about our data normalization.

![Normalization Format](https://databento.com/docs/normalization-format.svg.md)

**[DBN files and encoding](https://databento.com/docs/conventions/databento-binary-encoding.md)**

Save and read our data in DBN, our lightning-fast binary format.

![DBN Encoding](https://databento.com/docs/files-and-encoding.svg.md)

**[Equities](https://databento.com/docs/examples/equities/equities-introduction.md)**

Get started on equities data like Nasdaq TotalView-ITCH.

![Equities](https://databento.com/docs/equities.svg.md)

**[Equity options](https://databento.com/docs/examples/options/equity-options-introduction.md)**

Get started on equity options data like OPRA.

![Equity Options](https://databento.com/docs/equity-options.svg.md)

**[Futures](https://databento.com/docs/examples/futures/futures-introduction.md)**

Get started on futures data like CME Globex MDP 3.0.

![Futures](https://databento.com/docs/futures.svg.md)

**[Options on futures](https://databento.com/docs/examples/options/options-on-futures-introduction.md)**

Get started on options on futures data.

![Futures Options](https://databento.com/docs/futures-options.svg.md)


## New user guides

**[What's a schema?](https://databento.com/docs/schemas/whats-a-schema.md)**

See fields and columns included with each schema.

![Supported Schemas](https://databento.com/docs/supported-chemas.svg.md)

**[Symbology](https://databento.com/docs/conventions/symbology.md)**

How to interpret instrument IDs, symbols, and definitions.

![Symbology](https://databento.com/docs/quickstart-symbology.svg.md)

**[Normalization format](https://databento.com/docs/conventions/normalization.md)**

Learn more about our data normalization.

![Normalization Format](https://databento.com/docs/normalization-format.svg.md)

**[DBN files and encoding](https://databento.com/docs/conventions/databento-binary-encoding.md)**

Save and read our data in DBN, our lightning-fast binary format.

![DBN Encoding](https://databento.com/docs/files-and-encoding.svg.md)

**[Equities](https://databento.com/docs/examples/equities/equities-introduction.md)**

Get started on equities data like Nasdaq TotalView-ITCH.

![Equities](https://databento.com/docs/equities.svg.md)

**[Equity options](https://databento.com/docs/examples/options/equity-options-introduction.md)**

Get started on equity options data like OPRA.

![Equity Options](https://databento.com/docs/equity-options.svg.md)

**[Futures](https://databento.com/docs/examples/futures/futures-introduction.md)**

Get started on futures data like CME Globex MDP 3.0.

![Futures](https://databento.com/docs/futures.svg.md)

**[Options on futures](https://databento.com/docs/examples/options/options-on-futures-introduction.md)**

Get started on options on futures data.

![Futures Options](https://databento.com/docs/futures-options.svg.md)


## New user guides

**[What's a schema?](https://databento.com/docs/schemas/whats-a-schema.md)**

See fields and columns included with each schema.

![Supported Schemas](https://databento.com/docs/supported-chemas.svg.md)

**[Symbology](https://databento.com/docs/conventions/symbology.md)**

How to interpret instrument IDs, symbols, and definitions.

![Symbology](https://databento.com/docs/quickstart-symbology.svg.md)

**[Normalization format](https://databento.com/docs/conventions/normalization.md)**

Learn more about our data normalization.

![Normalization Format](https://databento.com/docs/normalization-format.svg.md)

**[DBN files and encoding](https://databento.com/docs/conventions/databento-binary-encoding.md)**

Save and read our data in DBN, our lightning-fast binary format.

![DBN Encoding](https://databento.com/docs/files-and-encoding.svg.md)

**[Equities](https://databento.com/docs/examples/equities/equities-introduction.md)**

Get started on equities data like Nasdaq TotalView-ITCH.

![Equities](https://databento.com/docs/equities.svg.md)

**[Equity options](https://databento.com/docs/examples/options/equity-options-introduction.md)**

Get started on equity options data like OPRA.

![Equity Options](https://databento.com/docs/equity-options.svg.md)

**[Futures](https://databento.com/docs/examples/futures/futures-introduction.md)**

Get started on futures data like CME Globex MDP 3.0.

![Futures](https://databento.com/docs/futures.svg.md)

**[Options on futures](https://databento.com/docs/examples/options/options-on-futures-introduction.md)**

Get started on options on futures data.

![Futures Options](https://databento.com/docs/futures-options.svg.md)
