nautilus_model/ffi/data/
order.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::BookOrder,
26    enums::OrderSide,
27    types::{Price, Quantity},
28};
29
30#[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}
40
41#[no_mangle]
42pub extern "C" fn book_order_eq(lhs: &BookOrder, rhs: &BookOrder) -> u8 {
43    u8::from(lhs == rhs)
44}
45
46#[no_mangle]
47pub extern "C" fn book_order_hash(order: &BookOrder) -> u64 {
48    let mut hasher = DefaultHasher::new();
49    order.hash(&mut hasher);
50    hasher.finish()
51}
52
53#[no_mangle]
54pub extern "C" fn book_order_exposure(order: &BookOrder) -> f64 {
55    order.exposure()
56}
57
58#[no_mangle]
59pub extern "C" fn book_order_signed_size(order: &BookOrder) -> f64 {
60    order.signed_size()
61}
62
63/// Returns a [`BookOrder`] display string as a C string pointer.
64#[no_mangle]
65pub extern "C" fn book_order_display_to_cstr(order: &BookOrder) -> *const c_char {
66    str_to_cstr(&format!("{order}"))
67}
68
69/// Returns a [`BookOrder`] debug string as a C string pointer.
70#[no_mangle]
71pub extern "C" fn book_order_debug_to_cstr(order: &BookOrder) -> *const c_char {
72    str_to_cstr(&format!("{order:?}"))
73}