nautilus_model/ffi/data/
quote.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, UnixNanos};
23
24use crate::{
25    data::QuoteTick,
26    identifiers::InstrumentId,
27    types::{Price, Quantity},
28};
29
30#[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}
51
52#[no_mangle]
53pub extern "C" fn quote_tick_eq(lhs: &QuoteTick, rhs: &QuoteTick) -> u8 {
54    assert_eq!(lhs.ask_price, rhs.ask_price);
55    assert_eq!(lhs.ask_size, rhs.ask_size);
56    assert_eq!(lhs.bid_price, rhs.bid_price);
57    assert_eq!(lhs.bid_size, rhs.bid_size);
58    assert_eq!(lhs.ts_event, rhs.ts_event);
59    assert_eq!(lhs.ts_init, rhs.ts_init);
60    assert_eq!(lhs.instrument_id.symbol, rhs.instrument_id.symbol);
61    assert_eq!(lhs.instrument_id.venue, rhs.instrument_id.venue);
62    u8::from(lhs == rhs)
63}
64
65#[no_mangle]
66pub extern "C" fn quote_tick_hash(delta: &QuoteTick) -> u64 {
67    let mut hasher = DefaultHasher::new();
68    delta.hash(&mut hasher);
69    hasher.finish()
70}
71
72/// Returns a [`QuoteTick`] as a C string pointer.
73#[no_mangle]
74pub extern "C" fn quote_tick_to_cstr(quote: &QuoteTick) -> *const c_char {
75    str_to_cstr(&quote.to_string())
76}