Skip to content

Commit

Permalink
Add Rust docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 23, 2024
1 parent 509392b commit e0fc34b
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions nautilus_core/core/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub fn floor_to_nearest_microsecond(unix_nanos: u64) -> u64 {
(unix_nanos / NANOSECONDS_IN_MICROSECOND) * NANOSECONDS_IN_MICROSECOND
}

/// Calculates the last weekday (Mon-Fri) from the given `year`, `month` and `day`.
pub fn last_weekday_nanos(year: i32, month: u32, day: u32) -> anyhow::Result<UnixNanos> {
let date =
NaiveDate::from_ymd_opt(year, month, day).ok_or_else(|| anyhow::anyhow!("Invalid date"))?;
Expand Down Expand Up @@ -128,6 +129,7 @@ pub fn last_weekday_nanos(year: i32, month: u32, day: u32) -> anyhow::Result<Uni
))
}

/// Check whether the given UNIX nanoseconds timestamp is within the last 24 hours.
pub fn is_within_last_24_hours(timestamp_ns: UnixNanos) -> anyhow::Result<bool> {
let timestamp_ns = timestamp_ns.as_u64();
let seconds = timestamp_ns / NANOSECONDS_IN_SECOND;
Expand Down
2 changes: 1 addition & 1 deletion nautilus_core/core/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn precision_from_str(s: &str) -> u8 {
return lower_s.split('.').last().unwrap().len() as u8;
}

/// Returns a usize from the given bytes.
/// Returns a `usize` from the given bytes.
pub fn bytes_to_usize(bytes: &[u8]) -> anyhow::Result<usize> {
// Check bytes width
if bytes.len() >= std::mem::size_of::<usize>() {
Expand Down
1 change: 1 addition & 0 deletions nautilus_core/model/src/currencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ impl Currency {
}
}

/// Provides a map of built-in `Currency` constants.
pub static CURRENCY_MAP: Lazy<Mutex<HashMap<String, Currency>>> = Lazy::new(|| {
let mut map = HashMap::new();
///////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions nautilus_core/model/src/data/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

//! Bar aggregate structures, data types and functionality.
use std::{
collections::HashMap,
fmt::{Debug, Display, Formatter},
Expand Down
2 changes: 2 additions & 0 deletions nautilus_core/model/src/data/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

//! An `OrderBookDelta` data type intended to carry book state information.
use std::{
collections::HashMap,
fmt::{Display, Formatter},
Expand Down
2 changes: 2 additions & 0 deletions nautilus_core/model/src/data/deltas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

//! An `OrderBookDeltas` container type to carry a bulk of `OrderBookDelta` records.
use std::{
fmt::{Display, Formatter},
hash::{Hash, Hasher},
Expand Down
6 changes: 4 additions & 2 deletions nautilus_core/model/src/data/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

//! An `OrderBookDepth10` aggregated top-of-book data type with a fixed depth of 10 levels per side.
use std::{
collections::HashMap,
fmt::{Display, Formatter},
Expand All @@ -27,9 +29,9 @@ use crate::identifiers::instrument_id::InstrumentId;

pub const DEPTH10_LEN: usize = 10;

/// Represents a self-contained order book update with a fixed depth of 10 levels per side.
/// Represents a aggregated order book update with a fixed depth of 10 levels per side.
///
/// This struct is specifically designed for scenarios where a snapshot of the top 10 bid and
/// This structure is specifically designed for scenarios where a snapshot of the top 10 bid and
/// ask levels in an order book is needed. It differs from `OrderBookDelta` or `OrderBookDeltas`
/// in its fixed-depth nature and is optimized for cases where a full depth representation is not
/// required or practical.
Expand Down
2 changes: 2 additions & 0 deletions nautilus_core/model/src/data/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

//! A `BookOrder` for use with the `OrderBookDelta` data type.
use std::{
fmt::{Display, Formatter},
hash::{Hash, Hasher},
Expand Down
2 changes: 2 additions & 0 deletions nautilus_core/model/src/data/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

//! A `QuoteTick` data type representing a top-of-book quote state.
use std::{
cmp,
collections::HashMap,
Expand Down
2 changes: 2 additions & 0 deletions nautilus_core/model/src/data/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

//! A `TradeTick` data type representing a single trade in a market.
use std::{
collections::HashMap,
fmt::{Display, Formatter},
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/core/includes/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,9 @@ typedef struct OrderBookDeltas_API {
} OrderBookDeltas_API;

/**
* Represents a self-contained order book update with a fixed depth of 10 levels per side.
* Represents a aggregated order book update with a fixed depth of 10 levels per side.
*
* This struct is specifically designed for scenarios where a snapshot of the top 10 bid and
* This structure is specifically designed for scenarios where a snapshot of the top 10 bid and
* ask levels in an order book is needed. It differs from `OrderBookDelta` or `OrderBookDeltas`
* in its fixed-depth nature and is optimized for cases where a full depth representation is not
* required or practical.
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/core/rust/model.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ cdef extern from "../includes/model.h":
cdef struct OrderBookDeltas_API:
OrderBookDeltas_t *_0;

# Represents a self-contained order book update with a fixed depth of 10 levels per side.
# Represents a aggregated order book update with a fixed depth of 10 levels per side.
#
# This struct is specifically designed for scenarios where a snapshot of the top 10 bid and
# This structure is specifically designed for scenarios where a snapshot of the top 10 bid and
# ask levels in an order book is needed. It differs from `OrderBookDelta` or `OrderBookDeltas`
# in its fixed-depth nature and is optimized for cases where a full depth representation is not
# required or practical.
Expand Down

0 comments on commit e0fc34b

Please sign in to comment.