ccxt-pro 4.5.78

CCXT – CryptoCurrency eXchange Trading Library (Rust) – pro (WebSocket / watch*) exchanges
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
use crate::pro::*;


pub struct BitoproCore {
    pub parent: crate::exchanges::bitopro::BitoproCore,
}

impl BitoproCore {
    pub fn new(config: Option<crate::Value>) -> Self {
        let mut s = Self { parent: crate::exchanges::bitopro::BitoproCore::new(config) };
        s.init();
        s
    }

    pub fn init(&mut self) {
        let described = BitoproCore::describe(self);
        self.initialize_properties(described);
        <Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
    }

    /// Compatibility no-op. The old pointer-based dispatch needed a post-move
    /// `bind()`; static trait dispatch (review #1) needs no binding, so this
    /// just exists so callers that still call it keep compiling.
    #[inline]
    pub fn bind(&mut self) {}
}

impl crate::exchange::DerivedExchange for BitoproCore {
    fn nonce(&self, ) -> crate::Value {
        crate::exchange::DerivedExchange::nonce(&self.parent)
    }
    fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_ticker(&self.parent, ticker, market)
    }
    fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_trade(&self.parent, trade, market)
    }
    fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_order(&self.parent, order, market)
    }
    fn parse_market(&self, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_market(&self.parent, market)
    }
    fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_ohlcv(&self.parent, ohlcv, market)
    }
    fn parse_order_book(&self, ob: crate::Value, symbol: crate::Value, ts: crate::Value, bk: crate::Value, ak: crate::Value, pk: crate::Value, ak2: crate::Value, ck: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_order_book(&self.parent, ob, symbol, ts, bk, ak, pk, ak2, ck)
    }
    fn parse_balance(&self, response: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_balance(&self.parent, response)
    }
    fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_position(&self.parent, position, market)
    }
    fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_funding_rate(&self.parent, rate, market)
    }
    fn parse_deposit(&self, tx: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_deposit(&self.parent, tx, currency)
    }
    fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_deposit_address(&self.parent, depositAddress, currency)
    }
    fn parse_last_price(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_last_price(&self.parent, entry, market)
    }
    fn parse_withdrawal(&self, tx: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_withdrawal(&self.parent, tx, currency)
    }
    fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_ledger_entry(&self.parent, entry, currency)
    }
    fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_transfer(&self.parent, transfer, currency)
    }
    fn parse_currency(&self, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_currency(&self.parent, currency)
    }
    fn parse_bid_ask(&self, bidask: crate::Value, price_key: crate::Value, amount_key: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_bid_ask(&self.parent, bidask, price_key, amount_key, market)
    }
    fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_open_interest(&self.parent, interest, market)
    }
    fn parse_liquidation(&self, liquidation: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_liquidation(&self.parent, liquidation, market)
    }
    fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_funding_rate_history(&self.parent, entry, market)
    }
    fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_margin_modification(&self.parent, data, market)
    }
    fn parse_account(&self, account: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_account(&self.parent, account)
    }
    fn parse_my_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_my_trade(&self.parent, trade, market)
    }
    fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_transaction(&self.parent, transaction, currency)
    }
    fn parse_borrow_interest(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_borrow_interest(&self.parent, info, market)
    }
    fn parse_adl_rank(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_adl_rank(&self.parent, info, market)
    }
    fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_income(&self.parent, info, market)
    }
    fn parse_greeks(&self, greeks: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_greeks(&self.parent, greeks, market)
    }
    fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_margin_mode(&self.parent, margin_mode, market)
    }
    fn parse_conversion(&self, conversion: crate::Value, from_currency: crate::Value, to_currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_conversion(&self.parent, conversion, from_currency, to_currency)
    }
    fn parse_borrow_rate(&self, info: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_borrow_rate(&self.parent, info, currency)
    }
    fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_leverage(&self.parent, leverage, market)
    }
    fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_market_leverage_tiers(&self.parent, info, market)
    }
    fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_deposit_withdraw_fee(&self.parent, fee, currency)
    }
    fn parse_prediction_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_prediction_trade(&self.parent, trade, market)
    }
    fn parse_prediction_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_prediction_order(&self.parent, order, market)
    }
    fn parse_prediction_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_prediction_position(&self.parent, position, market)
    }
    fn create_expired_option_market(&self, symbol: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::create_expired_option_market(&self.parent, symbol)
    }
    fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::sign(&self.parent, path, api, method, params, headers, body)
    }
    fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::handle_errors(&self.parent, code, reason, url, method, headers, body, response, request_headers, request_body)
    }
}

