nautilus_bybit/common/
models.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
16//! Shared data transfer objects used across Bybit HTTP and WebSocket payloads.
17
18use serde::{Deserialize, Serialize};
19
20/// Generic wrapper that contains a list payload returned by Bybit.
21#[derive(Clone, Debug, Default, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase")]
23pub struct BybitList<T> {
24    /// Collection returned by the endpoint.
25    pub list: Vec<T>,
26}
27
28/// Generic list result that also carries pagination cursor information.
29#[derive(Clone, Debug, Default, Serialize, Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct BybitCursorList<T> {
32    /// Collection returned by the endpoint.
33    pub list: Vec<T>,
34    /// Pagination cursor for the next page, when provided.
35    pub next_page_cursor: Option<String>,
36}
37
38/// Common leverage filter that describes leverage bounds and step.
39#[derive(Clone, Debug, Serialize, Deserialize)]
40#[serde(rename_all = "camelCase")]
41pub struct LeverageFilter {
42    /// Minimum leverage supported.
43    pub min_leverage: String,
44    /// Maximum leverage supported.
45    pub max_leverage: String,
46    /// Step between successive leverage values.
47    pub leverage_step: String,
48}
49
50/// Price filter for linear/inverse contracts describing min/max and tick.
51#[derive(Clone, Debug, Serialize, Deserialize)]
52#[serde(rename_all = "camelCase")]
53pub struct LinearPriceFilter {
54    /// Minimum allowed order price.
55    pub min_price: String,
56    /// Maximum allowed order price.
57    pub max_price: String,
58    /// Tick size for price increments.
59    pub tick_size: String,
60}
61
62/// Price filter for spot instruments (only tick size is provided).
63#[derive(Clone, Debug, Serialize, Deserialize)]
64#[serde(rename_all = "camelCase")]
65pub struct SpotPriceFilter {
66    /// Tick size for price increments.
67    pub tick_size: String,
68}
69
70/// Lot size filter for spot instruments.
71#[derive(Clone, Debug, Serialize, Deserialize)]
72#[serde(rename_all = "camelCase")]
73pub struct SpotLotSizeFilter {
74    /// Base asset precision.
75    pub base_precision: String,
76    /// Quote asset precision.
77    pub quote_precision: String,
78    /// Minimum order quantity.
79    pub min_order_qty: String,
80    /// Maximum order quantity.
81    pub max_order_qty: String,
82    /// Minimum order notional.
83    pub min_order_amt: String,
84    /// Maximum order notional.
85    pub max_order_amt: String,
86}
87
88/// Lot size filter for derivatives instruments.
89#[derive(Clone, Debug, Serialize, Deserialize)]
90#[serde(rename_all = "camelCase")]
91pub struct LinearLotSizeFilter {
92    /// Maximum order quantity.
93    pub max_order_qty: String,
94    /// Minimum order quantity.
95    pub min_order_qty: String,
96    /// Quantity increment step.
97    pub qty_step: String,
98    /// Maximum order quantity for post-only orders.
99    #[serde(default)]
100    pub post_only_max_order_qty: Option<String>,
101    /// Maximum order quantity for market orders.
102    #[serde(default)]
103    pub max_mkt_order_qty: Option<String>,
104    /// Minimum notional value.
105    #[serde(default)]
106    pub min_notional_value: Option<String>,
107}
108
109/// Lot size filter for option instruments.
110#[derive(Clone, Debug, Serialize, Deserialize)]
111#[serde(rename_all = "camelCase")]
112pub struct OptionLotSizeFilter {
113    /// Maximum order quantity.
114    pub max_order_qty: String,
115    /// Minimum order quantity.
116    pub min_order_qty: String,
117    /// Quantity increment step.
118    pub qty_step: String,
119}
120
121/// Top-level response envelope returned by Bybit HTTP endpoints.
122#[derive(Clone, Debug, Serialize, Deserialize)]
123#[serde(rename_all = "camelCase")]
124pub struct BybitResponse<T> {
125    /// Return code (0 = success).
126    pub ret_code: i64,
127    /// Textual message accompanying the response.
128    pub ret_msg: String,
129    /// Actual payload returned by the endpoint.
130    pub result: T,
131    /// Additional metadata returned by some endpoints.
132    #[serde(default)]
133    pub ret_ext_info: Option<serde_json::Value>,
134    /// Server time in milliseconds when the response was produced.
135    #[serde(default)]
136    pub time: Option<i64>,
137}
138
139/// Convenience alias for responses that return a simple list.
140pub type BybitListResponse<T> = BybitResponse<BybitList<T>>;
141
142/// Convenience alias for responses that return a cursor-based list.
143pub type BybitCursorListResponse<T> = BybitResponse<BybitCursorList<T>>;