From 1521b52aa0ba60c4a939f75099e59221081d08a8 Mon Sep 17 00:00:00 2001 From: Chris Sellers Date: Sun, 22 Oct 2023 14:30:09 +1100 Subject: [PATCH] Add initial Python type stubs --- build.py | 4 +- nautilus_core/pyo3/src/lib.rs | 69 +- nautilus_trader/adapters/betfair/client.py | 6 +- nautilus_trader/adapters/betfair/sockets.py | 6 +- nautilus_trader/adapters/binance/factories.py | 2 +- .../adapters/binance/futures/http/account.py | 2 +- .../adapters/binance/futures/http/market.py | 2 +- .../adapters/binance/futures/http/wallet.py | 2 +- .../adapters/binance/http/account.py | 2 +- .../adapters/binance/http/client.py | 8 +- .../adapters/binance/http/endpoint.py | 2 +- .../adapters/binance/http/market.py | 2 +- nautilus_trader/adapters/binance/http/user.py | 2 +- .../adapters/binance/spot/http/account.py | 2 +- .../adapters/binance/spot/http/market.py | 2 +- .../adapters/binance/spot/http/wallet.py | 2 +- .../adapters/binance/websocket/client.py | 2 +- nautilus_trader/backtest/node.py | 2 +- nautilus_trader/core/datetime.pxd | 7 - nautilus_trader/core/datetime.pyx | 135 +-- nautilus_trader/core/nautilus_pyo3.pyi | 788 ++++++++++++++++++ nautilus_trader/model/data/__init__.py | 8 +- nautilus_trader/model/data/tick.pyx | 4 +- nautilus_trader/persistence/funcs.py | 2 +- nautilus_trader/persistence/wranglers_v2.py | 22 +- nautilus_trader/serialization/arrow/schema.py | 8 +- .../serialization/arrow/serializer.py | 2 +- nautilus_trader/test_kit/rust/instruments.py | 18 +- nautilus_trader/test_kit/rust/types.py | 2 +- .../adapters/binance/test_execution_spot.py | 2 +- tests/integration_tests/network/test_http.py | 6 +- .../integration_tests/network/test_socket.py | 4 +- .../network/test_websocket.py | 2 +- tests/performance_tests/test_perf_catalog.py | 4 +- tests/performance_tests/test_perf_http.py | 4 +- tests/unit_tests/core/test_core_pyo3.py | 2 +- tests/unit_tests/core/test_uuid_pyo3.py | 2 +- .../instruments/test_crypto_future_pyo3.py | 2 +- .../instruments/test_crypto_perpetual_pyo3.py | 3 +- tests/unit_tests/model/test_bar_pyo3.py | 22 +- tests/unit_tests/model/test_currency_pyo3.py | 4 +- .../unit_tests/model/test_identifiers_pyo3.py | 12 +- .../model/test_objects_money_pyo3.py | 6 +- .../model/test_objects_price_pyo3.py | 5 +- .../model/test_objects_quantity_pyo3.py | 2 +- tests/unit_tests/model/test_orders_pyo3.py | 20 +- tests/unit_tests/model/test_tick_pyo3.py | 20 +- tests/unit_tests/persistence/test_backend.py | 4 +- .../persistence/test_transformer.py | 2 +- tests/unit_tests/persistence/test_writing.py | 2 +- 50 files changed, 961 insertions(+), 284 deletions(-) create mode 100644 nautilus_trader/core/nautilus_pyo3.pyi diff --git a/build.py b/build.py index f8072e81a628..16f852f32b26 100644 --- a/build.py +++ b/build.py @@ -104,7 +104,7 @@ def _build_rust_libs() -> None: ) except subprocess.CalledProcessError as e: raise RuntimeError( - f"Error running cargo: {e.stderr.decode()}", + f"Error running cargo: {e}", ) from e @@ -297,7 +297,7 @@ def _strip_unneeded_symbols() -> None: capture_output=True, ) except subprocess.CalledProcessError as e: - raise RuntimeError(f"Error when stripping symbols.\n{e.stderr.decode()}") from e + raise RuntimeError(f"Error when stripping symbols.\n{e}") from e def build() -> None: diff --git a/nautilus_core/pyo3/src/lib.rs b/nautilus_core/pyo3/src/lib.rs index 62d5160c5bde..e4f639e3f77e 100644 --- a/nautilus_core/pyo3/src/lib.rs +++ b/nautilus_core/pyo3/src/lib.rs @@ -15,7 +15,10 @@ use std::str::FromStr; -use pyo3::{prelude::*, types::PyDict}; +use pyo3::{ + prelude::*, + types::{PyDict, PyString}, +}; use tracing::Level; use tracing_appender::{ non_blocking::WorkerGuard, @@ -93,54 +96,66 @@ pub fn set_global_log_collector( /// Need to modify sys modules so that submodule can be loaded directly as /// import supermodule.submodule /// +/// Also re-exports all submodule attributes so they can be imported directly from `nautilus_pyo3`. /// refer: https://github.com/PyO3/pyo3/issues/2644 #[pymodule] fn nautilus_pyo3(py: Python<'_>, m: &PyModule) -> PyResult<()> { let sys = PyModule::import(py, "sys")?; let sys_modules: &PyDict = sys.getattr("modules")?.downcast()?; + let module_name = "nautilus_trader.core.nautilus_pyo3"; + + // Set pyo3_nautilus to be recognized as a subpackage + sys_modules.set_item(module_name, m)?; + + m.add_class::()?; + m.add_function(wrap_pyfunction!(set_global_log_collector, m)?)?; // Core + let n = "core"; let submodule = pyo3::wrap_pymodule!(nautilus_core::python::core); m.add_wrapped(submodule)?; - sys_modules.set_item( - "nautilus_trader.core.nautilus_pyo3.core", - m.getattr("core")?, - )?; - - // Indicators - let submodule = pyo3::wrap_pymodule!(nautilus_indicators::indicators); - m.add_wrapped(submodule)?; - sys_modules.set_item( - "nautilus_trader.core.nautilus_pyo3.indicators", - m.getattr("indicators")?, - )?; + sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?; + re_export_module_attributes(m, n)?; // Model + let n = "model"; let submodule = pyo3::wrap_pymodule!(nautilus_model::python::model); m.add_wrapped(submodule)?; - sys_modules.set_item( - "nautilus_trader.core.nautilus_pyo3.model", - m.getattr("model")?, - )?; + sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?; + re_export_module_attributes(m, n)?; + + // Indicators + let n = "indicators"; + let submodule = pyo3::wrap_pymodule!(nautilus_indicators::indicators); + m.add_wrapped(submodule)?; + sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?; + re_export_module_attributes(m, n)?; // Network + let n = "network"; let submodule = pyo3::wrap_pymodule!(nautilus_network::network); m.add_wrapped(submodule)?; - sys_modules.set_item( - "nautilus_trader.core.nautilus_pyo3.network", - m.getattr("network")?, - )?; + sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?; + re_export_module_attributes(m, n)?; // Persistence + let n = "persistence"; let submodule = pyo3::wrap_pymodule!(nautilus_persistence::python::persistence); m.add_wrapped(submodule)?; - sys_modules.set_item( - "nautilus_trader.core.nautilus_pyo3.persistence", - m.getattr("persistence")?, - )?; + sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?; + re_export_module_attributes(m, n)?; - m.add_class::()?; - m.add_function(wrap_pyfunction!(set_global_log_collector, m)?)?; + Ok(()) +} + +fn re_export_module_attributes(parent_module: &PyModule, submodule_name: &str) -> PyResult<()> { + let submodule = parent_module.getattr(submodule_name)?; + for item in submodule.dir() { + let item_name: &PyString = item.extract()?; + if let Ok(attr) = submodule.getattr(item_name) { + parent_module.add(item_name.to_str()?, attr)?; + } + } Ok(()) } diff --git a/nautilus_trader/adapters/betfair/client.py b/nautilus_trader/adapters/betfair/client.py index 2c02f80beabb..b1b36b4de632 100644 --- a/nautilus_trader/adapters/betfair/client.py +++ b/nautilus_trader/adapters/betfair/client.py @@ -61,9 +61,9 @@ from nautilus_trader.common.logging import Logger from nautilus_trader.common.logging import LoggerAdapter -from nautilus_trader.core.nautilus_pyo3.network import HttpClient -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod -from nautilus_trader.core.nautilus_pyo3.network import HttpResponse +from nautilus_trader.core.nautilus_pyo3 import HttpClient +from nautilus_trader.core.nautilus_pyo3 import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpResponse from nautilus_trader.core.rust.common import LogColor diff --git a/nautilus_trader/adapters/betfair/sockets.py b/nautilus_trader/adapters/betfair/sockets.py index 2403cb79f649..8c6377d620c0 100644 --- a/nautilus_trader/adapters/betfair/sockets.py +++ b/nautilus_trader/adapters/betfair/sockets.py @@ -22,8 +22,8 @@ from nautilus_trader.adapters.betfair.client import BetfairHttpClient from nautilus_trader.common.logging import Logger from nautilus_trader.common.logging import LoggerAdapter -from nautilus_trader.core.nautilus_pyo3.network import SocketClient -from nautilus_trader.core.nautilus_pyo3.network import SocketConfig +from nautilus_trader.core.nautilus_pyo3 import SocketClient +from nautilus_trader.core.nautilus_pyo3 import SocketConfig HOST = "stream-api.betfair.com" @@ -123,6 +123,8 @@ async def post_disconnection(self) -> None: async def send(self, message: bytes): self._log.debug(f"[SEND] {message.decode()}") + if self._client is None: + raise RuntimeError("Cannot send message: no client.") await self._client.send(message) self._log.debug("[SENT]") diff --git a/nautilus_trader/adapters/binance/factories.py b/nautilus_trader/adapters/binance/factories.py index 03e7f3bf9f3f..d325c1e6f0d8 100644 --- a/nautilus_trader/adapters/binance/factories.py +++ b/nautilus_trader/adapters/binance/factories.py @@ -32,7 +32,7 @@ from nautilus_trader.common.clock import LiveClock from nautilus_trader.common.logging import Logger from nautilus_trader.config import InstrumentProviderConfig -from nautilus_trader.core.nautilus_pyo3.network import Quota +from nautilus_trader.core.nautilus_pyo3 import Quota from nautilus_trader.live.factories import LiveDataClientFactory from nautilus_trader.live.factories import LiveExecClientFactory from nautilus_trader.msgbus.bus import MessageBus diff --git a/nautilus_trader/adapters/binance/futures/http/account.py b/nautilus_trader/adapters/binance/futures/http/account.py index 91b38fdf6187..74127f974852 100644 --- a/nautilus_trader/adapters/binance/futures/http/account.py +++ b/nautilus_trader/adapters/binance/futures/http/account.py @@ -29,7 +29,7 @@ from nautilus_trader.adapters.binance.http.client import BinanceHttpClient from nautilus_trader.adapters.binance.http.endpoint import BinanceHttpEndpoint from nautilus_trader.common.clock import LiveClock -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceFuturesPositionModeHttp(BinanceHttpEndpoint): diff --git a/nautilus_trader/adapters/binance/futures/http/market.py b/nautilus_trader/adapters/binance/futures/http/market.py index 4dc438fafb2e..fdf46c5df738 100644 --- a/nautilus_trader/adapters/binance/futures/http/market.py +++ b/nautilus_trader/adapters/binance/futures/http/market.py @@ -21,7 +21,7 @@ from nautilus_trader.adapters.binance.http.client import BinanceHttpClient from nautilus_trader.adapters.binance.http.endpoint import BinanceHttpEndpoint from nautilus_trader.adapters.binance.http.market import BinanceMarketHttpAPI -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceFuturesExchangeInfoHttp(BinanceHttpEndpoint): diff --git a/nautilus_trader/adapters/binance/futures/http/wallet.py b/nautilus_trader/adapters/binance/futures/http/wallet.py index 82fb5ae2dfe8..62ab803faf56 100644 --- a/nautilus_trader/adapters/binance/futures/http/wallet.py +++ b/nautilus_trader/adapters/binance/futures/http/wallet.py @@ -24,7 +24,7 @@ from nautilus_trader.adapters.binance.http.client import BinanceHttpClient from nautilus_trader.adapters.binance.http.endpoint import BinanceHttpEndpoint from nautilus_trader.common.clock import LiveClock -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceFuturesCommissionRateHttp(BinanceHttpEndpoint): diff --git a/nautilus_trader/adapters/binance/http/account.py b/nautilus_trader/adapters/binance/http/account.py index bb5374466eef..b437626d07d9 100644 --- a/nautilus_trader/adapters/binance/http/account.py +++ b/nautilus_trader/adapters/binance/http/account.py @@ -30,7 +30,7 @@ from nautilus_trader.adapters.binance.http.endpoint import BinanceHttpEndpoint from nautilus_trader.common.clock import LiveClock from nautilus_trader.core.correctness import PyCondition -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceOrderHttp(BinanceHttpEndpoint): diff --git a/nautilus_trader/adapters/binance/http/client.py b/nautilus_trader/adapters/binance/http/client.py index b1c8f3f1c72f..32a548110d5f 100644 --- a/nautilus_trader/adapters/binance/http/client.py +++ b/nautilus_trader/adapters/binance/http/client.py @@ -28,10 +28,10 @@ from nautilus_trader.common.clock import LiveClock from nautilus_trader.common.logging import Logger from nautilus_trader.common.logging import LoggerAdapter -from nautilus_trader.core.nautilus_pyo3.network import HttpClient -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod -from nautilus_trader.core.nautilus_pyo3.network import HttpResponse -from nautilus_trader.core.nautilus_pyo3.network import Quota +from nautilus_trader.core.nautilus_pyo3 import HttpClient +from nautilus_trader.core.nautilus_pyo3 import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpResponse +from nautilus_trader.core.nautilus_pyo3 import Quota class BinanceHttpClient: diff --git a/nautilus_trader/adapters/binance/http/endpoint.py b/nautilus_trader/adapters/binance/http/endpoint.py index c3aa553c123a..897fa08bd0c4 100644 --- a/nautilus_trader/adapters/binance/http/endpoint.py +++ b/nautilus_trader/adapters/binance/http/endpoint.py @@ -21,7 +21,7 @@ from nautilus_trader.adapters.binance.common.schemas.symbol import BinanceSymbol from nautilus_trader.adapters.binance.common.schemas.symbol import BinanceSymbols from nautilus_trader.adapters.binance.http.client import BinanceHttpClient -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod def enc_hook(obj: Any) -> Any: diff --git a/nautilus_trader/adapters/binance/http/market.py b/nautilus_trader/adapters/binance/http/market.py index 1ff3ee81919b..63373b3c9f3f 100644 --- a/nautilus_trader/adapters/binance/http/market.py +++ b/nautilus_trader/adapters/binance/http/market.py @@ -37,7 +37,7 @@ from nautilus_trader.adapters.binance.http.endpoint import BinanceHttpEndpoint from nautilus_trader.core.correctness import PyCondition from nautilus_trader.core.datetime import nanos_to_millis -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod from nautilus_trader.model.data import BarType from nautilus_trader.model.data import OrderBookDeltas from nautilus_trader.model.data import TradeTick diff --git a/nautilus_trader/adapters/binance/http/user.py b/nautilus_trader/adapters/binance/http/user.py index 75bc7d44b02c..8546a8555643 100644 --- a/nautilus_trader/adapters/binance/http/user.py +++ b/nautilus_trader/adapters/binance/http/user.py @@ -24,7 +24,7 @@ from nautilus_trader.adapters.binance.http.client import BinanceHttpClient from nautilus_trader.adapters.binance.http.endpoint import BinanceHttpEndpoint from nautilus_trader.core.correctness import PyCondition -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceListenKeyHttp(BinanceHttpEndpoint): diff --git a/nautilus_trader/adapters/binance/spot/http/account.py b/nautilus_trader/adapters/binance/spot/http/account.py index 33b01be0acad..264e4b279ddb 100644 --- a/nautilus_trader/adapters/binance/spot/http/account.py +++ b/nautilus_trader/adapters/binance/spot/http/account.py @@ -31,7 +31,7 @@ from nautilus_trader.adapters.binance.spot.schemas.account import BinanceSpotAccountInfo from nautilus_trader.adapters.binance.spot.schemas.account import BinanceSpotOrderOco from nautilus_trader.common.clock import LiveClock -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceSpotOpenOrdersHttp(BinanceOpenOrdersHttp): diff --git a/nautilus_trader/adapters/binance/spot/http/market.py b/nautilus_trader/adapters/binance/spot/http/market.py index ec8513d3525f..ca06e8e5144d 100644 --- a/nautilus_trader/adapters/binance/spot/http/market.py +++ b/nautilus_trader/adapters/binance/spot/http/market.py @@ -27,7 +27,7 @@ from nautilus_trader.adapters.binance.spot.enums import BinanceSpotPermissions from nautilus_trader.adapters.binance.spot.schemas.market import BinanceSpotAvgPrice from nautilus_trader.adapters.binance.spot.schemas.market import BinanceSpotExchangeInfo -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceSpotExchangeInfoHttp(BinanceHttpEndpoint): diff --git a/nautilus_trader/adapters/binance/spot/http/wallet.py b/nautilus_trader/adapters/binance/spot/http/wallet.py index 4bd88f4db5c5..46a36a4691d4 100644 --- a/nautilus_trader/adapters/binance/spot/http/wallet.py +++ b/nautilus_trader/adapters/binance/spot/http/wallet.py @@ -24,7 +24,7 @@ from nautilus_trader.adapters.binance.http.endpoint import BinanceHttpEndpoint from nautilus_trader.adapters.binance.spot.schemas.wallet import BinanceSpotTradeFee from nautilus_trader.common.clock import LiveClock -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod class BinanceSpotTradeFeeHttp(BinanceHttpEndpoint): diff --git a/nautilus_trader/adapters/binance/websocket/client.py b/nautilus_trader/adapters/binance/websocket/client.py index 055339e14e0d..87a4a3e84448 100644 --- a/nautilus_trader/adapters/binance/websocket/client.py +++ b/nautilus_trader/adapters/binance/websocket/client.py @@ -22,7 +22,7 @@ from nautilus_trader.common.enums import LogColor from nautilus_trader.common.logging import Logger from nautilus_trader.common.logging import LoggerAdapter -from nautilus_trader.core.nautilus_pyo3.network import WebSocketClient +from nautilus_trader.core.nautilus_pyo3 import WebSocketClient class BinanceWebSocketClient: diff --git a/nautilus_trader/backtest/node.py b/nautilus_trader/backtest/node.py index 0b7bacfb05ed..ee2877bd6d4d 100644 --- a/nautilus_trader/backtest/node.py +++ b/nautilus_trader/backtest/node.py @@ -28,7 +28,7 @@ from nautilus_trader.config import BacktestVenueConfig from nautilus_trader.core.correctness import PyCondition from nautilus_trader.core.inspect import is_nautilus_class -from nautilus_trader.core.nautilus_pyo3.persistence import DataBackendSession +from nautilus_trader.core.nautilus_pyo3 import DataBackendSession from nautilus_trader.model.currency import Currency from nautilus_trader.model.data import Bar from nautilus_trader.model.data.base import capsule_to_list diff --git a/nautilus_trader/core/datetime.pxd b/nautilus_trader/core/datetime.pxd index d3c4ab2f990e..524b904edee0 100644 --- a/nautilus_trader/core/datetime.pxd +++ b/nautilus_trader/core/datetime.pxd @@ -19,13 +19,6 @@ from cpython.datetime cimport datetime from libc.stdint cimport uint64_t -cpdef uint64_t secs_to_nanos(double seconds) -cpdef uint64_t secs_to_millis(double secs) -cpdef uint64_t millis_to_nanos(double millis) -cpdef uint64_t micros_to_nanos(double micros) -cpdef double nanos_to_secs(uint64_t nanos) -cpdef uint64_t nanos_to_millis(uint64_t nanos) -cpdef uint64_t nanos_to_micros(uint64_t nanos) cpdef unix_nanos_to_dt(uint64_t nanos) cpdef dt_to_unix_nanos(dt: pd.Timestamp) cpdef maybe_unix_nanos_to_dt(nanos) diff --git a/nautilus_trader/core/datetime.pyx b/nautilus_trader/core/datetime.pyx index cc4688dd83f2..2d647d8f2481 100644 --- a/nautilus_trader/core/datetime.pyx +++ b/nautilus_trader/core/datetime.pyx @@ -22,19 +22,21 @@ Functions include awareness/tz checks and conversions, as well as ISO 8601 conve import pandas as pd import pytz +# Re-exports +from nautilus_trader.core.nautilus_pyo3 import micros_to_nanos as micros_to_nanos +from nautilus_trader.core.nautilus_pyo3 import millis_to_nanos as millis_to_nanos +from nautilus_trader.core.nautilus_pyo3 import nanos_to_micros as nanos_to_micros +from nautilus_trader.core.nautilus_pyo3 import nanos_to_millis as nanos_to_millis +from nautilus_trader.core.nautilus_pyo3 import nanos_to_secs as nanos_to_secs +from nautilus_trader.core.nautilus_pyo3 import secs_to_millis as secs_to_millis +from nautilus_trader.core.nautilus_pyo3 import secs_to_nanos as secs_to_nanos + cimport cpython.datetime from cpython.datetime cimport datetime_tzinfo from cpython.unicode cimport PyUnicode_Contains from libc.stdint cimport uint64_t from nautilus_trader.core.correctness cimport Condition -from nautilus_trader.core.rust.core cimport micros_to_nanos as rust_micros_to_nanos -from nautilus_trader.core.rust.core cimport millis_to_nanos as rust_millis_to_nanos -from nautilus_trader.core.rust.core cimport nanos_to_micros as rust_nanos_to_micros -from nautilus_trader.core.rust.core cimport nanos_to_millis as rust_nanos_to_millis -from nautilus_trader.core.rust.core cimport nanos_to_secs as rust_nanos_to_secs -from nautilus_trader.core.rust.core cimport secs_to_millis as rust_secs_to_millis -from nautilus_trader.core.rust.core cimport secs_to_nanos as rust_secs_to_nanos # UNIX epoch is the UTC time at 00:00:00 on 1/1/1970 @@ -42,125 +44,6 @@ from nautilus_trader.core.rust.core cimport secs_to_nanos as rust_secs_to_nanos cdef datetime UNIX_EPOCH = pd.Timestamp("1970-01-01", tz=pytz.utc) -cpdef uint64_t secs_to_nanos(double secs): - """ - Return round nanoseconds (ns) converted from the given seconds. - - Parameters - ---------- - secs : double - The seconds to convert. - - Returns - ------- - uint64_t - - """ - return rust_secs_to_nanos(secs) - - -cpdef uint64_t secs_to_millis(double secs): - """ - Return round milliseconds (ms) converted from the given seconds. - - Parameters - ---------- - secs : double - The seconds to convert. - - Returns - ------- - uint64_t - - """ - return rust_secs_to_millis(secs) - - -cpdef uint64_t millis_to_nanos(double millis): - """ - Return round nanoseconds (ns) converted from the given milliseconds (ms). - - Parameters - ---------- - millis : double - The milliseconds to convert. - - Returns - ------- - uint64_t - - """ - return rust_millis_to_nanos(millis) - - -cpdef uint64_t micros_to_nanos(double micros): - """ - Return round nanoseconds (ns) converted from the given microseconds (μs). - - Parameters - ---------- - micros : double - The microseconds to convert. - - Returns - ------- - uint64_t - - """ - return rust_micros_to_nanos(micros) - - -cpdef double nanos_to_secs(uint64_t nanos): - """ - Return seconds converted from the given nanoseconds (ns). - - Parameters - ---------- - nanos : uint64_t - The nanoseconds to convert. - - Returns - ------- - double - - """ - return rust_nanos_to_secs(nanos) - - -cpdef uint64_t nanos_to_millis(uint64_t nanos): - """ - Return round milliseconds (ms) converted from the given nanoseconds (ns). - - Parameters - ---------- - nanos : uint64_t - The nanoseconds to convert. - - Returns - ------- - uint64_t - - """ - return rust_nanos_to_millis(nanos) - - -cpdef uint64_t nanos_to_micros(uint64_t nanos): - """ - Return round microseconds (μs) converted from the given nanoseconds (ns). - - Parameters - ---------- - nanos : uint64_t - The nanoseconds to convert. - - Returns - ------- - uint64_t - - """ - return rust_nanos_to_micros(nanos) - - cpdef unix_nanos_to_dt(uint64_t nanos): """ Return the datetime (UTC) from the given UNIX time (nanoseconds). diff --git a/nautilus_trader/core/nautilus_pyo3.pyi b/nautilus_trader/core/nautilus_pyo3.pyi new file mode 100644 index 000000000000..f6e060e99ebe --- /dev/null +++ b/nautilus_trader/core/nautilus_pyo3.pyi @@ -0,0 +1,788 @@ +# ruff: noqa: UP007 PYI021 PYI044 PYI053 +# fmt: off +from __future__ import annotations + +import datetime as dt +from collections.abc import Awaitable +from collections.abc import Callable +from decimal import Decimal +from enum import Enum +from typing import Any + +from pyarrow import RecordBatch + +from nautilus_trader.core.data import Data + + +# Python Interface typing: +# We will eventually separate these into separate .pyi files per module, for now this at least +# provides import resolution as well as docstring. + +################################################################################################### +# Core +################################################################################################### + +class UUID4: ... +class LogGuard: ... + +def set_global_log_collector( + stdout_level: str | None, + stderr_level: str | None, + file_level: tuple[str, str, str] | None, +) -> LogGuard: ... +def secs_to_nanos(secs: float) -> int: + """ + Return round nanoseconds (ns) converted from the given seconds. + + Parameters + ---------- + secs : float + The seconds to convert. + + Returns + ------- + int + + """ + +def secs_to_millis(secs: float) -> int: + """ + Return round milliseconds (ms) converted from the given seconds. + + Parameters + ---------- + secs : float + The seconds to convert. + + Returns + ------- + int + + """ + +def millis_to_nanos(millis: float) -> int: + """ + Return round nanoseconds (ns) converted from the given milliseconds (ms). + + Parameters + ---------- + millis : float + The milliseconds to convert. + + Returns + ------- + int + + """ + +def micros_to_nanos(micros: float) -> int: + """ + Return round nanoseconds (ns) converted from the given microseconds (μs). + + Parameters + ---------- + micros : float + The microseconds to convert. + + Returns + ------- + int + + """ + +def nanos_to_secs(nanos: int) -> float: + """ + Return seconds converted from the given nanoseconds (ns). + + Parameters + ---------- + nanos : int + The nanoseconds to convert. + + Returns + ------- + float + + """ + +def nanos_to_millis(nanos: int) -> int: + """ + Return round milliseconds (ms) converted from the given nanoseconds (ns). + + Parameters + ---------- + nanos : int + The nanoseconds to convert. + + Returns + ------- + int + + """ + +def nanos_to_micros(nanos: int) -> int: + """ + Return round microseconds (μs) converted from the given nanoseconds (ns). + + Parameters + ---------- + nanos : int + The nanoseconds to convert. + + Returns + ------- + int + + """ + +def convert_to_snake_case(s: str) -> str: + """ + Convert the given string from any common case (PascalCase, camelCase, kebab-case, etc.) + to *lower* snake_case. + + This function uses the `heck` crate under the hood. + + Parameters + ---------- + s : str + The input string to convert. + + Returns + ------- + str + + """ + +################################################################################################### +# Model +################################################################################################### + +### Data types + +class BarSpecification: + def __init__( + self, + step: int, + aggregation: BarAggregation, + price_type: PriceType, + ) -> None: ... + @property + def step(self) -> int: ... + @property + def aggregation(self) -> BarAggregation: ... + @property + def price_type(self) -> PriceType: ... + @property + def timedelta(self) -> dt.timedelta: ... + @classmethod + def from_str(cls, value: str) -> BarSpecification: ... + +class BarType: + def __init__( + self, + instrument_id: InstrumentId, + bar_spec: BarSpecification, + aggregation_source: AggregationSource | None = None, + ) -> None: ... + @property + def instrument_id(self) -> InstrumentId: ... + @property + def spec(self) -> BarSpecification: ... + @property + def aggregation_source(self) -> AggregationSource: ... + @classmethod + def from_str(cls, value: str) -> BarType: ... + +class Bar: + @staticmethod + def get_fields() -> dict[str, str]: ... + +class BookOrder: ... + +class OrderBookDelta: + @staticmethod + def get_fields() -> dict[str, str]: ... + +class QuoteTick: + @staticmethod + def get_fields() -> dict[str, str]: ... + +class TradeTick: + @staticmethod + def get_fields() -> dict[str, str]: ... + @classmethod + def from_dict(cls, values: dict[str, str]) -> TradeTick: ... + +### Enums + +class AccountType(Enum): + CASH = "CASH" + MARGIN = "MARGIN" + BETTING = "BETTING" + +class AggregationSource(Enum): + EXTERNAL = "EXTERNAL" + INTERNAL = "INTERNAL" + +class AggressorSide(Enum): + BUYER = "BUYER" + SELLER = "SELLER" + +class AssetClass(Enum): + EQUITY = "EQUITY" + COMMODITY = "COMMODITY" + METAL = "METAL" + ENERGY = "ENERGY" + BOND = "BOND" + INDEX = "INDEX" + CRYPTO_CURRENCY = "CRYPTO_CURRENCY" + SPORTS_BETTING = "SPORTS_BETTING" + +class AssetType(Enum): + SPOT = "SPOT" + SWAP = "SWAP" + FUTURE = "FUTURE" + FORWARD = "FORWARD" + CFD = "CFD" + OPTION = "OPTION" + WARRANT = "WARRANT" + +class BarAggregation(Enum): + TICK = "TICK" + TICK_IMBALANCE = "TICK_IMBALANCE" + TICK_RUNS = "TICK_RUNS" + VOLUME = "VOLUME" + VOLUME_IMBALANCE = "VOLUME_IMBALANCE" + VOLUME_RUNS = "VOLUME_RUNS" + VALUE = "VALUE" + VALUE_IMBALANCE = "VALUE_IMBALANCE" + VALUE_RUNS = "VALUE_RUNS" + MILLISECOND = "MILLISECOND" + SECOND = "SECOND" + MINUTE = "MINUTE" + HOUR = "HOUR" + DAY = "DAY" + WEEK = "WEEK" + MONTH = "MONTH" + +class BookAction(Enum): + ADD = "ADD" + UPDATE = "UPDATE" + DELETE = "DELETE" + CLEAR = "CLEAR" + +class BookType(Enum): + L1_MBP = "L1_MBP" + L2_MBP = "L2_MBP" + L3_MBO = "L3_MBO" + +class ContingencyType(Enum): + OCO = "OCO" + OTO = "OTO" + OUO = "OUO" + +class CurrencyType(Enum): + CRYPTO = "CRYPTO" + FIAT = "FIAT" + COMMODITY_BACKED = "COMMODITY_BACKED" + +class InstrumentCloseType(Enum): + END_OF_SESSION = "END_OF_SESSION" + CONTRACT_EXPIRED = "CONTRACT_EXPIRED" + +class LiquiditySide(Enum): + MAKER = "MAKER" + TAKER = "TAKER" + +class MarketStatus(Enum): + PRE_OPEN = "PRE_OPEN" + OPEN = "OPEN" + PAUSE = "PAUSE" + HALT = "HALT" + REOPEN = "REOPEN" + PRE_CLOSE = "PRE_CLOSE" + CLOSED = "CLOSED" + +class HaltReason(Enum): + NOT_HALTED = "NOT_HALTED" + GENERAL = "GENERAL" + VOLATILITY = "VOLATILITY" + +class OmsType(Enum): + UNSPECIFIED = "UNSPECIFIED" + NETTING = "NETTING" + HEDGING = "HEDGIN" + +class OptionKind(Enum): + CALL = "CALL" + PUT = "PUT" + +class OrderSide(Enum): + NO_ORDER_SIDE = "NO_ORDER_SIDE" + BUY = "BUY" + SELL = "SELL" + +class OrderStatus(Enum): + INITIALIZED = "INITIALIZED" + DENIED = "DENIED" + EMULATED = "EMULATED" + RELEASED = "RELEASED" + SUBMITTED = "SUBMITTED" + ACCEPTED = "ACCEPTED" + REJECTED = "REJECTED" + CANCELED = "CANCELED" + EXPIRED = "EXPIRED" + TRIGGERED = "TRIGGERED" + PENDING_UPDATE = "PENDING_UPDATE" + PENDING_CANCEL = "PENDING_CANCEL" + PARTIALLY_FILLED = "PARTIALLY_FILLED" + FILLED = "FILLED" + +class OrderType(Enum): + MARKET = "MARKET" + LIMIT = "LIMIT" + STOP_MARKET = "STOP_MARKET" + STOP_LIMIT = "STOP_LIMIT" + MARKET_TO_LIMIT = "MARKET_TO_LIMIT" + MARKET_IF_TOUCHED = "MARKET_IF_TOUCHED" + LIMIT_IF_TOUCHED = "LIMIT_IF_TOUCHED" + TRAILING_STOP_MARKET = "TRAILING_STOP_MARKET" + TRAILING_STOP_LIMIT = "TRAILING_STOP_LIMIT" + +class PositionSide(Enum): + FLAT = "FLAT" + LONG = "LONG" + SHORT = "SHORT" + +class PriceType(Enum): + BID = "BID" + ASK = "ASK" + MID = "MID" + LAST = "LAST" + +class TimeInForce(Enum): + GTC = "GTC" + IOC = "IOC" + FOK = "FOK" + GTD = "GTD" + DAY = "DAY" + AT_THE_OPEN = "AT_THE_OPEN" + AT_THE_CLOSE = "AT_THE_CLOSE" + +class TradingState(Enum): + ACTIVE = "ACTIVE" + HALTED = "HALTED" + REDUCING = "REDUCING" + +class TrailingOffsetType(Enum): + PRICE = "PRICE" + BASIS_POINTS = "BASIS_POINTS" + TICKS = "TICKS" + PRICE_TIER = "PRICE_TIER" + +class TriggerType(Enum): + DEFAULT = "DEFAULT" + BID_ASK = "BID_ASK" + LAST_TRADE = "LAST_TRADE" + DOUBLE_LAST = "DOUBLE_LAST" + DOUBLE_BID_ASK = "DOUBLE_BID_ASK" + LAST_OR_BID_ASK = "LAST_OR_BID_ASK" + MID_POINT = "MID_POINT" + MARK_PRICE = "MARK_PRICE" + INDEX_PRICE = "INDEX_PRICE" + +### Identifiers + +class AccountId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class ClientId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class ClientOrderId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class ComponentId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class ExecAlgorithmId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class InstrumentId: + def __init__(self, symbol: Symbol, venue: Venue) -> None: ... + @classmethod + def from_str(cls, value: str) -> InstrumentId: ... + @property + def symbol(self) -> Symbol: ... + @property + def venue(self) -> Venue: ... + def value(self) -> str: ... + +class OrderListId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class PositionId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class StrategyId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class Symbol: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class TradeId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class TraderId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class Venue: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +class VenueOrderId: + def __init__(self, value: str) -> None: ... + def value(self) -> str: ... + +### Orders + +class LimitOrder: ... +class LimitIfTouchedOrder: ... + +class MarketOrder: + def __init__( + self, + trader_id: TraderId, + strategy_id: StrategyId, + instrument_id: InstrumentId, + client_order_id: ClientOrderId, + order_side: OrderSide, + quantity: Quantity, + init_id: UUID4, + ts_init: int, + time_in_force: TimeInForce = ..., + reduce_only: bool = False, + quote_quantity: bool = False, + contingency_type: ContingencyType | None = None, + order_list_id: OrderListId | None = None, + linked_order_ids: list[ClientOrderId] | None = None, + parent_order_id: ClientOrderId | None = None, + exec_algorithm_id: ExecAlgorithmId | None = None, + exec_algorithm_params: dict[str, str] | None = None, + exec_spawn_id: ClientOrderId | None = None, + tags: str | None = None, + ) -> None: ... + @staticmethod + def opposite_side(side: OrderSide) -> OrderSide: ... + @staticmethod + def closing_side(side: PositionSide) -> OrderSide: ... + def signed_decimal_qty(self) -> Decimal: ... + def would_reduce_only(self, side: PositionSide, position_qty: Quantity) -> bool: ... + def commission(self, currency: Currency) -> Money | None: ... + def commissions(self) -> dict[Currency, Money]: ... + +class MarketToLimitOrder: ... +class StopLimitOrder: ... +class StopMarketOrder: ... +class TrailingStopLimitOrder: ... +class TrailingStopMarketOrder: ... + +### Objects + +class Currency: + def __init__( + self, + code: str, + precision: int, + iso4217: int, + name: str, + currency_type: CurrencyType, + ) -> None: ... + @property + def code(self) -> str: ... + @property + def precision(self) -> int: ... + @property + def iso4217(self) -> int: ... + @property + def name(self) -> str: ... + @property + def currency_type(self) -> CurrencyType: ... + @staticmethod + def is_fiat(code: str) -> bool: ... + @staticmethod + def is_crypto(code: str) -> bool: ... + @staticmethod + def is_commodity_backed(code: str) -> bool: ... + @staticmethod + def from_str(value: str, strict: bool = False) -> Currency: ... + @staticmethod + def register(currency: Currency, overwrite: bool = False) -> None: ... + +class Money: + def __init__(self, value: float, currency: Currency) -> None: ... + @property + def raw(self) -> int: ... + @property + def currency(self) -> Currency: ... + @staticmethod + def zero(currency: Currency) -> Money: ... + @staticmethod + def from_raw(raw: int, currency: Currency) -> Money: ... + @staticmethod + def from_str(value: str) -> Money: ... + def is_zero(self) -> bool: ... + def as_decimal(self) -> Decimal: ... + def as_double(self) -> float: ... + def to_formatted_str(self) -> str: ... + +class Price: + def __init__(self, value: float, precision: int) -> None: ... + @property + def raw(self) -> int: ... + @property + def precision(self) -> int: ... + @staticmethod + def from_raw(raw: int, precision: int) -> Price: ... + @staticmethod + def zero(precision: int = 0) -> Price: ... + @staticmethod + def from_int(value: int) -> Price: ... + @staticmethod + def from_str(value: str) -> Price: ... + def is_zero(self) -> bool: ... + def is_positive(self) -> bool: ... + def as_double(self) -> float: ... + def as_decimal(self) -> Decimal: ... + def to_formatted_str(self) -> str: ... + +class Quantity: + def __init__(self, value: float, precision: int) -> None: ... + @property + def raw(self) -> int: ... + @property + def precision(self) -> int: ... + @staticmethod + def from_raw(raw: int, precision: int) -> Quantity: ... + @staticmethod + def zero(precision: int = 0) -> Quantity: ... + @staticmethod + def from_int(value: int) -> Quantity: ... + @staticmethod + def from_str(value: str) -> Quantity: ... + def is_zero(self) -> bool: ... + def is_positive(self) -> bool: ... + def as_decimal(self) -> Decimal: ... + def as_double(self) -> float: ... + def to_formatted_str(self) -> str: ... + +### Instruments + +class CryptoFuture: ... +class CryptoPerpetual: ... +class CurrenyPair: ... +class Equity: ... +class FuturesContract: ... +class OptionsContract: ... +class SyntheticInstrument: ... + +################################################################################################### +# Network +################################################################################################### + +class HttpClient: + def __init__( + self, + header_keys: list[str] = [], + keyed_quotas: list[tuple[str, Quota]] = [], + default_quota: Quota | None = None, + ) -> None: ... + async def request( + self, + method: HttpMethod, + url: str, + headers: dict[str, str] | None = None, + body: bytes | None = None, + keys: list[str] | None = None, + ) -> HttpResponse: ... + +class HttpMethod(Enum): + GET = "GET" + POST = "POST" + PUT = "PUT" + DELETE = "DELETE" + PATCH = "PATCH" + +class HttpResponse: + @property + def status(self) -> int: ... + @property + def body(self) -> bytes: ... + @property + def headers(self) -> dict[str, str]: ... + +class Quota: + @classmethod + def rate_per_second(cls, max_burst: int) -> Quota: ... + @classmethod + def rate_per_minute(cls, max_burst: int) -> Quota: ... + @classmethod + def rate_per_hour(cls, max_burst: int) -> Quota: ... + +class WebSocketClient: + @classmethod + def connect( + cls, + url: str, + handler: Callable[[Any], Any], + heartbeat: int | None = None, + post_connection: Callable[..., None] | None = None, + post_reconnection: Callable[..., None] | None = None, + post_disconnection: Callable[..., None] | None = None, + ) -> Awaitable[WebSocketClient]: ... + def disconnect(self) -> Any: ... + @property + def is_alive(self) -> bool: ... + def send_text(self, data: str) -> Awaitable[None]: ... + def send(self, data: bytes) -> Awaitable[None]: ... + +class SocketClient: + @classmethod + def connect( + cls, + config: SocketConfig, + post_connection: Callable[..., None] | None = None, + post_reconnection: Callable[..., None] | None = None, + post_disconnection: Callable[..., None] | None = None, + ) -> Awaitable[SocketClient]: ... + def disconnect(self) -> None: ... + @property + def is_alive(self) -> bool: ... + def send(self, data: bytes) -> Awaitable[None]: ... + +class SocketConfig: + def __init__( + self, + url: str, + ssl: bool, + suffix: list[int], + handler: Callable[..., Any], + heartbeat: tuple[int, list[int]] | None = None, + ) -> None: ... + +################################################################################################### +# Persistence +################################################################################################### + +class NautilusDataType(Enum): + OrderBookDelta = 1 + QuoteTick = 2 + TradeTick = 3 + Bar = 4 + +class DataBackendSession: + def __init__(self, chunk_size: int = 5000) -> None: ... + def add_file( + self, + data_type: NautilusDataType, + table_name: str, + file_path: str, + sql_query: str | None = None, + ) -> None: ... + def to_query_result(self) -> DataQueryResult: ... + +class QueryResult: + def next(self) -> Data | None: ... + +class DataQueryResult: + def __init__(self, result: QueryResult, size: int) -> None: ... + def drop_chunk(self) -> None: ... + def __iter__(self) -> DataQueryResult: ... + def __next__(self) -> Any | None: ... + +class DataTransformer: + @staticmethod + def get_schema_map(data_cls: type) -> dict[str, str]: ... + @staticmethod + def pyobjects_to_batches_bytes(data: list[Data]) -> bytes: ... + @staticmethod + def pyo3_order_book_deltas_to_batches_bytes(data: list[OrderBookDelta]) -> bytes: ... + @staticmethod + def pyo3_quote_ticks_to_batches_bytes(data: list[QuoteTick]) -> bytes: ... + @staticmethod + def pyo3_trade_ticks_to_batches_bytes(data: list[TradeTick]) -> bytes: ... + @staticmethod + def pyo3_bars_to_batches_bytes(data: list[Bar]) -> bytes: ... + @staticmethod + def record_batches_to_pybytes(batches: list[RecordBatch], schema: Any) -> bytes: ... + +class BarDataWrangler: + def __init__( + self, + bar_type: str, + price_precision: int, + size_precision: int, + ) -> None: ... + @property + def bar_type(self) -> str: ... + @property + def price_precision(self) -> int: ... + @property + def size_precision(self) -> int: ... + def process_record_batches_bytes(self, data: bytes) -> list[Bar]: ... + +class OrderBookDeltaDataWrangler: + def __init__( + self, + instrument_id: str, + price_precision: int, + size_precision: int, + ) -> None: ... + @property + def instrument_id(self) -> str: ... + @property + def price_precision(self) -> int: ... + @property + def size_precision(self) -> int: ... + def process_record_batches_bytes(self, data: bytes) -> list[OrderBookDelta]: ... + +class QuoteTickDataWrangler: + def __init__( + self, + instrument_id: str, + price_precision: int, + size_precision: int, + ) -> None: ... + @property + def instrument_id(self) -> str: ... + @property + def price_precision(self) -> int: ... + @property + def size_precision(self) -> int: ... + def process_record_batches_bytes(self, data: bytes) -> list[QuoteTick]: ... + +class TradeTickDataWrangler: + def __init__( + self, + instrument_id: str, + price_precision: int, + size_precision: int, + ) -> None: ... + @property + def instrument_id(self) -> str: ... + @property + def price_precision(self) -> int: ... + @property + def size_precision(self) -> int: ... + def process_record_batches_bytes(self, data: bytes) -> list[TradeTick]: ... diff --git a/nautilus_trader/model/data/__init__.py b/nautilus_trader/model/data/__init__.py index cc80205db0ca..bdb91bfa6bf4 100644 --- a/nautilus_trader/model/data/__init__.py +++ b/nautilus_trader/model/data/__init__.py @@ -16,10 +16,10 @@ Defines the fundamental data types represented within the trading domain. """ -from nautilus_trader.core.nautilus_pyo3.model import Bar as RustBar -from nautilus_trader.core.nautilus_pyo3.model import OrderBookDelta as RustOrderBookDelta -from nautilus_trader.core.nautilus_pyo3.model import QuoteTick as RustQuoteTick -from nautilus_trader.core.nautilus_pyo3.model import TradeTick as RustTradeTick +from nautilus_trader.core.nautilus_pyo3 import Bar as RustBar +from nautilus_trader.core.nautilus_pyo3 import OrderBookDelta as RustOrderBookDelta +from nautilus_trader.core.nautilus_pyo3 import QuoteTick as RustQuoteTick +from nautilus_trader.core.nautilus_pyo3 import TradeTick as RustTradeTick from nautilus_trader.model.data.bar import Bar from nautilus_trader.model.data.bar import BarSpecification from nautilus_trader.model.data.bar import BarType diff --git a/nautilus_trader/model/data/tick.pyx b/nautilus_trader/model/data/tick.pyx index 062cfe649dbe..b915d211d08e 100644 --- a/nautilus_trader/model/data/tick.pyx +++ b/nautilus_trader/model/data/tick.pyx @@ -13,8 +13,8 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -from nautilus_trader.core.nautilus_pyo3.model import QuoteTick as RustQuoteTick -from nautilus_trader.core.nautilus_pyo3.model import TradeTick as RustTradeTick +from nautilus_trader.core.nautilus_pyo3 import QuoteTick as RustQuoteTick +from nautilus_trader.core.nautilus_pyo3 import TradeTick as RustTradeTick from cpython.mem cimport PyMem_Free from cpython.mem cimport PyMem_Malloc diff --git a/nautilus_trader/persistence/funcs.py b/nautilus_trader/persistence/funcs.py index ed90be371121..23c5e2648ab7 100644 --- a/nautilus_trader/persistence/funcs.py +++ b/nautilus_trader/persistence/funcs.py @@ -16,7 +16,7 @@ from __future__ import annotations from nautilus_trader.core.inspect import is_nautilus_class -from nautilus_trader.core.nautilus_pyo3.core import convert_to_snake_case +from nautilus_trader.core.nautilus_pyo3 import convert_to_snake_case INVALID_WINDOWS_CHARS = r'<>:"/\|?* ' diff --git a/nautilus_trader/persistence/wranglers_v2.py b/nautilus_trader/persistence/wranglers_v2.py index 7a703aa9f1b1..9e437f48101b 100644 --- a/nautilus_trader/persistence/wranglers_v2.py +++ b/nautilus_trader/persistence/wranglers_v2.py @@ -21,16 +21,16 @@ import pandas as pd import pyarrow as pa -from nautilus_trader.core.nautilus_pyo3.model import Bar as RustBar +from nautilus_trader.core.nautilus_pyo3 import Bar as RustBar +from nautilus_trader.core.nautilus_pyo3 import BarDataWrangler as RustBarDataWrangler # fmt: off -from nautilus_trader.core.nautilus_pyo3.model import OrderBookDelta as RustOrderBookDelta -from nautilus_trader.core.nautilus_pyo3.model import QuoteTick as RustQuoteTick -from nautilus_trader.core.nautilus_pyo3.model import TradeTick as RustTradeTick -from nautilus_trader.core.nautilus_pyo3.persistence import BarDataWrangler as RustBarDataWrangler -from nautilus_trader.core.nautilus_pyo3.persistence import OrderBookDeltaDataWrangler as RustOrderBookDeltaDataWrangler -from nautilus_trader.core.nautilus_pyo3.persistence import QuoteTickDataWrangler as RustQuoteTickDataWrangler -from nautilus_trader.core.nautilus_pyo3.persistence import TradeTickDataWrangler as RustTradeTickDataWrangler +from nautilus_trader.core.nautilus_pyo3 import OrderBookDelta as RustOrderBookDelta +from nautilus_trader.core.nautilus_pyo3 import OrderBookDeltaDataWrangler as RustOrderBookDeltaDataWrangler +from nautilus_trader.core.nautilus_pyo3 import QuoteTick as RustQuoteTick +from nautilus_trader.core.nautilus_pyo3 import QuoteTickDataWrangler as RustQuoteTickDataWrangler +from nautilus_trader.core.nautilus_pyo3 import TradeTick as RustTradeTick +from nautilus_trader.core.nautilus_pyo3 import TradeTickDataWrangler as RustTradeTickDataWrangler from nautilus_trader.model.data import BarType from nautilus_trader.model.instruments import Instrument @@ -100,7 +100,7 @@ def __init__( def from_arrow( self, table: pa.Table, - ) -> list[RustQuoteTick]: + ) -> list[RustOrderBookDelta]: sink = pa.BufferOutputStream() writer: pa.RecordBatchStreamWriter = pa.ipc.new_stream(sink, table.schema) writer.write_table(table) @@ -322,7 +322,7 @@ def __init__( def from_arrow( self, table: pa.Table, - ) -> list[RustQuoteTick]: + ) -> list[RustTradeTick]: sink = pa.BufferOutputStream() writer: pa.RecordBatchStreamWriter = pa.ipc.new_stream(sink, table.schema) writer.write_table(table) @@ -441,7 +441,7 @@ def __init__( def from_arrow( self, table: pa.Table, - ) -> list[RustQuoteTick]: + ) -> list[RustBar]: sink = pa.BufferOutputStream() writer: pa.RecordBatchStreamWriter = pa.ipc.new_stream(sink, table.schema) writer.write_table(table) diff --git a/nautilus_trader/serialization/arrow/schema.py b/nautilus_trader/serialization/arrow/schema.py index 9180d4cf7506..7a52b734a43b 100644 --- a/nautilus_trader/serialization/arrow/schema.py +++ b/nautilus_trader/serialization/arrow/schema.py @@ -21,10 +21,10 @@ from nautilus_trader.adapters.binance.common.types import BinanceBar from nautilus_trader.common.messages import ComponentStateChanged from nautilus_trader.common.messages import TradingStateChanged -from nautilus_trader.core.nautilus_pyo3.model import Bar as RustBar -from nautilus_trader.core.nautilus_pyo3.model import OrderBookDelta as RustOrderBookDelta -from nautilus_trader.core.nautilus_pyo3.model import QuoteTick as RustQuoteTick -from nautilus_trader.core.nautilus_pyo3.model import TradeTick as RustTradeTick +from nautilus_trader.core.nautilus_pyo3 import Bar as RustBar +from nautilus_trader.core.nautilus_pyo3 import OrderBookDelta as RustOrderBookDelta +from nautilus_trader.core.nautilus_pyo3 import QuoteTick as RustQuoteTick +from nautilus_trader.core.nautilus_pyo3 import TradeTick as RustTradeTick from nautilus_trader.model.data import Bar from nautilus_trader.model.data import InstrumentClose from nautilus_trader.model.data import InstrumentStatus diff --git a/nautilus_trader/serialization/arrow/serializer.py b/nautilus_trader/serialization/arrow/serializer.py index 980956f970d4..20e04848940a 100644 --- a/nautilus_trader/serialization/arrow/serializer.py +++ b/nautilus_trader/serialization/arrow/serializer.py @@ -23,7 +23,7 @@ from nautilus_trader.core.correctness import PyCondition from nautilus_trader.core.data import Data from nautilus_trader.core.message import Event -from nautilus_trader.core.nautilus_pyo3.persistence import DataTransformer +from nautilus_trader.core.nautilus_pyo3 import DataTransformer from nautilus_trader.model.data import Bar from nautilus_trader.model.data import OrderBookDelta from nautilus_trader.model.data import OrderBookDeltas diff --git a/nautilus_trader/test_kit/rust/instruments.py b/nautilus_trader/test_kit/rust/instruments.py index ed554e67ba6b..8f7d55411900 100644 --- a/nautilus_trader/test_kit/rust/instruments.py +++ b/nautilus_trader/test_kit/rust/instruments.py @@ -19,20 +19,20 @@ import pandas as pd import pytz -from nautilus_trader.core.nautilus_pyo3.model import CryptoFuture -from nautilus_trader.core.nautilus_pyo3.model import CryptoPerpetual -from nautilus_trader.core.nautilus_pyo3.model import InstrumentId -from nautilus_trader.core.nautilus_pyo3.model import Money -from nautilus_trader.core.nautilus_pyo3.model import Price -from nautilus_trader.core.nautilus_pyo3.model import Quantity -from nautilus_trader.core.nautilus_pyo3.model import Symbol +from nautilus_trader.core.nautilus_pyo3 import CryptoFuture +from nautilus_trader.core.nautilus_pyo3 import CryptoPerpetual +from nautilus_trader.core.nautilus_pyo3 import InstrumentId +from nautilus_trader.core.nautilus_pyo3 import Money +from nautilus_trader.core.nautilus_pyo3 import Price +from nautilus_trader.core.nautilus_pyo3 import Quantity +from nautilus_trader.core.nautilus_pyo3 import Symbol from nautilus_trader.test_kit.rust.types import TestTypesProviderPyo3 class TestInstrumentProviderPyo3: @staticmethod def ethusdt_perp_binance() -> CryptoPerpetual: - return CryptoPerpetual( + return CryptoPerpetual( # type: ignore InstrumentId.from_str("ETHUSDT-PERP.BINANCE"), Symbol("ETHUSDT"), TestTypesProviderPyo3.currency_eth(), @@ -61,7 +61,7 @@ def btcusdt_future_binance(expiry: Optional[pd.Timestamp] = None) -> CryptoFutur expiry = pd.Timestamp(datetime(2022, 3, 25), tz=pytz.UTC) nanos_expiry = int(expiry.timestamp() * 1e9) instrument_id_str = f"BTCUSDT_{expiry.strftime('%y%m%d')}.BINANCE" - return CryptoFuture( + return CryptoFuture( # type: ignore InstrumentId.from_str(instrument_id_str), Symbol("BTCUSDT"), TestTypesProviderPyo3.currency_btc(), diff --git a/nautilus_trader/test_kit/rust/types.py b/nautilus_trader/test_kit/rust/types.py index 09db55382c9c..d91ccb9d28a3 100644 --- a/nautilus_trader/test_kit/rust/types.py +++ b/nautilus_trader/test_kit/rust/types.py @@ -13,7 +13,7 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -from nautilus_trader.core.nautilus_pyo3.model import Currency +from nautilus_trader.core.nautilus_pyo3 import Currency class TestTypesProviderPyo3: diff --git a/tests/integration_tests/adapters/binance/test_execution_spot.py b/tests/integration_tests/adapters/binance/test_execution_spot.py index 333fe28114bb..ece5cdd5a062 100644 --- a/tests/integration_tests/adapters/binance/test_execution_spot.py +++ b/tests/integration_tests/adapters/binance/test_execution_spot.py @@ -29,7 +29,7 @@ from nautilus_trader.common.clock import LiveClock from nautilus_trader.common.logging import Logger from nautilus_trader.config import InstrumentProviderConfig -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpMethod from nautilus_trader.core.uuid import UUID4 from nautilus_trader.data.engine import DataEngine from nautilus_trader.execution.engine import ExecutionEngine diff --git a/tests/integration_tests/network/test_http.py b/tests/integration_tests/network/test_http.py index 4d9aa983a4c0..1d50537e62bf 100644 --- a/tests/integration_tests/network/test_http.py +++ b/tests/integration_tests/network/test_http.py @@ -21,9 +21,9 @@ from aiohttp import web from aiohttp.test_utils import TestServer -from nautilus_trader.core.nautilus_pyo3.network import HttpClient -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod -from nautilus_trader.core.nautilus_pyo3.network import HttpResponse +from nautilus_trader.core.nautilus_pyo3 import HttpClient +from nautilus_trader.core.nautilus_pyo3 import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpResponse @pytest.fixture(name="test_server") diff --git a/tests/integration_tests/network/test_socket.py b/tests/integration_tests/network/test_socket.py index 7aa1fc8988d6..9cd0efe245cd 100644 --- a/tests/integration_tests/network/test_socket.py +++ b/tests/integration_tests/network/test_socket.py @@ -17,8 +17,8 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.network import SocketClient -from nautilus_trader.core.nautilus_pyo3.network import SocketConfig +from nautilus_trader.core.nautilus_pyo3 import SocketClient +from nautilus_trader.core.nautilus_pyo3 import SocketConfig from nautilus_trader.test_kit.functions import eventually diff --git a/tests/integration_tests/network/test_websocket.py b/tests/integration_tests/network/test_websocket.py index 11d44f5532f4..42e636bb01eb 100644 --- a/tests/integration_tests/network/test_websocket.py +++ b/tests/integration_tests/network/test_websocket.py @@ -19,7 +19,7 @@ import pytest from aiohttp.test_utils import TestServer -from nautilus_trader.core.nautilus_pyo3.network import WebSocketClient +from nautilus_trader.core.nautilus_pyo3 import WebSocketClient from nautilus_trader.test_kit.functions import eventually diff --git a/tests/performance_tests/test_perf_catalog.py b/tests/performance_tests/test_perf_catalog.py index 9c9ac0adbcbe..ff0279a9654a 100644 --- a/tests/performance_tests/test_perf_catalog.py +++ b/tests/performance_tests/test_perf_catalog.py @@ -20,8 +20,8 @@ import pytest from nautilus_trader import PACKAGE_ROOT -from nautilus_trader.core.nautilus_pyo3.persistence import DataBackendSession -from nautilus_trader.core.nautilus_pyo3.persistence import NautilusDataType +from nautilus_trader.core.nautilus_pyo3 import DataBackendSession +from nautilus_trader.core.nautilus_pyo3 import NautilusDataType from nautilus_trader.model.data.base import capsule_to_list from nautilus_trader.test_kit.mocks.data import data_catalog_setup from nautilus_trader.test_kit.performance import PerformanceHarness diff --git a/tests/performance_tests/test_perf_http.py b/tests/performance_tests/test_perf_http.py index 0d99f5059728..357d688fba20 100644 --- a/tests/performance_tests/test_perf_http.py +++ b/tests/performance_tests/test_perf_http.py @@ -16,8 +16,8 @@ import asyncio import time -from nautilus_trader.core.nautilus_pyo3.network import HttpClient -from nautilus_trader.core.nautilus_pyo3.network import HttpMethod +from nautilus_trader.core.nautilus_pyo3 import HttpClient +from nautilus_trader.core.nautilus_pyo3 import HttpMethod CONCURRENCY = 256 diff --git a/tests/unit_tests/core/test_core_pyo3.py b/tests/unit_tests/core/test_core_pyo3.py index 81b796a40d2e..6f07408d402d 100644 --- a/tests/unit_tests/core/test_core_pyo3.py +++ b/tests/unit_tests/core/test_core_pyo3.py @@ -15,7 +15,7 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.core import convert_to_snake_case +from nautilus_trader.core.nautilus_pyo3 import convert_to_snake_case @pytest.mark.parametrize( diff --git a/tests/unit_tests/core/test_uuid_pyo3.py b/tests/unit_tests/core/test_uuid_pyo3.py index 52f1a3f0a96c..b4881f551527 100644 --- a/tests/unit_tests/core/test_uuid_pyo3.py +++ b/tests/unit_tests/core/test_uuid_pyo3.py @@ -15,7 +15,7 @@ import pickle -from nautilus_trader.core.nautilus_pyo3.core import UUID4 +from nautilus_trader.core.nautilus_pyo3 import UUID4 class TestUUID: diff --git a/tests/unit_tests/model/instruments/test_crypto_future_pyo3.py b/tests/unit_tests/model/instruments/test_crypto_future_pyo3.py index 1638a4c81e8f..5ef25dccb9ff 100644 --- a/tests/unit_tests/model/instruments/test_crypto_future_pyo3.py +++ b/tests/unit_tests/model/instruments/test_crypto_future_pyo3.py @@ -13,7 +13,7 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -from nautilus_trader.core.nautilus_pyo3.model import CryptoFuture +from nautilus_trader.core.nautilus_pyo3 import CryptoFuture from nautilus_trader.test_kit.rust.instruments import TestInstrumentProviderPyo3 diff --git a/tests/unit_tests/model/instruments/test_crypto_perpetual_pyo3.py b/tests/unit_tests/model/instruments/test_crypto_perpetual_pyo3.py index 9392a981bfbb..47db75f75d9a 100644 --- a/tests/unit_tests/model/instruments/test_crypto_perpetual_pyo3.py +++ b/tests/unit_tests/model/instruments/test_crypto_perpetual_pyo3.py @@ -13,8 +13,7 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- - -from nautilus_trader.core.nautilus_pyo3.model import CryptoPerpetual +from nautilus_trader.core.nautilus_pyo3 import CryptoPerpetual from nautilus_trader.test_kit.rust.instruments import TestInstrumentProviderPyo3 diff --git a/tests/unit_tests/model/test_bar_pyo3.py b/tests/unit_tests/model/test_bar_pyo3.py index 02bb0381b2a7..6495c388434e 100644 --- a/tests/unit_tests/model/test_bar_pyo3.py +++ b/tests/unit_tests/model/test_bar_pyo3.py @@ -18,17 +18,17 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.model import AggregationSource -from nautilus_trader.core.nautilus_pyo3.model import Bar -from nautilus_trader.core.nautilus_pyo3.model import BarAggregation -from nautilus_trader.core.nautilus_pyo3.model import BarSpecification -from nautilus_trader.core.nautilus_pyo3.model import BarType -from nautilus_trader.core.nautilus_pyo3.model import InstrumentId -from nautilus_trader.core.nautilus_pyo3.model import Price -from nautilus_trader.core.nautilus_pyo3.model import PriceType -from nautilus_trader.core.nautilus_pyo3.model import Quantity -from nautilus_trader.core.nautilus_pyo3.model import Symbol -from nautilus_trader.core.nautilus_pyo3.model import Venue +from nautilus_trader.core.nautilus_pyo3 import AggregationSource +from nautilus_trader.core.nautilus_pyo3 import Bar +from nautilus_trader.core.nautilus_pyo3 import BarAggregation +from nautilus_trader.core.nautilus_pyo3 import BarSpecification +from nautilus_trader.core.nautilus_pyo3 import BarType +from nautilus_trader.core.nautilus_pyo3 import InstrumentId +from nautilus_trader.core.nautilus_pyo3 import Price +from nautilus_trader.core.nautilus_pyo3 import PriceType +from nautilus_trader.core.nautilus_pyo3 import Quantity +from nautilus_trader.core.nautilus_pyo3 import Symbol +from nautilus_trader.core.nautilus_pyo3 import Venue pytestmark = pytest.mark.skip(reason="WIP") diff --git a/tests/unit_tests/model/test_currency_pyo3.py b/tests/unit_tests/model/test_currency_pyo3.py index 5f3ab11a3bb1..8b462bfb397d 100644 --- a/tests/unit_tests/model/test_currency_pyo3.py +++ b/tests/unit_tests/model/test_currency_pyo3.py @@ -17,8 +17,8 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.model import Currency -from nautilus_trader.core.nautilus_pyo3.model import CurrencyType +from nautilus_trader.core.nautilus_pyo3 import Currency +from nautilus_trader.core.nautilus_pyo3 import CurrencyType AUD = Currency.from_str("AUD") diff --git a/tests/unit_tests/model/test_identifiers_pyo3.py b/tests/unit_tests/model/test_identifiers_pyo3.py index dbc0149bc18f..df037e5159b5 100644 --- a/tests/unit_tests/model/test_identifiers_pyo3.py +++ b/tests/unit_tests/model/test_identifiers_pyo3.py @@ -17,12 +17,12 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.model import AccountId -from nautilus_trader.core.nautilus_pyo3.model import ExecAlgorithmId -from nautilus_trader.core.nautilus_pyo3.model import InstrumentId -from nautilus_trader.core.nautilus_pyo3.model import Symbol -from nautilus_trader.core.nautilus_pyo3.model import TraderId -from nautilus_trader.core.nautilus_pyo3.model import Venue +from nautilus_trader.core.nautilus_pyo3 import AccountId +from nautilus_trader.core.nautilus_pyo3 import ExecAlgorithmId +from nautilus_trader.core.nautilus_pyo3 import InstrumentId +from nautilus_trader.core.nautilus_pyo3 import Symbol +from nautilus_trader.core.nautilus_pyo3 import TraderId +from nautilus_trader.core.nautilus_pyo3 import Venue def test_trader_identifier() -> None: diff --git a/tests/unit_tests/model/test_objects_money_pyo3.py b/tests/unit_tests/model/test_objects_money_pyo3.py index c54e1f60b0bf..5d2579886436 100644 --- a/tests/unit_tests/model/test_objects_money_pyo3.py +++ b/tests/unit_tests/model/test_objects_money_pyo3.py @@ -19,11 +19,11 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.model import Currency +from nautilus_trader.core.nautilus_pyo3 import Currency # from nautilus_trader.model.objects import AccountBalance # from nautilus_trader.model.objects import MarginBalance -from nautilus_trader.core.nautilus_pyo3.model import Money +from nautilus_trader.core.nautilus_pyo3 import Money AUD = Currency.from_str("AUD") @@ -168,7 +168,7 @@ def test_repr(self) -> None: ) def test_from_raw_given_valid_values_returns_expected_result( self, - value: str, + value: int, currency: Currency, expected: Money, ) -> None: diff --git a/tests/unit_tests/model/test_objects_price_pyo3.py b/tests/unit_tests/model/test_objects_price_pyo3.py index 96ff0efa9fc9..f06421488bbc 100644 --- a/tests/unit_tests/model/test_objects_price_pyo3.py +++ b/tests/unit_tests/model/test_objects_price_pyo3.py @@ -19,7 +19,7 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.model import Price +from nautilus_trader.core.nautilus_pyo3 import Price class TestPrice: @@ -30,9 +30,6 @@ def test_instantiate_with_nan_raises_value_error(self): def test_instantiate_with_none_value_raises_type_error(self): # Arrange, Act, Assert - with pytest.raises(TypeError): - Price(None) - with pytest.raises(TypeError): Price(None, precision=0) diff --git a/tests/unit_tests/model/test_objects_quantity_pyo3.py b/tests/unit_tests/model/test_objects_quantity_pyo3.py index b6333ca0aea2..d70428b77520 100644 --- a/tests/unit_tests/model/test_objects_quantity_pyo3.py +++ b/tests/unit_tests/model/test_objects_quantity_pyo3.py @@ -19,7 +19,7 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.model import Quantity +from nautilus_trader.core.nautilus_pyo3 import Quantity class TestQuantity: diff --git a/tests/unit_tests/model/test_orders_pyo3.py b/tests/unit_tests/model/test_orders_pyo3.py index ff620a14974a..2ec8e4c04428 100644 --- a/tests/unit_tests/model/test_orders_pyo3.py +++ b/tests/unit_tests/model/test_orders_pyo3.py @@ -15,16 +15,16 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.core import UUID4 -from nautilus_trader.core.nautilus_pyo3.model import AccountId -from nautilus_trader.core.nautilus_pyo3.model import ClientOrderId -from nautilus_trader.core.nautilus_pyo3.model import InstrumentId -from nautilus_trader.core.nautilus_pyo3.model import MarketOrder -from nautilus_trader.core.nautilus_pyo3.model import OrderSide -from nautilus_trader.core.nautilus_pyo3.model import PositionSide -from nautilus_trader.core.nautilus_pyo3.model import Quantity -from nautilus_trader.core.nautilus_pyo3.model import StrategyId -from nautilus_trader.core.nautilus_pyo3.model import TraderId +from nautilus_trader.core.nautilus_pyo3 import UUID4 +from nautilus_trader.core.nautilus_pyo3 import AccountId +from nautilus_trader.core.nautilus_pyo3 import ClientOrderId +from nautilus_trader.core.nautilus_pyo3 import InstrumentId +from nautilus_trader.core.nautilus_pyo3 import MarketOrder +from nautilus_trader.core.nautilus_pyo3 import OrderSide +from nautilus_trader.core.nautilus_pyo3 import PositionSide +from nautilus_trader.core.nautilus_pyo3 import Quantity +from nautilus_trader.core.nautilus_pyo3 import StrategyId +from nautilus_trader.core.nautilus_pyo3 import TraderId AUDUSD_SIM = InstrumentId.from_str("AUD/USD.SIM") diff --git a/tests/unit_tests/model/test_tick_pyo3.py b/tests/unit_tests/model/test_tick_pyo3.py index 1de26510751c..7e250f97d5e9 100644 --- a/tests/unit_tests/model/test_tick_pyo3.py +++ b/tests/unit_tests/model/test_tick_pyo3.py @@ -17,16 +17,16 @@ import pytest -from nautilus_trader.core.nautilus_pyo3.model import AggressorSide -from nautilus_trader.core.nautilus_pyo3.model import InstrumentId -from nautilus_trader.core.nautilus_pyo3.model import Price -from nautilus_trader.core.nautilus_pyo3.model import PriceType -from nautilus_trader.core.nautilus_pyo3.model import Quantity -from nautilus_trader.core.nautilus_pyo3.model import QuoteTick -from nautilus_trader.core.nautilus_pyo3.model import Symbol -from nautilus_trader.core.nautilus_pyo3.model import TradeId -from nautilus_trader.core.nautilus_pyo3.model import TradeTick -from nautilus_trader.core.nautilus_pyo3.model import Venue +from nautilus_trader.core.nautilus_pyo3 import AggressorSide +from nautilus_trader.core.nautilus_pyo3 import InstrumentId +from nautilus_trader.core.nautilus_pyo3 import Price +from nautilus_trader.core.nautilus_pyo3 import PriceType +from nautilus_trader.core.nautilus_pyo3 import Quantity +from nautilus_trader.core.nautilus_pyo3 import QuoteTick +from nautilus_trader.core.nautilus_pyo3 import Symbol +from nautilus_trader.core.nautilus_pyo3 import TradeId +from nautilus_trader.core.nautilus_pyo3 import TradeTick +from nautilus_trader.core.nautilus_pyo3 import Venue AUDUSD_SIM_ID = InstrumentId.from_str("AUD/USD.SIM") diff --git a/tests/unit_tests/persistence/test_backend.py b/tests/unit_tests/persistence/test_backend.py index 7bb43c5e2647..749df9423b46 100644 --- a/tests/unit_tests/persistence/test_backend.py +++ b/tests/unit_tests/persistence/test_backend.py @@ -18,8 +18,8 @@ import pandas as pd from nautilus_trader import PACKAGE_ROOT -from nautilus_trader.core.nautilus_pyo3.persistence import DataBackendSession -from nautilus_trader.core.nautilus_pyo3.persistence import NautilusDataType +from nautilus_trader.core.nautilus_pyo3 import DataBackendSession +from nautilus_trader.core.nautilus_pyo3 import NautilusDataType from nautilus_trader.model.data.base import capsule_to_list diff --git a/tests/unit_tests/persistence/test_transformer.py b/tests/unit_tests/persistence/test_transformer.py index 3cb617d3b145..03305e28c0af 100644 --- a/tests/unit_tests/persistence/test_transformer.py +++ b/tests/unit_tests/persistence/test_transformer.py @@ -19,7 +19,7 @@ import pyarrow as pa import pytest -from nautilus_trader.core.nautilus_pyo3.persistence import DataTransformer +from nautilus_trader.core.nautilus_pyo3 import DataTransformer from nautilus_trader.model.data import Bar from nautilus_trader.model.data import OrderBookDelta from nautilus_trader.model.data import QuoteTick diff --git a/tests/unit_tests/persistence/test_writing.py b/tests/unit_tests/persistence/test_writing.py index d551c969aabc..dc1c230e63b7 100644 --- a/tests/unit_tests/persistence/test_writing.py +++ b/tests/unit_tests/persistence/test_writing.py @@ -17,7 +17,7 @@ import pyarrow as pa -from nautilus_trader.core.nautilus_pyo3.persistence import DataTransformer +from nautilus_trader.core.nautilus_pyo3 import DataTransformer from nautilus_trader.model.data import OrderBookDelta