nautilus_deribit/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
16//! Deribit HTTP API query parameter builders.
17
18use derive_builder::Builder;
19use serde::{Deserialize, Serialize};
20
21use super::models::{DeribitCurrency, DeribitInstrumentKind};
22
23/// Query parameters for `/public/get_instruments` endpoint.
24#[derive(Clone, Debug, Deserialize, Serialize, Builder)]
25#[builder(setter(into, strip_option))]
26pub struct GetInstrumentsParams {
27    /// Currency filter
28    pub currency: DeribitCurrency,
29    /// Optional instrument kind filter
30    #[serde(skip_serializing_if = "Option::is_none")]
31    #[builder(default)]
32    pub kind: Option<DeribitInstrumentKind>,
33    /// Whether to include expired instruments
34    #[serde(skip_serializing_if = "Option::is_none")]
35    #[builder(default)]
36    pub expired: Option<bool>,
37}
38
39impl GetInstrumentsParams {
40    /// Creates a new builder for [`GetInstrumentsParams`].
41    #[must_use]
42    pub fn builder() -> GetInstrumentsParamsBuilder {
43        GetInstrumentsParamsBuilder::default()
44    }
45
46    /// Creates parameters for a specific currency.
47    #[must_use]
48    pub fn new(currency: DeribitCurrency) -> Self {
49        Self {
50            currency,
51            kind: None,
52            expired: None,
53        }
54    }
55
56    /// Creates parameters for a specific currency and kind.
57    #[must_use]
58    pub fn with_kind(currency: DeribitCurrency, kind: DeribitInstrumentKind) -> Self {
59        Self {
60            currency,
61            kind: Some(kind),
62            expired: None,
63        }
64    }
65}
66
67/// Query parameters for `/public/get_instrument` endpoint.
68#[derive(Clone, Debug, Deserialize, Serialize, Builder)]
69pub struct GetInstrumentParams {
70    /// Instrument name (e.g., "BTC-PERPETUAL", "ETH-25MAR23-2000-C")
71    pub instrument_name: String,
72}
73
74/// Query parameters for `/private/get_account_summaries` endpoint.
75#[derive(Clone, Debug, Default, Deserialize, Serialize)]
76pub struct GetAccountSummariesParams {
77    /// The user id for the subaccount.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub subaccount_id: Option<String>,
80    /// Include extended fields
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub extended: Option<bool>,
83}
84
85impl GetAccountSummariesParams {
86    /// Creates a new instance with both subaccount ID and extended flag.
87    #[must_use]
88    pub fn new(subaccount_id: String, extended: bool) -> Self {
89        Self {
90            subaccount_id: Some(subaccount_id),
91            extended: Some(extended),
92        }
93    }
94}
95
96/// Query parameters for `/public/get_last_trades_by_instrument_and_time` endpoint.
97#[derive(Clone, Debug, Deserialize, Serialize, Builder)]
98#[builder(setter(into, strip_option))]
99pub struct GetLastTradesByInstrumentAndTimeParams {
100    /// Instrument name (e.g., "BTC-PERPETUAL")
101    pub instrument_name: String,
102    /// The earliest timestamp to return result from (milliseconds since the UNIX epoch)
103    pub start_timestamp: i64,
104    /// The most recent timestamp to return result from (milliseconds since the UNIX epoch)
105    pub end_timestamp: i64,
106    /// Number of requested items, default - 10, maximum - 1000
107    #[serde(skip_serializing_if = "Option::is_none")]
108    #[builder(default)]
109    pub count: Option<u32>,
110    /// Direction of results sorting: "asc", "desc", or "default"
111    #[serde(skip_serializing_if = "Option::is_none")]
112    #[builder(default)]
113    pub sorting: Option<String>,
114}
115
116impl GetLastTradesByInstrumentAndTimeParams {
117    /// Creates a new instance with the required parameters.
118    #[must_use]
119    pub fn new(
120        instrument_name: impl Into<String>,
121        start_timestamp: i64,
122        end_timestamp: i64,
123        count: Option<u32>,
124        sorting: Option<String>,
125    ) -> Self {
126        Self {
127            instrument_name: instrument_name.into(),
128            start_timestamp,
129            end_timestamp,
130            count,
131            sorting,
132        }
133    }
134}
135
136/// Query parameters for `/public/get_tradingview_chart_data` endpoint.
137#[derive(Clone, Debug, Deserialize, Serialize)]
138pub struct GetTradingViewChartDataParams {
139    /// Instrument name (e.g., "BTC-PERPETUAL")
140    pub instrument_name: String,
141    /// The earliest timestamp to return result from (milliseconds since UNIX epoch)
142    pub start_timestamp: i64,
143    /// The most recent timestamp to return result from (milliseconds since UNIX epoch)
144    pub end_timestamp: i64,
145    /// Chart bars resolution given in full minutes or keyword "1D"
146    /// Supported resolutions: 1, 3, 5, 10, 15, 30, 60, 120, 180, 360, 720, 1D
147    pub resolution: String,
148}
149
150impl GetTradingViewChartDataParams {
151    /// Creates new parameters for chart data request.
152    #[must_use]
153    pub fn new(
154        instrument_name: String,
155        start_timestamp: i64,
156        end_timestamp: i64,
157        resolution: String,
158    ) -> Self {
159        Self {
160            instrument_name,
161            start_timestamp,
162            end_timestamp,
163            resolution,
164        }
165    }
166}
167
168/// Query parameters for `/public/get_order_book` endpoint.
169#[derive(Clone, Debug, Deserialize, Serialize, Builder)]
170#[builder(setter(into, strip_option))]
171pub struct GetOrderBookParams {
172    /// Instrument name (e.g., "BTC-PERPETUAL")
173    pub instrument_name: String,
174    /// The number of entries to return for bids and asks.
175    /// Valid values: 1, 5, 10, 20, 50, 100, 1000, 10000
176    /// Maximum: 10000
177    #[serde(skip_serializing_if = "Option::is_none")]
178    #[builder(default)]
179    pub depth: Option<u32>,
180}
181
182impl GetOrderBookParams {
183    /// Creates parameters with required fields.
184    #[must_use]
185    pub fn new(instrument_name: String, depth: Option<u32>) -> Self {
186        Self {
187            instrument_name,
188            depth,
189        }
190    }
191}