Skip to content

Commit 92aee66

Browse files
authored
Release 1.188.0
See release notes.
2 parents 61debf2 + 303b9f4 commit 92aee66

File tree

356 files changed

+14405
-5528
lines changed

Some content is hidden

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

356 files changed

+14405
-5528
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*.tar.gz*
1919
*.zip
2020

21+
*.dbn
22+
*.dbn.zst
23+
2124
.benchmarks*
2225
.coverage*
2326
.history*
@@ -34,6 +37,7 @@
3437
.vscode/
3538

3639
/catalog/
40+
/examples/notebooks/catalog/
3741

3842
__pycache__
3943
_build/

.pre-commit-config.yaml

+2-2
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: 24.1.1
76+
rev: 24.2.0
7777
hooks:
7878
- id: black
7979
types_or: [python, pyi]
@@ -82,7 +82,7 @@ repos:
8282
exclude: "docs/_pygments/monokai.py"
8383

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

RELEASES.md

+44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
# NautilusTrader 1.188.0 Beta
2+
3+
Released on 25th February 2024 (UTC).
4+
5+
### Enhancements
6+
- Added `FuturesSpread` instrument type
7+
- Added `OptionsSpread` instrument type
8+
- Added `InstrumentClass.FUTURE_SPREAD`
9+
- Added `InstrumentClass.OPTION_SPREAD`
10+
- Added `managed` parameter to `subscribe_order_book_deltas`, default true to retain current behavior (if false then the data engine will not automatically manage a book)
11+
- Added `managed` parameter to `subscribe_order_book_snapshots`, default true to retain current behavior (if false then the data engine will not automatically manage a book)
12+
- Added additional validations for `OrderMatchingEngine` (will now reject orders with incorrect price or quantity precisions)
13+
- Removed `interval_ms` 20 millisecond limitation for `subscribe_order_book_snapshots` (i.e. just needs to be positive), although we recommend you consider subscribing to deltas below 100 milliseconds
14+
- Ported `LiveClock` and `LiveTimer` implementations to Rust
15+
- Implemented `OrderBookDeltas` pickling
16+
- Implemented `AverageTrueRange` in Rust, thanks @rsmb7z
17+
18+
### Breaking Changes
19+
- Changed `TradeId` value maximum length to 36 characters (will raise a `ValueError` if value exceeds the maximum)
20+
21+
### Fixes
22+
- Fixed `TradeId` memory leak due assigning unique values to the `Ustr` global string cache (which are never freed for the lifetime of the program)
23+
- Fixed `TradeTick` size precision for pyo3 conversion (size precision was incorrectly price precision)
24+
- Fixed `RiskEngine` cash value check when selling (would previously divide quantity by price which is too much), thanks for reporting@AnthonyVince
25+
- Fixed FOK time in force behavior (allows fills beyond the top level, will cancel if cannot fill full size)
26+
- Fixed IOC time in force behavior (allows fills beyond the top level, will cancel any remaining after all fills are applied)
27+
- Fixed `LiveClock` timer behavior for small intervals causing next time to be less than now (timer then would not run)
28+
- Fixed log level filtering for `log_level_file` (bug introduced in v1.187.0), thanks @twitu
29+
- Fixed logging `print_config` config option (was not being passed through to the logging system)
30+
- Fixed logging timestamps for backtesting (static clock was not being incrementally set to individual `TimeEvent` timestamps)
31+
- Fixed account balance updates (fills from zero quantity `NETTING` positions will generate account balance updates)
32+
- Fixed `MessageBus` publishable types collection type (needed to be `tuple` not `set`)
33+
- Fixed `Controller` registration of components to ensure all active clocks are iterated correctly during backtests
34+
- Fixed `Equity` short selling for `CASH` accounts (will now reject)
35+
- Fixed `ActorFactory.create` JSON encoding (was missing the encoding hook)
36+
- Fixed `ImportableConfig.create` JSON encoding (was missing the encoding hook)
37+
- Fixed `ImportableStrategyConfig.create` JSON encoding (was missing the encoding hook)
38+
- Fixed `ExecAlgorithmFactory.create` JSON encoding (was missing the encoding hook)
39+
- Fixed `ControllerConfig` base class and docstring
40+
- Fixed Interactive Brokers historical bar data bug, thanks @benjaminsingleton
41+
- Fixed persistence `freeze_dict` function to handle `fs_storage_options`, thanks @dimitar-petrov
42+
43+
---
44+
145
# NautilusTrader 1.187.0 Beta
246

