nautilus_model/ffi/data/
quote.rs1use std::{
17 collections::hash_map::DefaultHasher,
18 ffi::c_char,
19 hash::{Hash, Hasher},
20};
21
22use nautilus_core::{ffi::string::str_to_cstr, UnixNanos};
23
24use crate::{
25 data::QuoteTick,
26 identifiers::InstrumentId,
27 types::{Price, Quantity},
28};
29
30#[no_mangle]
31#[cfg_attr(feature = "high-precision", allow(improper_ctypes_definitions))]
32pub extern "C" fn quote_tick_new(
33 instrument_id: InstrumentId,
34 bid_price: Price,
35 ask_price: Price,
36 bid_size: Quantity,
37 ask_size: Quantity,
38 ts_event: UnixNanos,
39 ts_init: UnixNanos,
40) -> QuoteTick {
41 QuoteTick::new(
42 instrument_id,
43 bid_price,
44 ask_price,
45 bid_size,
46 ask_size,
47 ts_event,
48 ts_init,
49 )
50}
51
52#[no_mangle]
53pub extern "C" fn quote_tick_eq(lhs: &QuoteTick, rhs: &QuoteTick) -> u8 {
54 assert_eq!(lhs.ask_price, rhs.ask_price);
55 assert_eq!(lhs.ask_size, rhs.ask_size);
56 assert_eq!(lhs.bid_price, rhs.bid_price);
57 assert_eq!(lhs.bid_size, rhs.bid_size);
58 assert_eq!(lhs.ts_event, rhs.ts_event);
59 assert_eq!(lhs.ts_init, rhs.ts_init);
60 assert_eq!(lhs.instrument_id.symbol, rhs.instrument_id.symbol);
61 assert_eq!(lhs.instrument_id.venue, rhs.instrument_id.venue);
62 u8::from(lhs == rhs)
63}
64
65#[no_mangle]
66pub extern "C" fn quote_tick_hash(delta: &QuoteTick) -> u64 {
67 let mut hasher = DefaultHasher::new();
68 delta.hash(&mut hasher);
69 hasher.finish()
70}
71
72#[no_mangle]
74pub extern "C" fn quote_tick_to_cstr(quote: &QuoteTick) -> *const c_char {
75 str_to_cstr("e.to_string())
76}