Skip to content

Commit a25dfe0

Browse files
authored
1.103.1
2 parents 8a1cbeb + 7b24b49 commit a25dfe0

Some content is hidden

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

47 files changed

+327
-93
lines changed

README.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ The package is tested against Python 3.7 - 3.9 on both Linux and MacOS.
107107
We recommend users setup a virtual environment to isolate the dependencies, and run the platform
108108
with the latest stable version of Python.
109109

110+
`pyenv` is the recommended tool for handling Python installations and virtual environments.
111+
112+
> https://github.com/pyenv/pyenv
113+
110114
Installation for Unix-like systems can be achieved through _one_ of the following options;
111115

112116
#### From PyPI
@@ -143,9 +147,17 @@ Installation from source requires Cython to compile the Python C extensions.
143147
cd nautilus_trader
144148
pip install .
145149

150+
## Examples
151+
152+
Examples of both backtest and live trading launch scripts are available in the `examples` directory.
153+
These can run through PyCharm, or by running:
154+
155+
python <name_of_script>.py
156+
146157
## Data Types
147158

148-
The following data types can be requested, and also subscribed to as streams.
159+
The following market data types can be requested historically, and also subscribed to as live streams
160+
when available from an exchange/broker, and implemented in an integrations adapter.
149161

150162
- `Instrument`
151163
- `OrderBook` (L1, L2 and L3 if available. Streaming or interval snapshots)
@@ -229,6 +241,11 @@ exchanges.
229241
For development we recommend using the PyCharm _Professional_ edition IDE, as it interprets Cython
230242
syntax. Alternatively, you could use Visual Studio Code with a Cython extension.
231243

244+
`pyenv` is the recommended tool for handling Python installations and virtual environments.
245+
246+
> https://github.com/pyenv/pyenv
247+
248+
232249
`poetry` is the preferred tool for handling all Python package and dev dependencies.
233250

234251
> https://python-poetry.org/
@@ -242,22 +259,22 @@ at commit.
242259

243260
The following steps are for Unix-like systems, and only need to be completed once.
244261

245-
1. Install the `pre-commit` package by running:
246-
247-
pip install pre-commit
248-
249-
2. Install the Cython package by running:
262+
1. Install the Cython package by running:
250263

251264
pip install -U Cython==3.0a6
252265

253-
3. Install `poetry` by running:
266+
2. Install `poetry` by running:
254267

255268
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
256269

257-
4. Then install all Python package dependencies, and compile the C extensions by running:
270+
3. Then install all Python package dependencies, and compile the C extensions by running:
258271

259272
poetry install
260273

274+
4. Install the `pre-commit` package by running:
275+
276+
pip install pre-commit
277+
261278
5. Setup the `pre-commit` hook which will then run automatically at commit by running:
262279

263280
pre-commit run --all-files

build.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22
import os
3-
import platform
43
from pathlib import Path
4+
import platform
55
import shutil
66
from typing import List
77

@@ -12,7 +12,6 @@
1212
from setuptools import Distribution
1313
from setuptools import Extension
1414

15-
1615
# If DEBUG mode is enabled, skip compiler optimizations (TODO: implement)
1716
DEBUG_MODE = bool(os.getenv("DEBUG_MODE", ""))
1817
# If PROFILING mode is enabled, include traces necessary for coverage and profiling

docs/source/api_reference/common.rst

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ Logging
6767
:members:
6868
:member-order: bysource
6969

70+
Queue
71+
-----
72+
73+
.. automodule:: nautilus_trader.common.queue
74+
:show-inheritance:
75+
:inherited-members:
76+
:members:
77+
:member-order: bysource
78+
7079
Timer
7180
-----
7281

docs/source/developer_guide/coding_standards.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ Code Style
99

