Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Mar 2, 2024
1 parent 03fa6c7 commit 4fb94e3
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 43 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ NautilusTrader is designed in a modular way to work with 'adapters' which provid
connectivity to data providers and/or trading venues - converting their raw API
into a unified interface. The following integrations are currently supported:

| Name | ID | Type | Status | Docs |
| :-------------------------------------------------------- | :-------------------- | :---------------------- | :------------------------------------------------------ | :---------------------------------------------------------------- |
| [Betfair](https://betfair.com) | `BETFAIR` | Sports betting exchange | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/betfair.html) |
| [Binance](https://binance.com) | `BINANCE` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance US](https://binance.us) | `BINANCE` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance Futures](https://www.binance.com/en/futures) | `BINANCE` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Bybit](https://www.bybit.com) | `BYBIT` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/building-orange) | |
| [Databento](https://databento.com) | `DATABENTO` | Data provider | ![status](https://img.shields.io/badge/building-orange) | |
| [Interactive Brokers](https://www.interactivebrokers.com) | `INTERACTIVE_BROKERS` | Brokerage (multi-venue) | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/ib.html) |
| Name | ID | Type | Status | Docs |
| :-------------------------------------------------------- | :-------------------- | :---------------------- | :------------------------------------------------------ | :------------------------------------------------------------------ |
| [Betfair](https://betfair.com) | `BETFAIR` | Sports betting exchange | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/betfair.html) |
| [Binance](https://binance.com) | `BINANCE` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance US](https://binance.us) | `BINANCE` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance Futures](https://www.binance.com/en/futures) | `BINANCE` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Bybit](https://www.bybit.com) | `BYBIT` | Crypto exchange (CEX) | ![status](https://img.shields.io/badge/building-orange) | |
| [Databento](https://databento.com) | `DATABENTO` | Data provider | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/databento.html) |
| [Interactive Brokers](https://www.interactivebrokers.com) | `INTERACTIVE_BROKERS` | Brokerage (multi-venue) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/ib.html) |

Refer to the [Integrations](https://docs.nautilustrader.io/integrations/index.html) documentation for further details.

Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
```

To get started with NautilusTrader you will need the following:
- A Python environment with `nautilus_trader` installed
- A Python environment with the `nautilus_trader` package installed
- A way to launch Python scripts for backtesting and/or live trading (either from the command line, or jupyter notebook etc)

## [Installation](installation.md)
Expand Down
18 changes: 9 additions & 9 deletions docs/getting_started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ catalog.instruments()

## Writing a trading strategy

NautilusTrader includes a handful of indicators built-in, in this example we will use a MACD indicator to
build a simple trading strategy.
NautilusTrader includes many indicators built-in, in this example we will use the MACD indicator to
build a simple trading strategy.

You can read more about [MACD here](https://www.investopedia.com/terms/m/macd.asp), so this
You can read more about [MACD here](https://www.investopedia.com/terms/m/macd.asp), this
indicator merely serves as an example without any expected alpha. There is also a way of
registering indicators to receive certain data types, however in this example we manually pass the received
`QuoteTick` to the indicator in the `on_quote_tick` method.
Expand Down Expand Up @@ -167,9 +167,9 @@ class MACDStrategy(Strategy):

## Configuring Backtests

Now that we have a trading strategy and data, we can begin to configure a backtest run! Nautilus uses a `BacktestNode`
to orchestrate backtest runs, which requires some setup. This may seem a little complex at first,
however this is necessary for the capabilities that Nautilus strives for.
Now that we have a trading strategy and data, we can begin to configure a backtest run.

Nautilus uses a `BacktestNode` to orchestrate backtest runs, which requires some setup.

To configure a `BacktestNode`, we first need to create an instance of a `BacktestRunConfig`, configuring the
following (minimal) aspects of the backtest:
Expand All @@ -178,7 +178,7 @@ following (minimal) aspects of the backtest:
- `venues` - The simulated execution venues (exchanges or brokers) available in the backtest
- `data` - The input data we would like to perform the backtest on

There are many more configurable features which will be described later in the docs, for now this will get us up and running.
There are many more configuration options which are described the docs, for now this will get us up and running.

## Venue

Expand All @@ -205,7 +205,7 @@ venue = BacktestVenueConfig(

## Instruments

Second, we need to know about the instruments that we would like to load data for, we can use the `ParquetDataCatalog` for this:
Second, we need to specify the instruments that we would like to load data for, we can use the `ParquetDataCatalog` for this:

```python
instruments = catalog.instruments()
Expand Down Expand Up @@ -237,7 +237,7 @@ data = BacktestDataConfig(

Then, we need a `BacktestEngineConfig` which represents the configuration of our core trading system.
Here we need to pass our trading strategies, we can also adjust the log level
and configure many other components (however, it's also fine to use the defaults):
and configure many other components (however, it's also fine to use the sensible defaults):

Strategies are added via the `ImportableStrategyConfig`, which allows importing strategies from arbitrary files or
user packages. In this instance, our `MACDStrategy` is defined in the current module, which python refers to as `__main__`.
Expand Down
134 changes: 127 additions & 7 deletions docs/integrations/databento.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,136 @@
# Databento

NautilusTrader offers an adapter for integrating with the Databento API and [Databento Binary Encoding (DBN)](https://docs.databento.com/knowledge-base/new-users/dbn-encoding) format data.
This includes loading historical data from disk into Nautilus objects for research and backtesting purposes,
as well as subscribing to real-time data feeds to support live trading.
```{warning}
We are currently working on this integration guide - consider it incomplete.
```

NautilusTrader provides an adapter for integrating with the Databento API and [Databento Binary Encoding (DBN)](https://docs.databento.com/knowledge-base/new-users/dbn-encoding) format data.

The capabilities of this adapter include:
- Loading historical data from DBN files on disk into Nautilus objects for backtesting and writing to the data catalog
- Requesting historical data which is converted to Nautilus objects to support live trading and backtesting
- Subscribing to real-time data feeds which is converted to Nautilus objects to support live trading and sandbox environments

```{tip}
For testing purposes, [Databento](https://databento.com/signup) currently offers $125 USD in free data credits for new account sign-ups.
[Databento](https://databento.com/signup) currently offers 125 USD in free data credits for new account sign-ups.
With careful requests, this is more than enough for testing and evaluation purposes.
It's recommended you make use of the [/metadata.get_cost](https://docs.databento.com/api-reference-historical/metadata/metadata-get-cost) endpoint.
```

## Overview

The integrations implementation takes the [databento-rs](https://crates.io/crates/databento) crate as a dependency,
which is the official Rust client library provided by Databento. There are actually no Databento Python dependencies.

The following adapter classes are available:
- `DatabentoDataLoader` which allows loading Databento Binary Encoding (DBN) data from disk.
- `DatabentoInstrumentProvider` which connects to the Databento API to provide latest or historical instrument definitions.
- `DatabentoDataClient` which allows requesting historical market data and subscribing to real-time data feeds.
- `DatabentoDataLoader` which allows loading Databento Binary Encoding (DBN) data from disk
- `DatabentoInstrumentProvider` which integrates with the Databento API (HTTP) to provide latest or historical instrument definitions
- `DatabentoHistoricalClient` which integrates with the Databento API (HTTP) for historical market data requests
- `DatabentoLiveClient` which integrates with the Databento API (raw TCP) for subscribing to real-time data feeds
- `DatabentoDataClient` providing a `LiveMarketDataClient` implementation for running a trading node in real time

```{note}
There is no optional extra installation for `databento`, at this stage the core components of the adapter are compiled
as static libraries and linked during the build by default.
```

## Documentation

Databento provides extensive documentation for users https://docs.databento.com/knowledge-base/new-users.
It's recommended you also refer to this documentation in conjunction with this Nautilus integration guide.

## Databento Binary Encoding (DBN)

The integration provides a decoder which can convert DBN format data to Nautilus objects.
You can read more about the DBN format [here](https://docs.databento.com/knowledge-base/new-users/dbn-encoding).

The same Rust implemented decoder is used for:
- Loading and decoding DBN files from disk
- Decoding historical and live data in real-time

## Supported schemas

The following Databento schemas are supported by NautilusTrader:

| Databento schema | Nautilus type |
|------------------|------------------------------|
| `MBO` | `OrderBookDelta` |
| `MBP_1` | `QuoteTick` & `TradeTick` |
| `MBP_10` | `OrderBookDepth10` |
| `TBBO` | `QuoteTick` & `TradeTick` |
| `TRADES` | `TradeTick` |
| `OHLCV_1S` | `Bar` |
| `OHLCV_1M` | `Bar` |
| `OHLCV_1H` | `Bar` |
| `OHLCV_1D` | `Bar` |
| `DEFINITION` | `Instrument` (various types) |
| `IMBALANCE` | `DatabentoImbalance` (under development) |
| `STATISTICS` | `DatabentoStatistics` (under development) |
| `STATUS` | Not yet available |

## Performance considerations

When backtesting with Databento DBN data, there are two options:
- Store the data in DBN (`.dbn.zst`) format files and decode to Nautilus objects on every run
- Convert the DBN files to Nautilus Parquet format and write to the data catalog once (stored as Parquet on disk)

Whilst the DBN -> Nautilus decoder is implemented in Rust and has been optimized,
the best performance for backtesting will be achieved by writing the Nautilus
objects to the data catalog, which performs the decoding step once.

[DataFusion](https://arrow.apache.org/datafusion/) provides a query engine which is leveraged as a backend to load
the Nautilus Parquet data from disk, which achieves extremely high through-put (at least an order of magnitude faster
than converting DBN -> Nautilus on the fly for every backtest run).

```{note}
Performance benchmarks are under development.
```

## Data types

The following section discusses Databento schema -> Nautilus data type equivalence
and considerations.

### Instrument definitions

Databento provides a single schema to cover all instrument classes, these are
decoded to the appropriate Nautilus `Instrument` types.

The following Databento instrument classes are supported by NautilusTrader:

| Databento instrument class | Nautilus instrument type
|----------------------------|------------------------------|
| `BOND` | Not available |
| `CALL` | `OptionsContract` |
| `FUTURE` | `FuturesContract` |
| `STOCK` | `Equity |
| `MIXEDSPREAD` | `OptionsSpread` |
| `PUT` | `OptionsContract` |
| `FUTURESPREAD` | `FuturesSpread` |
| `OPTIONSPREAD` | `OptionsSpread` |
| `FXSPOT` | `CurrencyPair` |

### MBO (market by order)

This schema is the highest granularity offered by Databento, and represents
full order book depth. Some messages also provide trade information, and so when
decoding MBO messages Nautilus will produce an `OrderBookDelta` and optionally a
`TradeTick`.

The Nautilus live data client will buffer MBO messages until an `F_LAST` flag
is seen. A discrete `OrderBookDeltas` container object will then be passed to the
registered handler.

Order book snapshots are also buffered into a discrete `OrderBookDeltas` container
object, which occurs during the replay startup sequence.

### MBP-1 (market by price, top-level)

This schema represents the top-of-book only. Like with MBO messages, some
messages carry trade information, and so when decoding MBP-1 messages Nautilus
will produce a `QuoteTick` and optionally a `TradeTick`.

### OHLCV (bar aggregates)

The `ts_event` timestamps are normalized to bar close during Nautilus decoding.
9 changes: 2 additions & 7 deletions nautilus_core/adapters/src/databento/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ use super::{
///
/// # Supported schemas:
/// - MBO -> `OrderBookDelta`
/// - MBP_1 -> `QuoteTick` | `TradeTick`
/// - MBP_1 -> `QuoteTick` & `TradeTick`
/// - MBP_10 -> `OrderBookDepth10`
/// - TBBO -> `QuoteTick` | `TradeTick`
/// - TBBO -> `QuoteTick` & `TradeTick`
/// - TRADES -> `TradeTick`
/// - OHLCV_1S -> `Bar`
/// - OHLCV_1M -> `Bar`
Expand All @@ -52,11 +52,6 @@ use super::{
/// - IMBALANCE -> `DatabentoImbalance`
/// - STATISTICS -> `DatabentoStatistics`
///
/// # Warnings
/// The following Databento instrument classes are not supported:
/// - ``BOND``
/// - ``FX_SPOT``
///
/// # References
/// <https://docs.databento.com/knowledge-base/new-users/dbn-encoding>
#[cfg_attr(
Expand Down
12 changes: 2 additions & 10 deletions nautilus_trader/adapters/databento/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@ class DatabentoDataLoader:
- OHLCV_1H -> `Bar`
- OHLCV_1D -> `Bar`
- DEFINITION -> `Instrument`
- IMBALANCE -> `DatabentoImbalance`
- STATISTICS -> `DatabentoStatistics`
Warnings
--------
The following Databento instrument classes are not currently supported:
- ``FUTURE_SPREAD``
- ``OPTION_SPEAD``
- ``MIXED_SPREAD``
- ``FX_SPOT``
- IMBALANCE -> `DatabentoImbalance` (under development)
- STATISTICS -> `DatabentoStatistics` (under development)
References
----------
Expand Down

0 comments on commit 4fb94e3

Please sign in to comment.