347
Released on 9th February 2024 (UTC).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env python3
2+
# -------------------------------------------------------------------------------------------------
3+
# Copyright (C) 2015-2024 Nautech Systems Pty Ltd. All rights reserved.
4+
# https://nautechsystems.io
5+
#
6+
# Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
7+
# You may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# -------------------------------------------------------------------------------------------------
16+
17+
from decimal import Decimal
18+
19+
from nautilus_trader.adapters.binance.common.enums import BinanceAccountType
20+
from nautilus_trader.adapters.binance.config import BinanceDataClientConfig
21+
from nautilus_trader.adapters.binance.config import BinanceExecClientConfig
22+
from nautilus_trader.adapters.binance.factories import BinanceLiveDataClientFactory
23+
from nautilus_trader.adapters.binance.factories import BinanceLiveExecClientFactory
24+
from nautilus_trader.config import CacheConfig
25+
from nautilus_trader.config import InstrumentProviderConfig
26+
from nautilus_trader.config import LiveExecEngineConfig
27+
from nautilus_trader.config import LoggingConfig
28+
from nautilus_trader.config import TradingNodeConfig
29+
from nautilus_trader.examples.strategies.orderbook_imbalance_rust import OrderBookImbalance
30+
from nautilus_trader.examples.strategies.orderbook_imbalance_rust import OrderBookImbalanceConfig
31+
from nautilus_trader.live.node import TradingNode
32+
from nautilus_trader.model.identifiers import InstrumentId
33+
from nautilus_trader.model.identifiers import TraderId
34+
35+
36+
# *** THIS IS A TEST STRATEGY WITH NO ALPHA ADVANTAGE WHATSOEVER. ***
37+
# *** IT IS NOT INTENDED TO BE USED TO TRADE LIVE WITH REAL MONEY. ***
38+
39+
40+
# Configure the trading node
41+
config_node = TradingNodeConfig(
42+
trader_id=TraderId("TESTER-001"),
43+
logging=LoggingConfig(
44+
log_level="INFO",
45+
# log_level_file="DEBUG",
46+
# log_file_format="json",
47+
),
48+
exec_engine=LiveExecEngineConfig(
49+
reconciliation=True,
50+
reconciliation_lookback_mins=1440,
51+
filter_position_reports=True,
52+
),
53+
cache=CacheConfig(
54+
database=None,
55+
timestamps_as_iso8601=True,
56+
flush_on_start=False,
57+
),
58+
# snapshot_orders=True,
59+
# snapshot_positions=True,
60+
# snapshot_positions_interval=5.0,
61+
data_clients={
62+
"BINANCE": BinanceDataClientConfig(
63+
api_key=None, # 'BINANCE_API_KEY' env var
64+
api_secret=None, # 'BINANCE_API_SECRET' env var
65+
account_type=BinanceAccountType.SPOT,
66+
base_url_http=None, # Override with custom endpoint
67+
base_url_ws=None, # Override with custom endpoint
68+
us=False, # If client is for Binance US
69+
testnet=False, # If client uses the testnet
70+
instrument_provider=InstrumentProviderConfig(load_all=True),
71+
),
72+
},
73+
exec_clients={
74+
"BINANCE": BinanceExecClientConfig(
75+
api_key=None, # 'BINANCE_API_KEY' env var
76+
api_secret=None, # 'BINANCE_API_SECRET' env var
77+
account_type=BinanceAccountType.SPOT,
78+
base_url_http=None, # Override with custom endpoint
79+
base_url_ws=None, # Override with custom endpoint
80+
us=False, # If client is for Binance US
81+
testnet=False, # If client uses the testnet
82+
instrument_provider=InstrumentProviderConfig(load_all=True),
83+
),
84+
},
85+
timeout_connection=20.0,
86+
timeout_reconciliation=10.0,
87+
timeout_portfolio=10.0,
88+
timeout_disconnection=10.0,
89+
timeout_post_stop=5.0,
90+
)
91+
92+
# Instantiate the node with a configuration
93+
node = TradingNode(config=config_node)
94+
95+
# Configure your strategy
96+
strat_config = OrderBookImbalanceConfig(
97+
instrument_id=InstrumentId.from_str("ETHUSDT.BINANCE"),
98+
external_order_claims=[InstrumentId.from_str("ETHUSDT.BINANCE")],
99+
max_trade_size=Decimal("0.010"),
100+
)
101+
102+
# Instantiate your strategy
103+
strategy = OrderBookImbalance(config=strat_config)
104+
105+
# Add your strategies and modules
106+
node.trader.add_strategy(strategy)
107+
108+
# Register your client factories with the node (can take user defined factories)
109+
node.add_data_client_factory("BINANCE", BinanceLiveDataClientFactory)
110+
node.add_exec_client_factory("BINANCE", BinanceLiveExecClientFactory)
111+
node.build()
112+
113+
114+
# Stop and dispose of the node with SIGINT/CTRL+C
115+
if __name__ == "__main__":
116+
try:
117+
node.run()
118+
finally:
119+
node.dispose()

