nautilus_model/ffi/data/
depth.rsuse std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
use nautilus_core::nanos::UnixNanos;
use crate::{
data::{
depth::{OrderBookDepth10, DEPTH10_LEN},
order::BookOrder,
},
identifiers::InstrumentId,
};
#[no_mangle]
pub unsafe extern "C" fn orderbook_depth10_new(
instrument_id: InstrumentId,
bids_ptr: *const BookOrder,
asks_ptr: *const BookOrder,
bid_counts_ptr: *const u32,
ask_counts_ptr: *const u32,
flags: u8,
sequence: u64,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> OrderBookDepth10 {
assert!(!bids_ptr.is_null());
assert!(!asks_ptr.is_null());
assert!(!bid_counts_ptr.is_null());
assert!(!ask_counts_ptr.is_null());
let bids_slice = std::slice::from_raw_parts(bids_ptr, DEPTH10_LEN);
let asks_slice = std::slice::from_raw_parts(asks_ptr, DEPTH10_LEN);
let bids: [BookOrder; DEPTH10_LEN] = bids_slice.try_into().expect("Slice length != 10");
let asks: [BookOrder; DEPTH10_LEN] = asks_slice.try_into().expect("Slice length != 10");
let bid_counts_slice = std::slice::from_raw_parts(bid_counts_ptr, DEPTH10_LEN);
let ask_counts_slice = std::slice::from_raw_parts(ask_counts_ptr, DEPTH10_LEN);
let bid_counts: [u32; DEPTH10_LEN] = bid_counts_slice.try_into().expect("Slice length != 10");
let ask_counts: [u32; DEPTH10_LEN] = ask_counts_slice.try_into().expect("Slice length != 10");
OrderBookDepth10::new(
instrument_id,
bids,
asks,
bid_counts,
ask_counts,
flags,
sequence,
ts_event,
ts_init,
)
}
#[no_mangle]
pub extern "C" fn orderbook_depth10_eq(lhs: &OrderBookDepth10, rhs: &OrderBookDepth10) -> u8 {
u8::from(lhs == rhs)
}
#[no_mangle]
pub extern "C" fn orderbook_depth10_hash(delta: &OrderBookDepth10) -> u64 {
let mut hasher = DefaultHasher::new();
delta.hash(&mut hasher);
hasher.finish()
}
#[no_mangle]
pub extern "C" fn orderbook_depth10_bids_array(depth: &OrderBookDepth10) -> *const BookOrder {
depth.bids.as_ptr()
}
#[no_mangle]
pub extern "C" fn orderbook_depth10_asks_array(depth: &OrderBookDepth10) -> *const BookOrder {
depth.asks.as_ptr()
}
#[no_mangle]
pub extern "C" fn orderbook_depth10_bid_counts_array(depth: &OrderBookDepth10) -> *const u32 {
depth.bid_counts.as_ptr()
}
#[no_mangle]
pub extern "C" fn orderbook_depth10_ask_counts_array(depth: &OrderBookDepth10) -> *const u32 {
depth.ask_counts.as_ptr()
}