Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing tests and betfair #1517

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ docs-python: install-just-deps-all

.PHONY: docs-rust
docs-rust:
(cd nautilus_core && RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo +nightly doc --no-deps)
(cd nautilus_core && RUSTDOCFLAGS="--enable-index-page -Zunstable-options --deny warnings" cargo +nightly doc --no-deps)

.PHONY: clippy
clippy:
(cd nautilus_core && cargo clippy --fix --all-targets --all-features -- -D warnings -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used -W clippy::expect_used)

.PHONY: clippy-nightly
clippy-nightly:
(cd nautilus_core && cargo +nightly clippy --fix --all-targets --all-features --allow-dirty --allow-staged -- -D warnings -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used -W clippy::expect_used)

.PHONY: cargo-build
cargo-build:
(cd nautilus_core && cargo build --release --all-features)
Expand Down
16 changes: 16 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# NautilusTrader 1.189.0 Beta

Released on TBD (UTC).

### Enhancements
- Added additional validations for `OrderMatchingEngine` (will now raise a `RuntimeError` when a price or size precision for a fill does not match the instruments precisions)

### Breaking Changes
None

### Fixes
- Fixed `OrderBookDelta.to_pyo3_list` using zero precision from clear delta
- Fixed `DataTransformer.pyo3_order_book_deltas_to_record_batch_bytes` using zero precision from clear delta

---

# NautilusTrader 1.188.0 Beta

Released on 25th February 2024 (UTC).
Expand Down
8 changes: 4 additions & 4 deletions nautilus_core/Cargo.lock

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

3 changes: 1 addition & 2 deletions nautilus_core/accounting/src/account/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ use nautilus_model::{
balance::AccountBalance, currency::Currency, money::Money, price::Price, quantity::Quantity,
},
};
use pyo3::prelude::*;
use rust_decimal::prelude::ToPrimitive;

#[derive(Debug)]
#[cfg_attr(
feature = "python",
pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
)]
pub struct BaseAccount {
#[pyo3(get)]
Expand Down
3 changes: 1 addition & 2 deletions nautilus_core/accounting/src/account/cash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ use nautilus_model::{
balance::AccountBalance, currency::Currency, money::Money, price::Price, quantity::Quantity,
},
};
use pyo3::prelude::*;

use crate::account::{base::BaseAccount, Account};

#[derive(Debug)]
#[cfg_attr(
feature = "python",
pyclass(module = "nautilus_trader.core.nautilus_pyo3.accounting")
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.accounting")
)]
pub struct CashAccount {
pub base: BaseAccount,
Expand Down
3 changes: 1 addition & 2 deletions nautilus_core/accounting/src/account/margin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ use nautilus_model::{
quantity::Quantity,
},
};
use pyo3::prelude::*;
use rust_decimal::prelude::ToPrimitive;

use crate::account::{base::BaseAccount, Account};