examples/live/databento/databento_subscriber.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
# limitations under the License.
1515
# -------------------------------------------------------------------------------------------------
1616

17-
from nautilus_trader.adapters.databento.config import DatabentoDataClientConfig
18-
from nautilus_trader.adapters.databento.constants import DATABENTO
19-
from nautilus_trader.adapters.databento.constants import DATABENTO_CLIENT_ID
20-
from nautilus_trader.adapters.databento.factories import DatabentoLiveDataClientFactory
17+
from nautilus_trader.adapters.databento import DATABENTO
18+
from nautilus_trader.adapters.databento import DATABENTO_CLIENT_ID
19+
from nautilus_trader.adapters.databento import DatabentoDataClientConfig
20+
from nautilus_trader.adapters.databento import DatabentoLiveDataClientFactory
21+
from nautilus_trader.cache.config import CacheConfig
22+
from nautilus_trader.common.config import DatabaseConfig
2123
from nautilus_trader.common.enums import LogColor
2224
from nautilus_trader.config import InstrumentProviderConfig
2325
from nautilus_trader.config import LiveExecEngineConfig
@@ -43,8 +45,9 @@
4345
# For correct subscription operation, you must specify all instruments to be immediately
4446
# subscribed for as part of the data client configuration
4547
instrument_ids = [
46-
InstrumentId.from_str("ESH4.GLBX"),
47-
# InstrumentId.from_str("ESM4.GLBX"),
48+
InstrumentId.from_str("ESH4.XCME"),
49+
# InstrumentId.from_str("ESM4.XCME"),
50+
# InstrumentId.from_str("ESU4.XCME"),
4851
# InstrumentId.from_str("AAPL.XCHI"),
4952
]
5053

@@ -56,12 +59,12 @@
5659
reconciliation=False, # Not applicable
5760
inflight_check_interval_ms=0, # Not applicable
5861
),
59-
# cache=CacheConfig(
60-
# database=DatabaseConfig(),
61-
# encoding="json",
62-
# timestamps_as_iso8601=True,
63-
# buffer_interval_ms=100,
64-
# ),
62+
cache=CacheConfig(
63+
database=DatabaseConfig(),
64+
encoding="msgpack",
65+
timestamps_as_iso8601=True,
66+
buffer_interval_ms=100,
67+
),
6568
# message_bus=MessageBusConfig(
6669
# database=DatabaseConfig(),
6770
# encoding="json",

