From 06dc8610d77782b2c081655310a28936d0c7f19e Mon Sep 17 00:00:00 2001 From: Chris Sellers Date: Fri, 23 Feb 2024 19:27:47 +1100 Subject: [PATCH] Cleanup Rust imports --- nautilus_core/accounting/src/account/base.rs | 21 +++--- nautilus_core/accounting/src/account/cash.rs | 71 ++++++++---------- .../accounting/src/account/margin.rs | 55 +++++++------- nautilus_core/accounting/src/account/mod.rs | 22 +++--- nautilus_core/accounting/src/account/stubs.rs | 18 ++--- nautilus_core/accounting/src/python/cash.rs | 33 ++++----- nautilus_core/accounting/src/python/margin.rs | 22 +++--- nautilus_core/accounting/src/stubs.rs | 20 +++-- .../src/databento/python/historical.rs | 3 +- .../adapters/src/databento/python/live.rs | 44 +++++------ .../indicators/src/momentum/aroon.rs | 6 +- nautilus_core/model/src/data/bar.rs | 1 - nautilus_core/model/src/data/mod.rs | 3 +- .../model/src/events/account/stubs.rs | 4 +- nautilus_core/model/src/orders/market.rs | 10 ++- nautilus_core/model/src/orders/stubs.rs | 4 +- nautilus_core/model/src/position.rs | 74 +++++++++---------- nautilus_core/model/src/python/data/bar.rs | 3 +- nautilus_core/model/src/python/data/delta.rs | 3 +- nautilus_core/model/src/python/data/depth.rs | 3 +- nautilus_core/model/src/python/data/quote.rs | 3 +- nautilus_core/model/src/python/data/trade.rs | 3 +- .../model/src/python/orders/market.rs | 6 +- nautilus_core/model/src/python/position.rs | 53 +++++++------ nautilus_core/model/src/stubs.rs | 27 +++---- 25 files changed, 235 insertions(+), 277 deletions(-) diff --git a/nautilus_core/accounting/src/account/base.rs b/nautilus_core/accounting/src/account/base.rs index 376367622a3f..b1be482d6ce6 100644 --- a/nautilus_core/accounting/src/account/base.rs +++ b/nautilus_core/accounting/src/account/base.rs @@ -16,17 +16,16 @@ use std::collections::HashMap; use anyhow::Result; -use nautilus_model::enums::{AccountType, LiquiditySide, OrderSide}; -use nautilus_model::events::account::state::AccountState; -use nautilus_model::events::order::filled::OrderFilled; -use nautilus_model::identifiers::account_id::AccountId; -use nautilus_model::instruments::Instrument; -use nautilus_model::position::Position; -use nautilus_model::types::balance::AccountBalance; -use nautilus_model::types::currency::Currency; -use nautilus_model::types::money::Money; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; +use nautilus_model::{ + enums::{AccountType, LiquiditySide, OrderSide}, + events::{account::state::AccountState, order::filled::OrderFilled}, + identifiers::account_id::AccountId, + instruments::Instrument, + position::Position, + types::{ + balance::AccountBalance, currency::Currency, money::Money, price::Price, quantity::Quantity, + }, +}; use pyo3::prelude::*; use rust_decimal::prelude::ToPrimitive; diff --git a/nautilus_core/accounting/src/account/cash.rs b/nautilus_core/accounting/src/account/cash.rs index caaee89fca98..4bad53bfe8f9 100644 --- a/nautilus_core/accounting/src/account/cash.rs +++ b/nautilus_core/accounting/src/account/cash.rs @@ -13,25 +13,25 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use std::collections::HashMap; -use std::fmt::Display; -use std::ops::{Deref, DerefMut}; +use std::{ + collections::HashMap, + fmt::Display, + ops::{Deref, DerefMut}, +}; use anyhow::Result; -use nautilus_model::enums::{AccountType, LiquiditySide, OrderSide}; -use nautilus_model::events::account::state::AccountState; -use nautilus_model::events::order::filled::OrderFilled; -use nautilus_model::instruments::Instrument; -use nautilus_model::position::Position; -use nautilus_model::types::balance::AccountBalance; -use nautilus_model::types::currency::Currency; -use nautilus_model::types::money::Money; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; +use nautilus_model::{ + enums::{AccountType, LiquiditySide, OrderSide}, + events::{account::state::AccountState, order::filled::OrderFilled}, + instruments::Instrument, + position::Position, + types::{ + balance::AccountBalance, currency::Currency, money::Money, price::Price, quantity::Quantity, + }, +}; use pyo3::prelude::*; -use crate::account::base::BaseAccount; -use crate::account::Account; +use crate::account::{base::BaseAccount, Account}; #[derive(Debug)] #[cfg_attr( @@ -185,31 +185,24 @@ impl Display for CashAccount { //////////////////////////////////////////////////////////////////////////////// #[cfg(test)] mod tests { - use crate::account::cash::CashAccount; - use crate::account::stubs::*; - use crate::account::Account; - use nautilus_common::factories::OrderFactory; - use nautilus_common::stubs::*; - use nautilus_model::enums::{AccountType, LiquiditySide, OrderSide}; - use nautilus_model::events::account::state::AccountState; - use nautilus_model::events::account::stubs::*; - use nautilus_model::identifiers::account_id::AccountId; - use nautilus_model::identifiers::position_id::PositionId; - use nautilus_model::identifiers::strategy_id::StrategyId; - use nautilus_model::instruments::crypto_perpetual::CryptoPerpetual; - use nautilus_model::instruments::currency_pair::CurrencyPair; - use nautilus_model::instruments::equity::Equity; - use nautilus_model::instruments::stubs::*; - use nautilus_model::orders::market::MarketOrder; - use nautilus_model::orders::stubs::TestOrderEventStubs; - use nautilus_model::position::Position; - use nautilus_model::types::currency::Currency; - use nautilus_model::types::money::Money; - use nautilus_model::types::price::Price; - use nautilus_model::types::quantity::Quantity; + use std::collections::{HashMap, HashSet}; + + use nautilus_common::{factories::OrderFactory, stubs::*}; + use nautilus_model::{ + enums::{AccountType, LiquiditySide, OrderSide}, + events::account::{state::AccountState, stubs::*}, + identifiers::{account_id::AccountId, position_id::PositionId, strategy_id::StrategyId}, + instruments::{ + crypto_perpetual::CryptoPerpetual, currency_pair::CurrencyPair, equity::Equity, + stubs::*, + }, + orders::{market::MarketOrder, stubs::TestOrderEventStubs}, + position::Position, + types::{currency::Currency, money::Money, price::Price, quantity::Quantity}, + }; use rstest::rstest; - use std::collections::HashMap; - use std::collections::HashSet; + + use crate::account::{cash::CashAccount, stubs::*, Account}; #[rstest] fn test_display(cash_account: CashAccount) { diff --git a/nautilus_core/accounting/src/account/margin.rs b/nautilus_core/accounting/src/account/margin.rs index 34b805d7189b..0090e1526a87 100644 --- a/nautilus_core/accounting/src/account/margin.rs +++ b/nautilus_core/accounting/src/account/margin.rs @@ -15,30 +15,32 @@ #![allow(dead_code)] -use std::ops::{Deref, DerefMut}; use std::{ collections::HashMap, fmt::Display, hash::{Hash, Hasher}, + ops::{Deref, DerefMut}, }; use anyhow::Result; -use nautilus_model::enums::{AccountType, LiquiditySide, OrderSide}; -use nautilus_model::events::account::state::AccountState; -use nautilus_model::events::order::filled::OrderFilled; -use nautilus_model::identifiers::instrument_id::InstrumentId; -use nautilus_model::instruments::Instrument; -use nautilus_model::position::Position; -use nautilus_model::types::balance::{AccountBalance, MarginBalance}; -use nautilus_model::types::currency::Currency; -use nautilus_model::types::money::Money; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; +use nautilus_model::{ + enums::{AccountType, LiquiditySide, OrderSide}, + events::{account::state::AccountState, order::filled::OrderFilled}, + identifiers::instrument_id::InstrumentId, + instruments::Instrument, + position::Position, + types::{ + balance::{AccountBalance, MarginBalance}, + currency::Currency, + money::Money, + price::Price, + quantity::Quantity, + }, +}; use pyo3::prelude::*; use rust_decimal::prelude::ToPrimitive; -use crate::account::base::BaseAccount; -use crate::account::Account; +use crate::account::{base::BaseAccount, Account}; #[derive(Debug)] #[cfg_attr( @@ -384,23 +386,18 @@ impl Hash for MarginAccount { //////////////////////////////////////////////////////////////////////////////// #[cfg(test)] mod tests { - use crate::account::margin::MarginAccount; - use crate::account::stubs::*; - use crate::account::Account; - use nautilus_model::events::account::state::AccountState; - use nautilus_model::events::account::stubs::*; - use nautilus_model::identifiers::instrument_id::InstrumentId; - use nautilus_model::identifiers::stubs::*; - use nautilus_model::instruments::crypto_perpetual::CryptoPerpetual; - use nautilus_model::instruments::currency_pair::CurrencyPair; - use nautilus_model::instruments::stubs::*; - use nautilus_model::types::currency::Currency; - use nautilus_model::types::money::Money; - use nautilus_model::types::price::Price; - use nautilus_model::types::quantity::Quantity; - use rstest::rstest; use std::collections::HashMap; + use nautilus_model::{ + events::account::{state::AccountState, stubs::*}, + identifiers::{instrument_id::InstrumentId, stubs::*}, + instruments::{crypto_perpetual::CryptoPerpetual, currency_pair::CurrencyPair, stubs::*}, + types::{currency::Currency, money::Money, price::Price, quantity::Quantity}, + }; + use rstest::rstest; + + use crate::account::{margin::MarginAccount, stubs::*, Account}; + #[rstest] fn test_display(margin_account: MarginAccount) { assert_eq!( diff --git a/nautilus_core/accounting/src/account/mod.rs b/nautilus_core/accounting/src/account/mod.rs index 5aafc0ee5018..122b24c02a9d 100644 --- a/nautilus_core/accounting/src/account/mod.rs +++ b/nautilus_core/accounting/src/account/mod.rs @@ -13,19 +13,19 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use anyhow::Result; -use nautilus_model::enums::{LiquiditySide, OrderSide}; -use nautilus_model::events::account::state::AccountState; -use nautilus_model::events::order::filled::OrderFilled; -use nautilus_model::instruments::Instrument; -use nautilus_model::position::Position; -use nautilus_model::types::balance::AccountBalance; -use nautilus_model::types::currency::Currency; -use nautilus_model::types::money::Money; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; use std::collections::HashMap; +use anyhow::Result; +use nautilus_model::{ + enums::{LiquiditySide, OrderSide}, + events::{account::state::AccountState, order::filled::OrderFilled}, + instruments::Instrument, + position::Position, + types::{ + balance::AccountBalance, currency::Currency, money::Money, price::Price, quantity::Quantity, + }, +}; + pub trait Account { fn balance_total(&self, currency: Option) -> Option; fn balances_total(&self) -> HashMap; diff --git a/nautilus_core/accounting/src/account/stubs.rs b/nautilus_core/accounting/src/account/stubs.rs index 7aea09c4437d..03d778a3a287 100644 --- a/nautilus_core/accounting/src/account/stubs.rs +++ b/nautilus_core/accounting/src/account/stubs.rs @@ -13,19 +13,15 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use nautilus_model::enums::LiquiditySide; -use nautilus_model::events::account::state::AccountState; -use nautilus_model::events::account::stubs::*; -use nautilus_model::instruments::Instrument; -use nautilus_model::types::currency::Currency; -use nautilus_model::types::money::Money; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; +use nautilus_model::{ + enums::LiquiditySide, + events::account::{state::AccountState, stubs::*}, + instruments::Instrument, + types::{currency::Currency, money::Money, price::Price, quantity::Quantity}, +}; use rstest::fixture; -use crate::account::cash::CashAccount; -use crate::account::margin::MarginAccount; -use crate::account::Account; +use crate::account::{cash::CashAccount, margin::MarginAccount, Account}; #[fixture] pub fn margin_account(margin_account_state: AccountState) -> MarginAccount { diff --git a/nautilus_core/accounting/src/python/cash.rs b/nautilus_core/accounting/src/python/cash.rs index dbea9fad488c..43481bb44a1d 100644 --- a/nautilus_core/accounting/src/python/cash.rs +++ b/nautilus_core/accounting/src/python/cash.rs @@ -16,26 +16,21 @@ use std::collections::HashMap; use nautilus_core::python::to_pyvalue_err; -use nautilus_model::enums::{LiquiditySide, OrderSide}; -use nautilus_model::events::account::state::AccountState; -use nautilus_model::events::order::filled::OrderFilled; -use nautilus_model::identifiers::account_id::AccountId; -use nautilus_model::instruments::crypto_future::CryptoFuture; -use nautilus_model::instruments::crypto_perpetual::CryptoPerpetual; -use nautilus_model::instruments::currency_pair::CurrencyPair; -use nautilus_model::instruments::equity::Equity; -use nautilus_model::instruments::futures_contract::FuturesContract; -use nautilus_model::instruments::options_contract::OptionsContract; -use nautilus_model::position::Position; -use nautilus_model::types::currency::Currency; -use nautilus_model::types::money::Money; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; -use pyo3::basic::CompareOp; -use pyo3::prelude::*; +use nautilus_model::{ + enums::{LiquiditySide, OrderSide}, + events::{account::state::AccountState, order::filled::OrderFilled}, + identifiers::account_id::AccountId, + instruments::{ + crypto_future::CryptoFuture, crypto_perpetual::CryptoPerpetual, + currency_pair::CurrencyPair, equity::Equity, futures_contract::FuturesContract, + options_contract::OptionsContract, + }, + position::Position, + types::{currency::Currency, money::Money, price::Price, quantity::Quantity}, +}; +use pyo3::{basic::CompareOp, prelude::*}; -use crate::account::cash::CashAccount; -use crate::account::Account; +use crate::account::{cash::CashAccount, Account}; #[pymethods] impl CashAccount { diff --git a/nautilus_core/accounting/src/python/margin.rs b/nautilus_core/accounting/src/python/margin.rs index a0bef7a4ad54..82fef0b13f05 100644 --- a/nautilus_core/accounting/src/python/margin.rs +++ b/nautilus_core/accounting/src/python/margin.rs @@ -14,18 +14,16 @@ // ------------------------------------------------------------------------------------------------- use nautilus_core::python::to_pyvalue_err; -use nautilus_model::events::account::state::AccountState; -use nautilus_model::identifiers::account_id::AccountId; -use nautilus_model::identifiers::instrument_id::InstrumentId; -use nautilus_model::instruments::crypto_future::CryptoFuture; -use nautilus_model::instruments::crypto_perpetual::CryptoPerpetual; -use nautilus_model::instruments::currency_pair::CurrencyPair; -use nautilus_model::instruments::equity::Equity; -use nautilus_model::instruments::futures_contract::FuturesContract; -use nautilus_model::instruments::options_contract::OptionsContract; -use nautilus_model::types::money::Money; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; +use nautilus_model::{ + events::account::state::AccountState, + identifiers::{account_id::AccountId, instrument_id::InstrumentId}, + instruments::{ + crypto_future::CryptoFuture, crypto_perpetual::CryptoPerpetual, + currency_pair::CurrencyPair, equity::Equity, futures_contract::FuturesContract, + options_contract::OptionsContract, + }, + types::{money::Money, price::Price, quantity::Quantity}, +}; use pyo3::{basic::CompareOp, prelude::*, types::PyDict}; use crate::account::margin::MarginAccount; diff --git a/nautilus_core/accounting/src/stubs.rs b/nautilus_core/accounting/src/stubs.rs index 04c66711470a..d5a62794b14e 100644 --- a/nautilus_core/accounting/src/stubs.rs +++ b/nautilus_core/accounting/src/stubs.rs @@ -13,17 +13,15 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use nautilus_common::factories::OrderFactory; -use nautilus_common::stubs::*; -use nautilus_model::enums::OrderSide; -use nautilus_model::identifiers::instrument_id::InstrumentId; -use nautilus_model::instruments::currency_pair::CurrencyPair; -use nautilus_model::instruments::stubs::audusd_sim; -use nautilus_model::orders::market::MarketOrder; -use nautilus_model::orders::stubs::TestOrderEventStubs; -use nautilus_model::position::Position; -use nautilus_model::types::price::Price; -use nautilus_model::types::quantity::Quantity; +use nautilus_common::{factories::OrderFactory, stubs::*}; +use nautilus_model::{ + enums::OrderSide, + identifiers::instrument_id::InstrumentId, + instruments::{currency_pair::CurrencyPair, stubs::audusd_sim}, + orders::{market::MarketOrder, stubs::TestOrderEventStubs}, + position::Position, + types::{price::Price, quantity::Quantity}, +}; use rstest::fixture; #[fixture] diff --git a/nautilus_core/adapters/src/databento/python/historical.rs b/nautilus_core/adapters/src/databento/python/historical.rs index 74d8a9a91ef2..ecfdcbfd52c2 100644 --- a/nautilus_core/adapters/src/databento/python/historical.rs +++ b/nautilus_core/adapters/src/databento/python/historical.rs @@ -34,6 +34,7 @@ use pyo3::{ }; use tokio::sync::Mutex; +use super::loader::convert_instrument_to_pyobject; use crate::databento::{ common::get_date_time_range, decode::{decode_instrument_def_msg, decode_record, raw_ptr_to_ustr}, @@ -41,8 +42,6 @@ use crate::databento::{ types::{DatabentoPublisher, PublisherId}, }; -use super::loader::convert_instrument_to_pyobject; - #[cfg_attr( feature = "python", pyclass(module = "nautilus_trader.core.nautilus_pyo3.databento") diff --git a/nautilus_core/adapters/src/databento/python/live.rs b/nautilus_core/adapters/src/databento/python/live.rs index 5f0e76adb337..40b954bdc770 100644 --- a/nautilus_core/adapters/src/databento/python/live.rs +++ b/nautilus_core/adapters/src/databento/python/live.rs @@ -13,43 +13,37 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use std::collections::HashMap; -use std::ffi::CStr; -use std::fs; -use std::str::FromStr; -use std::sync::Arc; +use std::{collections::HashMap, ffi::CStr, fs, str::FromStr, sync::Arc}; use anyhow::{anyhow, bail, Result}; use databento::live::Subscription; use dbn::{PitSymbolMap, Record, SymbolIndex, VersionUpgradePolicy}; use indexmap::IndexMap; use log::{error, info}; -use nautilus_core::ffi::cvec::CVec; -use nautilus_core::python::to_pyruntime_err; -use nautilus_core::time::AtomicTime; use nautilus_core::{ - python::to_pyvalue_err, - time::{get_atomic_clock_realtime, UnixNanos}, + ffi::cvec::CVec, + python::{to_pyruntime_err, to_pyvalue_err}, + time::{get_atomic_clock_realtime, AtomicTime, UnixNanos}, }; -use nautilus_model::data::delta::OrderBookDelta; -use nautilus_model::data::deltas::OrderBookDeltas; -use nautilus_model::data::Data; -use nautilus_model::ffi::data::deltas::orderbook_deltas_new; -use nautilus_model::identifiers::instrument_id::InstrumentId; -use nautilus_model::identifiers::symbol::Symbol; -use nautilus_model::identifiers::venue::Venue; -use nautilus_model::python::data::data_to_pycapsule; -use pyo3::exceptions::PyRuntimeError; -use pyo3::prelude::*; +use nautilus_model::{ + data::{delta::OrderBookDelta, deltas::OrderBookDeltas, Data}, + ffi::data::deltas::orderbook_deltas_new, + identifiers::{instrument_id::InstrumentId, symbol::Symbol, venue::Venue}, + python::data::data_to_pycapsule, +}; +use pyo3::{exceptions::PyRuntimeError, prelude::*}; use time::OffsetDateTime; -use tokio::sync::Mutex; -use tokio::time::{timeout, Duration}; +use tokio::{ + sync::Mutex, + time::{timeout, Duration}, +}; use ustr::Ustr; -use crate::databento::decode::{decode_instrument_def_msg, decode_record}; -use crate::databento::types::{DatabentoPublisher, PublisherId}; - use super::loader::convert_instrument_to_pyobject; +use crate::databento::{ + decode::{decode_instrument_def_msg, decode_record}, + types::{DatabentoPublisher, PublisherId}, +}; #[cfg_attr( feature = "python", diff --git a/nautilus_core/indicators/src/momentum/aroon.rs b/nautilus_core/indicators/src/momentum/aroon.rs index 970f38442161..d267d2fc7801 100644 --- a/nautilus_core/indicators/src/momentum/aroon.rs +++ b/nautilus_core/indicators/src/momentum/aroon.rs @@ -13,7 +13,10 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use std::fmt::{Debug, Display}; +use std::{ + collections::VecDeque, + fmt::{Debug, Display}, +}; use anyhow::Result; use nautilus_model::{ @@ -21,7 +24,6 @@ use nautilus_model::{ enums::PriceType, }; use pyo3::prelude::*; -use std::collections::VecDeque; use crate::indicator::Indicator; diff --git a/nautilus_core/model/src/data/bar.rs b/nautilus_core/model/src/data/bar.rs index 7ad0d75b0f88..c1f4d0ef890e 100644 --- a/nautilus_core/model/src/data/bar.rs +++ b/nautilus_core/model/src/data/bar.rs @@ -24,7 +24,6 @@ use indexmap::IndexMap; use nautilus_core::{serialization::Serializable, time::UnixNanos}; use pyo3::prelude::*; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use thiserror; use crate::{ enums::{AggregationSource, BarAggregation, PriceType}, diff --git a/nautilus_core/model/src/data/mod.rs b/nautilus_core/model/src/data/mod.rs index 3d086f10a088..051a88d855e6 100644 --- a/nautilus_core/model/src/data/mod.rs +++ b/nautilus_core/model/src/data/mod.rs @@ -23,12 +23,11 @@ pub mod trade; use nautilus_core::time::UnixNanos; -use crate::ffi::data::deltas::OrderBookDeltas_API; - use self::{ bar::Bar, delta::OrderBookDelta, deltas::OrderBookDeltas, depth::OrderBookDepth10, quote::QuoteTick, trade::TradeTick, }; +use crate::ffi::data::deltas::OrderBookDeltas_API; #[repr(C)] #[derive(Clone, Debug)] diff --git a/nautilus_core/model/src/events/account/stubs.rs b/nautilus_core/model/src/events/account/stubs.rs index dcf0eeb1b8ed..f9db3758deb7 100644 --- a/nautilus_core/model/src/events/account/stubs.rs +++ b/nautilus_core/model/src/events/account/stubs.rs @@ -15,14 +15,14 @@ use rstest::fixture; -use crate::types::balance::AccountBalance; -use crate::types::money::Money; use crate::{ enums::AccountType, events::account::state::AccountState, identifiers::stubs::{account_id, uuid4}, types::{ + balance::AccountBalance, currency::Currency, + money::Money, stubs::{account_balance_test, margin_balance_test}, }, }; diff --git a/nautilus_core/model/src/orders/market.rs b/nautilus_core/model/src/orders/market.rs index ad8edf766862..b3ef513850e0 100644 --- a/nautilus_core/model/src/orders/market.rs +++ b/nautilus_core/model/src/orders/market.rs @@ -367,10 +367,12 @@ impl From for MarketOrder { mod tests { use rstest::rstest; - use crate::enums::OrderSide; - use crate::instruments::currency_pair::CurrencyPair; - use crate::instruments::stubs::*; - use crate::{enums::TimeInForce, orders::stubs::*, types::quantity::Quantity}; + use crate::{ + enums::{OrderSide, TimeInForce}, + instruments::{currency_pair::CurrencyPair, stubs::*}, + orders::stubs::*, + types::quantity::Quantity, + }; #[rstest] #[should_panic(expected = "Condition failed: invalid `Quantity`, should be positive and was 0")] diff --git a/nautilus_core/model/src/orders/stubs.rs b/nautilus_core/model/src/orders/stubs.rs index d3d326318391..381acb3eabd9 100644 --- a/nautilus_core/model/src/orders/stubs.rs +++ b/nautilus_core/model/src/orders/stubs.rs @@ -17,13 +17,13 @@ use std::str::FromStr; use nautilus_core::uuid::UUID4; -use crate::identifiers::client_order_id::ClientOrderId; -use crate::identifiers::instrument_id::InstrumentId; use crate::{ enums::{LiquiditySide, OrderSide, TimeInForce}, events::order::filled::OrderFilled, identifiers::{ account_id::AccountId, + client_order_id::ClientOrderId, + instrument_id::InstrumentId, position_id::PositionId, strategy_id::StrategyId, stubs::{strategy_id_ema_cross, trader_id}, diff --git a/nautilus_core/model/src/position.rs b/nautilus_core/model/src/position.rs index cdd6c2ca17dc..64ae7c469fbf 100644 --- a/nautilus_core/model/src/position.rs +++ b/nautilus_core/model/src/position.rs @@ -13,32 +13,28 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use std::collections::{HashMap, HashSet}; -use std::fmt::Display; -use std::hash::{Hash, Hasher}; +use std::{ + collections::{HashMap, HashSet}, + fmt::Display, + hash::{Hash, Hasher}, +}; use anyhow::Result; use nautilus_core::time::UnixNanos; use pyo3::prelude::*; use serde::{Deserialize, Serialize}; -use crate::enums::{OrderSide, PositionSide}; -use crate::events::order::filled::OrderFilled; -use crate::identifiers::account_id::AccountId; -use crate::identifiers::client_order_id::ClientOrderId; -use crate::identifiers::instrument_id::InstrumentId; -use crate::identifiers::position_id::PositionId; -use crate::identifiers::strategy_id::StrategyId; -use crate::identifiers::symbol::Symbol; -use crate::identifiers::trade_id::TradeId; -use crate::identifiers::trader_id::TraderId; -use crate::identifiers::venue::Venue; -use crate::identifiers::venue_order_id::VenueOrderId; -use crate::instruments::Instrument; -use crate::types::currency::Currency; -use crate::types::money::Money; -use crate::types::price::Price; -use crate::types::quantity::Quantity; +use crate::{ + enums::{OrderSide, PositionSide}, + events::order::filled::OrderFilled, + identifiers::{ + account_id::AccountId, client_order_id::ClientOrderId, instrument_id::InstrumentId, + position_id::PositionId, strategy_id::StrategyId, symbol::Symbol, trade_id::TradeId, + trader_id::TraderId, venue::Venue, venue_order_id::VenueOrderId, + }, + instruments::Instrument, + types::{currency::Currency, money::Money, price::Price, quantity::Quantity}, +}; /// Represents a position in a financial market. /// @@ -525,27 +521,27 @@ impl Display for Position { //////////////////////////////////////////////////////////////////////////////// #[cfg(test)] mod tests { - use crate::enums::{LiquiditySide, OrderSide, OrderType, PositionSide}; - use crate::events::order::filled::OrderFilled; - use crate::identifiers::account_id::AccountId; - use crate::identifiers::position_id::PositionId; - use crate::identifiers::strategy_id::StrategyId; - use crate::identifiers::stubs::uuid4; - use crate::identifiers::trade_id::TradeId; - use crate::identifiers::venue_order_id::VenueOrderId; - use crate::instruments::crypto_perpetual::CryptoPerpetual; - use crate::instruments::currency_pair::CurrencyPair; - use crate::instruments::stubs::*; - use crate::orders::market::MarketOrder; - use crate::orders::stubs::{TestOrderEventStubs, TestOrderStubs}; - use crate::position::Position; - use crate::stubs::*; - use crate::types::money::Money; - use crate::types::price::Price; - use crate::types::quantity::Quantity; - use rstest::rstest; use std::str::FromStr; + use rstest::rstest; + + use crate::{ + enums::{LiquiditySide, OrderSide, OrderType, PositionSide}, + events::order::filled::OrderFilled, + identifiers::{ + account_id::AccountId, position_id::PositionId, strategy_id::StrategyId, stubs::uuid4, + trade_id::TradeId, venue_order_id::VenueOrderId, + }, + instruments::{crypto_perpetual::CryptoPerpetual, currency_pair::CurrencyPair, stubs::*}, + orders::{ + market::MarketOrder, + stubs::{TestOrderEventStubs, TestOrderStubs}, + }, + position::Position, + stubs::*, + types::{money::Money, price::Price, quantity::Quantity}, + }; + #[rstest] fn test_position_long_display(test_position_long: Position) { let display = format!("{test_position_long}"); diff --git a/nautilus_core/model/src/python/data/bar.rs b/nautilus_core/model/src/python/data/bar.rs index f1d7330ef032..c76eaa86a3b1 100644 --- a/nautilus_core/model/src/python/data/bar.rs +++ b/nautilus_core/model/src/python/data/bar.rs @@ -26,6 +26,7 @@ use nautilus_core::{ }; use pyo3::{prelude::*, pyclass::CompareOp, types::PyDict}; +use super::data_to_pycapsule; use crate::{ data::{ bar::{Bar, BarSpecification, BarType}, @@ -37,8 +38,6 @@ use crate::{ types::{price::Price, quantity::Quantity}, }; -use super::data_to_pycapsule; - #[pymethods] impl BarSpecification { #[new] diff --git a/nautilus_core/model/src/python/data/delta.rs b/nautilus_core/model/src/python/data/delta.rs index f1a4e87908ab..6f3e42133ff4 100644 --- a/nautilus_core/model/src/python/data/delta.rs +++ b/nautilus_core/model/src/python/data/delta.rs @@ -25,6 +25,7 @@ use nautilus_core::{ }; use pyo3::{prelude::*, pyclass::CompareOp, types::PyDict}; +use super::data_to_pycapsule; use crate::{ data::{delta::OrderBookDelta, order::BookOrder, Data}, enums::BookAction, @@ -32,8 +33,6 @@ use crate::{ python::common::PY_MODULE_MODEL, }; -use super::data_to_pycapsule; - #[pymethods] impl OrderBookDelta { #[new] diff --git a/nautilus_core/model/src/python/data/depth.rs b/nautilus_core/model/src/python/data/depth.rs index 8d22e5ed2a12..c5d75e050df3 100644 --- a/nautilus_core/model/src/python/data/depth.rs +++ b/nautilus_core/model/src/python/data/depth.rs @@ -25,6 +25,7 @@ use nautilus_core::{ }; use pyo3::{prelude::*, pyclass::CompareOp, types::PyDict}; +use super::data_to_pycapsule; use crate::{ data::{ depth::{OrderBookDepth10, DEPTH10_LEN}, @@ -37,8 +38,6 @@ use crate::{ types::{price::Price, quantity::Quantity}, }; -use super::data_to_pycapsule; - #[pymethods] impl OrderBookDepth10 { #[allow(clippy::too_many_arguments)] diff --git a/nautilus_core/model/src/python/data/quote.rs b/nautilus_core/model/src/python/data/quote.rs index 2d15b2c8fb19..a3dd4e1f4079 100644 --- a/nautilus_core/model/src/python/data/quote.rs +++ b/nautilus_core/model/src/python/data/quote.rs @@ -30,6 +30,7 @@ use pyo3::{ types::{PyDict, PyLong, PyString, PyTuple}, }; +use super::data_to_pycapsule; use crate::{ data::{quote::QuoteTick, Data}, enums::PriceType, @@ -38,8 +39,6 @@ use crate::{ types::{price::Price, quantity::Quantity}, }; -use super::data_to_pycapsule; - #[pymethods] impl QuoteTick { #[new] diff --git a/nautilus_core/model/src/python/data/trade.rs b/nautilus_core/model/src/python/data/trade.rs index 55c7ec87e10a..b9c4c32f4325 100644 --- a/nautilus_core/model/src/python/data/trade.rs +++ b/nautilus_core/model/src/python/data/trade.rs @@ -30,6 +30,7 @@ use pyo3::{ types::{PyDict, PyLong, PyString, PyTuple}, }; +use super::data_to_pycapsule; use crate::{ data::{trade::TradeTick, Data}, enums::{AggressorSide, FromU8}, @@ -38,8 +39,6 @@ use crate::{ types::{price::Price, quantity::Quantity}, }; -use super::data_to_pycapsule; - #[pymethods] impl TradeTick { #[new] diff --git a/nautilus_core/model/src/python/orders/market.rs b/nautilus_core/model/src/python/orders/market.rs index 92869f3aec5f..a78341ad13d3 100644 --- a/nautilus_core/model/src/python/orders/market.rs +++ b/nautilus_core/model/src/python/orders/market.rs @@ -20,12 +20,10 @@ use pyo3::prelude::*; use rust_decimal::Decimal; use ustr::Ustr; -use crate::enums::OrderType; -use crate::identifiers::account_id::AccountId; use crate::{ - enums::{ContingencyType, OrderSide, PositionSide, TimeInForce}, + enums::{ContingencyType, OrderSide, OrderType, PositionSide, TimeInForce}, identifiers::{ - client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, + account_id::AccountId, client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, trader_id::TraderId, }, diff --git a/nautilus_core/model/src/python/position.rs b/nautilus_core/model/src/python/position.rs index 230a0f4bb23e..001f3232863f 100644 --- a/nautilus_core/model/src/python/position.rs +++ b/nautilus_core/model/src/python/position.rs @@ -13,36 +13,33 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use nautilus_core::python::serialization::from_dict_pyo3; -use nautilus_core::python::to_pyvalue_err; -use nautilus_core::time::UnixNanos; -use pyo3::basic::CompareOp; -use pyo3::prelude::*; -use pyo3::types::{PyDict, PyList}; +use nautilus_core::{ + python::{serialization::from_dict_pyo3, to_pyvalue_err}, + time::UnixNanos, +}; +use pyo3::{ + basic::CompareOp, + prelude::*, + types::{PyDict, PyList}, +}; use rust_decimal::prelude::ToPrimitive; -use crate::enums::{OrderSide, PositionSide}; -use crate::events::order::filled::OrderFilled; -use crate::identifiers::client_order_id::ClientOrderId; -use crate::identifiers::instrument_id::InstrumentId; -use crate::identifiers::position_id::PositionId; -use crate::identifiers::strategy_id::StrategyId; -use crate::identifiers::symbol::Symbol; -use crate::identifiers::trade_id::TradeId; -use crate::identifiers::trader_id::TraderId; -use crate::identifiers::venue::Venue; -use crate::identifiers::venue_order_id::VenueOrderId; -use crate::instruments::crypto_future::CryptoFuture; -use crate::instruments::crypto_perpetual::CryptoPerpetual; -use crate::instruments::currency_pair::CurrencyPair; -use crate::instruments::equity::Equity; -use crate::instruments::futures_contract::FuturesContract; -use crate::instruments::options_contract::OptionsContract; -use crate::position::Position; -use crate::types::currency::Currency; -use crate::types::money::Money; -use crate::types::price::Price; -use crate::types::quantity::Quantity; +use crate::{ + enums::{OrderSide, PositionSide}, + events::order::filled::OrderFilled, + identifiers::{ + client_order_id::ClientOrderId, instrument_id::InstrumentId, position_id::PositionId, + strategy_id::StrategyId, symbol::Symbol, trade_id::TradeId, trader_id::TraderId, + venue::Venue, venue_order_id::VenueOrderId, + }, + instruments::{ + crypto_future::CryptoFuture, crypto_perpetual::CryptoPerpetual, + currency_pair::CurrencyPair, equity::Equity, futures_contract::FuturesContract, + options_contract::OptionsContract, + }, + position::Position, + types::{currency::Currency, money::Money, price::Price, quantity::Quantity}, +}; #[pymethods] impl Position { diff --git a/nautilus_core/model/src/stubs.rs b/nautilus_core/model/src/stubs.rs index 4c229d59d997..b71abb032446 100644 --- a/nautilus_core/model/src/stubs.rs +++ b/nautilus_core/model/src/stubs.rs @@ -13,23 +13,24 @@ // limitations under the License. // ------------------------------------------------------------------------------------------------- -use crate::data::order::BookOrder; -use crate::enums::{LiquiditySide, OrderSide}; -use crate::identifiers::instrument_id::InstrumentId; -use crate::instruments::currency_pair::CurrencyPair; -use crate::instruments::stubs::audusd_sim; -use crate::instruments::Instrument; -use crate::orderbook::book_mbp::OrderBookMbp; -use crate::orders::market::MarketOrder; -use crate::orders::stubs::{TestOrderEventStubs, TestOrderStubs}; -use crate::position::Position; -use crate::types::money::Money; -use crate::types::price::Price; -use crate::types::quantity::Quantity; use anyhow::Result; use rstest::fixture; use rust_decimal::prelude::ToPrimitive; +use crate::{ + data::order::BookOrder, + enums::{LiquiditySide, OrderSide}, + identifiers::instrument_id::InstrumentId, + instruments::{currency_pair::CurrencyPair, stubs::audusd_sim, Instrument}, + orderbook::book_mbp::OrderBookMbp, + orders::{ + market::MarketOrder, + stubs::{TestOrderEventStubs, TestOrderStubs}, + }, + position::Position, + types::{money::Money, price::Price, quantity::Quantity}, +}; + /// Calculate commission for testing pub fn calculate_commission( instrument: T,