diff --git a/nightly/.doctrees/api_reference/accounting.doctree b/nightly/.doctrees/api_reference/accounting.doctree index f36279d48dd4..a7a1661effa9 100644 Binary files a/nightly/.doctrees/api_reference/accounting.doctree and b/nightly/.doctrees/api_reference/accounting.doctree differ diff --git a/nightly/.doctrees/api_reference/adapters/betfair.doctree b/nightly/.doctrees/api_reference/adapters/betfair.doctree index 5af2a2dd0d28..cbfc97224139 100644 Binary files a/nightly/.doctrees/api_reference/adapters/betfair.doctree and b/nightly/.doctrees/api_reference/adapters/betfair.doctree differ diff --git a/nightly/.doctrees/api_reference/adapters/binance.doctree b/nightly/.doctrees/api_reference/adapters/binance.doctree index d9f6191d2235..fe7a0fb1246b 100644 Binary files a/nightly/.doctrees/api_reference/adapters/binance.doctree and b/nightly/.doctrees/api_reference/adapters/binance.doctree differ diff --git a/nightly/.doctrees/api_reference/adapters/interactive_brokers.doctree b/nightly/.doctrees/api_reference/adapters/interactive_brokers.doctree index 6459899bc423..41a0fdabc976 100644 Binary files a/nightly/.doctrees/api_reference/adapters/interactive_brokers.doctree and b/nightly/.doctrees/api_reference/adapters/interactive_brokers.doctree differ diff --git a/nightly/.doctrees/api_reference/analysis.doctree b/nightly/.doctrees/api_reference/analysis.doctree index de7081dededa..d349c47a2296 100644 Binary files a/nightly/.doctrees/api_reference/analysis.doctree and b/nightly/.doctrees/api_reference/analysis.doctree differ diff --git a/nightly/.doctrees/api_reference/backtest.doctree b/nightly/.doctrees/api_reference/backtest.doctree index ebb7c9363cd2..da2e8b127594 100644 Binary files a/nightly/.doctrees/api_reference/backtest.doctree and b/nightly/.doctrees/api_reference/backtest.doctree differ diff --git a/nightly/.doctrees/api_reference/cache.doctree b/nightly/.doctrees/api_reference/cache.doctree index 62320b1f93ee..ba98b8f0314c 100644 Binary files a/nightly/.doctrees/api_reference/cache.doctree and b/nightly/.doctrees/api_reference/cache.doctree differ diff --git a/nightly/.doctrees/api_reference/common.doctree b/nightly/.doctrees/api_reference/common.doctree index b8c09597cda2..38414d56bd5f 100644 Binary files a/nightly/.doctrees/api_reference/common.doctree and b/nightly/.doctrees/api_reference/common.doctree differ diff --git a/nightly/.doctrees/api_reference/config.doctree b/nightly/.doctrees/api_reference/config.doctree index e6be3c890372..1e9871765334 100644 Binary files a/nightly/.doctrees/api_reference/config.doctree and b/nightly/.doctrees/api_reference/config.doctree differ diff --git a/nightly/.doctrees/api_reference/core.doctree b/nightly/.doctrees/api_reference/core.doctree index 469fad6590ab..6be478780674 100644 Binary files a/nightly/.doctrees/api_reference/core.doctree and b/nightly/.doctrees/api_reference/core.doctree differ diff --git a/nightly/.doctrees/api_reference/data.doctree b/nightly/.doctrees/api_reference/data.doctree index 9d803d2fa4e7..5ec06ae66db4 100644 Binary files a/nightly/.doctrees/api_reference/data.doctree and b/nightly/.doctrees/api_reference/data.doctree differ diff --git a/nightly/.doctrees/api_reference/execution.doctree b/nightly/.doctrees/api_reference/execution.doctree index d61179a9390c..26ff82f03aed 100644 Binary files a/nightly/.doctrees/api_reference/execution.doctree and b/nightly/.doctrees/api_reference/execution.doctree differ diff --git a/nightly/.doctrees/api_reference/index.doctree b/nightly/.doctrees/api_reference/index.doctree index bb436f0dc9e1..7b762632355d 100644 Binary files a/nightly/.doctrees/api_reference/index.doctree and b/nightly/.doctrees/api_reference/index.doctree differ diff --git a/nightly/.doctrees/api_reference/indicators.doctree b/nightly/.doctrees/api_reference/indicators.doctree index 921cb1ec0306..93909bf71d91 100644 Binary files a/nightly/.doctrees/api_reference/indicators.doctree and b/nightly/.doctrees/api_reference/indicators.doctree differ diff --git a/nightly/.doctrees/api_reference/infrastructure.doctree b/nightly/.doctrees/api_reference/infrastructure.doctree deleted file mode 100644 index d0bd04278b29..000000000000 Binary files a/nightly/.doctrees/api_reference/infrastructure.doctree and /dev/null differ diff --git a/nightly/.doctrees/api_reference/live.doctree b/nightly/.doctrees/api_reference/live.doctree index b4482a10cc6c..0c9063a0a54b 100644 Binary files a/nightly/.doctrees/api_reference/live.doctree and b/nightly/.doctrees/api_reference/live.doctree differ diff --git a/nightly/.doctrees/api_reference/model/book.doctree b/nightly/.doctrees/api_reference/model/book.doctree index 6f137458514f..235631acbab3 100644 Binary files a/nightly/.doctrees/api_reference/model/book.doctree and b/nightly/.doctrees/api_reference/model/book.doctree differ diff --git a/nightly/.doctrees/api_reference/model/data.doctree b/nightly/.doctrees/api_reference/model/data.doctree index 0c61fcea072a..34c5f2166f02 100644 Binary files a/nightly/.doctrees/api_reference/model/data.doctree and b/nightly/.doctrees/api_reference/model/data.doctree differ diff --git a/nightly/.doctrees/api_reference/model/events.doctree b/nightly/.doctrees/api_reference/model/events.doctree index d54a98a72122..3ec942edeb72 100644 Binary files a/nightly/.doctrees/api_reference/model/events.doctree and b/nightly/.doctrees/api_reference/model/events.doctree differ diff --git a/nightly/.doctrees/api_reference/model/identifiers.doctree b/nightly/.doctrees/api_reference/model/identifiers.doctree index 682582ee0196..f75054df5220 100644 Binary files a/nightly/.doctrees/api_reference/model/identifiers.doctree and b/nightly/.doctrees/api_reference/model/identifiers.doctree differ diff --git a/nightly/.doctrees/api_reference/model/instruments.doctree b/nightly/.doctrees/api_reference/model/instruments.doctree index faa2e4e48e56..2ef2c22f6686 100644 Binary files a/nightly/.doctrees/api_reference/model/instruments.doctree and b/nightly/.doctrees/api_reference/model/instruments.doctree differ diff --git a/nightly/.doctrees/api_reference/model/objects.doctree b/nightly/.doctrees/api_reference/model/objects.doctree index c75cd7e9a776..d946dc05cf2e 100644 Binary files a/nightly/.doctrees/api_reference/model/objects.doctree and b/nightly/.doctrees/api_reference/model/objects.doctree differ diff --git a/nightly/.doctrees/api_reference/model/orders.doctree b/nightly/.doctrees/api_reference/model/orders.doctree index 155f88046fed..036caa74cbbd 100644 Binary files a/nightly/.doctrees/api_reference/model/orders.doctree and b/nightly/.doctrees/api_reference/model/orders.doctree differ diff --git a/nightly/.doctrees/api_reference/model/position.doctree b/nightly/.doctrees/api_reference/model/position.doctree index 70681a22e7d2..e5d92cf42de5 100644 Binary files a/nightly/.doctrees/api_reference/model/position.doctree and b/nightly/.doctrees/api_reference/model/position.doctree differ diff --git a/nightly/.doctrees/api_reference/model/tick_scheme.doctree b/nightly/.doctrees/api_reference/model/tick_scheme.doctree index a2326029fb43..2783dbe0c599 100644 Binary files a/nightly/.doctrees/api_reference/model/tick_scheme.doctree and b/nightly/.doctrees/api_reference/model/tick_scheme.doctree differ diff --git a/nightly/.doctrees/api_reference/persistence.doctree b/nightly/.doctrees/api_reference/persistence.doctree index be17f8be7413..fb4f39929a9e 100644 Binary files a/nightly/.doctrees/api_reference/persistence.doctree and b/nightly/.doctrees/api_reference/persistence.doctree differ diff --git a/nightly/.doctrees/api_reference/portfolio.doctree b/nightly/.doctrees/api_reference/portfolio.doctree index a92c1856ca7d..19fe77b7bf90 100644 Binary files a/nightly/.doctrees/api_reference/portfolio.doctree and b/nightly/.doctrees/api_reference/portfolio.doctree differ diff --git a/nightly/.doctrees/api_reference/risk.doctree b/nightly/.doctrees/api_reference/risk.doctree index b001d8ba9c64..9cccaa402eea 100644 Binary files a/nightly/.doctrees/api_reference/risk.doctree and b/nightly/.doctrees/api_reference/risk.doctree differ diff --git a/nightly/.doctrees/api_reference/serialization.doctree b/nightly/.doctrees/api_reference/serialization.doctree index 9037c3929cca..e8f8b6482208 100644 Binary files a/nightly/.doctrees/api_reference/serialization.doctree and b/nightly/.doctrees/api_reference/serialization.doctree differ diff --git a/nightly/.doctrees/api_reference/system.doctree b/nightly/.doctrees/api_reference/system.doctree index 495e072ac652..6d8eea400874 100644 Binary files a/nightly/.doctrees/api_reference/system.doctree and b/nightly/.doctrees/api_reference/system.doctree differ diff --git a/nightly/.doctrees/api_reference/trading.doctree b/nightly/.doctrees/api_reference/trading.doctree index 223f23365ba2..1c3610f0ba6c 100644 Binary files a/nightly/.doctrees/api_reference/trading.doctree and b/nightly/.doctrees/api_reference/trading.doctree differ diff --git a/nightly/.doctrees/environment.pickle b/nightly/.doctrees/environment.pickle index 06b0bb6f2998..063a48ee427a 100644 Binary files a/nightly/.doctrees/environment.pickle and b/nightly/.doctrees/environment.pickle differ diff --git a/nightly/.doctrees/integrations/binance.doctree b/nightly/.doctrees/integrations/binance.doctree index 7d1b68131345..ffbfed79a352 100644 Binary files a/nightly/.doctrees/integrations/binance.doctree and b/nightly/.doctrees/integrations/binance.doctree differ diff --git a/nightly/.doctrees/integrations/databento.doctree b/nightly/.doctrees/integrations/databento.doctree index 1d831492ddc9..408c83060238 100644 Binary files a/nightly/.doctrees/integrations/databento.doctree and b/nightly/.doctrees/integrations/databento.doctree differ diff --git a/nightly/.doctrees/integrations/ib.doctree b/nightly/.doctrees/integrations/ib.doctree index 78374ebdcc6e..cb3dec0e7b4c 100644 Binary files a/nightly/.doctrees/integrations/ib.doctree and b/nightly/.doctrees/integrations/ib.doctree differ diff --git a/nightly/.doctrees/integrations/index.doctree b/nightly/.doctrees/integrations/index.doctree index fbb1ec9e003b..7078fc17e5c1 100644 Binary files a/nightly/.doctrees/integrations/index.doctree and b/nightly/.doctrees/integrations/index.doctree differ diff --git a/nightly/_sources/api_reference/common.md.txt b/nightly/_sources/api_reference/common.md.txt index 64cce70b87a8..42a464b4394f 100644 --- a/nightly/_sources/api_reference/common.md.txt +++ b/nightly/_sources/api_reference/common.md.txt @@ -57,20 +57,3 @@ :members: :member-order: bysource ``` - -```{eval-rst} -.. automodule:: nautilus_trader.common.throttler - :show-inheritance: - :inherited-members: - :members: - :member-order: bysource -``` - -## Message Bus -```{eval-rst} -.. automodule:: nautilus_trader.common.msgbus - :show-inheritance: - :inherited-members: - :members: - :member-order: bysource -``` diff --git a/nightly/_sources/api_reference/index.md.txt b/nightly/_sources/api_reference/index.md.txt index bad661d9288c..8356e1699549 100644 --- a/nightly/_sources/api_reference/index.md.txt +++ b/nightly/_sources/api_reference/index.md.txt @@ -16,7 +16,6 @@ data.md execution.md indicators.md - infrastructure.md live.md model/index.md persistence.md diff --git a/nightly/_sources/api_reference/infrastructure.md.txt b/nightly/_sources/api_reference/infrastructure.md.txt deleted file mode 100644 index 743d611d4f54..000000000000 --- a/nightly/_sources/api_reference/infrastructure.md.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Infrastructure - -```{eval-rst} -.. automodule:: nautilus_trader.infrastructure -``` - -```{eval-rst} -.. automodule:: nautilus_trader.infrastructure.cache - :show-inheritance: - :inherited-members: - :members: - :member-order: bysource -``` diff --git a/nightly/_sources/integrations/binance.md.txt b/nightly/_sources/integrations/binance.md.txt index d37a745931db..49fe65fa57d7 100644 --- a/nightly/_sources/integrations/binance.md.txt +++ b/nightly/_sources/integrations/binance.md.txt @@ -6,24 +6,26 @@ derivative products. This integration supports live market data ingest and order execution with Binance. ## Overview + The following documentation assumes a trader is setting up for both live market data feeds, and trade execution. The full Binance integration consists of an assortment of components, which can be used together or separately depending on the users needs. -- `BinanceHttpClient` provides low-level HTTP API connectivity -- `BinanceWebSocketClient` provides low-level WebSocket API connectivity -- `BinanceInstrumentProvider` provides instrument parsing and loading functionality -- `BinanceSpotDataClient`/ `BinanceFuturesDataClient` provide a market data feed manager -- `BinanceSpotExecutionClient`/`BinanceFuturesExecutionClient` provide an account management and trade execution gateway -- `BinanceLiveDataClientFactory` creation factory for Binance data clients (used by the trading node builder) -- `BinanceLiveExecClientFactory` creation factory for Binance execution clients (used by the trading node builder) +- `BinanceHttpClient` - Low-level HTTP API connectivity +- `BinanceWebSocketClient` - Low-level WebSocket API connectivity +- `BinanceInstrumentProvider` - Instrument parsing and loading functionality +- `BinanceSpotDataClient`/ `BinanceFuturesDataClient` - A market data feed manager +- `BinanceSpotExecutionClient`/`BinanceFuturesExecutionClient` - An account management and trade execution gateway +- `BinanceLiveDataClientFactory` - Factory for Binance data clients (used by the trading node builder) +- `BinanceLiveExecClientFactory` - Factory for Binance execution clients (used by the trading node builder) ```{note} Most users will simply define a configuration for a live trading node (as below), -and won't need to necessarily work with these lower level components individually. +and won't need to necessarily work with these lower level components directly. ``` ## Data types + To provide complete API functionality to traders, the integration includes several custom data types: - `BinanceTicker` returned when subscribing to Binance 24hr tickers (contains many prices and stats). @@ -33,6 +35,7 @@ custom data types: See the Binance [API Reference](../api_reference/adapters/binance.md) for full definitions. ## Symbology + As per the Nautilus unification policy for symbols, the native Binance symbols are used where possible including for spot assets and futures contracts. However, because NautilusTrader is capable of multi-venue + multi-account trading, it's necessary to explicitly clarify the difference between `BTCUSDT` as the spot and margin traded @@ -51,6 +54,7 @@ E.g. for Binance Futures, the said instruments symbol is `BTCUSDT-PERP` within t | `TRAILING_STOP_MARKET` | | | ✓ | ### Trailing stops + Binance use the concept of an *activation price* for trailing stops ([see docs](https://www.binance.com/en-AU/support/faq/what-is-a-trailing-stop-order-360042299292)). To get trailing stop orders working for Binance we need to use the `trigger_price` value to set the *activation price*. @@ -65,6 +69,7 @@ You must also have at least *one* of the following: - You have subscribed to trade ticks for the instrument you're submitting the order for (used to infer activation price) ## Configuration + The most common use case is to configure a live `TradingNode` to include Binance data and execution clients. To achieve this, add a `BINANCE` section to your client configuration(s): @@ -116,6 +121,7 @@ node.build() ``` ### API credentials + There are two options for supplying your credentials to the Binance clients. Either pass the corresponding `api_key` and `api_secret` values to the configuration objects, or set the following environment variables: @@ -140,6 +146,7 @@ When starting the trading node, you'll receive immediate confirmation of whether credentials are valid and have trading permissions. ### Account Type + All the Binance account types will be supported for live trading. Set the `account_type` using the `BinanceAccountType` enum. The account type options are: - `SPOT` @@ -149,16 +156,19 @@ using the `BinanceAccountType` enum. The account type options are: - `COIN_FUTURE` (other cryptocurrency as collateral) ### Base URL overrides + It's possible to override the default base URLs for both HTTP Rest and WebSocket APIs. This is useful for configuring API clusters for performance reasons, or when Binance has provided you with specialized endpoints. ### Binance US + There is support for Binance US accounts by setting the `us` option in the configs to `True` (this is `False` by default). All functionality available to US accounts should behave identically to standard Binance. ### Testnets + It's also possible to configure one or both clients to connect to the Binance testnet. Simply set the `testnet` option to `True` (this is `False` by default): @@ -185,6 +195,7 @@ config = TradingNodeConfig( ``` ### Aggregated Trades + Binance provide aggregated trade data endpoints as an alternative source of trade ticks. In comparison to the default trade endpoints, aggregated trade data endpoints can return all ticks between a `start_time` and `end_time`. @@ -193,6 +204,7 @@ To use aggregated trades and the endpoint features, set the `use_agg_trade_ticks to `True` (this is `False` by default.) ### Parser warnings + Some Binance instruments are unable to be parsed into Nautilus objects if they contain enormous field values beyond what can be handled by the platform. In these cases, a _warn and continue_ approach is taken (the instrument will not @@ -212,6 +224,7 @@ instrument_provider=InstrumentProviderConfig( ``` ## Binance specific data + It's possible to subscribe to Binance specific data streams as they become available to the adapter over time. @@ -222,6 +235,7 @@ methods may eventually become first-class (not requiring custom/generic subscrip ``` ### BinanceFuturesMarkPriceUpdate + You can subscribe to `BinanceFuturesMarkPriceUpdate` (included funding rating info) data streams by subscribing in the following way from your actor or strategy: diff --git a/nightly/_sources/integrations/databento.md.txt b/nightly/_sources/integrations/databento.md.txt index 7ebcdd0f3064..5af0cba1ed8c 100644 --- a/nightly/_sources/integrations/databento.md.txt +++ b/nightly/_sources/integrations/databento.md.txt @@ -1,15 +1,17 @@ # Databento ```{warning} -We are currently working on this integration guide - consider it incomplete. +We are currently working on this integration guide - consider it incomplete for now. ``` 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. +As Databento is purely a market data provider, there is no execution client provided - although a sandbox environment with simulated execution could still be set up. +It's also possible to match Databento data with Interactive Brokers execution, or to calculate traditional asset class signals for crypto trading. 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 +- Loading historical data from DBN files and decoding into Nautilus objects for backtesting or writing to the data catalog +- Requesting historical data which is decoded to Nautilus objects to support live trading and backtesting +- Subscribing to real-time data feeds which are decoded to Nautilus objects to support live trading and sandbox environments ```{tip} [Databento](https://databento.com/signup) currently offers 125 USD in free data credits (historical data only) for new account sign-ups. @@ -20,40 +22,45 @@ It's recommended you make use of the [/metadata.get_cost](https://docs.databento ## 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 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 +The adapter 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. ```{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. ``` +The following adapter classes are available: +- `DatabentoDataLoader` - Loads Databento Binary Encoding (DBN) data from files +- `DatabentoInstrumentProvider` - Integrates with the Databento API (HTTP) to provide latest or historical instrument definitions +- `DatabentoHistoricalClient` - Integrates with the Databento API (HTTP) for historical market data requests +- `DatabentoLiveClient` - Integrates with the Databento API (raw TCP) for subscribing to real-time data feeds +- `DatabentoDataClient` - Provides a `LiveMarketDataClient` implementation for running a trading node in real time + +```{note} +As with the other integration adapters, most users will simply define a configuration for a live trading node (covered below), +and won't need to necessarily work with these lower level components directly. +``` + ## 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 provides extensive documentation for users which can be found in the knowledge base https://docs.databento.com/knowledge-base/new-users. +It's recommended you also refer to the Databento 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: +The same Rust implemented Nautilus decoder is used for: - Loading and decoding DBN files from disk -- Decoding historical and live data in real-time +- Decoding historical and live data in real time ## Supported schemas The following Databento schemas are supported by NautilusTrader: -| Databento schema | Nautilus type | +| Databento schema | Nautilus data type | |------------------|------------------------------| | MBO | `OrderBookDelta` | | MBP_1 | `QuoteTick` + `TradeTick` | @@ -65,27 +72,56 @@ The following Databento schemas are supported by NautilusTrader: | OHLCV_1H | `Bar` | | OHLCV_1D | `Bar` | | DEFINITION | `Instrument` (various types) | -| IMBALANCE | `DatabentoImbalance` (under development) | -| STATISTICS | `DatabentoStatistics` (under development) | -| STATUS | Not yet available | +| IMBALANCE | `DatabentoImbalance` | +| STATISTICS | `DatabentoStatistics` | +| STATUS | Not yet available | -## Performance considerations +## Instrument IDs and symbology -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) +Databento market data includes an `instrument_id` field which is an integer assigned +by either the original source venue, or internally by Databento during normalization. -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. +It's important to realize that this is different to the Nautilus `InstrumentId` +which is a string made up of a symbol + venue with a period separator i.e. `"{symbol}.{venue}"`. -[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). +The Nautilus decoder will use the Databento `raw_symbol` for the Nautilus `symbol` and an [ISO 10383 MIC (Market Identification Code)](https://www.iso20022.org/market-identifier-codes) +from the Databento instrument definition message for the Nautilus `venue`. -```{note} -Performance benchmarks are under development. -``` +Databento datasets are identified with a *dataset code* which is not the same +as a venue identifier. You can read more about Databento dataset naming conventions [here](https://docs.databento.com/api-reference-historical/basics/datasets). + +Of particular note is for CME Globex MDP 3.0 data (`GLBX.MDP3` dataset code), the `venue` that +Nautilus will use is the CME exchange code provided by instrument definition messages (which the Interactive Brokers adapter can map): +- `CBCM` - XCME-XCBT inter-exchange spread +- `NYUM` - XNYM-DUMX inter-exchange spread +- `XCBT` - Chicago Board of Trade (CBOT) +- `XCEC` - Commodities Exchange Center (COMEX) +- `XCME` - Chicago Mercantile Exchange (CME) +- `XFXS` - CME FX Link spread +- `XNYM` - New York Mercantile Exchange (NYMEX) + +Other venue MICs can be found in the `venue` field of responses from the [metadata.list_publishers](https://docs.databento.com/api-reference-historical/metadata/metadata-list-publishers?historical=http&live=python) endpoint. + +## Timestamps + +Databento data includes various timestamp fields including (but not limited to): + +- `ts_event` - The matching-engine-received timestamp expressed as the number of nanoseconds since the UNIX epoch +- `ts_in_delta` - The matching-engine-sending timestamp expressed as the number of nanoseconds before `ts_recv` +- `ts_recv` - The capture-server-received timestamp expressed as the number of nanoseconds since the UNIX epoch +- `ts_out` - The Databento sending timestamp + +Nautilus data includes at *least* two timestamps (required by the `Data` contract): + +- `ts_event` - The UNIX timestamp (nanoseconds) when the data event occurred +- `ts_init` - The UNIX timestamp (nanoseconds) when the data object was initialized + +When decoding and normalizing Databento to Nautilus we generally assign the Databento `ts_recv` value to the Nautilus +`ts_event` field, as this timestamp is much more reliable and consistent, and is guaranteed to be monotonically increasing per symbol. + +See the following Databento docs for further information: +- [Databento standards and conventions - timestamps](https://docs.databento.com/knowledge-base/new-users/standards-conventions/timestamps) +- [Databento timestamping guide](https://docs.databento.com/knowledge-base/data-integrity/timestamping/timestamps-on-databento-and-how-to-use-them) ## Data types @@ -101,19 +137,19 @@ The following Databento instrument classes are supported by NautilusTrader: | Databento instrument class | Nautilus instrument type | |----------------------------|------------------------------| -| BOND | Not yet available | -| CALL | `OptionsContract` | -| FUTURE | `FuturesContract` | | STOCK | `Equity` | -| MIXEDSPREAD | `OptionsSpread` | +| FUTURE | `FuturesContract` | +| CALL | `OptionsContract` | | PUT | `OptionsContract` | | FUTURESPREAD | `FuturesSpread` | | OPTIONSPREAD | `OptionsSpread` | +| MIXEDSPREAD | `OptionsSpread` | | FXSPOT | `CurrencyPair` | +| BOND | Not yet available | ### MBO (market by order) -This schema is the highest granularity offered by Databento, and represents +This schema is the highest granularity data 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`. @@ -125,7 +161,7 @@ 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) +### MBP-1 (market by price, top-of-book) 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 @@ -133,4 +169,93 @@ will produce a `QuoteTick` and optionally a `TradeTick`. ### OHLCV (bar aggregates) -The `ts_event` timestamps are normalized to bar close during Nautilus decoding. +The Databento bar aggregation schemas are timestamped at the **open** of the bar interval. +The Nautilus decoder will normalize the `ts_event` timestamps to the **close** of the bar +(original `ts_event` + bar interval). + +## 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 objects and then write to the data catalog once (stored as Nautilus Parquet format 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 backend to efficiently load and stream +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. +``` + +## Real-time client architecture + +The `DatabentoDataClient` is a Python class which contains other Databento adapter classes. +There are two `DatabentoLiveClient`s per Databento dataset: +- One for MBO (order book deltas) real-time feeds +- One for all other real-time feeds + +```{note} +There is currently a limitation that all MBO (order book deltas) subscriptions for a dataset have to be made at +node startup, to then be able to replay data from the beginning of the session. If subsequent subscriptions +arrive after start, then they will be ignored and an error logged. + +There is no such limitation for any of the other Databento schemas. +``` + +A single `DatabentoHistoricalClient` instance is reused between the `DatabentoInstrumentProvider` and `DatabentoDataClient`, +which makes historical instrument definitions and data requests. + +## Configuration + +The most common use case is to configure a live `TradingNode` to include a +Databento data client. To achieve this, add a `DATABENTO` section to your client +configuration(s): + +```python +from nautilus_trader.adapters.databento import DATABENTO +from nautilus_trader.live.node import TradingNode + +config = TradingNodeConfig( + ..., # Omitted + data_clients={ + DATABENTO: { + "api_key": None, # 'DATABENTO_API_KEY' env var + "http_gateway": None, # Override for the default HTTP gateway + "instrument_provider": InstrumentProviderConfig(load_all=True), + "instrument_ids": None, # Nautilus instrument IDs to load on start + "parent_symbols": None, # Databento parent symbols to load on start + }, + }, + ..., # Omitted +) +``` + +Then, create a `TradingNode` and add the client factory: + +```python +from nautilus_trader.adapters.databento.factories import DatabentoLiveDataClientFactory +from nautilus_trader.live.node import TradingNode + +# Instantiate the live trading node with a configuration +node = TradingNode(config=config) + +# Register the client factory with the node +node.add_data_client_factory(DATABENTO, DatabentoLiveDataClientFactory) + +# Finally build the node +node.build() +``` + +### Configuration parameters + +- `api_key` - The Databento API secret key. If ``None`` then will source the `DATABENTO_API_KEY` environment variable +- `http_gateway` - The historical HTTP client gateway override (useful for testing and typically not needed by most users) +- `live_gateway` - The live client gateway override (useful for testing and typically not needed by most users) +- `parent_symbols` - The Databento parent symbols to subscribe to instrument definitions for on start. This is a map of Databento dataset keys -> to a sequence of the parent symbols, e.g. {'GLBX.MDP3', ['ES.FUT', 'ES.OPT']} (for all E-mini S&P 500 futures and options products) +- `instrument_ids` - The instrument IDs to request instrument definitions for on start +- `timeout_initial_load` - The timeout (seconds) to wait for instruments to load (concurrently per dataset). +- `mbo_subscriptions_delay` - The timeout (seconds) to wait for MBO/L3 subscriptions (concurrently per dataset). After the timeout the MBO order book feed will start and replay messages from the start of the week which encompasses the initial snapshot and then all deltas diff --git a/nightly/_sources/integrations/ib.md.txt b/nightly/_sources/integrations/ib.md.txt index b54d275b4162..e1c97e96b661 100644 --- a/nightly/_sources/integrations/ib.md.txt +++ b/nightly/_sources/integrations/ib.md.txt @@ -63,23 +63,23 @@ print(gateway.container.logs()) ## Overview The adapter includes several major components: -- `InteractiveBrokersClient`: Executes TWS API requests using `ibapi`. -- `HistoricInteractiveBrokersClient`: Provides methods for retrieving instruments and historical data, useful for backtesting. -- `InteractiveBrokersInstrumentProvider`: Retrieves or queries instruments for trading. -- `InteractiveBrokersDataClient`: Connects to the Gateway for streaming market data. -- `InteractiveBrokersExecutionClient`: Handles account information and executes trades. +- `InteractiveBrokersClient` - Executes TWS API requests using `ibapi`. +- `HistoricInteractiveBrokersClient` - Provides methods for retrieving instruments and historical data, useful for backtesting. +- `InteractiveBrokersInstrumentProvider` - Retrieves or queries instruments for trading. +- `InteractiveBrokersDataClient` - Connects to the Gateway for streaming market data. +- `InteractiveBrokersExecutionClient` - Handles account information and executes trades. ## The Interactive Brokers Client The `InteractiveBrokersClient` serves as the central component of the IB adapter, overseeing a range of critical functions. These include establishing and maintaining connections, handling API errors, executing trades, and gathering various types of data such as market data, contract/instrument data, and account details. To ensure efficient management of these diverse responsibilities, the `InteractiveBrokersClient` is divided into several specialized mixin classes. This modular approach enhances manageability and clarity. The key subcomponents are: -- `InteractiveBrokersClientConnectionMixin`: This class is dedicated to managing the connection with TWS/Gateway. -- `InteractiveBrokersClientErrorMixin`: It focuses on addressing all encountered errors and warnings. -- `InteractiveBrokersClientAccountMixin`: Responsible for handling requests related to account information and positions. -- `InteractiveBrokersClientContractMixin`: Handles retrieving contracts (instruments) data -- `InteractiveBrokersClientMarketDataMixin`: Handles market data requests, subscriptions and data processing -- `InteractiveBrokersClientOrderMixin`: Oversees all aspects of order placement and management. +- `InteractiveBrokersClientConnectionMixin` - This class is dedicated to managing the connection with TWS/Gateway. +- `InteractiveBrokersClientErrorMixin` - It focuses on addressing all encountered errors and warnings. +- `InteractiveBrokersClientAccountMixin` - Responsible for handling requests related to account information and positions. +- `InteractiveBrokersClientContractMixin` - Handles retrieving contracts (instruments) data +- `InteractiveBrokersClientMarketDataMixin` - Handles market data requests, subscriptions and data processing +- `InteractiveBrokersClientOrderMixin` - Oversees all aspects of order placement and management. ```{tip} To troubleshoot TWS API incoming message issues, consider starting at the `InteractiveBrokersClient._process_message` method, which acts as the primary gateway for processing all messages received from the API. diff --git a/nightly/_sources/integrations/index.md.txt b/nightly/_sources/integrations/index.md.txt index 5d08b498190d..3bbcf69628d4 100644 --- a/nightly/_sources/integrations/index.md.txt +++ b/nightly/_sources/integrations/index.md.txt @@ -24,15 +24,15 @@ It's advised to conduct some of your own testing with small amounts of capital b running strategies which are able to access larger capital allocations. ``` -| 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) | `IB` | 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) | `IB` | Brokerage (multi-venue) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/ib.html) | ## Implementation goals @@ -60,5 +60,5 @@ a warning or error when a user attempts to perform said action All integrations must be compatible with the NautilusTrader API at the system boundary, this means there is some normalization and standardization needed. -- All symbols will match the native/local symbol for the exchange, unless there are conflicts (such as Binance using the same symbol for both Spot and Perpetual Futures markets). -- All timestamps will be either normalized to UNIX nanoseconds, or clearly marked as UNIX milliseconds by appending `_ms` to param and property names. +- All symbols will match the raw/native/local symbol for the exchange, unless there are conflicts (such as Binance using the same symbol for both Spot and Perpetual Futures markets) +- All timestamps will be either normalized to UNIX nanoseconds, or clearly marked as UNIX milliseconds by appending `_ms` to param and property names diff --git a/nightly/api_reference/accounting.html b/nightly/api_reference/accounting.html index ff061aee255b..869431333ab5 100644 --- a/nightly/api_reference/accounting.html +++ b/nightly/api_reference/accounting.html @@ -541,11 +541,6 @@ Indicators -
-
- FXRolloverInterestConfig
-
-
-
-
-
-
-
-
-
@@ -5079,84 +4996,6 @@
-
- SimulationModuleConfig
-
-
-
-
-
-
-
-
-
@@ -22457,7 +22296,7 @@
- -
+
-
class
@@ -22467,7 +22306,7 @@
- FXRolloverInterestConfig
+ FXRolloverInterestModule
@@ -22476,35 +22315,7 @@
- rate_data
-
-
-
-
- :
-
-
-
-
-
-
- DataFrame
-
-
-
- ,
-
-
-
- *
-
-
-
- ,
-
-
-
- component_id
+ config
@@ -22515,54 +22326,28 @@
-
-
- nautilus_trader.model.identifiers.ComponentId
-
-
-
-
-
-
- |
-
-
-
-
-
- None
-
-
-
-
-
-
- =
-
-
-
-
-
- None
+ FXRolloverInterestConfig
)
-
+
¶
-
Bases:
-
-
- ActorConfig
-
-
+
+
+
+ SimulationModule
+
+
+
Provides an FX rollover interest simulation module.
@@ -22577,26 +22362,33 @@
-
- rate_data
+ config
(
- pd.DataFrame
+ FXRolloverInterestConfig
- ) – The interest rate data for the internal rollover interest calculator.
+ ) –
- -
+
-
- dict
+ active_task_ids
(
+
+
+
+ self
+
+
+
)
@@ -22606,40 +22398,17 @@
- dict
-
-
-
- [
-
-
-
- str
-
-
-
- ,
-
-
-
-
-
- Any
-
-
-
- ]
-
+ list
-
+
¶
-
- Return a dictionary representation of the configuration.
+ Return the active task identifiers.
-
@@ -22651,7 +22420,7 @@
-
- dict[str, Any]
+ list[TaskId]
@@ -22659,22 +22428,33 @@
- -
-
-
- classmethod
-
-
-
-
+
-
- fully_qualified_name
+ add_synthetic
(
+
+
+
+ self
+
+
+
+ ,
+
+
+
+ SyntheticInstrument
+
+
+ synthetic
+
+
+
)
@@ -22684,80 +22464,84 @@
- str
+ void
-
+
¶
-
- Return the fully qualified name for the
-
- NautilusConfig
-
- class.
+ Add the created synthetic instrument to the cache.
-
- Returns
+ Parameters
:
-
-
- str
-
+
+ synthetic
+
+ (
+
+
+ SyntheticInstrument
+
+
+ ) – The synthetic instrument to add to the cache.
+
+
+ -
+ Raises
+
+ :
+
+
+ -
+
+
+ KeyError
+
+ – If
+
+ synthetic
+
+ is already in the cache.
- References
+ Notes
-
- https://www.python.org/dev/peps/pep-3155/
-
+ If you are updating the synthetic instrument then you should use the
+
+ update_synthetic
+
+ method.
-
- -
-
-
- property
-
-
-
-
+
+ -
- id
+ cache
-
-
-
- :
-
-
-
-
-
- str
-
-
-
+
¶
-
- Return the hashed identifier for the configuration.
+ The read-only cache for the actor.
-
@@ -22768,24 +22552,31 @@
-
-
- str
-
+
+ CacheFacade
+
- -
+
-
- json
+ cancel_all_tasks
(
+
+
+
+ self
+
+
+
)
@@ -22795,128 +22586,42 @@
- bytes
+ void
-
+
¶
-
- Return serialized JSON encoded bytes.
+ Cancel all queued and active tasks.
-
- -
- Returns
-
- :
-
-
- -
-
-
- bytes
-
-
-
-
- -
+
-
- json_primitives
+ cancel_task
(
-
- )
-
-
-
-
- dict
-
-
-
- [
-
-
-
- str
-
-
-
- ,
-
-
-
-
+
+
- Any
-
-
-
- ]
-
-
-
-
-
- ¶
-
-
-
- -
-
- Return a dictionary representation of the configuration with JSON primitive
-types as values.
-
-
- -
- Returns
-
- :
+ self
-
- -
-
-
- dict[str, Any]
-
-
-
-
-
-
-
- -
-
-
- classmethod
-
-
-
-
- parse
-
-
-
- (
-
+ ,
- raw
+ task_id
@@ -22927,21 +22632,11 @@
-
- bytes
-
-
-
-
+
- |
+ TaskId
-
-
-
-
- str
-
+
@@ -22953,504 +22648,24 @@ - Return a decoded object of the given + Cancel the task with the given - cls + task_id - . -
-- - cls - - ( - - type - - ) – The type to decode to. -
-- - raw - - ( - - bytes - - - or - - - str - - ) – The raw bytes or JSON string to decode. -
-- - Any - -
-- Return whether the configuration can be represented as valid JSON. -
-- - bool - -
-
- Bases:
-
-
-
- SimulationModule
-
-
-
-
- Provides an FX rollover interest simulation module. -
-- - config - - ( - - - FXRolloverInterestConfig - - - ) – -
-- Return the active task identifiers. -
-- - list[TaskId] - -
-- Add the created synthetic instrument to the cache. -
-- - synthetic - - ( - - - SyntheticInstrument - - - ) – The synthetic instrument to add to the cache. -
-- - KeyError - - – If - - synthetic - - is already in the cache. -
-- Notes -
-- If you are updating the synthetic instrument then you should use the - - update_synthetic - - method. -
-- The read-only cache for the actor. -
-- - CacheFacade - -
-- Cancel all queued and active tasks. -
-- Cancel the task with the given - - task_id - - (if queued or active). -
-- If the task is not found then a warning is logged. + (if queued or active). +
++ If the task is not found then a warning is logged.
- Bases:
-
-
- ActorConfig
-
-
-
- Return a dictionary representation of the configuration. -
-- - dict[str, Any] - -
-- Return the fully qualified name for the - - NautilusConfig - - class. -
-- - str - -
-- References -
- -- Return the hashed identifier for the configuration. -
-- - str - -
-- Return serialized JSON encoded bytes. -
-- - bytes - -
-- Return a dictionary representation of the configuration with JSON primitive -types as values. -
-- - dict[str, Any] - -
-- Return a decoded object of the given - - cls - - . -
-- - cls - - ( - - type - - ) – The type to decode to. -
-- - raw - - ( - - bytes - - - or - - - str - - ) – The raw bytes or JSON string to decode. -
-- - Any - -
-- Return whether the configuration can be represented as valid JSON. -
-- - bool - -
-
All configurations inherit from
+
+
+ NautilusConfig
+
+
+ which in turn inherits from
msgspec.Struct
diff --git a/nightly/api_reference/core.html b/nightly/api_reference/core.html
index c913a859287d..2a97317b19f0 100644
--- a/nightly/api_reference/core.html
+++ b/nightly/api_reference/core.html
@@ -541,11 +541,6 @@
Indicators