Skip to content

Commit a79c2bb

Browse files
authored
Release 1.184.0
See release notes.
2 parents 178d621 + aef728b commit a79c2bb

File tree

337 files changed

+10805
-6386
lines changed

Some content is hidden

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

337 files changed

+10805
-6386
lines changed

.github/workflows/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: docs
22

33
on:
44
push:
5-
branches: [nightly]
5+
branches: [master, nightly]
66

77
jobs:
88
docs:

.github/workflows/nightly-merge.yml

+14-15
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ jobs:
1313
- name: Checkout repository
1414
uses: actions/checkout@v4
1515
with:
16-
fetch-depth: 0 # Fetch all history for all branches and tags
16+
token: ${{ secrets.NIGHTLY_TOKEN }}
17+
fetch-depth: 0 # Fetch all history for all tags and branches
1718

18-
# Temporary config before nautilus-bot account
19-
- name: Configure Git
20-
run: |
21-
git config --local user.email "[email protected]"
22-
git config --local user.name "Chris Sellers"
23-
24-
- name: Merge develop into nightly
25-
run: |
26-
git checkout nightly
27-
git merge --no-ff origin/develop -m "Automated merge of develop into nightly"
28-
29-
- name: Push changes
30-
run: |
31-
git push origin nightly
19+
- name: Nightly merge
20+
uses: robotology/[email protected]
21+
with:
22+
stable_branch: 'develop' # Branch to merge from
23+
development_branch: 'nightly' # Branch to merge to
24+
allow_ff: false
25+
user_name: 'Chris Sellers'
26+
user_email: '[email protected]'
27+
push_token: 'NIGHTLY_TOKEN'
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
NIGHTLY_TOKEN: ${{ secrets.NIGHTLY_TOKEN }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ venv*/
5454
PERF.JSON
5555
output.json
5656
*dask-worker-space*
57+
.cursorignore
5758

5859
docs/**/*.ipynb
5960
examples/backtest/notebooks/catalog

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repos:
3636
- id: codespell
3737
description: Checks for common misspellings.
3838
types_or: [python, cython, rst, markdown]
39-
args: ["-L", "ot,zar"]
39+
args: ["-L", "crate,ot,zar"]
4040

4141
##############################################################################
4242
# Rust formatting and linting
@@ -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.1.12
85+
rev: v0.1.14
8686
hooks:
8787
- id: ruff
8888
args: ["--fix"]

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ pre-commit:
5252
ruff:
5353
ruff check . --fix
5454

55+
.PHONY: outdated
56+
outdated:
57+
(cd nautilus_core && cargo outdated && poetry show --outdated)
58+
5559
.PHONY: update cargo-update
5660
update: cargo-update
5761
poetry update

RELEASES.md

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
# NautilusTrader 1.184.0 Beta
2+
3+
Released on 22nd January 2024 (UTC).
4+
5+
### Enhancements
6+
- Added `LogLevel.OFF` (matches the Rust `tracing` log levels)
7+
- Added `init_logging` function with sensible defaults to initialize the Rust implemented logging system
8+
- Updated Binance Futures enum members for `BinanceFuturesContractType` and `BinanceFuturesPositionUpdateReason`
9+
- Improved log header using the `sysinfo` crate (adds swap space metrics and a PID identifier)
10+
- Removed Python dependency on `psutil`
11+
12+
### Breaking Changes
13+
- Removed `clock` parameter from `Logger` (no dependency on `Clock` anymore)
14+
- Renamed `LoggerAdapter` to `Logger` (and removed old `Logger` class)
15+
- Renamed `Logger` `component_name` parameter to `name` (matches Python built-in `logging` API)
16+
- Renamed `OptionKind` `kind` parameter and property to `option_kind` (better clarity)
17+
- Renamed `OptionsContract` Arrow schema field `kind` to `option_kind`
18+
- Changed `level_file` log level to `OFF` (file logging is off by default)
19+
20+
### Fixes
21+
- Fixed memory leak for catalog queries (#1430), thanks @twitu
22+
- Fixed `DataEngine` order book snapshot timer names (could not parse instrument IDs with hyphens), thanks for reporting @x-zho14 and @dimitar-petrov
23+
- Fixed `LoggingConfig` parsing of `WARNING` log level (was not being recognized), thanks for reporting @davidsblom
24+
- Fixed Binance Futures `QuoteTick` parsing to capture event time for `ts_event`, thanks for reporting @x-zho14
25+
26+
---
27+
128
# NautilusTrader 1.183.0 Beta
229

330
Released on 12th January 2024 (UTC).
@@ -7,7 +34,7 @@ Released on 12th January 2024 (UTC).
734
- Added `InstrumentClass.BOND`
835
- Added `MessageBusConfig` `use_trader_prefix` and `use_trader_id` options (provides more control over stream names)
936
- Added `CacheConfig.drop_instruments_on_reset` (default true to retain current behavior)
10-
- Implemented core logging interface via the `log` library, thanks @twitu
37+
- Implemented core logging interface via the `log` crate, thanks @twitu
1138
- Implemented global atomic clock in Rust (improves performance and ensures properly monotonic timestamps in real-time), thanks @twitu
1239
- Improved Interactive Brokers adapter raising docker `RuntimeError` only when needed (not when using TWS), thanks @rsmb7z
1340
- Upgraded core HTTP client to latest `hyper` and `reqwest`, thanks @ayush-sb
@@ -42,7 +69,7 @@ Released on 12th January 2024 (UTC).
4269
- Fixed `BinanceSpotInstrumentProvider` fee loading key error for partial instruments load, thanks for reporting @doublier1
4370
- Fixed Binance API key configuration parsing for testnet (was falling through to non-testnet env vars)
4471
- Fixed TWAP execution algorithm scheduled size handling when first order should be for the entire size, thanks for reporting @pcgm-team
45-
- Added `BinanceErrorCode.SERVER_BUSY` (-1008). Also added to the retry error codes.
72+
- Added `BinanceErrorCode.SERVER_BUSY` (-1008), also added to the retry error codes
4673
- Added `BinanceOrderStatus.EXPIRED_IN_MATCH` which is when an order was canceled by the exchange due self-trade prevention (STP), thanks for reporting @doublier1
4774

4875
---
@@ -207,7 +234,7 @@ This will be the final release with support for Python 3.9.
207234
- Moved `manage_gtd_expiry` from `Strategy.submit_order(...)` and `Strategy.submit_order_list(...)` to `StrategyConfig` (simpler and allows re-activiting any GTD timers on start)
208235

209236
### Fixes
210-
- Fixed `LimitIfTouchedOrder.create` (exec_algorithm_params were not being passed in)
237+
- Fixed `LimitIfTouchedOrder.create` (`exec_algorithm_params` were not being passed in)
211238
- Fixed `OrderEmulator` start-up processing of OTO contingent orders (when position from parent is open)
212239
- Fixed `SandboxExecutionClientConfig` `kw_only=True` to allow importing without initializing
213240
- Fixed `OrderBook` pickling (did not include all attributes), thanks @limx0
@@ -282,7 +309,7 @@ this change.
282309
Released on 31st July 2023 (UTC).
283310

284311
### Enhancements
285-
- Implemented string interning with the [ustr](https://github.com/anderslanglands/ustr) library, thanks @twitu
312+
- Implemented string interning with the [ustr](https://github.com/anderslanglands/ustr) crate, thanks @twitu
286313
- Added `SyntheticInstrument` capability, including dynamic derivation formulas
287314
- Added `Order.commissions()` convenience method (also added to state snapshot dictionaries)
288315
- Added `Cache` position and order state snapshots (configure via `CacheConfig`)

build.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,23 @@ def _build_extensions() -> list[Extension]:
154154
extra_link_args += [
155155
"AdvAPI32.Lib",
156156
"bcrypt.lib",
157+
"Crypt32.lib",
158+
"Iphlpapi.lib",
157159
"Kernel32.lib",
160+
"ncrypt.lib",
161+
"Netapi32.lib",
158162
"ntdll.lib",
163+
"Ole32.lib",
164+
"OleAut32.lib",
165+
"Pdh.lib",
166+
"PowrProf.lib",
167+
"Psapi.lib",
168+
"schannel.lib",
169+
"secur32.lib",
170+
"Shell32.lib",
159171
"User32.Lib",
160172
"UserEnv.Lib",
161173
"WS2_32.Lib",
162-
"Crypt32.lib",
163-
"secur32.lib",
164-
"schannel.lib",
165-
"ncrypt.lib",
166174
]
167175

168176
print("Creating C extension modules...")

docs/concepts/adapters.md

-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ from nautilus_trader.adapters.binance.common.enums import BinanceAccountType
2828
from nautilus_trader.adapters.binance.factories import get_cached_binance_http_client
2929
from nautilus_trader.adapters.binance.futures.providers import BinanceFuturesInstrumentProvider
3030
from nautilus_trader.common.clock import LiveClock
31-
from nautilus_trader.common.logging import Logger
3231

3332

3433
clock = LiveClock()
@@ -37,7 +36,6 @@ account_type = BinanceAccountType.USDT_FUTURE
3736
client = get_cached_binance_http_client(
3837
loop=asyncio.get_event_loop(),
3938
clock=clock,
40-
logger=Logger(clock=clock),
4139
account_type=account_type,
4240
key=os.getenv("BINANCE_FUTURES_TESTNET_API_KEY"),
4341
secret=os.getenv("BINANCE_FUTURES_TESTNET_API_SECRET"),
@@ -47,7 +45,6 @@ await client.connect()
4745

4846
provider = BinanceFuturesInstrumentProvider(
4947
client=client,
50-
logger=Logger(clock=clock),
5148
account_type=BinanceAccountType.USDT_FUTURE,
5249
)
5350

docs/concepts/advanced/synthetic_instruments.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Note that the venue for a synthetic instrument is always designated as `'SYNTH'`
2121
## Formula
2222
A synthetic instrument is composed of a combination of two or more component instruments (which
2323
can include instruments from multiple venues), as well as a "derivation formula".
24-
Utilizing the dynamic expression engine powered by the [evalexpr](https://github.com/ISibboI/evalexpr)
25-
Rust library, the platform can evaluate the formula to calculate the latest synthetic price tick
24+
Utilizing the dynamic expression engine powered by the [evalexpr](https://github.com/ISibboI/evalexpr)
25+
Rust crate, the platform can evaluate the formula to calculate the latest synthetic price tick
2626
from the incoming component instrument prices.
2727

2828
See the `evalexpr` documentation for a full description of available features, operators and precedence.

docs/concepts/data.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ We have chosen Parquet as the storage format for the following reasons:
115115
- It does not require any separate running components (for example a database)
116116
- It is quick and simple to get up and running with
117117

118-
The Arrow schemas used for the Parquet format are either single sourced in the core `persistence` Rust library, or available
118+
The Arrow schemas used for the Parquet format are either single sourced in the core `persistence` Rust crate, or available
119119
from the `/serialization/arrow/schema.py` module.
120120

121121
```{note}

docs/concepts/instruments.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ Exchange specific instruments can be discovered from live exchange data using an
3737
from nautilus_trader.adapters.binance.spot.providers import BinanceSpotInstrumentProvider
3838
from nautilus_trader.model.identifiers import InstrumentId
3939

40-
provider = BinanceSpotInstrumentProvider(
41-
client=binance_http_client,
42-
logger=live_logger,
43-
)
40+
provider = BinanceSpotInstrumentProvider(client=binance_http_client)
4441
await self.provider.load_all_async()
4542

4643
btcusdt = InstrumentId.from_str("BTCUSDT.BINANCE")

docs/concepts/logging.md

+36-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Logging
22

3-
The platform provides logging for both backtesting and live trading using a high-performance logger implemented in Rust.
4-
The logger operates in a separate thread and uses a multi-producer single consumer (MPSC) channel to receive log messages.
5-
This design ensures that the main thread is not blocked by log string formatting or file I/O operations.
3+
The platform provides logging for both backtesting and live trading using a high-performance logging system implemented in Rust
4+
with a standardized facade from the `log` crate.
65

7-
```{note}
8-
The latest stable Rust MPSC channel is used, which is now based on the `crossbeam` implementation.
9-
```
6+
The core logger operates in a separate thread and uses a multi-producer single consumer (MPSC) channel to receive log messages.
7+
This design ensures that the main thread is not blocked by log string formatting or file I/O operations.
108

119
There are two configurable writers for logging:
1210
- stdout/stderr writer
@@ -19,11 +17,12 @@ Infrastructure such as [vector](https://github.com/vectordotdev/vector) can be c
1917
Logging can be configured by importing the `LoggingConfig` object.
2018
By default, log events with an 'INFO' `LogLevel` and higher are written to stdout/stderr.
2119

22-
Log level (`LogLevel`) values include:
23-
- 'DEBUG' or 'DBG'
24-
- 'INFO' or 'INF'
25-
- 'WARNING' or 'WRN'
26-
- 'ERROR' or 'ERR'
20+
Log level (`LogLevel`) values include (and generally match Rusts `tracing` level filters):
21+
- `OFF`
22+
- `DEBUG`
23+
- `INFO`
24+
- `WARNING` or `WARN`
25+
- `ERROR`
2726

2827
```{note}
2928
See the `LoggingConfig` [API Reference](../api_reference/config.md#LoggingConfig) for further details.
@@ -33,8 +32,12 @@ Logging can be configured in the following ways:
3332
- Minimum `LogLevel` for stdout/stderr
3433
- Minimum `LogLevel` for log files
3534
- Automatic log file naming and daily rotation, or custom log file name
35+
- Directory for writing log files
3636
- Plain text or JSON log file formatting
37+
- Filtering of individual components by log level
38+
- ANSI colors in log lines
3739
- Bypass logging completely
40+
- Print Rust config to stdout at initialization
3841

3942
### Standard output logging
4043
Log messages are written to the console via stdout/stderr writers. The minimum log level can be configured using the `log_level` parameter.
@@ -95,3 +98,25 @@ these color codes may not be appropriate as they can appear as raw text.
9598
To accommodate for such scenarios, the `LoggingConfig.log_colors` option can be set to `false`.
9699
Disabling `log_colors` will prevent the addition of ANSI color codes to the log messages, ensuring
97100
compatibility across different environments where color rendering is not supported.
101+
102+
### Using a Logger directly
103+
104+
It's possible to use `Logger` objects directly, and these can be initialized anywhere (very similar to the Python built-in `logging` API).
105+
106+
If you ***aren't*** using an object which already initializes a `NautilusKernel` (and logging) such as `BacktestEngine` or `TradingNode`,
107+
then you can initialize a logging in the following way:
108+
```python
109+
from nautilus_trader.common.logging import init_logging
110+
from nautilus_trader.common.logging import Logger
111+
112+
init_logging()
113+
logger = Logger("MyLogger")
114+
```
115+
116+
```{note}
117+
See the `init_logging` [API Reference](../api_reference/common.md#init_logging) for further details.
118+
```
119+
120+
```{warning}
121+
Only one logging system can be initialized per process with an `init_logging` call.
122+
```

docs/integrations/ib.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Interactive Brokers
22

3-
Interactive Brokers (IB) is a trading platform that allows trading in a wide range of financial instruments, including stocks, options, futures, currencies, bonds, funds, and cryptocurrencies. NautilusTrader offers an adapter to integrate with IB using their [Trader Workstation (TWS) API](https://interactivebrokers.github.io/tws-api/index.html) through their Python library, [ibapi](https://github.com/nautechsystems/ibapi).
3+
Interactive Brokers (IB) is a trading platform that allows trading across a wide range of financial instruments, including stocks, options, futures, currencies, bonds, funds, and cryptocurrencies. NautilusTrader offers an adapter to integrate with IB using their [Trader Workstation (TWS) API](https://interactivebrokers.github.io/tws-api/index.html) through their Python library, [ibapi](https://github.com/nautechsystems/ibapi).
44

55
The TWS API serves as an interface to IB's standalone trading applications: TWS and IB Gateway. Both can be downloaded from the IB website. If you haven't installed TWS or IB Gateway yet, refer to the [Initial Setup](https://interactivebrokers.github.io/tws-api/initial_setup.html) guide. In NautilusTrader, you'll establish a connection to one of these applications via the `InteractiveBrokersClient`.
66

77
Alternatively, you can start with a [dockerized version](https://github.com/gnzsnz/ib-gateway-docker) of the IB Gateway, particularly useful when deploying trading strategies on a hosted cloud platform. This requires having [Docker](https://www.docker.com/) installed on your machine, along with the [docker](https://pypi.org/project/docker/) Python package, which NautilusTrader conveniently includes as an extra package.
88

9-
**Note**: The standalone TWS and IB Gateway applications necessitate manual input of username, password, and trading mode (live or paper) at startup. The dockerized version of the IB Gateway handles these steps programmatically.
9+
```{note}
10+
The standalone TWS and IB Gateway applications necessitate manual input of username, password, and trading mode (live or paper) at startup. The dockerized version of the IB Gateway handles these steps programmatically.
11+
```
1012

1113
## Installation
1214

@@ -22,7 +24,9 @@ For installation via poetry, use:
2224
poetry add "nautilus_trader[ib,docker]"
2325
```
2426

25-
**Note**: Because IB does not provide wheels for `ibapi`, NautilusTrader [repackages]( https://pypi.org/project/nautilus-ibapi/) it for release on PyPI.
27+
```{note}
28+
Because IB does not provide wheels for `ibapi`, NautilusTrader [repackages]( https://pypi.org/project/nautilus-ibapi/) it for release on PyPI.
29+
```
2630

2731

2832
## Getting Started
@@ -65,6 +69,22 @@ The adapter includes several major components:
6569
- `InteractiveBrokersDataClient`: Connects to the Gateway for streaming market data.
6670
- `InteractiveBrokersExecutionClient`: Handles account information and executes trades.
6771

72+
## The Interactive Brokers Client
73+
74+
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.
75+
76+
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:
77+
- `InteractiveBrokersClientConnectionMixin`: This class is dedicated to managing the connection with TWS/Gateway.
78+
- `InteractiveBrokersClientErrorMixin`: It focuses on addressing all encountered errors and warnings.
79+
- `InteractiveBrokersClientAccountMixin`: Responsible for handling requests related to account information and positions.
80+
- `InteractiveBrokersClientContractMixin`: Handles retrieving contracts (instruments) data
81+
- `InteractiveBrokersClientMarketDataMixin`: Handles market data requests, subscriptions and data processing
82+
- `InteractiveBrokersClientOrderMixin`: Oversees all aspects of order placement and management.
83+
84+
```{tip}
85+
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.
86+
```
87+
6888
## Instruments & Contracts
6989

7090
In IB, a NautilusTrader `Instrument` is equivalent to a [Contract](https://interactivebrokers.github.io/tws-api/contracts.html). Contracts can be either a [basic contract](https://interactivebrokers.github.io/tws-api/classIBApi_1_1Contract.html) or a more [detailed](https://interactivebrokers.github.io/tws-api/classIBApi_1_1ContractDetails.html) version (ContractDetails). The adapter models these using `IBContract` and `IBContractDetails` classes. The latter includes critical data like order types and trading hours, which are absent in the basic contract. As a result, `IBContractDetails` can be converted to an `Instrument` while `IBContract` cannot.

examples/backtest/crypto_ema_cross_with_binance_provider.py

-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from nautilus_trader.backtest.engine import BacktestEngine
2727
from nautilus_trader.backtest.engine import BacktestEngineConfig
2828
from nautilus_trader.common.clock import LiveClock
29-
from nautilus_trader.common.logging import Logger
3029
from nautilus_trader.config import InstrumentProviderConfig
3130
from nautilus_trader.config import LoggingConfig
3231
from nautilus_trader.examples.strategies.ema_cross_trailing_stop import EMACrossTrailingStop
@@ -47,19 +46,16 @@ async def create_provider():
4746
Create a provider to load all instrument data from live exchange.
4847
"""
4948
clock = LiveClock()
50-
log = Logger(clock=clock)
5149

5250
client = get_cached_binance_http_client(
5351
clock=clock,
54-
logger=log,
5552
account_type=BinanceAccountType.USDT_FUTURE,
5653
is_testnet=True,
5754
)
5855

5956
binance_provider = BinanceFuturesInstrumentProvider(
6057
client=client,
6158
clock=clock,
62-
logger=log,
6359
config=InstrumentProviderConfig(load_all=True, log_warnings=False),
6460
)
6561

0 commit comments

Comments
 (0)