impl crate::exchange_generated::ExchangeBase for BitoproCore {
    fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
        -> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
    {
        Box::pin(async move {
            match method {
                "handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
                "parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
                "watch_balance" => self.watch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_my_trades" => self.watch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_order_book" => self.watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_public" => self.watch_public(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)).await,
                "watch_ticker" => self.watch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_trades" => self.watch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                // Go-style inheritance: an un-overridden method dispatches to the parent core.
                _ => crate::exchange_generated::ExchangeBase::call_dynamic(&mut self.parent, method, args).await,
            }
        })
    }
}
impl BitoproCore {
    /// Synchronous WS handler dispatch — routes a handler-name string (from the
    /// venue's handle_message dispatch table) to the real handler method.
    #[allow(dead_code, unreachable_patterns, clippy::all)]
    pub fn dispatch_ws_handler(&mut self, __name: &crate::Value, args: &[crate::Value]) -> crate::Value {
        let __n = match __name { crate::Value::Str(s) => s.as_str(), _ => return crate::Value::Null };
        match __n {
            "authenticate" => { self.authenticate(args.get(0).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_balance" => { self.handle_balance(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_my_trade" => { self.handle_my_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_order_book" => { self.handle_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_ticker" => { self.handle_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_trade" => { self.handle_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
            "watch_balance" => { crate::exchange_stubs::enqueue_spawn("watch_balance", args.to_vec()); crate::Value::Null },
            "watch_my_trades" => { crate::exchange_stubs::enqueue_spawn("watch_my_trades", args.to_vec()); crate::Value::Null },
            "watch_order_book" => { crate::exchange_stubs::enqueue_spawn("watch_order_book", args.to_vec()); crate::Value::Null },
            "watch_public" => { crate::exchange_stubs::enqueue_spawn("watch_public", args.to_vec()); crate::Value::Null },
            "watch_ticker" => { crate::exchange_stubs::enqueue_spawn("watch_ticker", args.to_vec()); crate::Value::Null },
            "watch_trades" => { crate::exchange_stubs::enqueue_spawn("watch_trades", args.to_vec()); crate::Value::Null },
            _ => crate::Value::Null,
        }
    }
}

impl std::ops::Deref for BitoproCore {
    type Target = crate::exchange::Exchange;
    fn deref(&self) -> &crate::exchange::Exchange { std::ops::Deref::deref(&self.parent) }
}

impl std::ops::DerefMut for BitoproCore {
    fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { std::ops::DerefMut::deref_mut(&mut self.parent) }
}

impl BitoproCore {
    pub fn describe(&self) -> Value {
        return self.deep_extend(self.parent.describe(), &[Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("has".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("ws".to_string(), Value::Bool(true));
        m.insert("watchBalance".to_string(), Value::Bool(true));
        m.insert("watchMyTrades".to_string(), Value::Bool(true));
        m.insert("watchOHLCV".to_string(), Value::Bool(false));
        m.insert("watchOrderBook".to_string(), Value::Bool(true));
        m.insert("watchOrders".to_string(), Value::Bool(false));
        m.insert("watchTicker".to_string(), Value::Bool(true));
        m.insert("watchTickers".to_string(), Value::Bool(false));
        m.insert("watchTrades".to_string(), Value::Bool(true));
        m.insert("watchTradesForSymbols".to_string(), Value::Bool(false));
    m
}));
        m.insert("urls".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("ws".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("public".to_string(), Value::Str("wss://stream.bitopro.com:443/ws/v1/pub".to_string()));
        m.insert("private".to_string(), Value::Str("wss://stream.bitopro.com:443/ws/v1/pub/auth".to_string()));
    m
}));
    m
}));
        m.insert("requiredCredentials".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("apiKey".to_string(), Value::Bool(true));
        m.insert("secret".to_string(), Value::Bool(true));
        m.insert("login".to_string(), Value::Bool(true));
    m
}));
        m.insert("options".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("tradesLimit".to_string(), Value::Int(1000));
        m.insert("ordersLimit".to_string(), Value::Int(1000));
        m.insert("ws".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("options".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("headers".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
    m
}));
    m
}));
    m
}));
    m
})]);

    Value::Null
}

    pub async fn watch_public(&mut self, mut path: Value, mut messageHash: Value, mut marketId: Value) -> Value {
        let mut url: Value = add(&add(&add(&add(&get_value(&get_value(&self.urls, &Value::Str("ws".to_string())), &Value::Str("public".to_string())), &Value::Str("/".to_string())), &path), &Value::Str("/".to_string())), &marketId);
        return self.watch(url.clone(), messageHash.clone(), &[Value::Null, messageHash.clone()]).await;

    Value::Null
}

