Skip to content

Commit f1b643d

Browse files
authored
Release 1.182.0
See release notes.
2 parents 63c191b + d5fb56a commit f1b643d

File tree

383 files changed

+21416
-4217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

383 files changed

+21416
-4217
lines changed

.github/workflows/build.yml

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ jobs:
7171
- name: Install build dependencies
7272
run: python -m pip install --upgrade pip setuptools wheel pre-commit msgspec
7373

74+
- name: Install TA-Lib (Linux)
75+
if: runner.os == 'Linux'
76+
run: |
77+
make install-talib
78+
poetry run pip install ta-lib
79+
7480
- name: Setup cached pre-commit
7581
id: cached-pre-commit
7682
uses: actions/cache@v3

.github/workflows/coverage.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
working-directory: ${{ github.workspace }}
3131

3232
- name: Set up Rust tool-chain (Linux, Windows) stable
33-
if: (runner.os == 'Linux') || (runner.os == 'Windows')
3433
uses: actions-rust-lang/[email protected]
3534
with:
3635
toolchain: ${{ env.RUST_VERSION }}
@@ -54,6 +53,11 @@ jobs:
5453
- name: Install build dependencies
5554
run: python -m pip install --upgrade pip setuptools wheel pre-commit msgspec
5655

56+
- name: Install TA-Lib (Linux)
57+
run: |
58+
make install-talib
59+
poetry run pip install ta-lib
60+
5761
- name: Setup cached pre-commit
5862
id: cached-pre-commit
5963
uses: actions/cache@v3

.github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545

4646
- name: Get branch name
4747
id: branch-name
48-
uses: tj-actions/branch-names@v6
48+
uses: tj-actions/branch-names@v7.0.7
4949

5050
- name: Build nautilus_trader image (develop)
5151
if: ${{ steps.branch-name.outputs.current_branch == 'develop' }}

.github/workflows/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959

6060
- name: Get branch name
6161
id: branch-name
62-
uses: tj-actions/branch-names@v6
62+
uses: tj-actions/branch-names@v7.0.7
6363

6464
- name: Build Python docs
6565
run: make docs-python

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*.key_secret
1616
*.sqlite
1717
*.env
18+
*.tar.gz*
19+
*.zip
1820

1921
.benchmarks*
2022
.coverage*
@@ -41,6 +43,7 @@ env/
4143
log/
4244
logs/
4345
secrets/
46+
ta-lib/
4447
*temp/
4548
*target/
4649
venv*/

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ repos:
7373
types: [python]
7474

7575
- repo: https://github.com/psf/black
76-
rev: 23.11.0
76+
rev: 23.12.0
7777
hooks:
7878
- id: black
7979
types_or: [python, pyi]
@@ -82,13 +82,13 @@ repos:
8282
exclude: "docs/_pygments/monokai.py"
8383

8484
- repo: https://github.com/astral-sh/ruff-pre-commit
85-
rev: v0.1.6
85+
rev: v0.1.9
8686
hooks:
8787
- id: ruff
8888
args: ["--fix"]
8989

9090
- repo: https://github.com/pycqa/isort
91-
rev: 5.12.0
91+
rev: 5.13.2
9292
hooks:
9393
- id: isort
9494
name: isort (cython)
@@ -111,7 +111,7 @@ repos:
111111
]
112112