1010
We philosophically agree with the ``Black`` formatting style, however it does not
1111
currently run over Cython code. So you could say we are "handcrafting towards"
12-
``Blacks`` stylistic conventions.
12+
``Black``s stylistic conventions.
1313
1414
The current codebase can be used as a guide for formatting guidance.
1515
16-
- For longer lines of code, and when passing more than a couple of arguments
16+
1- For longer lines of code, and when passing more than a couple of arguments
1717
it's common to take a new line which aligns at the next logical indent (rather
1818
than attempting a hanging alignment off an opening parenthesis).
1919
20-
- The closing parenthesis should be located on a new line, aligned at the logical
20+
2- The closing parenthesis should be located on a new line, aligned at the logical
2121
indent.
2222
23-
- Also ensure multiple hanging parameters or arguments end with a comma::
23+
3- Also ensure multiple hanging parameters or arguments end with a comma::
2424
2525
LongCodeLine(
2626
some_arg1,

docs/source/developer_guide/environment.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Environment
22
===========
33

4-
For development we recommend using the PyCharm _Professional_ edition IDE, as it
4+
For development we recommend using the PyCharm `Professional` edition IDE, as it
55
interprets Cython syntax. Alternatively, you could use Visual Studio Code with
66
a Cython extension.
77

@@ -18,29 +18,29 @@ Setup
1818
-----
1919
The following steps are for Unix-like systems, and only need to be completed once.
2020

21-
1. Install ``pre-commit`` by running:
21+
1. Install ``pre-commit`` by running::
2222

2323
pip install pre-commit
2424

2525
2. Install the Cython package by running:
2626

2727
pip install -U Cython==3.0a6
2828

29-
3. Install ``poetry`` by running:
29+
3. Install ``poetry`` by running::
3030

3131
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
3232

33-
4. Then install all Python package dependencies, and compile the C extensions by running:
33+
4. Then install all Python package dependencies, and compile the C extensions by running::
3434

3535
poetry install
3636

37-
5. Setup the ``pre-commit`` hook which will then run automatically at commit by running:
37+
5. Setup the ``pre-commit`` hook which will then run automatically at commit by running::
3838

3939
pre-commit run --all-files
4040

4141
Builds
4242
------
4343

44-
Following any changes to ``.pyx`` or ``.pxd`` files, you can re-compile by running:
44+
Following any changes to ``.pyx`` or ``.pxd`` files, you can re-compile by running::
4545

4646
python build.py
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Overview
2+
========
3+
4+
Welcome to the developer guide for NautilusTrader!
5+
6+
Here you will find information related to developing and extending the NautilusTrader
7+
codebase. These guides will assist you in both adding functionality for your own
8+
trading operation, and/or acting as a guide to assist with valuable contributions.
9+
10+
We believe in using the right tool for the job. The overall design philosophy is
11+
to fully utilize the high level power of Python, with its rich eco-system of
12+
frameworks and libraries, whilst overcoming some of its inherent shortcomings in
13+
performance and lack of built in type safety (with it being an interpreted
14+
dynamic language).
15+
16+
One of the advantages of Cython is that we don't have to concern ourselves with
17+
memory safety, as that is handled by its C code generator during the 'cythonization'
18+
step of the build. So we get the best of both worlds - with Pythons clean straight
19+
forward syntax, and a lot of potential to extract several orders of magnitude
20+
greater runtime performance through compiled C dynamic libraries.
21+
22+
The main development and runtime environment we are working in is of course Python.
23+
However with the introduction of Cython syntax throughout the production codebase
24+
in ``.pyx`` and ``.pxd`` files - it's important to be aware of how the CPython
25+
implementation of Python interacts with the underlying CPython API, and the
26+
NautilusTrader C extension modules which Cython produces.
27+
28+
We recommend a thorough review of the Cython documentation to familiarize yourself
29+
with some of its core concepts, and where C typing is being introduced.
30+
31+
> https://cython.org
32+
33+
Its not necessary to become a C language expert, however how Cython C syntax is
34+
used in function and method definitions, in local code blocks, and the common
35+
primitive C types and how these map to their corresponding ``PyObject`` types -
36+
should be well understood.
37+
38+
**work in progress**

docs/source/developer_guide/testing.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Code coverage output is generated using ``coverage`` and reported using ``codeco
4949
High test coverage is a goal for the project however not at the expense of
5050
appropriate error handling, or causing "test induced damage" to the architecture.
5151

52-
There are currently areas of the codebase which are 'impossible' to test unless
52+
There are currently areas of the codebase which are `impossible` to test unless
5353
there is a change to the production code. For example the last condition check
5454
of an if-else block which would catch an unrecognized value, these should be
5555
left in place in case there is a change to the production code - which these

docs/source/getting_started/installation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Installation from source requires Cython to compile the Python C extensions.
5151

5252
pip install -U git+https://github.com/nautechsystems/nautilus_trader
5353

54-
**Or** clone the source with ``git``, and install from the projects root directory by running::
54+
**Or** clone the source with ``git``, and install from the projects root directory by running::
5555

5656
git clone https://github.com/nautechsystems/nautilus_trader
5757
cd nautilus_trader

docs/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Index
140140
:caption: Developer Guide
141141
:hidden:
142142

143+
developer_guide/overview
143144
developer_guide/environment
144145
developer_guide/coding_standards
145146
developer_guide/testing

examples/backtest/crypto_ema_cross_ethusdt_trade_ticks.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
# -------------------------------------------------------------------------------------------------
1616

1717
from decimal import Decimal
18+
import pathlib
19+
import sys
1820

1921
import ccxt
2022
import pandas as pd
2123

24+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
25+
2226
from examples.strategies.ema_cross_simple import EMACross
2327
from nautilus_trader.adapters.ccxt.providers import CCXTInstrumentProvider
2428
from nautilus_trader.backtest.data_container import BacktestDataContainer

examples/backtest/fx_ema_cross_audusd_bars_from_ticks.py

+4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
from decimal import Decimal
1818
import os
19+
import pathlib
20+
import sys
1921

2022
import pandas as pd
2123

24+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
25+
2226
from examples.strategies.ema_cross_simple import EMACross
2327
from nautilus_trader.backtest.data_container import BacktestDataContainer
2428
from nautilus_trader.backtest.engine import BacktestEngine

examples/backtest/fx_ema_cross_audusd_ticks.py

+4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
from decimal import Decimal
1818
import os
19+
import pathlib
20+
import sys
1921

2022
import pandas as pd
2123

24+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
25+
2226
from examples.strategies.ema_cross_simple import EMACross
2327
from nautilus_trader.backtest.data_container import BacktestDataContainer
2428
from nautilus_trader.backtest.engine import BacktestEngine

examples/backtest/fx_ema_cross_gbpusd_bars.py

+4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
from decimal import Decimal
1818
import os
19+
import pathlib
20+
import sys
1921

2022
import pandas as pd
2123

24+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
25+
2226
from examples.strategies.ema_cross_simple import EMACross
2327
from nautilus_trader.backtest.data_container import BacktestDataContainer
2428
from nautilus_trader.backtest.engine import BacktestEngine

examples/backtest/fx_market_maker_gbpusd_bars.py

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

17-
from datetime import datetime
1817
from decimal import Decimal
1918
import os
19+
import pathlib
20+
import sys
2021

2122
import pandas as pd
2223

24+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
25+
2326
from examples.strategies.volatility_market_maker import VolatilityMarketMaker
2427
from nautilus_trader.backtest.data_container import BacktestDataContainer
2528
from nautilus_trader.backtest.engine import BacktestEngine

examples/live/binance_ema_cross.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# -------------------------------------------------------------------------------------------------
1616

1717
from decimal import Decimal
18+
import pathlib
19+
import sys
20+
21+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
1822

1923
from examples.strategies.ema_cross_simple import EMACross
2024
from nautilus_trader.live.node import TradingNode
@@ -28,8 +32,13 @@
2832
# file. Here it is hardcoded into the example for clarity.
2933
config = {
3034
"trader": {
31-
"name": "TESTER", # Not sent beyond system boundary
32-
"id_tag": "001", # Used to ensure orders are unique for this trader
35+
"name": "TESTER", # Not sent beyond system boundary
36+
"id_tag": "001", # Used to ensure orders are unique for this trader
37+
},
38+
39+
"system": {
40+
"connection_timeout": 5.0, # Timeout for successful connections for all engine clients
41+
"disconnection_timeout": 5.0, # Timeout for successful disconnection for all engine clients
3342
"check_residuals_delay": 5.0, # How long to wait after stopping for residual events (secs)
3443
},
3544

examples/live/binance_market_maker.py

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# -------------------------------------------------------------------------------------------------
1616

1717
from decimal import Decimal
18+
import pathlib
19+
import sys
20+
21+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
1822

1923
from examples.strategies.volatility_market_maker import VolatilityMarketMaker
2024
from nautilus_trader.live.node import TradingNode
@@ -30,6 +34,11 @@
3034
"trader": {
3135
"name": "TESTER", # Not sent beyond system boundary
3236
"id_tag": "001", # Used to ensure orders are unique for this trader
37+
},
38+
39+
"system": {
40+
"connection_timeout": 5.0, # Timeout for successful connections for all engine clients
41+
"disconnection_timeout": 5.0, # Timeout for successful disconnection for all engine clients
3342
"check_residuals_delay": 5.0, # How long to wait after stopping for residual events (secs)
3443
},
3544

examples/live/bitmex_ema_cross.py

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# -------------------------------------------------------------------------------------------------
1616

1717
from decimal import Decimal
18+
import pathlib
19+
import sys
20+
21+
sys.path.insert(0, str(pathlib.Path(__file__).parents[2])) # Allows relative imports from examples
1822

1923
from examples.strategies.ema_cross_simple import EMACross
2024
from nautilus_trader.live.node import TradingNode
@@ -30,6 +34,11 @@
3034
"trader": {
3135
"name": "TESTER", # Not sent beyond system boundary
3236
"id_tag": "001", # Used to ensure orders are unique for this trader
37+
},
38+
39+
"system": {
40+
"connection_timeout": 5.0, # Timeout for successful connections for all engine clients
41+
"disconnection_timeout": 5.0, # Timeout for successful disconnection for all engine clients
3342
"check_residuals_delay": 5.0, # How long to wait after stopping for residual events (secs)
3443
},
3544

0 commit comments

Comments
 (0)