/*
 * @method
 * @name bitopro#watchOrderBook
 * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
 * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/public/order_book_stream.md
 * @param {string} symbol unified symbol of the market to fetch the order book for
 * @param {int} [limit] the maximum amount of order book entries to return
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
 */
    pub async fn watch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
        let mut limit = get_arg(optional_args, 0, Value::Null);
        let mut params = get_arg(optional_args, 1, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        if !is_equal(&limit, &Value::Null) {
            if is_true(&(!is_equal(&limit, &Value::Int(5)))) && is_true(&(!is_equal(&limit, &Value::Int(10)))) && is_true(&(!is_equal(&limit, &Value::Int(20)))) && is_true(&(!is_equal(&limit, &Value::Int(50)))) && is_true(&(!is_equal(&limit, &Value::Int(100)))) && is_true(&(!is_equal(&limit, &Value::Int(500)))) && is_true(&(!is_equal(&limit, &Value::Int(1000)))) {
                panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" watchOrderBook limit argument must be undefined, 5, 10, 20, 50, 100, 500 or 1000".to_string()))));
            }
        }
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut market: Value = self.market(symbol.clone());
        symbol = get_value(&market, &Value::Str("symbol".to_string()));
        let mut messageHash: Value = add(&add(&Value::Str("ORDER_BOOK".to_string()), &Value::Str(":".to_string())), &symbol);
        let mut endPart: Value = Value::Null;
        if is_equal(&limit, &Value::Null) {
            endPart = get_value(&market, &Value::Str("id".to_string()));
        }  else {
            endPart = add(&add(&get_value(&market, &Value::Str("id".to_string())), &Value::Str(":".to_string())), &self.number_to_string(limit.clone()));
        }
        let mut orderbook: Value = self.watch_public(Value::Str("order-books".to_string()), messageHash.clone(), endPart.clone()).await;
        return orderbook.limit();

    Value::Null
}

    pub fn handle_order_book(&self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "event": "ORDER_BOOK",
        //         "timestamp": 1650121915308,
        //         "datetime": "2022-04-16T15:11:55.308Z",
        //         "pair": "BTC_TWD",
        //         "limit": 5,
        //         "scale": 0,
        //         "bids": [
        //             { price: "1188178", amount: '0.0425', count: 1, total: "0.0425" },
        //         ],
        //         "asks": [
        //             {
        //                 "price": "1190740",
        //                 "amount": "0.40943964",
        //                 "count": 1,
        //                 "total": "0.40943964"
        //             },
        //         ]
        //     }
        //
        let mut marketId: Value = self.safe_string_k(message.clone(), "pair", &[]);
        let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("_".to_string())]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
        let mut messageHash: Value = add(&add(&event, &Value::Str(":".to_string())), &symbol);
        let mut orderbook: Value = self.safe_value(self.orderbooks.clone(), symbol.clone(), &[]);
        if is_equal(&orderbook, &Value::Null) {
            orderbook = self.order_book(&[Value::Map({
                let mut m = indexmap::IndexMap::new();
                m
            })]);
        }
        let mut timestamp: Value = self.safe_integer_k(message.clone(), "timestamp", &[]);
        let mut snapshot: Value = self.parse_order_book(message.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Str("price".to_string()), Value::Str("amount".to_string())]);
        orderbook.reset(snapshot.clone());
        client.resolve(&[orderbook.clone(), messageHash.clone()]);
}

