Skip to content

Commit

Permalink
Reorganize infrastructure crate
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 20, 2024
1 parent 341481b commit a4e97f9
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 79 deletions.
3 changes: 3 additions & 0 deletions nautilus_core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions nautilus_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ log = { version = "0.4.21", features = ["std", "kv_unstable", "serde", "release_
pyo3 = { version = "0.20.3", features = ["rust_decimal"] }
pyo3-asyncio = { version = "0.20.0", features = ["tokio-runtime", "tokio", "attributes"] }
rand = "0.8.5"
redis = { version = "0.25.3", features = [
"connection-manager",
"keep-alive",
"tls-rustls",
"tls-rustls-webpki-roots",
"tokio-comp",
"tokio-rustls-comp",
] }
rmp-serde = "1.2.0"
rust_decimal = "1.35.0"
rust_decimal_macros = "1.34.2"
Expand Down
22 changes: 19 additions & 3 deletions nautilus_core/infrastructure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,32 @@ nautilus-core = { path = "../core" , features = ["python"] }
nautilus-model = { path = "../model" , features = ["python"] }
anyhow = { workspace = true }
pyo3 = { workspace = true, optional = true }
redis = { workspace = true, optional = true }
rmp-serde = { workspace = true }
rust_decimal = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
tracing = {workspace = true }
sqlx = { version = "0.7.4", features = ["sqlite", "postgres", "any", "runtime-tokio"] }
ustr = { workspace = true }
redis = { version = "0.25.3", features = [
"connection-manager",
"keep-alive",
"tls-rustls",
"tls-rustls-webpki-roots",
"tokio-comp",
"tokio-rustls-comp",
], optional = true }
sqlx = { version = "0.7.4", features = [
"sqlite",
"postgres",
"any",
"runtime-tokio",
], optional = true }

[dev-dependencies]
rstest = { workspace = true }

[features]
default = ["redis"]
default = ["redis"] # redis needed by `nautilus_trader` by default for now
extension-module = [
"pyo3/extension-module",
"nautilus-common/extension-module",
Expand All @@ -35,3 +50,4 @@ extension-module = [
]
python = ["pyo3"]
redis = ["dep:redis"]
sql = ["dep:sqlx"]
3 changes: 3 additions & 0 deletions nautilus_core/infrastructure/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ pub mod python;

#[cfg(feature = "redis")]
pub mod redis;

#[cfg(feature = "sql")]
pub mod sql;
8 changes: 4 additions & 4 deletions nautilus_core/infrastructure/src/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

//! Provides Python bindings from `pyo3`.
#![allow(warnings)] // non-local `impl` definition, temporary allow until pyo3 upgrade

use pyo3::{prelude::*, pymodule};

#[cfg(feature = "redis")]
pub mod redis;

use pyo3::{prelude::*, pymodule};

#[pymodule]
pub fn infrastructure(_: Python<'_>, m: &PyModule) -> PyResult<()> {
#[cfg(feature = "redis")]
m.add_class::<crate::redis::cache::RedisCacheDatabase>()?;
#[cfg(feature = "redis")]
m.add_class::<crate::redis::msgbus::RedisMessageBusDatabase>()?;
Ok(())
}
2 changes: 2 additions & 0 deletions nautilus_core/infrastructure/src/python/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@

//! Provides a Redis cache database and message bus backing.
#![allow(warnings)] // non-local `impl` definition, temporary allow until pyo3 upgrade

pub mod cache;
pub mod msgbus;
8 changes: 3 additions & 5 deletions nautilus_core/infrastructure/src/sql/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use nautilus_model::identifiers::trader_id::TraderId;
use sqlx::Error;

use crate::db::{database::Database, schema::GeneralItem};
use crate::sql::{database::Database, schema::GeneralItem};

pub struct SqlCacheDatabase {
trader_id: TraderId,
Expand Down Expand Up @@ -64,10 +64,8 @@ impl SqlCacheDatabase {
mod tests {
use nautilus_model::identifiers::stubs::trader_id;

use crate::db::{
database::{init_db_schema, setup_test_database},
sql::SqlCacheDatabase,
};
use super::SqlCacheDatabase;
use crate::sql::database::{init_db_schema, setup_test_database};

async fn setup_sql_cache_database() -> SqlCacheDatabase {
let db = setup_test_database().await;
Expand Down
5 changes: 4 additions & 1 deletion nautilus_core/infrastructure/src/sql/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ pub async fn setup_test_database() -> Database {
Database::new(Some(DatabaseEngine::SQLITE), Some("sqlite:test_db.sqlite")).await
}

////////////////////////////////////////////////////////////////////////////////
// Tests
////////////////////////////////////////////////////////////////////////////////
#[cfg(test)]
mod tests {

use sqlx::{FromRow, Row};

use crate::db::database::{setup_test_database, Database};
use crate::sql::database::{setup_test_database, Database};

async fn init_item_table(database: &Database) {
database
Expand Down
Loading

0 comments on commit a4e97f9

Please sign in to comment.