Skip to content

Commit

Permalink
Refine core instruments
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Dec 29, 2023
1 parent 7633268 commit d56080e
Show file tree
Hide file tree
Showing 28 changed files with 338 additions and 136 deletions.
12 changes: 7 additions & 5 deletions nautilus_core/adapters/src/databento/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn parse_raw_symbol_to_string(raw_symbol: [c_char; SYMBOL_CSTR_LEN]) -> Resu
pub fn parse_equity(
record: InstrumentDefMsg,
instrument_id: InstrumentId,
_ts_init: UnixNanos,
ts_init: UnixNanos,
) -> Result<Equity> {
// Use USD for all US equities venues for now
let currency = Currency::USD();
Expand All @@ -131,9 +131,11 @@ pub fn parse_equity(
dec!(0), // TBD
dec!(0), // TBD
Some(Quantity::new(record.min_lot_size_round_lot.into(), 0)?),
None, // TBD
None, // TBD
None, // TBD
None, // TBD
None, // TBD
None, // TBD
None, // TBD
None, // TBD
record.ts_recv, // More accurate and reliable timestamp
ts_init,
)
}
16 changes: 16 additions & 0 deletions nautilus_core/model/src/ffi/instruments/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------

pub mod synthetic;
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use nautilus_core::{
time::UnixNanos,
};

use super::synthetic::SyntheticInstrument;
use crate::{
identifiers::{instrument_id::InstrumentId, symbol::Symbol},
instruments::synthetic::SyntheticInstrument,
types::price::{Price, ERROR_PRICE},
};

Expand Down
1 change: 1 addition & 0 deletions nautilus_core/model/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ pub mod data;
pub mod enums;
pub mod events;
pub mod identifiers;
pub mod instruments;
pub mod orderbook;
pub mod types;
14 changes: 14 additions & 0 deletions nautilus_core/model/src/instruments/crypto_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub struct CryptoFuture {
pub min_notional: Option<Money>,
pub max_price: Option<Price>,
pub min_price: Option<Price>,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}