/*
 * @method
 * @name bitopro#watchTrades
 * @description get the list of most recent trades for a particular symbol
 * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/public/trade_stream.md
 * @param {string} symbol unified symbol of the market to fetch trades for
 * @param {int} [since] timestamp in ms of the earliest trade to fetch
 * @param {int} [limit] the maximum amount of trades to fetch
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
 */
    pub async fn watch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
        let mut since = get_arg(optional_args, 0, Value::Null);
        let mut limit = get_arg(optional_args, 1, Value::Null);
        let mut params = get_arg(optional_args, 2, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut market: Value = self.market(symbol.clone());
        symbol = get_value(&market, &Value::Str("symbol".to_string()));
        let mut messageHash: Value = add(&add(&Value::Str("TRADE".to_string()), &Value::Str(":".to_string())), &symbol);
        let mut trades: Value = self.watch_public(Value::Str("trades".to_string()), messageHash.clone(), get_value(&market, &Value::Str("id".to_string()))).await;
        if is_true(&self.newUpdates) {
            limit = trades.get_limit(symbol.clone(), limit.clone());
        }
        return self.filter_by_since_limit(trades.clone(), &[since.clone(), limit.clone(), Value::Str("timestamp".to_string()), Value::Bool(true)]);

    Value::Null
}

    pub fn handle_trade(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "event": "TRADE",
        //         "timestamp": 1650116346665,
        //         "datetime": "2022-04-16T13:39:06.665Z",
        //         "pair": "BTC_TWD",
        //         "data": [
        //             {
        //                 "event": '',
        //                 "datetime": '',
        //                 "pair": '',
        //                 "timestamp": 1650116227,
        //                 "price": "1189429",
        //                 "amount": "0.0153127",
        //                 "isBuyer": true
        //             },
        //         ]
        //     }
        //
        let mut marketId: Value = self.safe_string_k(message.clone(), "pair", &[]);
        let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("_".to_string())]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
        let mut messageHash: Value = add(&add(&event, &Value::Str(":".to_string())), &symbol);
        let mut rawData: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
        let mut trades: Value = self.parse_trades(rawData.clone(), &[market.clone()]);
        let mut tradesCache: Value = self.safe_value(self.trades.clone(), symbol.clone(), &[]);
        if is_equal(&tradesCache, &Value::Null) {
            let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
            tradesCache = ArrayCache::new(limit.clone());
        }
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_152: bool = true;
            while { if !__for_first_152 { i = add(&i, &Value::Int(1)); } __for_first_152 = false; is_less_than(&i, &get_array_length(&trades)) } {
            tradesCache.append(get_value(&trades, &i));
        }
        }
        add_element_to_object(&mut self.trades, &symbol, tradesCache.clone());
        client.resolve(&[tradesCache.clone(), messageHash.clone()]);
}

