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::{UnixNanos, ffi::string::str_to_cstr};
2324use crate::{
25 data::QuoteTick,
26 identifiers::InstrumentId,
27 types::{Price, Quantity},
28};
2930#[unsafe(no_mangle)]
31#[cfg_attr(feature = "high-precision", allow(improper_ctypes_definitions))]
32pub extern "C" fn quote_tick_new(
33 instrument_id: InstrumentId,
34 bid_price: Price,
35 ask_price: Price,
36 bid_size: Quantity,
37 ask_size: Quantity,
38 ts_event: UnixNanos,
39 ts_init: UnixNanos,
40) -> QuoteTick {
41 QuoteTick::new(
42 instrument_id,
43 bid_price,
44 ask_price,
45 bid_size,
46 ask_size,
47 ts_event,
48 ts_init,
49 )
50}
5152#[unsafe(no_mangle)]
53pub extern "C" fn quote_tick_eq(lhs: &QuoteTick, rhs: &QuoteTick) -> u8 {
54assert_eq!(lhs.ask_price, rhs.ask_price);
55assert_eq!(lhs.ask_size, rhs.ask_size);
56assert_eq!(lhs.bid_price, rhs.bid_price);
57assert_eq!(lhs.bid_size, rhs.bid_size);
58assert_eq!(lhs.ts_event, rhs.ts_event);
59assert_eq!(lhs.ts_init, rhs.ts_init);
60assert_eq!(lhs.instrument_id.symbol, rhs.instrument_id.symbol);
61assert_eq!(lhs.instrument_id.venue, rhs.instrument_id.venue);
62 u8::from(lhs == rhs)
63}
6465#[unsafe(no_mangle)]
66pub extern "C" fn quote_tick_hash(delta: &QuoteTick) -> u64 {
67let mut hasher = DefaultHasher::new();
68 delta.hash(&mut hasher);
69 hasher.finish()
70}
7172/// Returns a [`QuoteTick`] as a C string pointer.
73#[unsafe(no_mangle)]
74pub extern "C" fn quote_tick_to_cstr(quote: &QuoteTick) -> *const c_char {
75 str_to_cstr("e.to_string())
76}