1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
use crate::{
v5::api::{
BybitApi,
get::Get,
},
utils::{
deserialize_f64,
deserialize_string_to_u64,
},
};
use serde::{
Serialize,
Deserialize,
};
use serde_json::Value;
use anyhow::Result;
const PATH: &'static str = "/v5/market/delivery-price";
impl BybitApi {
/// Retrieves the delivery price based on the provided parameters.
///
/// # Arguments
///
/// * `params` - The parameters for the delivery price request.
///
/// # Examples
///
/// ```rust
/// use rsbit::v5::api::{
/// get::market::get_delivery_price::{
/// GetDeliveryPriceParameters,
/// GetDeliveryPriceCategory
/// },
/// BybitApi,
/// };
/// #[tokio::main]
/// async fn main() {
/// let api = BybitApi::new();
/// let params = GetDeliveryPriceParameters::new(GetDeliveryPriceCategory::Option);
/// let response = api.get_delivery_price(params).await;
/// match response {
/// Ok(info) => {
/// // Handle the data
/// },
/// Err(err) => {
/// // Handle the error
/// }
/// }
/// }
/// ```
pub async fn get_delivery_price(&self, params: GetDeliveryPriceParameters) -> Result<GetDeliveryPriceResponse> {
self.get(PATH, Some(params), false).await
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum GetDeliveryPriceCategory {
Option,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetDeliveryPriceParameters {
category: GetDeliveryPriceCategory,
symbol: Option<String>,
base_coin: Option<String>,
limit: Option<u32>,
cursor: Option<String>,
}
impl GetDeliveryPriceParameters {
/// Creates a new instance of `GetDeliveryPriceParameters` with the specified category.
///
/// # Arguments
///
/// * `category` - The category of the delivery price.
///
/// # Returns
///
/// A new instance of `GetDeliveryPriceParameters`.
pub fn new(category: GetDeliveryPriceCategory) -> Self {
Self {
category,
symbol: None,
base_coin: None,
limit: None,
cursor: None,
}
}
/// Sets the symbol for the delivery price.
///
/// # Arguments
///
/// * `symbol` - The symbol to set.
///
/// # Returns
///
/// The modified `GetDeliveryPriceParameters` instance.
pub fn with_symbol(mut self, symbol: String) -> Self {
self.symbol = Some(symbol);
self
}
/// Sets the base coin for the delivery price.
///
/// # Arguments
///
/// * `base_coin` - The base coin to set.
///
/// # Returns
///
/// The modified `GetDeliveryPriceParameters` instance.
pub fn with_base_coin(mut self, base_coin: String) -> Self {
self.base_coin = Some(base_coin);
self
}
/// Sets the limit for the delivery price.
///
/// # Arguments
///
/// * `limit` - The limit to set.
///
/// # Returns
///
/// The modified `GetDeliveryPriceParameters` instance.
pub fn with_limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
/// Sets the cursor for the delivery price.
///
/// # Arguments
///
/// * `cursor` - The cursor to set.
///
/// # Returns
///
/// The modified `GetDeliveryPriceParameters` instance.
pub fn with_cursor(mut self, cursor: String) -> Self {
self.cursor = Some(cursor);
self
}
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetDeliveryPriceResponse {
ret_code: i32,
ret_msg: String,
result: DeliveryPriceResult,
ret_ext_info: Value,
time: u64,
}
impl GetDeliveryPriceResponse {
pub fn ret_code(&self) -> i32 {
self.ret_code
}
pub fn set_ret_code(&mut self, ret_code: i32) {
self.ret_code = ret_code;
}
pub fn ret_msg(&self) -> &str {
&self.ret_msg
}
pub fn set_ret_msg(&mut self, ret_msg: String) {
self.ret_msg = ret_msg;
}
pub fn result(&self) -> &DeliveryPriceResult {
&self.result
}
pub fn set_result(&mut self, result: DeliveryPriceResult) {
self.result = result;
}
pub fn ret_ext_info(&self) -> &Value {
&self.ret_ext_info
}
pub fn set_ret_ext_info(&mut self, ret_ext_info: Value) {
self.ret_ext_info = ret_ext_info;
}
pub fn time(&self) -> u64 {
self.time
}
pub fn set_time(&mut self, time: u64) {
self.time = time;
}
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeliveryPriceResult {
category: String,
next_page_cursor: String,
list: Vec<DeliveryPrice>
}
impl DeliveryPriceResult {
pub fn category(&self) -> &str {
&self.category
}
pub fn set_category(&mut self, category: String) {
self.category = category;
}
pub fn next_page_cursor(&self) -> &str {
&self.next_page_cursor
}
pub fn set_next_page_cursor(&mut self, next_page_cursor: String) {
self.next_page_cursor = next_page_cursor;
}
pub fn list(&self) -> &Vec<DeliveryPrice> {
&self.list
}
pub fn set_list(&mut self, list: Vec<DeliveryPrice>) {
self.list = list;
}
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeliveryPrice {
symbol: String,
#[serde(deserialize_with = "deserialize_f64")]
delivery_price: f64,
#[serde(deserialize_with = "deserialize_string_to_u64")]
delivery_time: u64,
}
impl DeliveryPrice {
pub fn symbol(&self) -> &str {
&self.symbol
}
pub fn set_symbol(&mut self, symbol: String) {
self.symbol = symbol;
}
pub fn delivery_price(&self) -> f64 {
self.delivery_price
}
pub fn set_delivery_price(&mut self, delivery_price: f64) {
self.delivery_price = delivery_price;
}
pub fn delivery_time(&self) -> u64 {
self.delivery_time
}
pub fn set_delivery_time(&mut self, delivery_time: u64) {
self.delivery_time = delivery_time;
}
}