/*
 * @method
 * @name bitopro#watchMyTrades
 * @description watches information on multiple trades made by the user
 * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/private/matches_stream.md
 * @param {string} symbol unified market symbol of the market trades were made in
 * @param {int} [since] the earliest time in ms to fetch trades for
 * @param {int} [limit] the maximum number of trade structures to retrieve
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
 */
    pub async fn watch_my_trades(&mut self, optional_args: &[Value]) -> Value {
        let mut symbol = get_arg(optional_args, 0, Value::Null);
        let mut since = get_arg(optional_args, 1, Value::Null);
        let mut limit = get_arg(optional_args, 2, Value::Null);
        let mut params = get_arg(optional_args, 3, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        self.check_required_credentials(&[]);
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut messageHash: Value = Value::Str("USER_TRADE".to_string());
        if !is_equal(&symbol, &Value::Null) {
            let mut market: Value = self.market(symbol.clone());
            messageHash = add(&add(&messageHash, &Value::Str(":".to_string())), &get_value(&market, &Value::Str("symbol".to_string())));
        }
        let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("ws".to_string())), &Value::Str("private".to_string())), &Value::Str("/".to_string())), &Value::Str("user-trades".to_string()));
        self.authenticate(url.clone());
        let mut trades: Value = self.watch(url.clone(), messageHash.clone(), &[Value::Null, messageHash.clone()]).await;
        if is_true(&self.newUpdates) {
            limit = trades.get_limit(symbol.clone(), limit.clone());
        }
        return self.filter_by_since_limit(trades.clone(), &[since.clone(), limit.clone(), Value::Str("timestamp".to_string()), Value::Bool(true)]);

    Value::Null
}

    pub fn handle_my_trade(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "event": "USER_TRADE",
        //         "timestamp": 1694667358782,
        //         "datetime": "2023-09-14T12:55:58.782Z",
        //         "data": {
        //             "base": "usdt",
        //             "quote": "twd",
        //             "side": "ask",
        //             "price": "32.039",
        //             "volume": "1",
        //             "fee": "6407800",
        //             "feeCurrency": "twd",
        //             "transactionTimestamp": 1694667358,
        //             "eventTimestamp": 1694667358,
        //             "orderID": 390733918,
        //             "orderType": "LIMIT",
        //             "matchID": "bd07673a-94b1-419e-b5ee-d7b723261a5d",
        //             "isMarket": false,
        //             "isMaker": false
        //         }
        //     }
        //
        let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        })]);
        let mut baseId: Value = self.safe_string_k(data.clone(), "base", &[]);
        let mut quoteId: Value = self.safe_string_k(data.clone(), "quote", &[]);
        let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
        let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
        let mut symbol: Value = self.symbol(add(&add(&base, &Value::Str("/".to_string())), &quote));
        let mut messageHash: Value = self.safe_string_k(message.clone(), "event", &[]);
        if is_equal(&self.myTrades, &Value::Null) {
            let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
            self.myTrades = ArrayCacheBySymbolById::new(limit.clone());
        }
        let mut trades: Value = self.myTrades.clone();
        let mut parsed: Value = self.parse_ws_trade(data.clone(), &[]);
        trades.append(parsed.clone());
        client.resolve(&[trades.clone(), messageHash.clone()]);
        client.resolve(&[trades.clone(), add(&add(&messageHash, &Value::Str(":".to_string())), &symbol)]);
}

    pub fn parse_ws_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
        let mut market = get_arg(optional_args, 0, Value::Null);
        //
        //     {
        //         "base": "usdt",
        //         "quote": "twd",
        //         "side": "ask",
        //         "price": "32.039",
        //         "volume": "1",
        //         "fee": "6407800",
        //         "feeCurrency": "twd",
        //         "transactionTimestamp": 1694667358,
        //         "eventTimestamp": 1694667358,
        //         "orderID": 390733918,
        //         "orderType": "LIMIT",
        //         "matchID": "bd07673a-94b1-419e-b5ee-d7b723261a5d",
        //         "isMarket": false,
        //         "isMaker": false
        //     }
        //
        let mut id: Value = self.safe_string_k(trade.clone(), "matchID", &[]);
        let mut orderId: Value = self.safe_string_k(trade.clone(), "orderID", &[]);
        let mut timestamp: Value = self.safe_timestamp(trade.clone(), Value::Str("transactionTimestamp".to_string()), &[]);
        let mut baseId: Value = self.safe_string_k(trade.clone(), "base", &[]);
        let mut quoteId: Value = self.safe_string_k(trade.clone(), "quote", &[]);
        let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
        let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
        let mut symbol: Value = self.symbol(add(&add(&base, &Value::Str("/".to_string())), &quote));
        market = self.safe_market(&[symbol.clone(), market.clone()]);
        let mut price: Value = self.safe_string_k(trade.clone(), "price", &[]);
        let mut type_var: Value = self.safe_string_lower(trade.clone(), Value::Str("orderType".to_string()), &[]);
        let mut side: Value = self.safe_string_k(trade.clone(), "side", &[]);
        if !is_equal(&side, &Value::Null) {
            if is_equal(&side, &Value::Str("ask".to_string())) {
                side = Value::Str("sell".to_string());
            }  else if is_equal(&side, &Value::Str("bid".to_string())) {
                side = Value::Str("buy".to_string());
            }
        }
        let mut amount: Value = self.safe_string_k(trade.clone(), "volume", &[]);
        let mut fee: Value = Value::Null;
        let mut feeAmount: Value = self.safe_string_k(trade.clone(), "fee", &[]);
        let mut feeSymbol: Value = self.safe_currency_code(self.safe_string_k(trade.clone(), "feeCurrency", &[]), &[]);
        if !is_equal(&feeAmount, &Value::Null) {
            fee = Value::Map({
                let mut m = indexmap::IndexMap::new();
                    m.insert("cost".to_string(), feeAmount.clone());
                    m.insert("currency".to_string(), feeSymbol.clone());
                    m.insert("rate".to_string(), Value::Null);
                m
            });
        }
        let mut isMaker: Value = self.safe_value_k(trade.clone(), "isMaker", &[]);
        let mut takerOrMaker: Value = Value::Null;
        if !is_equal(&isMaker, &Value::Null) {
            if is_equal(&isMaker, &Value::Bool(true)) {
                takerOrMaker = Value::Str("maker".to_string());
            }  else {
                takerOrMaker = Value::Str("taker".to_string());
            }
        }
        return self.safe_trade(Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("id".to_string(), id.clone());
        m.insert("info".to_string(), trade.clone());
        m.insert("order".to_string(), orderId.clone());
        m.insert("timestamp".to_string(), timestamp.clone());
        m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
        m.insert("symbol".to_string(), symbol.clone());
        m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
        m.insert("type".to_string(), type_var.clone());
        m.insert("side".to_string(), side.clone());
        m.insert("price".to_string(), price.clone());
        m.insert("amount".to_string(), amount.clone());
        m.insert("cost".to_string(), Value::Null);
        m.insert("fee".to_string(), fee.clone());
    m
}), &[market.clone()]);

    Value::Null
}

