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