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// -------------------------------------------------------------------------------------------------
1516use std::{
17 collections::hash_map::DefaultHasher,
18 ffi::c_char,
19 hash::{Hash, Hasher},
20};
2122use nautilus_core::ffi::string::str_to_cstr;
2324use crate::{
25 data::BookOrder,
26 enums::OrderSide,
27 types::{Price, Quantity},
28};
2930#[unsafe(no_mangle)]
31#[cfg_attr(feature = "high-precision", allow(improper_ctypes_definitions))]
32pub extern "C" fn book_order_new(
33 order_side: OrderSide,
34 price: Price,
35 size: Quantity,
36 order_id: u64,
37) -> BookOrder {
38 BookOrder::new(order_side, price, size, order_id)
39}
4041#[unsafe(no_mangle)]
42pub extern "C" fn book_order_eq(lhs: &BookOrder, rhs: &BookOrder) -> u8 {
43 u8::from(lhs == rhs)
44}
4546#[unsafe(no_mangle)]
47pub extern "C" fn book_order_hash(order: &BookOrder) -> u64 {
48let mut hasher = DefaultHasher::new();
49 order.hash(&mut hasher);
50 hasher.finish()
51}
5253#[unsafe(no_mangle)]
54pub extern "C" fn book_order_exposure(order: &BookOrder) -> f64 {
55 order.exposure()
56}
5758#[unsafe(no_mangle)]
59pub extern "C" fn book_order_signed_size(order: &BookOrder) -> f64 {
60 order.signed_size()
61}
6263/// Returns a [`BookOrder`] display string as a C string pointer.
64#[unsafe(no_mangle)]
65pub extern "C" fn book_order_display_to_cstr(order: &BookOrder) -> *const c_char {
66 str_to_cstr(&format!("{order}"))
67}
6869/// Returns a [`BookOrder`] debug string as a C string pointer.
70#[unsafe(no_mangle)]
71pub extern "C" fn book_order_debug_to_cstr(order: &BookOrder) -> *const c_char {
72 str_to_cstr(&format!("{order:?}"))
73}