examples/notebooks/backtest_binance_orderbook.ipynb

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"source": [
88
"# Backtest on Binance OrderBook data\n",
99
"\n",
10-
"This example runs through how to setup the data catalog and a `BacktestNode` to backtest an `OrderBookImbalance` strategy or order book data. This example requires you bring your Binance own order book data.\n",
10+
"This tutorial runs through how to setup the data catalog and a `BacktestNode` to backtest an `OrderBookImbalance` strategy or order book data. This example requires you bring your Binance own order book data.\n",
1111
"\n",
1212
"**Warning:**\n",
1313
"\n",
@@ -41,14 +41,17 @@
4141
"import pandas as pd\n",
4242
"\n",
4343
"from nautilus_trader.backtest.node import BacktestNode\n",
44+
"from nautilus_trader.backtest.node import BacktestVenueConfig\n",
45+
"from nautilus_trader.backtest.node import BacktestDataConfig\n",
46+
"from nautilus_trader.backtest.node import BacktestRunConfig\n",
47+
"from nautilus_trader.backtest.node import BacktestEngineConfig\n",
4448
"from nautilus_trader.core.datetime import dt_to_unix_nanos\n",
45-
"from nautilus_trader.config import BacktestRunConfig, BacktestVenueConfig, BacktestDataConfig, BacktestEngineConfig\n",
4649
"from nautilus_trader.config import ImportableStrategyConfig\n",
4750
"from nautilus_trader.config import LoggingConfig\n",
4851
"from nautilus_trader.examples.strategies.ema_cross import EMACross, EMACrossConfig\n",
4952
"from nautilus_trader.model.data import OrderBookDelta\n",
5053
"from nautilus_trader.persistence.loaders import BinanceOrderBookDeltaDataLoader\n",
51-
"from nautilus_trader.persistence.wranglers import OrderBookDeltaDataWranglerV2\n",
54+
"from nautilus_trader.persistence.wranglers import OrderBookDeltaDataWrangler\n",
5255
"from nautilus_trader.persistence.catalog import ParquetDataCatalog\n",
5356
"from nautilus_trader.test_kit.providers import TestInstrumentProvider"
5457
]
@@ -113,7 +116,7 @@
113116
"source": [
114117
"# Process deltas using a wrangler\n",
115118
"BTCUSDT_BINANCE = TestInstrumentProvider.btcusdt_binance()\n",
116-
"wrangler = OrderBookDeltaDataWranglerV2(BTCUSDT_BINANCE)\n",
119+
"wrangler = OrderBookDeltaDataWrangler(BTCUSDT_BINANCE)\n",
117120
"\n",
118121
"deltas = wrangler.process(df_snap)\n",
119122
"deltas += wrangler.process(df_update)\n",
@@ -146,7 +149,7 @@
146149
"metadata": {},
147150
"outputs": [],
148151
"source": [
149-
"# Write instrument and ticks to catalog (this currently takes a minute - investigating)\n",
152+
"# Write instrument and ticks to catalog\n",
150153
"catalog.write_data([BTCUSDT_BINANCE])\n",
151154
"catalog.write_data(deltas)"
152155
]

examples/notebooks/backtest_example.ipynb

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "0",
66
"metadata": {},
77
"source": [
8-
"# Complete backtest using the data catalog and a BacktestNode (higher level)\n",
8+
"# Complete backtest using the data catalog and a BacktestNode (high-level API)\n",
99
"\n",
1010
"This example runs through how to setup the data catalog and a `BacktestNode` for a single 'one-shot' backtest run."
1111
]
@@ -32,8 +32,11 @@
3232
"import pandas as pd\n",
3333
"\n",
3434
"from nautilus_trader.backtest.node import BacktestNode\n",
35+
"from nautilus_trader.backtest.node import BacktestVenueConfig\n",
36+
"from nautilus_trader.backtest.node import BacktestDataConfig\n",
37+
"from nautilus_trader.backtest.node import BacktestRunConfig\n",
38+
"from nautilus_trader.backtest.node import BacktestEngineConfig\n",
3539
"from nautilus_trader.core.datetime import dt_to_unix_nanos\n",
36-
"from nautilus_trader.config import BacktestRunConfig, BacktestVenueConfig, BacktestDataConfig, BacktestEngineConfig\n",
3740
"from nautilus_trader.config import ImportableStrategyConfig\n",
3841
"from nautilus_trader.config import LoggingConfig\n",
3942
"from nautilus_trader.examples.strategies.ema_cross import EMACross, EMACrossConfig\n",
@@ -170,6 +173,14 @@
170173
"source": [
171174
"result"
172175
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": null,
180+
"id": "10",
181+
"metadata": {},
182+
"outputs": [],
183+
"source": []
173184
}
174185
],
175186
"metadata": {

examples/notebooks/backtest_fx_usdjpy.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"id": "0",
66
"metadata": {},
77
"source": [
8-
"# Complete backtest using a wrangler and BacktestEngine (lower level)\n",
8+
"# Complete backtest using a wrangler and BacktestEngine (low-level API)\n",
99
"\n",
10-
"This example runs through how to setup a `BacktestEngine` for a single 'one-shot' backtest run."
10+
"This tutorial runs through how to setup a `BacktestEngine` for a single 'one-shot' backtest run."
1111
]
1212
},
1313
{

0 commit comments

Comments
 (0)