nautilus_model/ffi/data/
prices.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;
23
24use crate::{
25 data::{IndexPriceUpdate, MarkPriceUpdate},
26 identifiers::InstrumentId,
27 types::Price,
28};
29
30#[unsafe(no_mangle)]
31#[cfg_attr(feature = "high-precision", allow(improper_ctypes_definitions))]
32pub extern "C" fn mark_price_update_new(
33 instrument_id: InstrumentId,
34 value: Price,
35 ts_event: u64,
36 ts_init: u64,
37) -> MarkPriceUpdate {
38 MarkPriceUpdate::new(instrument_id, value, ts_event.into(), ts_init.into())
39}
40
41#[unsafe(no_mangle)]
42pub extern "C" fn mark_price_update_eq(lhs: &MarkPriceUpdate, rhs: &MarkPriceUpdate) -> u8 {
43 u8::from(lhs == rhs)
44}
45
46#[unsafe(no_mangle)]
47pub extern "C" fn mark_price_update_hash(value: &MarkPriceUpdate) -> u64 {
48 let mut hasher = DefaultHasher::new();
49 value.hash(&mut hasher);
50 hasher.finish()
51}
52
53#[unsafe(no_mangle)]
54pub extern "C" fn mark_price_update_to_cstr(value: &MarkPriceUpdate) -> *const c_char {
55 str_to_cstr(&value.to_string())
56}
57
58#[unsafe(no_mangle)]
59#[cfg_attr(feature = "high-precision", allow(improper_ctypes_definitions))]
60pub extern "C" fn index_price_update_new(
61 instrument_id: InstrumentId,
62 value: Price,
63 ts_event: u64,
64 ts_init: u64,
65) -> IndexPriceUpdate {
66 IndexPriceUpdate::new(instrument_id, value, ts_event.into(), ts_init.into())
67}
68
69#[unsafe(no_mangle)]
70pub extern "C" fn index_price_update_eq(lhs: &IndexPriceUpdate, rhs: &IndexPriceUpdate) -> u8 {
71 u8::from(lhs == rhs)
72}
73
74#[unsafe(no_mangle)]
75pub extern "C" fn index_price_update_hash(value: &IndexPriceUpdate) -> u64 {
76 let mut hasher = DefaultHasher::new();
77 value.hash(&mut hasher);
78 hasher.finish()
79}
80
81#[unsafe(no_mangle)]
82pub extern "C" fn index_price_update_to_cstr(value: &IndexPriceUpdate) -> *const c_char {
83 str_to_cstr(&value.to_string())
84}