rsbit 0.5.4

This is a library for the Bybit API.
Documentation
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
use crate::{
    v5::api::{
        BybitApi,
        get::Get,
    },
    utils::{
        deserialize_f64,
        deserialize_option_f64,
        deserialize_string_to_u64,
    },
};

use serde::{
    Serialize,
    Deserialize,
};
use serde_json::Value;
use anyhow::Result;

const PATH: &'static str = "/v5/order/history";

impl BybitApi {
    /// Retrieves the order history for the specified parameters.
    ///
    /// # Arguments
    ///
    /// * `params` - The parameters for the order history request.
    ///
    /// # Returns
    ///
    /// Returns a `Result` containing the order history response if successful, or an error if the request fails.
    /// 
    /// # Examples
    /// 
    /// ```rust
    /// use rsbit::v5::api::{
    ///     get::trade::get_order_history::{
    ///         GetOrderHistoryParameters,
    ///         GetOrderHistoryCategory
    ///     },
    ///     BybitApi,
    /// };
    /// #[tokio::main]
    /// async fn main() {
    ///     let api = BybitApi::new();
    ///     let params = GetOrderHistoryParameters::new(GetOrderHistoryCategory::Linear);
    ///     let response = api.get_order_history(params).await;
    ///     match response {
    ///         Ok(info) => {
    ///             // Handle the data
    ///         },
    ///         Err(err) => {
    ///             // Handle the error
    ///         }
    ///     }
    /// }
    /// ```
    pub async fn get_order_history(&self, params: GetOrderHistoryParameters) -> Result<GetOrderHistoryResponse> {
        self.get(PATH, Some(params), true).await
    }
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum GetOrderHistoryCategory {
    Linear,
    Inverse,
    Option,
    Spot,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetOrderHistoryParameters {
    category: GetOrderHistoryCategory,
    symbol: Option<String>,
    base_coin: Option<String>,
    settle_coin: Option<String>,
    order_id: Option<String>,
    order_link_id: Option<String>,
    order_filter: Option<String>,
    order_status: Option<String>,
    start_time: Option<u64>,
    end_time: Option<u64>,
    limit: Option<u32>,
    cursor: Option<String>,
}

impl GetOrderHistoryParameters {
    /// Creates a new instance of `GetOrderHistoryParameters` with the specified category.
    ///
    /// # Arguments
    ///
    /// * `category` - The category of the risk limit.
    ///
    /// # Returns
    ///
    /// A new instance of `GetOrderHistoryParameters`.
    pub fn new(category: GetOrderHistoryCategory) -> Self {
        Self {
            category,
            symbol: None,
            base_coin: None,
            settle_coin: None,
            order_id: None,
            order_link_id: None,
            order_filter: None,
            order_status: None,
            start_time: None,
            end_time: None,
            limit: None,
            cursor: None,
        }
    }

    /// Sets the symbol for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `symbol` - The symbol to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_symbol(mut self, symbol: String) -> Self {
        self.symbol = Some(symbol);
        self
    }

    /// Sets the base coin for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `base_coin` - The base coin to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_base_coin(mut self, base_coin: String) -> Self {
        self.base_coin = Some(base_coin);
        self
    }

