Available languages: [Python](https://databento.com/docs/api-live/basics/protocol.python.md) · [C++](https://databento.com/docs/api-live/basics/protocol.cpp.md) · [Rust](https://databento.com/docs/api-live/basics/protocol.rust.md) · [Raw](https://databento.com/docs/api-live/basics/protocol.raw.md)

Source: https://databento.com/docs/api-live/basics/protocol


# Protocol

The Raw API protocol is divided into two main parts: control messages and data records.

All messages sent by the client to the gateway are control messages.

## Control messages

Control messages are used for authentication and subscribing to the gateway, and are encoded
as ASCII text. A single control message is composed by a series of `key=value`
pairs (called fields from now) separated by the `|` character.

Every control message terminates with a newline character (`\n`).

A control message can have optional and required fields.
A control message which contains an unknown field or does not contain a required field will be considered invalid by the gateway.
Control messages are limited to 64KiB; messages exceeding this length are invalid.
After an invalid control message, the gateway will terminate the session with an [error message](https://databento.com/docs/api-live/basics/errors.md).

An example of a correctly-formatted [subscription request](https://databento.com/docs/api-live/client-control-messages/subscription-request.md) control message is `schema=trades|stype_in=raw_symbol|symbols=SPY\n`.

## Data records

Once authenticated with the gateway, the gateway will not send any new control messages;
subsequent messages will always be data records.

If [compression](https://databento.com/docs/api-live/basics/compression.md) is enabled, the data record stream will need to be decompressed with the compression algorithm
of choice before decoding.

Data records are sent in the [encoding](https://databento.com/docs/api-live/basics/encodings.md) specified during authentication.
Unlike in the historical API, the CSV encoding is not supported.

In the DBN encoding, the records will be sequentially streamed.
In the JSON encoding, the records will follow the [JSON lines specification](https://jsonlines.org/),
where each line of the file is a JSON object. Lines use UNIX-style `\n` separators.

## The `ts_out` parameter

If the client chose to set the `ts_out` parameter during the authentication, the gateway will send its send
timestamp with every data record. The format will vary per encoding.

In the `dbn` encoding, the `ts_out` is a 64-bit unsigned integer appended to every data record.
In the `json` encoding, the `ts_out` is added as an additional field within each JSON object.
Some records may share a `ts_out` value captured before those records are encoded.
