nautilus_model/ffi/data/delta.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 hash::{Hash, Hasher},
19};
20
21use nautilus_core::UnixNanos;
22
23use crate::{
24 data::{BookOrder, OrderBookDelta},
25 enums::BookAction,
26 identifiers::InstrumentId,
27};
28
29#[no_mangle]
30#[cfg_attr(feature = "high-precision", allow(improper_ctypes_definitions))]
31pub extern "C" fn orderbook_delta_new(
32 instrument_id: InstrumentId,
33 action: BookAction,
34 order: BookOrder,
35 flags: u8,
36 sequence: u64,
37 ts_event: UnixNanos,
38 ts_init: UnixNanos,
39) -> OrderBookDelta {
40 OrderBookDelta::new(
41 instrument_id,
42 action,
43 order,
44 flags,
45 sequence,
46 ts_event,
47 ts_init,
48 )
49}
50
51#[no_mangle]
52pub extern "C" fn orderbook_delta_eq(lhs: &OrderBookDelta, rhs: &OrderBookDelta) -> u8 {
53 u8::from(lhs == rhs)
54}
55
56#[no_mangle]
57pub extern "C" fn orderbook_delta_hash(delta: &OrderBookDelta) -> u64 {
58 let mut hasher = DefaultHasher::new();
59 delta.hash(&mut hasher);
60 hasher.finish()
61}