Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.205.0 #2038

Merged
merged 147 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
b9e6270
Bump version
cjdsellers Oct 23, 2024
9f37289
Improve Postgres testing (#2018)
filipmacek Oct 23, 2024
d7992c5
Update dependencies
cjdsellers Oct 24, 2024
1237f4f
Update release notes
cjdsellers Oct 24, 2024
487d323
Fix clippy lints
cjdsellers Oct 24, 2024
871efff
Add TardisHttpClient
cjdsellers Oct 24, 2024
ef1a22c
Fix clippy lints
cjdsellers Oct 24, 2024
f9a9acb
Upgrade Polymarket WebSocket data API
cjdsellers Oct 24, 2024
b1e5050
Upgrade Polymarket WebSocket data API
cjdsellers Oct 24, 2024
54bb5d9
Fix README typo
cjdsellers Oct 24, 2024
3a952a7
Move definition of TEST_DATA_DIR (#2020)
faysou Oct 24, 2024
80aa22c
Remove redundant method
cjdsellers Oct 25, 2024
83f4be7
Refine TimeEvent imports
cjdsellers Oct 25, 2024
fd607bf
Refine TimeEvent imports
cjdsellers Oct 25, 2024
b251da4
Update dependencies
cjdsellers Oct 25, 2024
b9f3b8a
Refine core Bar API to reduce unwraps
cjdsellers Oct 25, 2024
571d46e
Update release notes
cjdsellers Oct 25, 2024
1669871
Refine path constants type annotations
cjdsellers Oct 25, 2024
1e47971
Add timeout for TardisHttpClient
cjdsellers Oct 25, 2024
52c9528
Fix poetry.lock
cjdsellers Oct 25, 2024
9c4b002
Add Tardis replay runner
cjdsellers Oct 25, 2024
42ff4d9
Add raise_exception optional parameter to TradingNode.run (#2021)
faysou Oct 25, 2024
7dacfe8
Update release notes
cjdsellers Oct 25, 2024
e7ffaea
Add nautilus_cryptography crate
cjdsellers Oct 25, 2024
4761dc1
Add nautilus_serialization crate
cjdsellers Oct 25, 2024
9bb95bb
Single source install_cryptographic_provider
cjdsellers Oct 25, 2024
dc4ceeb
Refine Arrow serialization in Rust
cjdsellers Oct 26, 2024
d1f73f3
Improve Redis version parsing robustness
cjdsellers Oct 26, 2024
efc474a
Add aggregation of bars from historical data (#2002)
faysou Oct 26, 2024
8e59287
Refine logging config changes
cjdsellers Oct 26, 2024
acd487e
Expand histo abbreviation to historical
cjdsellers Oct 26, 2024
30e2520
Update test and release notes
cjdsellers Oct 26, 2024
edf2acb
Standardize sentence casing
cjdsellers Oct 26, 2024
0899426
Standardize network client logging
cjdsellers Oct 26, 2024
edba119
Refine redis connection message
cjdsellers Oct 26, 2024
c732298
Single-source version and path constants
cjdsellers Oct 26, 2024
7169342
Refine path constants
cjdsellers Oct 26, 2024
7df0881
Fix clippy lints
cjdsellers Oct 26, 2024
0e191cd
Fix use of Redis KEYS command
cjdsellers Oct 26, 2024
9ae9beb
Fix Polymarket WebSocket execution API
cjdsellers Oct 26, 2024
ef27407
Fix decoding fill HTTP messages for dYdX (#2022)
davidsblom Oct 26, 2024
4c1a7cc
Revert single-source versioning
cjdsellers Oct 26, 2024
abe40d3
Fix account balance report for dYdX (#2024)
davidsblom Oct 26, 2024
fa21064
Update dependencies
cjdsellers Oct 26, 2024
7a61897
Update release notes
cjdsellers Oct 26, 2024
d85b035
Refine versioning and constants
cjdsellers Oct 26, 2024
601a570
Refine core build.rs
cjdsellers Oct 26, 2024
3c3588a
Fix historical_bars_catalog directory naming
cjdsellers Oct 26, 2024
7c3d971
Continue Tardis machine integration
cjdsellers Oct 27, 2024
52c3ba9
Fix IB subscription logging
cjdsellers Oct 27, 2024
b07de2e
Update release notes
cjdsellers Oct 27, 2024
c105b7e
Add OrderBook.get_avg_px_qty_for_exposure in Rust
cjdsellers Oct 27, 2024
b4aceeb
Add time constants from Rust
cjdsellers Oct 27, 2024
b9c633a
Refine DateCursor
cjdsellers Oct 27, 2024
f77322f
Refine DateCursor
cjdsellers Oct 27, 2024
1264797
Refine Tardis Machine replay
cjdsellers Oct 27, 2024
237bfc0
Refine Tardis Machine example
cjdsellers Oct 27, 2024
7c9a248
Port analysis to Rust (#2016)
Pushkarm029 Oct 27, 2024
aaa3aab
Add monthly and weekly bar aggregations (#2025)
faysou Oct 27, 2024
65961a8
Add timeouts to Interactive Brokers adapter configurations (#2026)
rsmb7z Oct 27, 2024
7ca8d56
Remove redundant comment
cjdsellers Oct 27, 2024
a1c7820
Standardize timeout docstrings
cjdsellers Oct 27, 2024
eab57a3
Fix clippy lints
cjdsellers Oct 27, 2024
e50abeb
Update release notes
cjdsellers Oct 27, 2024
696b8c2
Add codspeed benchmarks
cjdsellers Oct 28, 2024
37c15a5
Standardize docs formatting
cjdsellers Oct 28, 2024
01661af
Improve docs
cjdsellers Oct 28, 2024
62e23cb
Add path arg for tardis-replay
cjdsellers Oct 27, 2024
f8bf617
Add Tardis instrument parsing
cjdsellers Oct 28, 2024
750c74b
Refine performance tests
cjdsellers Oct 28, 2024
8dfd847
Refine docstrings (#2027)
Pushkarm029 Oct 28, 2024
8b3c746
Standardize docs and comments
cjdsellers Oct 28, 2024
dcc18d1
Implement Tardis spot instrument parsing
cjdsellers Oct 28, 2024
3f417ba
Fix codspeed run in CI
cjdsellers Oct 28, 2024
ef27ead
Implement Tardis instrument parsing
cjdsellers Oct 28, 2024
19340f5
Disable codspeed in CI for now
cjdsellers Oct 28, 2024
ae21afc
Configure codspeed
cjdsellers Oct 28, 2024
0076909
Improve benchmarks in CI
cjdsellers Oct 28, 2024
704e782
Improve benchmarks in CI
cjdsellers Oct 28, 2024
2902749
Improve benchmarks in CI
cjdsellers Oct 29, 2024
cebf79e
Upgrade pyo3 and pyo3-async-runtimes
cjdsellers Oct 29, 2024
8b625ce
Fix install-cli
cjdsellers Oct 29, 2024
2119ed9
Fix clippy lints (#2030)
Pushkarm029 Oct 29, 2024
d223761
Fix warnings
cjdsellers Oct 29, 2024
81ec3bf
Fix warnings
cjdsellers Oct 29, 2024
3a5e918
Fix pyo3 deprecations
cjdsellers Oct 29, 2024
d291c9e
Fix pyo3 deprecations
cjdsellers Oct 29, 2024
249f442
Repair some pyo3 tests
cjdsellers Oct 29, 2024
55b43c8
Resume codspeed in CI
cjdsellers Oct 29, 2024
7244d9b
Change path conventions to match catalog
cjdsellers Oct 30, 2024
f0dde02
Implement Tardis Machine replay bar handling
cjdsellers Oct 30, 2024
e6ca6fa
Improve Tardis Machine replay catalog path handling
cjdsellers Oct 30, 2024
c5a2ce3
Add optional output path arg
cjdsellers Oct 30, 2024
bf7f0d3
Add Tardis config pyo3 interface
cjdsellers Oct 30, 2024
7a3d375
Refine dev dependencies and build workflow
cjdsellers Oct 30, 2024
55ca6d5
Add optional time origins for time bar aggregation (#2028)
faysou Oct 30, 2024
8b84e4b
Fix catalog query mem leak test (#2031)
Pushkarm029 Oct 30, 2024
325a3a4
Update release notes
cjdsellers Oct 30, 2024
69b3bcd
Update release notes
cjdsellers Oct 30, 2024
c0921bd
Fix CI to run codspeed for latest python only
cjdsellers Oct 30, 2024
08383ed
Fix CI to run codspeed for latest python only
cjdsellers Oct 30, 2024
a2cda91
Fix CI to run codspeed for latest python only
cjdsellers Oct 30, 2024
357cfcc
PyO3 upgrade refactor: repair catalog tests, make PyObject cloneable …
twitu Oct 30, 2024
122e319
Fix clippy lints
cjdsellers Oct 30, 2024
8a01a26
Update dependencies
cjdsellers Oct 31, 2024
aada261
Scaffold RiskEngine in Rust
cjdsellers Oct 31, 2024
66781ad
Scaffold calculate_fixed_risk_position_size in Rust
cjdsellers Oct 31, 2024
df9263b
Refine Rust module re-exports
cjdsellers Oct 31, 2024
92da761
Prune and update dependencies
cjdsellers Nov 1, 2024
af0b1fa
Format checksums.json
cjdsellers Nov 1, 2024
7c3e71c
Refine Tardis Machine config and replay from Python
cjdsellers Nov 1, 2024
cb6296c
Update Databento docs links
cjdsellers Nov 1, 2024
e64ec5b
Update Databento docs
cjdsellers Nov 1, 2024
b6c1c71
Add Tardis integration docs
cjdsellers Nov 1, 2024
d021de4
Fix OrderInitialized.to_dict value types
cjdsellers Nov 1, 2024
41bc5d9
Fix Tardis docs code block markdown formatting
cjdsellers Nov 1, 2024
56ebe4f
Fix Tardis docs markdown formatting
cjdsellers Nov 1, 2024
1267b2e
Handle ValidationError for Binance websocket messages (#2034)
davidsblom Nov 1, 2024
39782d2
Update dependencies
cjdsellers Nov 1, 2024
00e6c3c
Improve OrderInitialized.from_dict robustness
cjdsellers Nov 1, 2024
8200b58
Add Tardis Machine quote tick support
cjdsellers Nov 1, 2024
230e887
Fix clippy lints
cjdsellers Nov 1, 2024
d64f882
Add examples links in docs
cjdsellers Nov 2, 2024
f280bbb
Improve Tardis integration docs
cjdsellers Nov 2, 2024
b5468b6
Fix doc comments
cjdsellers Nov 2, 2024
3fbf154
Improve Tardis integration docs
cjdsellers Nov 2, 2024
7fd9ab3
Improve Tardis clients error handling
cjdsellers Nov 2, 2024
f25b1ed
Fix Polymarket execution reconciliation
cjdsellers Nov 2, 2024
5be79e6
Improve Tardis docs formatting
cjdsellers Nov 2, 2024
7601bc6
Add USDC.e PoS to internal currency map
cjdsellers Nov 2, 2024
52c3d60
Update dependencies
cjdsellers Nov 2, 2024
b0376db
Improve Tardis docs formatting
cjdsellers Nov 2, 2024
50154c4
Add TardisHttpClient Python interface and docs
cjdsellers Nov 2, 2024
7b07ebb
Revert PythonMessageHandler handler to Arc
cjdsellers Nov 2, 2024
917da76
Add LiveExecutionEngine open order checks
cjdsellers Nov 3, 2024
aac0ce0
Improve Polymarket USDC.e conversion
cjdsellers Nov 3, 2024
2354ce4
Improve Tardis integration docs
cjdsellers Nov 3, 2024
902c36d
Improve data guide
cjdsellers Nov 3, 2024
5994f89
Standardize open_check_interval_secs
cjdsellers Nov 3, 2024
afe26bc
Revert PyObject cloneable changes
cjdsellers Nov 3, 2024
9301580
Improve docs
cjdsellers Nov 3, 2024
b5f6916
Pause benchmarks in CI
cjdsellers Nov 3, 2024
8a236d1
Fix Betfair shutdown (#2037)
limx0 Nov 3, 2024
403e2ce
Update release notes
cjdsellers Nov 3, 2024
8fe9cc7
Fix portfolio position updating
cjdsellers Nov 3, 2024
8eb03bd
Improve docs
cjdsellers Nov 3, 2024
3d62e42
Improve docs
cjdsellers Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 9 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
version: ${{ env.POETRY_VERSION }}

- name: Install build dependencies
run: python -m pip install --upgrade pip setuptools wheel pre-commit msgspec
run: python -m pip install --upgrade pip setuptools wheel pre-commit msgspec pytest-codspeed

# ta-lib Python install currently broken
# https://github.com/TA-Lib/ta-lib-python/issues/655
Expand Down Expand Up @@ -164,6 +164,14 @@ jobs:
make pytest
make test-examples

# Run codspeed for latest python-version only
# - name: Run benchmarks (Linux)
# if: ${{ matrix.python-version == '3.12' }}
# uses: CodSpeedHQ/action@v3
# with:
# token: ${{ secrets.CODSPEED_TOKEN }}
# run: make test-performance

build-windows:
strategy:
fail-fast: false
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ repos:
exclude: "docs/_pygments/monokai.py"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.7.2
hooks:
- id: ruff
args: ["--fix"]
Expand Down Expand Up @@ -112,7 +112,7 @@ repos:
]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.12.1
rev: v1.13.0
hooks:
- id: mypy
args: [
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ pytest:
pytest-coverage:
bash scripts/test-coverage.sh

.PHONY: test-performance
test-performance:
bash scripts/test-performance.sh

.PHONY: test-examples
test-examples:
bash scripts/test-examples.sh
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# <img src="https://github.com/nautechsystems/nautilus_trader/blob/develop/docs/_images/nautilus-trader-logo.png" width="500">

[![codecov](https://codecov.io/gh/nautechsystems/nautilus_trader/branch/master/graph/badge.svg?token=DXO9QQI40H)](https://codecov.io/gh/nautechsystems/nautilus_trader)
[![codspeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/nautechsystems/nautilus_trader)
![pythons](https://img.shields.io/pypi/pyversions/nautilus_trader)
![pypi-version](https://img.shields.io/pypi/v/nautilus_trader)
![pypi-format](https://img.shields.io/pypi/format/nautilus_trader?color=blue)
Expand Down Expand Up @@ -38,7 +39,7 @@ NautilusTraders design, architecture and implementation philosophy holds softwar
highest level, with the aim of supporting Python native, mission-critical, trading system backtesting
and live deployment workloads.

The platform is also univ2rsal and asset class agnostic - with any REST, WebSocket or FIX API able to be integrated via modular
The platform is also universal and asset class agnostic - with any REST, WebSocket or FIX API able to be integrated via modular
adapters. Thus, it can handle high-frequency trading operations for any asset classes
including FX, Equities, Futures, Options, CFDs, Crypto and Betting - across multiple venues simultaneously.

Expand Down Expand Up @@ -136,7 +137,7 @@ The following integrations are currently supported:
| [Interactive Brokers](https://www.interactivebrokers.com) | `INTERACTIVE_BROKERS` | Brokerage (multi-venue) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://nautilustrader.io/docs/latest/integrations/ib.html) |
| [OKX](https://okx.com) | `OKX` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/building-orange) | [Guide](https://nautilustrader.io/docs/latest/integrations/okx.html) |
| [Polymarket](https://polymarket.com) | `POLYMARKET` | Prediction Market (DEX) | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://nautilustrader.io/docs/latest/integrations/polymarket.html) |
| [Tardis](https://tardis.dev) | `TARDIS` | Data Provider | ![status](https://img.shields.io/badge/building-orange) | [Guide](https://nautilustrader.io/docs/latest/integrations/tardis.html) |
| [Tardis](https://tardis.dev) | `TARDIS` | Data Provider | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://nautilustrader.io/docs/latest/integrations/tardis.html) |

- **ID**: The default client ID for the integrations adapter clients.
- **Type**: The type of integration (often the venue type).
Expand Down
50 changes: 49 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
# NautilusTrader 1.205.0 Beta

Released on 3rd November 2024 (UTC).

### Enhancements
- Added Tardis Machine and HTTP API integration in Python and Rust
- Added `LiveExecEngineConfig.open_check_interval_secs` config option to actively reconcile open orders with the venue
- Added aggregation of bars from historical data (#2002), thanks @faysou
- Added monthly and weekly bar aggregations (#2025), thanks @faysou
- Added `raise_exception` optional parameter to `TradingNode.run` (#2021), thanks @faysou
- Added `OrderBook.get_avg_px_qty_for_exposure` in Rust (#1893), thanks @elementace
- Added timeouts to Interactive Brokers adapter configurations (#2026), thanks @rsmb7z
- Added optional time origins for time bar aggregation (#2028), thanks @faysou
- Added Polymarket position status reports and order status report generation based on fill reports
- Added USDC.e (PoS) currency (used by Polymarket) to internal currency map
- Upgraded Polymarket WebSocket API to new version

### Internal Improvements
- Ported analysis subpackage to Rust (#2016), thanks @Pushkarm029
- Improved Postgres testing (#2018), thanks @filipmacek
- Improved Redis version parsing to support truncated versions (improves compatibility with Redis-compliant databases)
- Refined Arrow serialization (record batch functions now also available in Rust)
- Refined core `Bar` API to remove unnecessary unwraps
- Standardized network client logging
- Fixed all pyo3 deprecations for API breaking changes
- Fixed all clippy warning lints for PyO3 changes (#2030), thanks @Pushkarm029
- PyO3 upgrade refactor and repair catalog tests (#2032), thanks @twitu
- Upgraded `pyo3` crate to v0.22.5
- Upgraded `pyo3-async-runtimes` crate to v0.22.0
- Upgraded `tokio` crate to v1.41.0

### Breaking Changes
- Removed pyo3 `DataTransformer` (was being used for namespacing, so refactored to separate functions)
- Moved `TEST_DATA_DIR` constant from `tests` to `nautilus_trader` package (#2020), thanks @faysou

### Fixes
- Fixed use of Redis `KEYS` command which, is unsupported in cluster environments (replaced with `SCAN` for compatibility)
- Fixed decoding fill HTTP messages for dYdX (#2022), thanks @davidsblom
- Fixed account balance report for dYdX (#2024), thanks @davidsblom
- Fixed Interactive Brokers market data client subscription log message (#2012), thanks @marcodambros
- Fixed Polymarket execution reconciliation (was not able to reconcile from closed orders)
- Fixed catalog query mem leak test (#2031), thanks @Pushkarm029
- Fixed `OrderInitialized.to_dict()` `tags` value type to `list[str]` (was a concatenated `str`)
- Fixed `OrderInitialized.to_dict()` `linked_order_ids` value type to `list[str]` (was a concatenated `str`)
- Fix Betfair clients shutdown (#2037), thanks @limx0

---

# NautilusTrader 1.204.0 Beta

Released on 22nd October 2024 (UTC).
Expand Down Expand Up @@ -33,7 +81,7 @@ Released on 22nd October 2024 (UTC).
- Removed legacy `TardisQuoteDataLoader` (now redundant with new Rust implemented loader)
- Removed legacy `TardisTradeDataLoader` (now redundant with new Rust implemented loader)
- Custom signals are now passed to `on_signal(signal)` instead of `on_data(data)`
- Changed `Position.to_dict()` `commissions` value type to `list[str]` (rather than an optional `str` of a list of strings)
- Changed `Position.to_dict()` `commissions` value type to `list[str]` (was an optional `str` of a list of strings)
- Changed `Position.to_dict()` `avg_px_open` value type to `float`
- Changed `Position.to_dict()` `avg_px_close` value type to `float | None`
- Changed `Position.to_dict()` `realized_return` value type to `float | None`
Expand Down
1 change: 1 addition & 0 deletions docs/api_reference/adapters/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
interactive_brokers.md
okx.md
polymarket.md
tardis.md
```
19 changes: 19 additions & 0 deletions docs/api_reference/adapters/tardis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tardis

```{eval-rst}
.. automodule:: nautilus_trader.adapters.tardis
:show-inheritance:
:inherited-members:
:members:
:member-order: bysource
```

## Loaders

```{eval-rst}
.. automodule:: nautilus_trader.adapters.tardis.loaders
:show-inheritance:
:inherited-members:
:members:
:member-order: bysource
```
8 changes: 8 additions & 0 deletions docs/concepts/backtesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ Data provided for backtesting drives the execution flow. Since a variety of data
it's crucial that your venue configurations align with the data being provided for backtesting.
Mismatches between data and configuration can lead to unexpected behavior during execution.

:::info
NautilusTrader is primarily designed and optimized for backtesting on order book or tick data, providing the highest
execution granularity and realism. If order book or tick data is unavailable or unsuitable, backtests
can also be run on bar data; however, users should note that this results in a loss of information and detail,
reducing execution precision and realism.
:::


## Venues

When initializing a venue for backtesting, you must specify its internal order `book_type` for execution processing from the following options:
Expand Down
99 changes: 97 additions & 2 deletions docs/concepts/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ These data types include:
- `QuoteTick`: Represents the best bid and ask prices along with their sizes at the top-of-book.
- `TradeTick`: A single trade/match event between counterparties.
- `Bar`: OHLCV (Open, High, Low, Close, Volume) bar/candle, aggregated using a specified *aggregation method*.
- `InstrumentStatus`: An instrument level status event.
- `InstrumentClose`: An instrument closing price.
- `InstrumentStatus`: An instrument-level status event.
- `InstrumentClose`: The closing price of an instrument.

NautilusTrader is designed primarily to operate on granular order book data, providing the highest realism
for execution simulations in backtesting.
However, backtests can also be conducted on any of the supported market data types, depending on the desired simulation fidelity.

## Order books

A high-performance order book implemented in Rust is available to maintain order book state based on provided data.

`OrderBook` instances are maintained per instrument for both backtesting and live trading, with the following book types available:
- `L3_MBO`: **Market by order (MBO)** or L3 data, uses every order book event at every price level, keyed by order ID.
- `L2_MBP`: **Market by price (MBP)** or L2 data, aggregates order book events by price level.
- `L1_MBP`: **Market by price (MBP)** or L1 data, also known as best bid and offer (BBO), captures only top-level updates.

:::note
Top-of-book data, such as `QuoteTick`, `TradeTick` and `Bar`, can also be used for backtesting, with markets operating on `L1_MBP` book types.
:::

## Timestamps

Expand Down Expand Up @@ -43,6 +60,84 @@ The following instrument definitions are available:
- `OptionsSpread`: Represents a generic options spread instrument.
- `Synthetic`: Represents a synthetic instrument with prices derived from component instruments using a formula.

## Bars and aggregation

A *bar*—also known as a candle, candlestick, or kline—is a data structure that represents price and
volume information over a specific period, including the opening price, highest price, lowest price, closing price,
and traded volume (or ticks as a volume proxy). These values are generated using an *aggregation method*,
which groups data based on specific criteria to create the bar.

The implemented aggregation methods are:

| Name | Description | Category |
|:-------------------|:---------------------------------------------------------------------------|:-------------|
| `TICK` | Aggregation of a number of ticks. | Threshold |
| `TICK_IMBALANCE` | Aggregation of the buy/sell imbalance of ticks. | Threshold |
| `TICK_RUNS` | Aggregation of sequential buy/sell runs of ticks. | Information |
| `VOLUME` | Aggregation of traded volume. | Threshold |
| `VOLUME_IMBALANCE` | Aggregation of the buy/sell imbalance of traded volume. | Threshold |
| `VOLUME_RUNS` | Aggregation of sequential runs of buy/sell traded volume. | Information |
| `VALUE` | Aggregation of the notional value of trades (also known as "Dollar bars"). | Threshold |
| `VALUE_IMBALANCE` | Aggregation of the buy/sell imbalance of trading by notional value. | Information |
| `VALUE_RUNS` | Aggregation of sequential buy/sell runs of trading by notional value. | Threshold |
| `MILLISECOND` | Aggregation of time intervals with millisecond granularity. | Time |
| `SECOND` | Aggregation of time intervals with second granularity. | Time |
| `MINUTE` | Aggregation of time intervals with minute granularity. | Time |
| `HOUR` | Aggregation of time intervals with hour granularity. | Time |
| `DAY` | Aggregation of time intervals with day granularity. | Time |
| `WEEK` | Aggregation of time intervals with week granularity. | Time |
| `MONTH` | Aggregation of time intervals with month granularity. | Time |

### Bar types

NautilusTrader defines a unique *bar type* (`BarType`) based on the following components:

- **Instrument ID** (`InstrumentId`): Specifies the particular instrument for the bar.
- **Bar Specification** (`BarSpecification`):
- `step`: Defines the interval or frequency of each bar.
- `aggregation`: Specifies the method used for data aggregation (see the list above).
- `price_type`: Indicates the price basis of the bar (e.g., bid, ask, mid, last).
- **Aggregation Source** (`AggregationSource`): Indicates whether the bar was aggregated internally (within Nautilus) or externally (by a trading venue or data provider).

Bar data can be aggregated either internally or externally:

- `INTERNAL`: The bar is aggregated inside the local Nautilus system boundary.
- `EXTERNAL`: The bar is aggregated outside the local Nautilus system boundary (typically by a trading venue or data provider).

Bar types can also be classified as either *standard* or *composite*:

- **Standard**: Generated from granular market data, such as quotes or trade ticks.
- **Composite**: Derived from a higher-granularity bar type through subsampling.

### Defining standard bars

You can define bar types from strings using the following convention:

`{instrument_id}-{step}-{aggregation}-{price_type}-{INTERNAL | EXTERNAL}`

For example, to define a `BarType` for AAPL trades (last price) on Nasdaq (XNAS) using a 5-minute interval, aggregated from trades locally by Nautilus:
```python
bar_type = BarType.from_str("AAPL.XNAS-5-MINUTE-LAST-INTERNAL")
```

### Defining composite bars

Composite bars are derived by aggregating higher-granularity bars into the desired bar type.
To define a composite bar, use a similar convention to standard bars:

`{instrument_id}-{step}-{aggregation}-{price_type}-INTERNAL@{step}-{aggregation}-{INTERNAL | EXTERNAL}`

**Notes**:
- The derived bar type must use an `INTERNAL` aggregation source (since this is how the bar is aggregated).
- The sampled bar type must have a higher granularity than the derived bar type.
- The sampled instrument ID is inferred to match that of the derived bar type.
- Composite bars can be aggregated *from* `INTERNAL` or `EXTERNAL` aggregation sources.

For example, to define a `BarType` for AAPL trades (last price) on Nasdaq (XNAS) using a 5-minute interval, aggregated locally by Nautilus, from 1-minute interval bars aggregated externally:
```python
bar_type = BarType.from_str("AAPL.XNAS-5-MINUTE-LAST-INTERNAL@1-MINUTE-EXTERNAL")
```

## Data flow

The platform ensures consistency by flowing data through the same pathways across all system [environment contexts](/concepts/architecture.md#environment-contexts)
Expand Down
6 changes: 3 additions & 3 deletions docs/concepts/message_bus.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def register_serializable_type(
...
```

- `cls`: The type to register
- `to_dict`: The delegate to instantiate a dict of primitive types from the object
- `from_dict`: The delegate to instantiate the object from a dict of primitive types
- `cls`: The type to register.
- `to_dict`: The delegate to instantiate a dict of primitive types from the object.
- `from_dict`: The delegate to instantiate the object from a dict of primitive types.

## Configuration

Expand Down
4 changes: 4 additions & 0 deletions docs/integrations/betfair.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ To install from source using poetry:
poetry install --extras betfair
```

## Examples

You can find working live example scripts [here](https://github.com/nautechsystems/nautilus_trader/tree/develop/examples/live/betfair/).

## Betfair documentation

Betfair provides extensive [documentation](https://developer.betfair.com/en/get-started/) for developers integrating with their exchange APIs.
Expand Down
4 changes: 4 additions & 0 deletions docs/integrations/binance.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ To install from source using poetry:
poetry install --extras binance
```

## Examples

You can find working live example scripts [here](https://github.com/nautechsystems/nautilus_trader/tree/develop/examples/live/binance/).

## Overview

The following documentation assumes a trader is setting up for both live market
Expand Down
4 changes: 4 additions & 0 deletions docs/integrations/bybit.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ To install from source using poetry:
poetry install --extras bybit
```

## Examples

You can find working live example scripts [here](https://github.com/nautechsystems/nautilus_trader/tree/develop/examples/live/bybit/).

## Overview

The following documentation assumes a trader is setting up for both live market
Expand Down
Loading
Loading