Skip to main content

nautilus_databento/arrow/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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
16//! Apache Arrow schema and encoding/decoding for Databento types.
17
18pub mod imbalance;
19pub mod statistics;
20
21use std::{collections::HashMap, str::FromStr};
22
23use nautilus_model::identifiers::InstrumentId;
24use nautilus_serialization::arrow::{
25    EncodingError, KEY_INSTRUMENT_ID, KEY_PRICE_PRECISION, KEY_SIZE_PRECISION,
26};
27
28fn parse_metadata(
29    metadata: &HashMap<String, String>,
30) -> Result<(InstrumentId, u8, u8), EncodingError> {
31    let instrument_id_str = metadata
32        .get(KEY_INSTRUMENT_ID)
33        .ok_or_else(|| EncodingError::MissingMetadata(KEY_INSTRUMENT_ID))?;
34    let instrument_id = InstrumentId::from_str(instrument_id_str)
35        .map_err(|e| EncodingError::ParseError(KEY_INSTRUMENT_ID, e.to_string()))?;
36
37    let price_precision = metadata
38        .get(KEY_PRICE_PRECISION)
39        .ok_or_else(|| EncodingError::MissingMetadata(KEY_PRICE_PRECISION))?
40        .parse::<u8>()
41        .map_err(|e| EncodingError::ParseError(KEY_PRICE_PRECISION, e.to_string()))?;
42
43    let size_precision = metadata
44        .get(KEY_SIZE_PRECISION)
45        .ok_or_else(|| EncodingError::MissingMetadata(KEY_SIZE_PRECISION))?
46        .parse::<u8>()
47        .map_err(|e| EncodingError::ParseError(KEY_SIZE_PRECISION, e.to_string()))?;
48
49    Ok((instrument_id, price_precision, size_precision))
50}