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