nautilus_model/ffi/data/
prices.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.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::{
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}