Skip to main content

nautilus_tardis/http/
query.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
16use derive_builder::Builder;
17use jiff::Timestamp;
18use serde::Serialize;
19
20mod datetime_format {
21    use jiff::Timestamp;
22    use serde::{self, Serializer};
23
24    pub(super) fn serialize<S>(date: &Option<Timestamp>, serializer: S) -> Result<S::Ok, S::Error>
25    where
26        S: Serializer,
27    {
28        match date {
29            Some(dt) => serializer.serialize_str(&format!("{dt:.3}")),
30            None => serializer.serialize_none(),
31        }
32    }
33}
34
35/// Provides an instrument metadata API filter object.
36///
37/// See <https://docs.tardis.dev/api/instruments-metadata-api>.
38#[derive(Debug, Default, Serialize, Builder)]
39#[serde(rename_all = "camelCase")]
40pub struct InstrumentFilter {
41    #[serde(skip_serializing_if = "Option::is_none")]
42    #[builder(default)]
43    pub base_currency: Option<Vec<String>>,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[builder(default)]
46    pub quote_currency: Option<Vec<String>>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    #[serde(rename = "type")]
49    #[builder(default)]
50    pub instrument_type: Option<Vec<String>>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    #[builder(default)]
53    pub contract_type: Option<Vec<String>>,
54    #[serde(skip_serializing_if = "Option::is_none")]
55    #[builder(default)]
56    pub active: Option<bool>,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    #[serde(with = "datetime_format")]
59    #[builder(default)]
60    pub available_since: Option<Timestamp>,
61    #[serde(skip_serializing_if = "Option::is_none")]
62    #[serde(with = "datetime_format")]
63    #[builder(default)]
64    pub available_to: Option<Timestamp>,
65}