/*
 * @method
 * @name bitopro#watchTicker
 * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
 * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/public/ticker_stream.md
 * @param {string} symbol unified symbol of the market to fetch the ticker for
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
 */
    pub async fn watch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
        let mut params = get_arg(optional_args, 0, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut market: Value = self.market(symbol.clone());
        symbol = get_value(&market, &Value::Str("symbol".to_string()));
        let mut messageHash: Value = add(&add(&Value::Str("TICKER".to_string()), &Value::Str(":".to_string())), &symbol);
        return self.watch_public(Value::Str("tickers".to_string()), messageHash.clone(), get_value(&market, &Value::Str("id".to_string()))).await;

    Value::Null
}

    pub fn handle_ticker(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "event": "TICKER",
        //         "timestamp": 1650119165710,
        //         "datetime": "2022-04-16T14:26:05.710Z",
        //         "pair": "BTC_TWD",
        //         "lastPrice": "1189110",
        //         "lastPriceUSD": "40919.1328",
        //         "lastPriceTWD": "1189110",
        //         "isBuyer": true,
        //         "priceChange24hr": "1.23",
        //         "volume24hr": "7.2090",
        //         "volume24hrUSD": "294985.5375",
        //         "volume24hrTWD": "8572279",
        //         "high24hr": "1193656",
        //         "low24hr": "1179321"
        //     }
        //
        let mut marketId: Value = self.safe_string_lower(message.clone(), Value::Str("pair".to_string()), &[]);
        if is_equal(&marketId, &Value::Null) {
            return;
        }
        // market-ids are lowercase in REST API and uppercase in WS API
        let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("_".to_string())]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
        let mut messageHash: Value = add(&add(&event, &Value::Str(":".to_string())), &symbol);
        let mut result: Value = self.parse_ticker(message.clone(), &[market.clone()]);
        add_element_to_object(&mut result, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "symbol", &[])); // symbol returned from REST's parseTicker is distorted for WS, so re-set it from market object
        let mut timestamp: Value = self.safe_integer_k(message.clone(), "timestamp", &[]);
        add_element_to_object(&mut result, &Value::Str("timestamp".to_string()), timestamp.clone());
        add_element_to_object(&mut result, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone())); // we shouldn't set "datetime" string provided by server, as those values are obviously wrong offset from UTC
        add_element_to_object(&mut self.tickers, &symbol, result.clone());
        client.resolve(&[result.clone(), messageHash.clone()]);
}

    pub fn authenticate(&mut self, mut url: Value) {
        if is_true(&(!is_equal(&self.clients, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.clients, &url)))) {
            return;
        }
        self.check_required_credentials(&[]);
        let mut nonce: Value = self.milliseconds();
        let mut rawData: Value = self.json(Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("nonce".to_string(), nonce.clone());
                m.insert("identity".to_string(), self.login.clone());
            m
        }));
        let mut payload: Value = self.string_to_base64(rawData.clone(), &[]);
        let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha384".to_string()), &[]);
        let mut defaultOptions: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("ws".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("options".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("headers".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
    m
}));
    m
}));
            m
        });
        // this.options = this.extend (defaultOptions, this.options);
        self.extend_exchange_options(&[defaultOptions.clone()]);
        let mut originalHeaders: Value = get_value(&get_value(&get_value(&self.options, &Value::Str("ws".to_string())), &Value::Str("options".to_string())), &Value::Str("headers".to_string()));
        let mut headers: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("X-BITOPRO-API".to_string(), Value::Str("ccxt".to_string()));
                m.insert("X-BITOPRO-APIKEY".to_string(), self.apiKey.clone());
                m.insert("X-BITOPRO-PAYLOAD".to_string(), payload.clone());
                m.insert("X-BITOPRO-SIGNATURE".to_string(), signature.clone());
            m
        });
        add_element_to_object(get_value_mut(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("ws".to_string())), &Value::Str("options".to_string())), &Value::Str("headers".to_string()), headers.clone());
        // instantiate client
        self.client(&[url.clone()]);
        add_element_to_object(get_value_mut(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("ws".to_string())), &Value::Str("options".to_string())), &Value::Str("headers".to_string()), originalHeaders.clone());
}

