nautilus_model/ffi/data/
prices.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use 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::{data::MarkPriceUpdate, identifiers::InstrumentId, types::Price};
25
26#[unsafe(no_mangle)]
27#[cfg_attr(feature = "high-precision", allow(improper_ctypes_definitions))]
28pub extern "C" fn mark_price_update_new(
29    instrument_id: InstrumentId,
30    value: Price,
31    ts_event: u64,
32    ts_init: u64,
33) -> MarkPriceUpdate {
34    MarkPriceUpdate::new(instrument_id, value, ts_event.into(), ts_init.into())
35}
36
37#[unsafe(no_mangle)]
38pub extern "C" fn mark_price_update_eq(lhs: &MarkPriceUpdate, rhs: &MarkPriceUpdate) -> u8 {
39    u8::from(lhs == rhs)
40}
41
42#[unsafe(no_mangle)]
43pub extern "C" fn mark_price_update_hash(value: &MarkPriceUpdate) -> u64 {
44    let mut hasher = DefaultHasher::new();
45    value.hash(&mut hasher);
46    hasher.finish()
47}
48
49#[unsafe(no_mangle)]
50pub extern "C" fn mark_price_update_to_cstr(value: &MarkPriceUpdate) -> *const c_char {
51    str_to_cstr(&value.to_string())
52}