#[derive(Debug)]
#[cfg_attr(
feature = "python",
pyclass(module = "nautilus_trader.core.nautilus_pyo3.accounting")
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.accounting")
)]
pub struct MarginAccount {
pub base: BaseAccount,
Expand Down
11 changes: 4 additions & 7 deletions nautilus_core/adapters/src/databento/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use nautilus_model::{
instruments::Instrument,
types::currency::Currency,
};
use pyo3::prelude::*;
use streaming_iterator::StreamingIterator;
use ustr::Ustr;

Expand All @@ -55,16 +54,14 @@ use super::{
///
/// # Warnings
/// The following Databento instrument classes are not supported:
/// - ``FUTURE_SPREAD``
/// - ``OPTION_SPEAD``
/// - ``MIXED_SPREAD``
/// - ``BOND``
/// - ``FX_SPOT``
///
/// # References
/// https://docs.databento.com/knowledge-base/new-users/dbn-encoding
/// <https://docs.databento.com/knowledge-base/new-users/dbn-encoding>
#[cfg_attr(
feature = "python",
pyclass(module = "nautilus_trader.core.nautilus_pyo3.databento")
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.databento")
)]
pub struct DatabentoDataLoader {
publishers_map: IndexMap<PublisherId, DatabentoPublisher>,
Expand Down Expand Up @@ -310,7 +307,7 @@ impl DatabentoDataLoader {
let mut instrument_id = self
.get_nautilus_instrument_id_for_record(&rec_ref, &metadata, *venue)
.unwrap_or_else(|_| {
panic!("Error resolving symbology mapping for {:?}", rec_ref)
panic!("Error resolving symbology mapping for {rec_ref:?}")
});

if publisher == Publisher::GlbxMdp3Glbx {
Expand Down
2 changes: 1 addition & 1 deletion nautilus_core/adapters/src/databento/python/historical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::databento::{

#[cfg_attr(
feature = "python",
pyclass(module = "nautilus_trader.core.nautilus_pyo3.databento")
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.databento")
)]
pub struct DatabentoHistoricalClient {
#[pyo3(get)]
Expand Down
36 changes: 15 additions & 21 deletions nautilus_core/adapters/src/databento/python/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use std::{collections::HashMap, ffi::CStr, fs, str::FromStr, sync::Arc};

use anyhow::{anyhow, bail, Result};
use anyhow::Result;
use databento::{
dbn::{PitSymbolMap, Record, SymbolIndex, VersionUpgradePolicy},
live::Subscription,
Expand Down Expand Up @@ -48,7 +48,7 @@ use crate::databento::{

#[cfg_attr(
feature = "python",
pyclass(module = "nautilus_trader.core.nautilus_pyo3.databento")
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.databento")
)]
pub struct DatabentoLiveClient {
#[pyo3(get)]
Expand Down Expand Up @@ -234,8 +234,7 @@ impl DatabentoLiveClient {
&mut instrument_id_map,
clock,
&callback,
)
.map_err(to_pyvalue_err)?;
)?;
} else {
let (mut data1, data2) = handle_record(
record,
Expand All @@ -244,8 +243,7 @@ impl DatabentoLiveClient {
&glbx_exchange_map,
&mut instrument_id_map,
clock,
)
.map_err(to_pyvalue_err)?;
)?;

if let Some(msg) = record.get::<dbn::MboMsg>() {
// SAFETY: An MBO message will always produce a delta
Expand Down Expand Up @@ -371,9 +369,9 @@ fn handle_instrument_def_msg(
instrument_id_map: &mut HashMap<u32, InstrumentId>,
clock: &AtomicTime,
callback: &PyObject,
) -> Result<()> {
) -> PyResult<Py<PyAny>> {
let c_str: &CStr = unsafe { CStr::from_ptr(msg.raw_symbol.as_ptr()) };
let raw_symbol: &str = c_str.to_str().map_err(|e| anyhow!(e))?;
let raw_symbol: &str = c_str.to_str().map_err(to_pyvalue_err)?;

let instrument_id = update_instrument_id_map(
msg.header(),
Expand All @@ -384,18 +382,13 @@ fn handle_instrument_def_msg(
);

let ts_init = clock.get_time_ns();
let result = decode_instrument_def_msg(msg, instrument_id, ts_init);

match result {
Ok(instrument) => Python::with_gil(|py| {
let py_obj = convert_instrument_to_pyobject(py, instrument).unwrap();
match callback.call1(py, (py_obj,)) {
Ok(_) => Ok(()),
Err(e) => bail!(e),
}
}),
Err(e) => Err(e),
}
let instrument =
decode_instrument_def_msg(msg, instrument_id, ts_init).map_err(to_pyvalue_err)?;

Python::with_gil(|py| {
let py_obj = convert_instrument_to_pyobject(py, instrument)?;
callback.call1(py, (py_obj,))
})
}

fn handle_record(
Expand All @@ -405,7 +398,7 @@ fn handle_record(
glbx_exchange_map: &HashMap<Symbol, Venue>,
instrument_id_map: &mut HashMap<u32, InstrumentId>,
clock: &AtomicTime,
) -> Result<(Option<Data>, Option<Data>)> {
) -> PyResult<(Option<Data>, Option<Data>)> {
let raw_symbol = symbol_map
.get_for_rec(&rec_ref)
.expect("Cannot resolve `raw_symbol` from `symbol_map`");
Expand All @@ -428,6 +421,7 @@ fn handle_record(
Some(ts_init),
true, // Always include trades
)
.map_err(to_pyvalue_err)
}

fn call_python_with_data(py: Python, callback: &PyObject, data: Data) {
Expand Down
Loading
Loading