impl CryptoFuture {
Expand Down Expand Up @@ -86,6 +88,8 @@ impl CryptoFuture {
min_notional: Option<Money>,
max_price: Option<Price>,
min_price: Option<Price>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<Self> {
Ok(Self {
id,
Expand All @@ -110,6 +114,8 @@ impl CryptoFuture {
min_notional,
max_price,
min_price,
ts_event,
ts_init,
})
}
}
Expand Down Expand Up @@ -217,6 +223,14 @@ impl Instrument for CryptoFuture {
fn taker_fee(&self) -> Decimal {
self.taker_fee
}

fn ts_event(&self) -> UnixNanos {
self.ts_event
}

fn ts_init(&self) -> UnixNanos {
self.ts_init
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 15 additions & 0 deletions nautilus_core/model/src/instruments/crypto_perpetual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use std::hash::{Hash, Hasher};

use anyhow::Result;
use nautilus_core::time::UnixNanos;
use pyo3::prelude::*;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -57,6 +58,8 @@ pub struct CryptoPerpetual {
pub min_notional: Option<Money>,
pub max_price: Option<Price>,
pub min_price: Option<Price>,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}

impl CryptoPerpetual {
Expand All @@ -83,6 +86,8 @@ impl CryptoPerpetual {
min_notional: Option<Money>,
max_price: Option<Price>,
min_price: Option<Price>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<Self> {
Ok(Self {
id,
Expand All @@ -106,6 +111,8 @@ impl CryptoPerpetual {
min_notional,
max_price,
min_price,
ts_event,
ts_init,
})
}
}
Expand Down Expand Up @@ -212,6 +219,14 @@ impl Instrument for CryptoPerpetual {
fn taker_fee(&self) -> Decimal {
self.taker_fee
}

fn ts_event(&self) -> UnixNanos {
self.ts_event
}

fn ts_init(&self) -> UnixNanos {
self.ts_init
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 15 additions & 0 deletions nautilus_core/model/src/instruments/currency_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use std::hash::{Hash, Hasher};

use anyhow::Result;
use nautilus_core::time::UnixNanos;
use pyo3::prelude::*;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -53,6 +54,8 @@ pub struct CurrencyPair {
pub min_quantity: Option<Quantity>,
pub max_price: Option<Price>,
pub min_price: Option<Price>,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}

impl CurrencyPair {
Expand All @@ -75,6 +78,8 @@ impl CurrencyPair {
min_quantity: Option<Quantity>,
max_price: Option<Price>,
min_price: Option<Price>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<Self> {
Ok(Self {
id,
Expand All @@ -94,6 +99,8 @@ impl CurrencyPair {
min_quantity,
max_price,
min_price,
ts_event,
ts_init,
})
}
}
Expand Down Expand Up @@ -201,6 +208,14 @@ impl Instrument for CurrencyPair {
fn taker_fee(&self) -> Decimal {
self.taker_fee
}

fn ts_event(&self) -> UnixNanos {
self.ts_event
}

fn ts_init(&self) -> UnixNanos {
self.ts_init
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 15 additions & 0 deletions nautilus_core/model/src/instruments/equity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use std::hash::{Hash, Hasher};

use anyhow::Result;
use nautilus_core::time::UnixNanos;
use pyo3::prelude::*;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -53,6 +54,8 @@ pub struct Equity {
pub min_quantity: Option<Quantity>,
pub max_price: Option<Price>,
pub min_price: Option<Price>,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}

impl Equity {
Expand All @@ -74,6 +77,8 @@ impl Equity {
min_quantity: Option<Quantity>,
max_price: Option<Price>,
min_price: Option<Price>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<Self> {
Ok(Self {
id,
Expand All @@ -92,6 +97,8 @@ impl Equity {
min_quantity,
max_price,
min_price,
ts_event,
ts_init,
})
}
}
Expand Down Expand Up @@ -198,6 +205,14 @@ impl Instrument for Equity {
fn taker_fee(&self) -> Decimal {
self.taker_fee
}

fn ts_event(&self) -> UnixNanos {
self.ts_event
}

fn ts_init(&self) -> UnixNanos {
self.ts_init
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 14 additions & 0 deletions nautilus_core/model/src/instruments/futures_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub struct FuturesContract {
pub min_quantity: Option<Quantity>,
pub max_price: Option<Price>,
pub min_price: Option<Price>,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}

impl FuturesContract {
Expand All @@ -80,6 +82,8 @@ impl FuturesContract {
min_quantity: Option<Quantity>,
max_price: Option<Price>,
min_price: Option<Price>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<Self> {
Ok(Self {
id,
Expand All @@ -101,6 +105,8 @@ impl FuturesContract {
min_quantity,
max_price,
min_price,
ts_event,
ts_init,
})
}
}
Expand Down Expand Up @@ -207,6 +213,14 @@ impl Instrument for FuturesContract {
fn taker_fee(&self) -> Decimal {
self.taker_fee
}

fn ts_event(&self) -> UnixNanos {
self.ts_event
}

fn ts_init(&self) -> UnixNanos {
self.ts_init
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion nautilus_core/model/src/instruments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ pub mod equity;
pub mod futures_contract;
pub mod options_contract;
pub mod synthetic;
pub mod synthetic_api;

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

use anyhow::Result;
use nautilus_core::time::UnixNanos;
use rust_decimal::Decimal;

use crate::{
Expand Down Expand Up @@ -63,6 +63,8 @@ pub trait Instrument {
fn margin_maint(&self) -> Decimal;
fn maker_fee(&self) -> Decimal;
fn taker_fee(&self) -> Decimal;
fn ts_event(&self) -> UnixNanos;
fn ts_init(&self) -> UnixNanos;

/// Creates a new price from the given `value` with the correct price precision for the instrument.
fn make_price(&self, value: f64) -> Result<Price> {
Expand Down
14 changes: 14 additions & 0 deletions nautilus_core/model/src/instruments/options_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct OptionsContract {
pub min_quantity: Option<Quantity>,
pub max_price: Option<Price>,
pub min_price: Option<Price>,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}

impl OptionsContract {
Expand All @@ -82,6 +84,8 @@ impl OptionsContract {
min_quantity: Option<Quantity>,
max_price: Option<Price>,
min_price: Option<Price>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<Self> {
Ok(Self {
id,
Expand All @@ -104,6 +108,8 @@ impl OptionsContract {
margin_maint,
maker_fee,
taker_fee,
ts_event,
ts_init,
})
}
}
Expand Down Expand Up @@ -210,6 +216,14 @@ impl Instrument for OptionsContract {
fn taker_fee(&self) -> Decimal {
self.taker_fee
}

fn ts_event(&self) -> UnixNanos {
self.ts_event
}

fn ts_init(&self) -> UnixNanos {
self.ts_init
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit d56080e

Please sign in to comment.