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
use crate::{
    v5::ws::BybitWS,
    constants::PRIVATE_ORDER_TOPIC,
    utils::{
        deserialize_f64,
        deserialize_string_to_u64,
        deserialize_option_f64,
    },
};
use serde::Deserialize;

pub enum OrderCategory {
    Linear,
    Inverse,
    Option,
    Spot,
}

impl BybitWS {
    pub fn add_order_args(&mut self, category: Option<OrderCategory>) {
        match category {
            Some(category) => {
                self.args.push(match category {
                    OrderCategory::Linear => format!("{}.{}", PRIVATE_ORDER_TOPIC, "linear"),
                    OrderCategory::Inverse => format!("{}.{}", PRIVATE_ORDER_TOPIC, "inverse"),
                    OrderCategory::Option => format!("{}.{}", PRIVATE_ORDER_TOPIC, "option"),
                    OrderCategory::Spot => format!("{}.{}", PRIVATE_ORDER_TOPIC, "spot"),
                });
            },
            None => {
                self.args.push(PRIVATE_ORDER_TOPIC.to_string());
            }
        }
    }
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PrivateOrderResponse {
    id: String,
    topic: String,
    creation_time: u64,
    data: Vec<PrivateOrderData>,
}

impl PrivateOrderResponse {
    pub fn id(&self) -> &str {
        &self.id
    }

    pub fn set_id(&mut self, id: String) {
        self.id = id;
    }

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

    pub fn set_topic(&mut self, topic: String) {
        self.topic = topic;
    }

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

    pub fn set_creation_time(&mut self, creation_time: u64) {
        self.creation_time = creation_time;
    }

    pub fn data(&self) -> &Vec<PrivateOrderData> {
        &self.data
    }

    pub fn set_data(&mut self, data: Vec<PrivateOrderData>) {
        self.data = data;
    }
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PrivateOrderData {
    symbol: String,
    order_id: String,
    side: String,
    order_type: String,
    cancel_type: String,
    #[serde(deserialize_with = "deserialize_f64")]
    price: f64,
    #[serde(deserialize_with = "deserialize_f64")]
    qty: f64,
    #[serde(deserialize_with = "deserialize_option_f64")]
    order_iv: Option<f64>,
    time_in_force: String,
    order_status: String,
    order_link_id: String,
    #[serde(deserialize_with = "deserialize_option_f64")]
    last_price_on_created: Option<f64>,
    reduce_only: bool,
    #[serde(deserialize_with = "deserialize_option_f64")]
    leaves_qty: Option<f64>,
    #[serde(deserialize_with = "deserialize_option_f64")]
    leaves_value: Option<f64>,
    #[serde(deserialize_with = "deserialize_f64")]
    cum_exec_qty: f64,
    #[serde(deserialize_with = "deserialize_f64")]
    cum_exec_value: f64,
    #[serde(deserialize_with = "deserialize_option_f64")]
    avg_price: Option<f64>,
    block_trade_id: String,
    position_idx: u64,
    #[serde(deserialize_with = "deserialize_f64")]
    cum_exec_fee: f64,
    #[serde(deserialize_with = "deserialize_string_to_u64")]
    created_time: u64,
    #[serde(deserialize_with = "deserialize_string_to_u64")]
    updated_time: u64,
    reject_reason: String,
    stop_order_type: 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: u8,
    trigger_by: String,
    close_on_trigger: bool,
    category: String,
    place_type: String,
    smp_type: String,
    smp_group: u64,
    smp_order_id: String,
}

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

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

    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 side(&self) -> &str {
        &self.side
    }

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

    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 cancel_type(&self) -> &str {
        &self.cancel_type
    }

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

    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 order_iv(&self) -> Option<f64> {
        self.order_iv
    }

    pub fn set_order_iv(&mut self, order_iv: Option<f64>) {
        self.order_iv = order_iv;
    }

    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_status(&self) -> &str {
        &self.order_status
    }

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

    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 last_price_on_created(&self) -> Option<f64> {
        self.last_price_on_created
    }

    pub fn set_last_price_on_created(&mut self, last_price_on_created: Option<f64>) {
        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 leaves_qty(&self) -> Option<f64> {
        self.leaves_qty
    }

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

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

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

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

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

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

    pub fn set_cum_exec_value(&mut self, cum_exec_value: f64) {
        self.cum_exec_value = cum_exec_value;
    }

    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 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 position_idx(&self) -> u64 {
        self.position_idx
    }

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

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

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

    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;
    }

    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 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 trigger_price(&self) -> Option<f64> {
        self.trigger_price
    }

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

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

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

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

    pub fn set_stop_loss(&mut self, stop_loss: Option<f64>) {
        self.stop_loss = 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) -> u8 {
        self.trigger_direction
    }

    pub fn set_trigger_direction(&mut self, trigger_direction: u8) {
        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 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 category(&self) -> &str {
        &self.category
    }

    pub fn set_category(&mut self, category: String) {
        self.category = category;
    }

    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 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;
    }

}