/*
 * @method
 * @name bitopro#watchBalance
 * @description watch balance and get the amount of funds available for trading or funds locked in orders
 * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/private/user_balance_stream.md
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
 */
    pub async fn watch_balance(&mut self, optional_args: &[Value]) -> Value {
        let mut params = get_arg(optional_args, 0, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        self.check_required_credentials(&[]);
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut messageHash: Value = Value::Str("ACCOUNT_BALANCE".to_string());
        let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("ws".to_string())), &Value::Str("private".to_string())), &Value::Str("/".to_string())), &Value::Str("account-balance".to_string()));
        self.authenticate(url.clone());
        return self.watch(url.clone(), messageHash.clone(), &[Value::Null, messageHash.clone()]).await;

    Value::Null
}

    pub fn handle_balance(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "event": "ACCOUNT_BALANCE",
        //         "timestamp": 1650450505715,
        //         "datetime": "2022-04-20T10:28:25.715Z",
        //         "data": {
        //           "ADA": {
        //             "currency": "ADA",
        //             "amount": "0",
        //             "available": "0",
        //             "stake": "0",
        //             "tradable": true
        //           },
        //         }
        //     }
        //
        let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
        let mut data: Value = self.safe_value_k(message.clone(), "data", &[]);
        let mut timestamp: Value = self.safe_integer_k(message.clone(), "timestamp", &[]);
        let mut datetime: Value = self.safe_string_k(message.clone(), "datetime", &[]);
        let mut currencies: Value = object_keys(&data);
        let mut result: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("info".to_string(), data.clone());
                m.insert("timestamp".to_string(), timestamp.clone());
                m.insert("datetime".to_string(), datetime.clone());
            m
        });
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_153: bool = true;
            while { if !__for_first_153 { i = add(&i, &Value::Int(1)); } __for_first_153 = false; is_less_than(&i, &get_array_length(&currencies)) } {
            let mut currency: Value = self.safe_string(currencies.clone(), i.clone(), &[]);
            let mut balance: Value = self.safe_value(data.clone(), currency.clone(), &[]);
            let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
            let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
            let mut account: Value = self.account();
            add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "available", &[]));
            add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "amount", &[]));
            if !is_equal(&code, &Value::Null) {
                add_element_to_object(&mut result, &code, account.clone());
            }
        }
        }
        { let __t = self.safe_balance(result.clone()); self.balance = __t; }
        client.resolve(&[self.balance.clone(), event.clone()]);
}

    pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
        let mut methods: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("TRADE".to_string(), Value::Str("handle_trade".to_string()).clone());
                m.insert("TICKER".to_string(), Value::Str("handle_ticker".to_string()).clone());
                m.insert("ORDER_BOOK".to_string(), Value::Str("handle_order_book".to_string()).clone());
                m.insert("ACCOUNT_BALANCE".to_string(), Value::Str("handle_balance".to_string()).clone());
                m.insert("USER_TRADE".to_string(), Value::Str("handle_my_trade".to_string()).clone());
            m
        });
        let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
        let mut method: Value = self.safe_value(methods.clone(), event.clone(), &[]);
        if !is_equal(&method, &Value::Null) {
            self.dispatch_ws_handler(&method, &[client.clone(), message.clone()]);
        }
}
}