nautilus_model/ffi/data/
deltas.rsuse nautilus_core::{ffi::cvec::CVec, nanos::UnixNanos};
use crate::{
data::{
delta::OrderBookDelta,
deltas::{OrderBookDeltas, OrderBookDeltas_API},
},
enums::BookAction,
identifiers::InstrumentId,
};
#[no_mangle]
pub extern "C" fn orderbook_deltas_new(
instrument_id: InstrumentId,
deltas: &CVec,
) -> OrderBookDeltas_API {
let CVec { ptr, len, cap } = *deltas;
let deltas: Vec<OrderBookDelta> =
unsafe { Vec::from_raw_parts(ptr.cast::<OrderBookDelta>(), len, cap) };
let cloned_deltas = deltas.clone();
std::mem::forget(deltas); OrderBookDeltas_API::new(OrderBookDeltas::new(instrument_id, cloned_deltas))
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_drop(deltas: OrderBookDeltas_API) {
drop(deltas); }
#[no_mangle]
pub extern "C" fn orderbook_deltas_clone(deltas: &OrderBookDeltas_API) -> OrderBookDeltas_API {
deltas.clone()
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_instrument_id(deltas: &OrderBookDeltas_API) -> InstrumentId {
deltas.instrument_id
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_vec_deltas(deltas: &OrderBookDeltas_API) -> CVec {
deltas.deltas.clone().into()
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_is_snapshot(deltas: &OrderBookDeltas_API) -> u8 {
u8::from(deltas.deltas[0].action == BookAction::Clear)
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_flags(deltas: &OrderBookDeltas_API) -> u8 {
deltas.flags
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_sequence(deltas: &OrderBookDeltas_API) -> u64 {
deltas.sequence
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_ts_event(deltas: &OrderBookDeltas_API) -> UnixNanos {
deltas.ts_event
}
#[no_mangle]
pub extern "C" fn orderbook_deltas_ts_init(deltas: &OrderBookDeltas_API) -> UnixNanos {
deltas.ts_init
}
#[allow(clippy::drop_non_drop)]
#[no_mangle]
pub extern "C" fn orderbook_deltas_vec_drop(v: CVec) {
let CVec { ptr, len, cap } = v;
let deltas: Vec<OrderBookDelta> =
unsafe { Vec::from_raw_parts(ptr.cast::<OrderBookDelta>(), len, cap) };
drop(deltas); }