    /// Sets the settle coin for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `settle_coin` - The settle coin to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_settle_coin(mut self, settle_coin: String) -> Self {
        self.settle_coin = Some(settle_coin);
        self
    }

    /// Sets the order id for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `order_id` - The order id to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_order_id(mut self, order_id: String) -> Self {
        self.order_id = Some(order_id);
        self
    }

    /// Sets the order link id for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `order_link_id` - The order link id to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_order_link_id(mut self, order_link_id: String) -> Self {
        self.order_link_id = Some(order_link_id);
        self
    }

    /// Sets the order filter for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `order_filter` - The order filter to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_order_filter(mut self, order_filter: String) -> Self {
        self.order_filter = Some(order_filter);
        self
    }

    /// Sets the order status for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `order_status` - The order status to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_order_status(mut self, order_status: String) -> Self {
        self.order_status = Some(order_status);
        self
    }

    /// Sets the start time for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `start_time` - The start time to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_start_time(mut self, start_time: u64) -> Self {
        self.start_time = Some(start_time);
        self
    }

    /// Sets the end time for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `end_time` - The end time to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_end_time(mut self, end_time: u64) -> Self {
        self.end_time = Some(end_time);
        self
    }

    /// Sets the limit for the order history parameters.
    ///
    /// # Arguments
    ///
    /// * `limit` - The limit to set.
    ///
    /// # Returns
    ///
    /// The modified `GetOrderHistoryParameters` instance.
    pub fn with_limit(mut self, limit: u32) -> Self {
        self.limit = Some(limit);
        self
    }

}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetOrderHistoryResponse {
    ret_code: i32,
    ret_msg: String,
    result: OrderHistoryResult,
    ret_ext_info: Value,
    time: u64,
}
impl GetOrderHistoryResponse {
    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) -> &OrderHistoryResult {
        &self.result
    }

    pub fn set_result(&mut self, result: OrderHistoryResult) {
        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 OrderHistoryResult {
    category: String,
    next_page_cursor: String,
    list: Vec<OrderHistory>
}
impl OrderHistoryResult {
    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<OrderHistory> {
        &self.list
    }

    pub fn set_list(&mut self, list: Vec<OrderHistory>) {
        self.list = list;
    }
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderHistory {
    order_id: String,
    order_link_id: String,
    block_trade_id: String,
    symbol: String,
    #[serde(deserialize_with = "deserialize_f64")]
    price: f64,
    #[serde(deserialize_with = "deserialize_f64")]
    qty: f64,
    side: String,
    is_leverage: String,
    position_idx: u64,
    order_status: String,
    cancel_type: String,
    reject_reason: String,
    #[serde(deserialize_with = "deserialize_option_f64")]
    avg_price: Option<f64>,
    #[serde(deserialize_with = "deserialize_option_f64")]
    leaves_qty: Option<f64>,
    #[serde(deserialize_with = "deserialize_option_f64")]
    leaves_value: Option<f64>,
    #[serde(deserialize_with = "deserialize_option_f64")]
    cum_exec_qty: Option<f64>,
    #[serde(deserialize_with = "deserialize_option_f64")]
    cum_exec_fee: Option<f64>,
    time_in_force: String,
    order_type: String,
    stop_order_type: String,
    order_iv: String,
    #[serde(deserialize_with = "deserialize_option_f64")]
    trigger_price: Option<f64>,
    #[serde(deserialize_with = "deserialize_option_f64")]
    take_profit: Option<f64>,
    #[serde(deserialize_with = "deserialize_option_f64")]
    stop_loss: Option<f64>,
    tp_trigger_by: String,
    sl_trigger_by: String,
    trigger_direction: f64,
    trigger_by: String,
    last_price_on_created: String,
    reduce_only: bool,
    close_on_trigger: bool,
    smp_type: String,
    smp_group: u64,
    smp_order_id: String,
    tpsl_mode: String,
    tp_limit_price: String,
    sl_limit_price: String,
    place_type: String,
    #[serde(deserialize_with = "deserialize_string_to_u64")]
    created_time: u64,
    #[serde(deserialize_with = "deserialize_string_to_u64")]
    updated_time: u64,
}
impl OrderHistory {
    pub fn order_id(&self) -> &str {
        &self.order_id
    }

    pub fn set_order_id(&mut self, order_id: String) {
        self.order_id = order_id;
    }

    pub fn order_link_id(&self) -> &str {
        &self.order_link_id
    }

    pub fn set_order_link_id(&mut self, order_link_id: String) {
        self.order_link_id = order_link_id;
    }

    pub fn block_trade_id(&self) -> &str {
        &self.block_trade_id
    }

    pub fn set_block_trade_id(&mut self, block_trade_id: String) {
        self.block_trade_id = block_trade_id;
    }

    pub fn symbol(&self) -> &str {
        &self.symbol
    }

    pub fn set_symbol(&mut self, symbol: String) {
        self.symbol = symbol;
    }

    pub fn price(&self) -> f64 {
        self.price
    }

    pub fn set_price(&mut self, price: f64) {
        self.price = price;
    }

    pub fn qty(&self) -> f64 {
        self.qty
    }

    pub fn set_qty(&mut self, qty: f64) {
        self.qty = qty;
    }

    pub fn side(&self) -> &str {
        &self.side
    }

    pub fn set_side(&mut self, side: String) {
        self.side = side;
    }

    pub fn is_leverage(&self) -> &str {
        &self.is_leverage
    }

    pub fn set_is_leverage(&mut self, is_leverage: String) {
        self.is_leverage = is_leverage;
    }

    pub fn position_idx(&self) -> u64 {
        self.position_idx
    }

    pub fn set_position_idx(&mut self, position_idx: u64) {
        self.position_idx = position_idx;
    }

    pub fn order_status(&self) -> &str {
        &self.order_status
    }

    pub fn set_order_status(&mut self, order_status: String) {
        self.order_status = order_status;
    }

    pub fn cancel_type(&self) -> &str {
        &self.cancel_type
    }

    pub fn set_cancel_type(&mut self, cancel_type: String) {
        self.cancel_type = cancel_type;
    }

    pub fn reject_reason(&self) -> &str {
        &self.reject_reason
    }

    pub fn set_reject_reason(&mut self, reject_reason: String) {
        self.reject_reason = reject_reason;
    }

    pub fn avg_price(&self) -> Option<f64> {
        self.avg_price
    }

    pub fn set_avg_price(&mut self, avg_price: f64) {
        self.avg_price = Some(avg_price);
    }

    pub fn leaves_qty(&self) -> Option<f64> {
        self.leaves_qty
    }

    pub fn set_leaves_qty(&mut self, leaves_qty: f64) {
        self.leaves_qty = Some(leaves_qty);
    }

    pub fn leaves_value(&self) -> Option<f64> {
        self.leaves_value
    }

    pub fn set_leaves_value(&mut self, leaves_value: f64) {
        self.leaves_value = Some(leaves_value);
    }

    pub fn cum_exec_qty(&self) -> Option<f64> {
        self.cum_exec_qty
    }

    pub fn set_cum_exec_qty(&mut self, cum_exec_qty: f64) {
        self.cum_exec_qty = Some(cum_exec_qty);
    }

    pub fn cum_exec_fee(&self) -> Option<f64> {
        self.cum_exec_fee
    }

    pub fn set_cum_exec_fee(&mut self, cum_exec_fee: f64) {
        self.cum_exec_fee = Some(cum_exec_fee);
    }

    pub fn time_in_force(&self) -> &str {
        &self.time_in_force
    }

    pub fn set_time_in_force(&mut self, time_in_force: String) {
        self.time_in_force = time_in_force;
    }

    pub fn order_type(&self) -> &str {
        &self.order_type
    }

    pub fn set_order_type(&mut self, order_type: String) {
        self.order_type = order_type;
    }

    pub fn stop_order_type(&self) -> &str {
        &self.stop_order_type
    }

    pub fn set_stop_order_type(&mut self, stop_order_type: String) {
        self.stop_order_type = stop_order_type;
    }

    pub fn order_iv(&self) -> &str {
        &self.order_iv
    }

    pub fn set_order_iv(&mut self, order_iv: String) {
        self.order_iv = order_iv;
    }

    pub fn trigger_price(&self) -> Option<f64> {
        self.trigger_price
    }

    pub fn set_trigger_price(&mut self, trigger_price: f64) {
        self.trigger_price = Some(trigger_price);
    }

    pub fn take_profit(&self) -> Option<f64> {
        self.take_profit
    }

    pub fn set_take_profit(&mut self, take_profit: f64) {
        self.take_profit = Some(take_profit);
    }

    pub fn stop_loss(&self) -> Option<f64> {
        self.stop_loss
    }

    pub fn set_stop_loss(&mut self, stop_loss: f64) {
        self.stop_loss = Some(stop_loss);
    }

    pub fn tp_trigger_by(&self) -> &str {
        &self.tp_trigger_by
    }

    pub fn set_tp_trigger_by(&mut self, tp_trigger_by: String) {
        self.tp_trigger_by = tp_trigger_by;
    }

    pub fn sl_trigger_by(&self) -> &str {
        &self.sl_trigger_by
    }

    pub fn set_sl_trigger_by(&mut self, sl_trigger_by: String) {
        self.sl_trigger_by = sl_trigger_by;
    }

    pub fn trigger_direction(&self) -> f64 {
        self.trigger_direction
    }

    pub fn set_trigger_direction(&mut self, trigger_direction: f64) {
        self.trigger_direction = trigger_direction;
    }

    pub fn trigger_by(&self) -> &str {
        &self.trigger_by
    }

    pub fn set_trigger_by(&mut self, trigger_by: String) {
        self.trigger_by = trigger_by;
    }

    pub fn last_price_on_created(&self) -> &str {
        &self.last_price_on_created
    }

    pub fn set_last_price_on_created(&mut self, last_price_on_created: String) {
        self.last_price_on_created = last_price_on_created;
    }

    pub fn reduce_only(&self) -> bool {
        self.reduce_only
    }

    pub fn set_reduce_only(&mut self, reduce_only: bool) {
        self.reduce_only = reduce_only;
    }

    pub fn close_on_trigger(&self) -> bool {
        self.close_on_trigger
    }

    pub fn set_close_on_trigger(&mut self, close_on_trigger: bool) {
        self.close_on_trigger = close_on_trigger;
    }

    pub fn smp_type(&self) -> &str {
        &self.smp_type
    }

    pub fn set_smp_type(&mut self, smp_type: String) {
        self.smp_type = smp_type;
    }

    pub fn smp_group(&self) -> u64 {
        self.smp_group
    }

    pub fn set_smp_group(&mut self, smp_group: u64) {
        self.smp_group = smp_group;
    }

    pub fn smp_order_id(&self) -> &str {
        &self.smp_order_id
    }

    pub fn set_smp_order_id(&mut self, smp_order_id: String) {
        self.smp_order_id = smp_order_id;
    }

    pub fn tpsl_mode(&self) -> &str {
        &self.tpsl_mode
    }

    pub fn set_tpsl_mode(&mut self, tpsl_mode: String) {
        self.tpsl_mode = tpsl_mode;
    }

    pub fn tp_limit_price(&self) -> &str {
        &self.tp_limit_price
    }

    pub fn set_tp_limit_price(&mut self, tp_limit_price: String) {
        self.tp_limit_price = tp_limit_price;
    }

    pub fn sl_limit_price(&self) -> &str {
        &self.sl_limit_price
    }

    pub fn set_sl_limit_price(&mut self, sl_limit_price: String) {
        self.sl_limit_price = sl_limit_price;
    }

    pub fn place_type(&self) -> &str {
        &self.place_type
    }

    pub fn set_place_type(&mut self, place_type: String) {
        self.place_type = place_type;
    }

    pub fn created_time(&self) -> u64 {
        self.created_time
    }

    pub fn set_created_time(&mut self, created_time: u64) {
        self.created_time = created_time;
    }

    pub fn updated_time(&self) -> u64 {
        self.updated_time
    }

    pub fn set_updated_time(&mut self, updated_time: u64) {
        self.updated_time = updated_time;
    }
}