113113
- repo: https://github.com/pre-commit/mirrors-mypy
114-
rev: v1.7.1
114+
rev: v1.8.0
115115
hooks:
116116
- id: mypy
117117
args: [

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ pytest-coverage:
130130
test-examples:
131131
bash scripts/test-examples.sh
132132

133+
.PHONY: install-talib
134+
install-talib:
135+
bash scripts/install-talib.sh
136+
133137
.PHONY: init-db
134138
init-db:
135139
(cd nautilus_core && cargo run --bin init-db)

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
| Platform | Rust | Python |
1616
| :----------------- | :------ | :----- |
17-
| `Linux (x86_64)` | 1.74.0+ | 3.10+ |
18-
| `macOS (x86_64)` | 1.74.0+ | 3.10+ |
19-
| `macOS (arm64)` | 1.74.0+ | 3.10+ |
20-
| `Windows (x86_64)` | 1.74.0+ | 3.10+ |
17+
| `Linux (x86_64)` | 1.74.1+ | 3.10+ |
18+
| `macOS (x86_64)` | 1.74.1+ | 3.10+ |
19+
| `macOS (arm64)` | 1.74.1+ | 3.10+ |
20+
| `Windows (x86_64)` | 1.74.1+ | 3.10+ |
2121

2222
- **Website:** https://nautilustrader.io
2323
- **Docs:** https://docs.nautilustrader.io

RELEASES.md

+40
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# NautilusTrader 1.182.0 Beta
2+
3+
Released on 23rd December 2023 (UTC).
4+
5+
### Enhancements
6+
- Added `CacheDatabaseFacade` and `CacheDatabaseAdapter` to abstract backing technology from Python codebase
7+
- Added `RedisCacheDatabase` implemented in Rust with separate MPSC channel thread for insert, update and delete operations
8+
- Added TA-Lib integration, thanks @rsmb7z
9+
- Added `OrderBookDelta` and `OrderBookDeltas` to serializable and publishable types
10+
- Moved `PortfolioFacade` to `Actor`
11+
- Improved `Actor` and `Strategy` usability to be more lenient to mistaken calls to `clock` and `logger` from the constructor (warnings also added to docs)
12+
- Removed `redis` and `hiredis` dependencies from Python codebase
13+
14+
### Breaking Changes
15+
- Changed configuration objects to take stronger types as these are now serializable when registered (rather than primitives)
16+
- Changed `NautilusKernelConfig.trader_id` to type `TraderId`
17+
- Changed `BacktestDataConfig.instrument_id` to type `InstrumentId`
18+
- Changed `ActorConfig.component_id` to type `ComponentId | None`
19+
- Changed `StrategyConfig.strategy_id` to type `StrategyId | None`
20+
- Changed `Instrument`, `OrderFilled` and `AccountState` `info` field serialization due below fix (you'll need to flush your cache)
21+
- Changed `CacheConfig` to take a `DatabaseConfig` (better symmetry with `MessageBusConfig`)
22+
- Changed `RedisCacheDatabase` data structure for currencies from hashset to simpler key-value (you'll need to clear cache or delete all curreny keys)
23+
- Changed `Actor` state loading to now use the standard `Serializer`
24+
- Renamed `register_json_encoding` to `register_config_encoding`
25+
- Renamed `register_json_decoding` to `register_config_decoding`
26+
- Removed `CacheDatabaseConfig` (due above config change)
27+
- Removed `infrastructure` subpackage (now redundant with new Rust implementation)
28+
29+
### Fixes
30+
- Fixed `json` encoding for `CacheDatabaseAdapter` from `info` field serialization fix below
31+
- Fixed `Instrument`, `OrderFilled` and `AccountState` `info` field serialization to retain JSON serializable dicts (rather than double encoding and losing information)
32+
- Fixed Binance Futures `good_till_date` value when `time_in_force` not GTD, such as when strategy is managing the GTD (was incorrectly passing through UNIX milliseconds)
33+
- Fixed `Executor` handling of queued task IDs (was not discarding from queued tasks on completion)
34+
- Fixed `DataEngine` handling of order book snapshots with very small intervals (now handles as short as 20 milliseconds)
35+
- Fixed `BacktestEngine.clear_actors()`, `BacktestEngine.clear_strategies()` and `BacktestEngine.clear_exec_algorithms()`, thanks for reporting @davidsblom
36+
- Fixed `BacktestEngine` OrderEmulator reset, thanks @davidsblom
37+
- Fixed `Throttler.reset` and reset of `RiskEngine` throttlers, thanks @davidsblom
38+
39+
---
40+
141
# NautilusTrader 1.181.0 Beta
242

343
Released on 2nd December (UTC).

build.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,14 @@ def _strip_unneeded_symbols() -> None:
277277
print("Stripping unneeded symbols from binaries...")
278278
for so in itertools.chain(Path("nautilus_trader").rglob("*.so")):
279279
if platform.system() == "Linux":
280-
strip_cmd = f"strip --strip-unneeded {so}"
280+
strip_cmd = ["strip", "--strip-unneeded", so]
281281
elif platform.system() == "Darwin":
282-
strip_cmd = f"strip -x {so}"
282+
strip_cmd = ["strip", "-x", so]
283283
else:
284284
raise RuntimeError(f"Cannot strip symbols for platform {platform.system()}")
285285
subprocess.run(
286-
strip_cmd,
286+
strip_cmd, # type: ignore [arg-type] # noqa
287287
check=True,
288-
shell=True, # noqa
289288
capture_output=True,
290289
)
291290
except subprocess.CalledProcessError as e:

docs/api_reference/model/book.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
```{eval-rst}
44
.. automodule:: nautilus_trader.model.book
5+
:show-inheritance:
6+
:inherited-members:
7+
:members:
8+
:member-order: bysource
59
```

docs/api_reference/model/data.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
```{eval-rst}
44
.. automodule:: nautilus_trader.model.data
5+
:show-inheritance:
6+
:inherited-members:
7+
:members:
8+
:member-order: bysource
59
```

docs/concepts/message_bus.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ message_bus=MessageBusConfig(
8888

8989
### Database config
9090
A `DatabaseConfig` must be provided, for a default Redis setup on the local
91-
loopback, you can simple pass a `DatabaseConfig()` which will use defaults to match.
91+
loopback you can pass a `DatabaseConfig()`, which will use defaults to match.
9292

9393
### Trader keys
9494

docs/concepts/strategies.md

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class MyStrategy(Strategy):
3939
super().__init__() # <-- the super class must be called to initialize the strategy
4040
```
4141

42+
```{warning}
43+
Do not call components such as `clock` and `logger` in the `__init__` constructor (which is prior to registration).
44+
This is because the systems clock and MPSC channel thread for logging have not yet been setup on initialization.
45+
```
46+
4247
From here, you can implement handlers as necessary to perform actions based on state transitions
4348
and events.
4449

docs/getting_started/installation.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ Install optional dependencies as 'extras' for specific integrations:
2424
- `betfair`: Betfair adapter
2525
- `docker`: Needed for Docker when using the IB gateway
2626
- `ib`: Interactive Brokers adapter
27-
- `redis`: Use Redis as a cache database
2827

2928
To install with specific extras using _pip_:
3029

31-
pip install -U "nautilus_trader[docker,ib,redis]"
30+
pip install -U "nautilus_trader[docker,ib]"
3231

3332
## From Source
3433
Installation from source requires the `Python.h` header file, which is included in development releases such as `python-dev`.
@@ -75,4 +74,4 @@ To install a binary wheel from GitHub, first navigate to the [latest release](ht
7574
Download the appropriate `.whl` for your operating system and Python version, then run:
7675

7776
pip install <file-name>.whl
78-
77+

examples/backtest/betfair_backtest_orderbook_imbalance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
strategies = [
7979
OrderBookImbalance(
8080
config=OrderBookImbalanceConfig(
81-
instrument_id=instrument.id.value,
81+
instrument_id=instrument.id,
8282
max_trade_size=Decimal(10),
8383
order_id_tag=instrument.selection_id,
8484
),

examples/backtest/crypto_ema_cross_ethusdt_trade_ticks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from nautilus_trader.examples.strategies.ema_cross_twap import EMACrossTWAPConfig
2828
from nautilus_trader.model.currencies import ETH
2929
from nautilus_trader.model.currencies import USDT
30+
from nautilus_trader.model.data import BarType
3031
from nautilus_trader.model.enums import AccountType
3132
from nautilus_trader.model.enums import OmsType
3233
from nautilus_trader.model.identifiers import Venue
@@ -71,8 +72,8 @@
7172

7273
# Configure your strategy
7374
config = EMACrossTWAPConfig(
74-
instrument_id=str(ETHUSDT_BINANCE.id),
75-
bar_type="ETHUSDT.BINANCE-250-TICK-LAST-INTERNAL",
75+
instrument_id=ETHUSDT_BINANCE.id,
76+
bar_type=BarType.from_str("ETHUSDT.BINANCE-250-TICK-LAST-INTERNAL"),
7677
trade_size=Decimal("0.10"),
7778
fast_ema_period=10,
7879
slow_ema_period=20,

examples/backtest/crypto_ema_cross_ethusdt_trailing_stop.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from nautilus_trader.examples.strategies.ema_cross_trailing_stop import EMACrossTrailingStopConfig
2626
from nautilus_trader.model.currencies import ETH
2727
from nautilus_trader.model.currencies import USDT
28+
from nautilus_trader.model.data import BarType
2829
from nautilus_trader.model.enums import AccountType
2930
from nautilus_trader.model.enums import OmsType
3031
from nautilus_trader.model.identifiers import Venue
@@ -63,8 +64,8 @@
6364

6465
# Configure your strategy
6566
config = EMACrossTrailingStopConfig(
66-
instrument_id=str(ETHUSDT_BINANCE.id),
67-
bar_type="ETHUSDT.BINANCE-100-TICK-LAST-INTERNAL",
67+
instrument_id=ETHUSDT_BINANCE.id,
68+
bar_type=BarType.from_str("ETHUSDT.BINANCE-100-TICK-LAST-INTERNAL"),
6869
trade_size=Decimal("0.10"),
6970
fast_ema_period=10,
7071
slow_ema_period=20,

examples/backtest/crypto_ema_cross_with_binance_provider.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from nautilus_trader.config import LoggingConfig
3232
from nautilus_trader.examples.strategies.ema_cross_trailing_stop import EMACrossTrailingStop
3333
from nautilus_trader.examples.strategies.ema_cross_trailing_stop import EMACrossTrailingStopConfig
34+
from nautilus_trader.model.data import BarType
3435
from nautilus_trader.model.enums import AccountType
3536
from nautilus_trader.model.enums import OmsType
3637
from nautilus_trader.model.identifiers import InstrumentId
@@ -97,7 +98,7 @@ async def create_provider():
9798

9899
engine.add_instrument(instrument)
99100

100-
bar_type = f"{instrument_id.value}-1-MINUTE-BID-INTERNAL"
101+
bar_type = BarType.from_str(f"{instrument_id.value}-1-MINUTE-BID-INTERNAL")
101102
wrangler = QuoteTickDataWrangler(instrument=instrument)
102103
ticks = wrangler.process_bar_data(
103104
bid_data=TestDataProvider().read_csv_bars("btc-perp-20211231-20220201_1m.csv"),
@@ -108,7 +109,7 @@ async def create_provider():
108109

109110
# Configure your strategy
110111
config = EMACrossTrailingStopConfig(
111-
instrument_id=str(instrument.id),
112+
instrument_id=instrument.id,
112113
bar_type=bar_type,
113114
trade_size=Decimal("1"),
114115
fast_ema_period=10,

examples/backtest/crypto_orderbook_imbalance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888

8989
# Configure your strategy
9090
config = OrderBookImbalanceConfig(
91-
instrument_id=str(BTCUSDT_BINANCE.id),
91+
instrument_id=BTCUSDT_BINANCE.id,
9292
max_trade_size=Decimal("1.000"),
9393
min_seconds_between_triggers=1.0,
9494
book_type=book_type_to_str(book_type),

examples/backtest/fx_ema_cross_audusd_bars_from_ticks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from nautilus_trader.examples.strategies.ema_cross import EMACross
2727
from nautilus_trader.examples.strategies.ema_cross import EMACrossConfig
2828
from nautilus_trader.model.currencies import USD
29+
from nautilus_trader.model.data import BarType
2930
from nautilus_trader.model.enums import AccountType
3031
from nautilus_trader.model.enums import OmsType
3132
from nautilus_trader.model.identifiers import Venue
@@ -73,8 +74,8 @@
7374

7475
# Configure your strategy
7576
config = EMACrossConfig(
76-
instrument_id=str(AUDUSD_SIM.id),
77-
bar_type="AUD/USD.SIM-1-MINUTE-MID-INTERNAL",
77+
instrument_id=AUDUSD_SIM.id,
78+
bar_type=BarType.from_str("AUD/USD.SIM-1-MINUTE-MID-INTERNAL"),
7879
fast_ema_period=10,
7980
slow_ema_period=20,
8081
trade_size=Decimal(1_000_000),

examples/backtest/fx_ema_cross_audusd_ticks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from nautilus_trader.examples.strategies.ema_cross import EMACross
2828
from nautilus_trader.examples.strategies.ema_cross import EMACrossConfig
2929
from nautilus_trader.model.currencies import USD
30+
from nautilus_trader.model.data import BarType
3031
from nautilus_trader.model.enums import AccountType
3132
from nautilus_trader.model.enums import OmsType
3233
from nautilus_trader.model.identifiers import Venue
@@ -84,8 +85,8 @@
8485

8586
# Configure your strategy
8687
config = EMACrossConfig(
87-
instrument_id=str(AUDUSD_SIM.id),
88-
bar_type="AUD/USD.SIM-100-TICK-MID-INTERNAL",
88+
instrument_id=AUDUSD_SIM.id,
89+
bar_type=BarType.from_str("AUD/USD.SIM-100-TICK-MID-INTERNAL"),
8990
trade_size=Decimal(1_000_000),
9091
fast_ema_period=10,
9192
slow_ema_period=20,

examples/backtest/fx_ema_cross_bracket_gbpusd_bars_external.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106

107107
# Configure your strategy
108108
config = EMACrossBracketConfig(
109-
instrument_id=str(GBPUSD_SIM.id),
110-
bar_type="GBP/USD.SIM-1-MINUTE-BID-EXTERNAL",
109+
instrument_id=GBPUSD_SIM.id,
110+
bar_type=BarType.from_str("GBP/USD.SIM-1-MINUTE-BID-EXTERNAL"),
111111
fast_ema_period=10,
112112
slow_ema_period=20,
113113
bracket_distance_atr=3.0,

examples/backtest/fx_ema_cross_bracket_gbpusd_bars_internal.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from nautilus_trader.examples.strategies.ema_cross_bracket import EMACrossBracket
3030
from nautilus_trader.examples.strategies.ema_cross_bracket import EMACrossBracketConfig
3131
from nautilus_trader.model.currencies import USD
32+
from nautilus_trader.model.data import BarType
3233
from nautilus_trader.model.enums import AccountType
3334
from nautilus_trader.model.enums import OmsType
3435
from nautilus_trader.model.identifiers import Venue
@@ -93,8 +94,8 @@
9394

9495
# Configure your strategy
9596
config = EMACrossBracketConfig(
96-
instrument_id=str(GBPUSD_SIM.id),
97-
bar_type="GBP/USD.SIM-5-MINUTE-BID-INTERNAL",
97+
instrument_id=GBPUSD_SIM.id,
98+
bar_type=BarType.from_str("GBP/USD.SIM-5-MINUTE-BID-INTERNAL"),
9899
fast_ema_period=10,
99100
slow_ema_period=20,
100101
bracket_distance_atr=3.0,

0 commit comments

Comments
 (0)