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
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
// 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 HashkeyCore {
    pub parent: crate::exchanges::hashkey::HashkeyCore,
}

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

    pub fn init(&mut self) {
        let described = HashkeyCore::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 HashkeyCore {
    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 HashkeyCore {
    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 {
                "authenticate" => self.authenticate(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
                "get_private_url" => self.get_private_url(args.get(0).cloned().unwrap_or(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 },
                "keep_alive_listen_key" => self.keep_alive_listen_key(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                "load_balance_snapshot" => self.load_balance_snapshot(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,
                "parse_ws_ohlcv" => self.parse_ws_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
                "parse_ws_order" => self.parse_ws_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
                "parse_ws_position" => self.parse_ws_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
                "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_ohlcv" => self.watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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_orders" => self.watch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_positions" => self.watch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_private" => self.watch_private(args.get(0).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,
                "wath_public" => self.wath_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), &args.get(3..).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 HashkeyCore {
    /// 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" => { crate::exchange_stubs::enqueue_spawn("authenticate", args.to_vec()); crate::Value::Null },
            "get_private_url" => self.get_private_url(args.get(0).cloned().unwrap_or(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), &args.get(2..).unwrap_or(&[]).to_vec()[..]); crate::Value::Null },
            "handle_ohlcv" => { self.handle_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_order" => { self.handle_order(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_position" => { self.handle_position(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_trades" => { self.handle_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "keep_alive_listen_key" => { crate::exchange_stubs::enqueue_spawn("keep_alive_listen_key", args.to_vec()); crate::Value::Null },
            "load_balance_snapshot" => { crate::exchange_stubs::enqueue_spawn("load_balance_snapshot", args.to_vec()); crate::Value::Null },
            "parse_ws_ohlcv" => self.parse_ws_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
            "parse_ws_order" => self.parse_ws_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
            "parse_ws_position" => self.parse_ws_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
            "parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
            "set_balance_cache" => { self.set_balance_cache(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)); crate::Value::Null },
            "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_ohlcv" => { crate::exchange_stubs::enqueue_spawn("watch_ohlcv", args.to_vec()); crate::Value::Null },
            "watch_order_book" => { crate::exchange_stubs::enqueue_spawn("watch_order_book", args.to_vec()); crate::Value::Null },
            "watch_orders" => { crate::exchange_stubs::enqueue_spawn("watch_orders", args.to_vec()); crate::Value::Null },
            "watch_positions" => { crate::exchange_stubs::enqueue_spawn("watch_positions", args.to_vec()); crate::Value::Null },
            "watch_private" => { crate::exchange_stubs::enqueue_spawn("watch_private", 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 },
            "wath_public" => { crate::exchange_stubs::enqueue_spawn("wath_public", args.to_vec()); crate::Value::Null },
            _ => crate::Value::Null,
        }
    }
}

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

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

impl HashkeyCore {
    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(true));
        m.insert("watchOrderBook".to_string(), Value::Bool(true));
        m.insert("watchOrders".to_string(), Value::Bool(true));
        m.insert("watchTicker".to_string(), Value::Bool(true));
        m.insert("watchTrades".to_string(), Value::Bool(true));
        m.insert("watchTradesForSymbols".to_string(), Value::Bool(false));
        m.insert("watchPositions".to_string(), Value::Bool(false));
    m
}));
        m.insert("urls".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("api".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-glb.hashkey.com/quote/ws/v1".to_string()));
        m.insert("private".to_string(), Value::Str("wss://stream-glb.hashkey.com/api/v1/ws".to_string()));
    m
}));
        m.insert("test".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-glb.sim.hashkeydev.com/quote/ws/v1".to_string()));
        m.insert("private".to_string(), Value::Str("wss://stream-glb.sim.hashkeydev.com/api/v1/ws".to_string()));
    m
}));
    m
}));
    m
}));
    m
}));
        m.insert("options".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("listenKeyRefreshRate".to_string(), Value::Int(3600000));
        m.insert("listenKey".to_string(), Value::Null);
        m.insert("watchBalance".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("fetchBalanceSnapshot".to_string(), Value::Bool(true));
        m.insert("awaitBalanceSnapshot".to_string(), Value::Bool(false));
    m
}));
    m
}));
        m.insert("streaming".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("keepAlive".to_string(), Value::Int(10000));
    m
}));
    m
})]);

    Value::Null
}

    pub async fn wath_public(&mut self, mut market: Value, mut topic: Value, mut messageHash: Value, optional_args: &[Value]) -> Value {
        let mut params = get_arg(optional_args, 0, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        let mut request: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
                m.insert("topic".to_string(), topic.clone());
                m.insert("event".to_string(), Value::Str("sub".to_string()));
            m
        });
        let mut url: Value = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
        let __ws_arg_0 = self.deep_extend(request.clone(), &[params.clone()]);
        return self.watch(url.clone(), messageHash.clone(), &[__ws_arg_0, messageHash.clone()]).await;

    Value::Null
}

    pub async fn watch_private(&mut self, mut messageHash: Value) -> Value {
        let mut listenKey: Value = self.authenticate(&[]).await;
        let mut url: Value = self.get_private_url(listenKey.clone());
        return self.watch(url.clone(), messageHash.clone(), &[Value::Null, messageHash.clone()]).await;

    Value::Null
}

    pub fn get_private_url(&self, mut listenKey: Value) -> Value {
        return add(&add(&get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("private".to_string())), &Value::Str("/".to_string())), &listenKey);

    Value::Null
}

/*
 * @method
 * @name hashkey#watchOHLCV
 * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#public-stream
 * @param {string} symbol unified symbol of the market to fetch OHLCV data for
 * @param {string} timeframe the length of time each candle represents
 * @param {int} [since] timestamp in ms of the earliest candle to fetch
 * @param {int} [limit] the maximum amount of candles to fetch
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @param {bool} [params.binary] true or false - default false
 * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
 */
    pub async fn watch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
        let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
        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
}));
        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 interval: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
        let mut topic: Value = add(&Value::Str("kline_".to_string()), &interval);
        let mut messageHash: Value = add(&add(&add(&Value::Str("ohlcv:".to_string()), &symbol), &Value::Str(":".to_string())), &timeframe);
        let mut ohlcv: Value = self.wath_public(market.clone(), topic.clone(), messageHash.clone(), &[params.clone()]).await;
        if is_true(&self.newUpdates) {
            limit = ohlcv.get_limit(symbol.clone(), limit.clone());
        }
        return self.filter_by_since_limit(ohlcv.clone(), &[since.clone(), limit.clone(), Value::Int(0), Value::Bool(true)]);

    Value::Null
}

    pub fn handle_ohlcv(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "symbol": "DOGEUSDT",
        //         "symbolName": "DOGEUSDT",
        //         "topic": "kline",
        //         "params": {
        //             "realtimeInterval": "24h",
        //             "klineType": "1m"
        //         },
        //         "data": [
        //             {
        //                 "t": 1722861660000,
        //                 "s": "DOGEUSDT",
        //                 "sn": "DOGEUSDT",
        //                 "c": "0.08389",
        //                 "h": "0.08389",
        //                 "l": "0.08389",
        //                 "o": "0.08389",
        //                 "v": "0"
        //             }
        //         ],
        //         "f": true,
        //         "sendTime": 1722861664258,
        //         "shared": false
        //     }
        //
        let mut marketId: Value = self.safe_string_k(message.clone(), "symbol", &[]);
        let mut market: Value = self.safe_market(&[marketId.clone()]);
        let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
        if !is_true(&(Value::Bool(in_op(&self.ohlcvs, &symbol)))) {
            add_element_to_object(&mut self.ohlcvs, &symbol, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        }
        let mut params: Value = self.safe_dict_k(message.clone(), "params", &[]);
        let mut klineType: Value = self.safe_string_k(params.clone(), "klineType", &[]);
        let mut timeframe: Value = self.find_timeframe(klineType.clone(), &[]);
        if !is_true(&(Value::Bool(in_op(&get_value(&self.ohlcvs, &symbol), &timeframe)))) {
            let mut limit: Value = self.safe_integer_k(self.options.clone(), "OHLCVLimit", &[Value::Int(1000)]);
            add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.ohlcvs) }, &symbol), &timeframe, ArrayCacheByTimestamp::new(limit.clone()));
        }
        let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
        let mut stored: Value = get_value(&get_value(&self.ohlcvs, &symbol), &timeframe);
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_369: bool = true;
            while { if !__for_first_369 { i = add(&i, &Value::Int(1)); } __for_first_369 = false; is_less_than(&i, &get_array_length(&data)) } {
            let mut candle: Value = self.safe_dict(data.clone(), i.clone(), &[Value::Map({
                let mut m = indexmap::IndexMap::new();
                m
            })]);
            let mut parsed: Value = self.parse_ws_ohlcv(candle.clone(), &[market.clone()]);
            stored.append(parsed.clone());
        }
        }
        let mut messageHash: Value = add(&add(&add(&Value::Str("ohlcv:".to_string()), &symbol), &Value::Str(":".to_string())), &timeframe);
        client.resolve(&[stored.clone(), messageHash.clone()]);
}

    pub fn parse_ws_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
        let mut market = get_arg(optional_args, 0, Value::Null);
        return Value::List(vec![self.safe_integer_k(ohlcv.clone(), "t", &[]), self.safe_number_k(ohlcv.clone(), "o", &[]), self.safe_number_k(ohlcv.clone(), "h", &[]), self.safe_number_k(ohlcv.clone(), "l", &[]), self.safe_number_k(ohlcv.clone(), "c", &[]), self.safe_number_k(ohlcv.clone(), "v", &[])]);

    Value::Null
}

/*
 * @method
 * @name hashkey#watchTicker
 * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#public-stream
 * @param {string} symbol unified symbol of the market to fetch the ticker for
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @param {bool} [params.binary] true or false - default false
 * @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 topic: Value = Value::Str("realtimes".to_string());
        let mut messageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
        return self.wath_public(market.clone(), topic.clone(), messageHash.clone(), &[params.clone()]).await;

    Value::Null
}

    pub fn handle_ticker(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "symbol": "ETHUSDT",
        //         "symbolName": "ETHUSDT",
        //         "topic": "realtimes",
        //         "params": {
        //             "realtimeInterval": "24h"
        //         },
        //         "data": [
        //             {
        //                 "t": 1722864411064,
        //                 "s": "ETHUSDT",
        //                 "sn": "ETHUSDT",
        //                 "c": "2195",
        //                 "h": "2918.85",
        //                 "l": "2135.5",
        //                 "o": "2915.78",
        //                 "v": "666.5019",
        //                 "qv": "1586902.757079",
        //                 "m": "-0.2472",
        //                 "e": 301
        //             }
        //         ],
        //         "f": false,
        //         "sendTime": 1722864411086,
        //         "shared": false
        //     }
        //
        let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
        let mut ticker: Value = self.parse_ticker(self.safe_dict(data.clone(), Value::Int(0), &[]), &[]);
        let mut symbol: Value = get_value(&ticker, &Value::Str("symbol".to_string()));
        let mut messageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
        add_element_to_object(&mut self.tickers, &symbol, ticker.clone());
        client.resolve(&[get_value(&self.tickers, &symbol), messageHash.clone()]);
}

/*
 * @method
 * @name hashkey#watchTrades
 * @description watches information on multiple trades made in a market
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#public-stream
 * @param {string} symbol unified market symbol of the market trades were made in
 * @param {int} [since] the earliest time in ms to fetch orders for
 * @param {int} [limit] the maximum number of trade structures to retrieve
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @param {bool} [params.binary] true or false - default false
 * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
 */
    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 topic: Value = Value::Str("trade".to_string());
        let mut messageHash: Value = add(&Value::Str("trades:".to_string()), &symbol);
        let mut trades: Value = self.wath_public(market.clone(), topic.clone(), messageHash.clone(), &[params.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_trades(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "symbol": "ETHUSDT",
        //         "symbolName": "ETHUSDT",
        //         "topic": "trade",
        //         "params": {
        //             "realtimeInterval": "24h"
        //         },
        //         "data": [
        //             {
        //                 "v": "1745922896272048129",
        //                 "t": 1722866228075,
        //                 "p": "2340.41",
        //                 "q": "0.0132",
        //                 "m": true
        //             },
        //             ...
        //         ],
        //         "f": true,
        //         "sendTime": 1722869464248,
        //         "channelId": "668498fffeba4108-00000001-00113184-562e27d215e43f9c-c188b319",
        //         "shared": false
        //     }
        //
        let mut marketId: Value = self.safe_string_k(message.clone(), "symbol", &[]);
        let mut market: Value = self.safe_market(&[marketId.clone()]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        if !is_true(&(Value::Bool(in_op(&self.trades, &symbol)))) {
            let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
            add_element_to_object(&mut self.trades, &symbol, ArrayCache::new(limit.clone()));
        }
        let mut stored: Value = get_value(&self.trades, &symbol);
        let mut data: Value = self.safe_list_k(message.clone(), "data", &[]);
        if !is_equal(&data, &Value::Null) {
            data = self.sort_by(data.clone(), Value::Str("t".to_string()), &[]);
            {
                                let mut i: Value = Value::Int(0);
                let mut __for_first_370: bool = true;
                while { if !__for_first_370 { i = add(&i, &Value::Int(1)); } __for_first_370 = false; is_less_than(&i, &get_array_length(&data)) } {
                let mut trade: Value = self.safe_dict(data.clone(), i.clone(), &[]);
                let mut parsed: Value = self.parse_ws_trade(trade.clone(), &[market.clone()]);
                stored.append(parsed.clone());
            }
            }
        }
        let mut messageHash: Value = add(&add(&Value::Str("trades".to_string()), &Value::Str(":".to_string())), &symbol);
        client.resolve(&[stored.clone(), messageHash.clone()]);
}

/*
 * @method
 * @name hashkey#watchOrderBook
 * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#public-stream
 * @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(&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 topic: Value = Value::Str("depth".to_string());
        let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
        let mut orderbook: Value = self.wath_public(market.clone(), topic.clone(), messageHash.clone(), &[params.clone()]).await;
        return orderbook.limit();

    Value::Null
}

    pub fn handle_order_book(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "symbol": "ETHUSDT",
        //         "symbolName": "ETHUSDT",
        //         "topic": "depth",
        //         "params": { "realtimeInterval": "24h" },
        //         "data": [
        //             {
        //                 "e": 301,
        //                 "s": "ETHUSDT",
        //                 "t": 1722873144371,
        //                 "v": "84661262_18",
        //                 "b": [
        //                     [ "1650", "0.0864" ],
        //                     ...
        //                 ],
        //                 "a": [
        //                     ["4085", "0.0074" ],
        //                     ...
        //                 ],
        //                 "o": 0
        //             }
        //         ],
        //         "f": false,
        //         "sendTime": 1722873144589,
        //         "channelId": "2265aafffe68b588-00000001-0011510c-9e9ca710b1500854-551830bd",
        //         "shared": false
        //     }
        //
        let mut marketId: Value = self.safe_string_k(message.clone(), "symbol", &[]);
        let mut symbol: Value = self.safe_symbol(marketId.clone(), &[]);
        let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
        if !is_true(&(Value::Bool(in_op(&self.orderbooks, &symbol)))) {
            { let __be_tmp = self.order_book(&[Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
})]); add_element_to_object(&mut self.orderbooks, &symbol, __be_tmp); };
        }
        let mut orderbook: Value = get_value(&self.orderbooks, &symbol);
        let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
        let mut dataEntry: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
        let mut timestamp: Value = self.safe_integer_k(dataEntry.clone(), "t", &[]);
        let mut snapshot: Value = self.parse_order_book(dataEntry.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("b".to_string()), Value::Str("a".to_string())]);
        orderbook.reset(snapshot.clone());
        add_element_to_object(&mut orderbook, &Value::Str("nonce".to_string()), self.safe_integer_k(message.clone(), "id", &[]));
        add_element_to_object(&mut self.orderbooks, &symbol, orderbook.clone());
        client.resolve(&[orderbook.clone(), messageHash.clone()]);
}

/*
 * @method
 * @name hashkey#watchOrders
 * @description watches information on multiple orders made by the user
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#private-stream
 * @param {string} symbol unified market symbol of the market orders were made in
 * @param {int} [since] the earliest time in ms to fetch orders for
 * @param {int} [limit] the maximum number of order structures to retrieve
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
 */
    pub async fn watch_orders(&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
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut messageHash: Value = Value::Str("orders".to_string());
        if !is_equal(&symbol, &Value::Null) {
            symbol = self.symbol(symbol.clone());
            messageHash = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
        }
        let mut orders: Value = self.watch_private(messageHash.clone()).await;
        if is_true(&self.newUpdates) {
            limit = orders.get_limit(symbol.clone(), limit.clone());
        }
        return self.filter_by_symbol_since_limit(orders.clone(), &[symbol.clone(), since.clone(), limit.clone(), Value::Bool(true)]);

    Value::Null
}

    pub fn handle_order(&mut self, mut client: Value, mut message: Value) {
        //
        // swap
        //     {
        //         "e": "contractExecutionReport",
        //         "E": "1723037391181",
        //         "s": "ETHUSDT-PERPETUAL",
        //         "c": "1723037389677",
        //         "S": "BUY_OPEN",
        //         "o": "LIMIT",
        //         "f": "IOC",
        //         "q": "1",
        //         "p": "2561.75",
        //         "X": "FILLED",
        //         "i": "1747358716129257216",
        //         "l": "1",
        //         "z": "1",
        //         "L": "2463.36",
        //         "n": "0.001478016",
        //         "N": "USDT",
        //         "u": true,
        //         "w": true,
        //         "m": false,
        //         "O": "1723037391140",
        //         "Z": "2463.36",
        //         "C": false,
        //         "v": "5",
        //         "reqAmt": "0",
        //         "d": "1747358716255075840",
        //         "r": "0",
        //         "V": "2463.36",
        //         "P": "0",
        //         "lo": false,
        //         "lt": ""
        //     }
        //
        if is_equal(&self.orders, &Value::Null) {
            let mut limit: Value = self.safe_integer_k(self.options.clone(), "ordersLimit", &[Value::Int(1000)]);
            self.orders = ArrayCacheBySymbolById::new(limit.clone());
        }
        let mut parsed: Value = self.parse_ws_order(message.clone(), &[]);
        let mut orders: Value = self.orders.clone();
        orders.append(parsed.clone());
        let mut messageHash: Value = Value::Str("orders".to_string());
        client.resolve(&[orders.clone(), messageHash.clone()]);
        let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
        let mut symbolSpecificMessageHash: Value = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
        client.resolve(&[orders.clone(), symbolSpecificMessageHash.clone()]);
}

    pub fn parse_ws_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
        let mut market = get_arg(optional_args, 0, Value::Null);
        let mut marketId: Value = self.safe_string_k(order.clone(), "s", &[]);
        market = self.safe_market(&[marketId.clone(), market.clone()]);
        let mut timestamp: Value = self.safe_integer_k(order.clone(), "O", &[]);
        let mut side: Value = self.safe_string_lower(order.clone(), Value::Str("S".to_string()), &[]);
        let mut reduceOnly: Value = Value::Null;
        { let __destr_tmp = self.parent.parse_order_side_and_reduce_only(side.clone()); side = get_value(&__destr_tmp, &Value::Int(0)); reduceOnly = get_value(&__destr_tmp, &Value::Int(1)); }
        let mut type_var: Value = self.parent.parse_order_type(self.safe_string_k(order.clone(), "o", &[]));
        let mut timeInForce: Value = self.safe_string_k(order.clone(), "f", &[]);
        let mut postOnly: Value = Value::Null;
        { let __destr_tmp = self.parent.parse_order_type_time_in_force_and_post_only(type_var.clone(), timeInForce.clone()); type_var = get_value(&__destr_tmp, &Value::Int(0)); timeInForce = get_value(&__destr_tmp, &Value::Int(1)); postOnly = get_value(&__destr_tmp, &Value::Int(2)); }
        if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
            type_var = Value::Null;
        }
        return self.safe_order(Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("id".to_string(), self.safe_string_k(order.clone(), "i", &[]));
        m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "c", &[]));
        m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
        m.insert("timestamp".to_string(), timestamp.clone());
        m.insert("lastTradeTimestamp".to_string(), Value::Null);
        m.insert("lastUpdateTimestamp".to_string(), Value::Null);
        m.insert("status".to_string(), self.parent.parse_order_status(self.safe_string_k(order.clone(), "X", &[])));
        m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
        m.insert("type".to_string(), type_var.clone());
        m.insert("timeInForce".to_string(), timeInForce.clone());
        m.insert("side".to_string(), side.clone());
        m.insert("price".to_string(), self.safe_string_k(order.clone(), "p", &[]));
        m.insert("average".to_string(), self.safe_string_k(order.clone(), "V", &[]));
        m.insert("amount".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "q", &[])));
        m.insert("filled".to_string(), self.safe_string_k(order.clone(), "z", &[]));
        m.insert("remaining".to_string(), self.safe_string_k(order.clone(), "r", &[]));
        m.insert("stopPrice".to_string(), Value::Null);
        m.insert("triggerPrice".to_string(), Value::Null);
        m.insert("takeProfitPrice".to_string(), Value::Null);
        m.insert("stopLossPrice".to_string(), Value::Null);
        m.insert("cost".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "Z", &[])));
        m.insert("trades".to_string(), Value::Null);
        m.insert("fee".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(order.clone(), "N", &[]), &[]));
        m.insert("amount".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "n", &[])));
    m
}));
        m.insert("reduceOnly".to_string(), reduceOnly.clone());
        m.insert("postOnly".to_string(), postOnly.clone());
        m.insert("info".to_string(), order.clone());
    m
}), &[market.clone()]);

    Value::Null
}

/*
 * @method
 * @name hashkey#watchMyTrades
 * @description watches information on multiple trades made by the user
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#private-stream
 * @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
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut messageHash: Value = Value::Str("myTrades".to_string());
        if !is_equal(&symbol, &Value::Null) {
            symbol = self.symbol(symbol.clone());
            messageHash = add(&messageHash, &add(&Value::Str(":".to_string()), &symbol));
        }
        let mut trades: Value = self.watch_private(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, optional_args: &[Value]) {
        let mut subscription = get_arg(optional_args, 0, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        //
        //     {
        //         "e": "ticketInfo",
        //         "E": "1723037391156",
        //         "s": "ETHUSDT-PERPETUAL",
        //         "q": "1.00",
        //         "t": "1723037391147",
        //         "p": "2463.36",
        //         "T": "1747358716187197441",
        //         "o": "1747358716129257216",
        //         "c": "1723037389677",
        //         "a": "1735619524953226496",
        //         "m": false,
        //         "S": "BUY"
        //     }
        //
        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 tradesArray: Value = self.myTrades.clone();
        let mut parsed: Value = self.parse_ws_trade(message.clone(), &[]);
        tradesArray.append(parsed.clone());
        self.myTrades = tradesArray.clone();
        let mut messageHash: Value = Value::Str("myTrades".to_string());
        client.resolve(&[tradesArray.clone(), messageHash.clone()]);
        let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
        let mut symbolSpecificMessageHash: Value = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
        client.resolve(&[tradesArray.clone(), symbolSpecificMessageHash.clone()]);
}

    pub fn parse_ws_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
        let mut market = get_arg(optional_args, 0, Value::Null);
        //
        // watchTrades
        //     {
        //         "v": "1745922896272048129",
        //         "t": 1722866228075,
        //         "p": "2340.41",
        //         "q": "0.0132",
        //         "m": true
        //     }
        //
        // watchMyTrades
        //     {
        //         "e": "ticketInfo",
        //         "E": "1723037391156",
        //         "s": "ETHUSDT-PERPETUAL",
        //         "q": "1.00",
        //         "t": "1723037391147",
        //         "p": "2463.36",
        //         "T": "1747358716187197441",
        //         "o": "1747358716129257216",
        //         "c": "1723037389677",
        //         "a": "1735619524953226496",
        //         "m": false,
        //         "S": "BUY"
        //     }
        //
        let mut marketId: Value = self.safe_string_k(trade.clone(), "s", &[]);
        market = self.safe_market(&[marketId.clone(), market.clone()]);
        let mut timestamp: Value = self.safe_integer_k(trade.clone(), "t", &[]);
        let mut isBuyerMaker: Value = self.safe_bool_k(trade.clone(), "m", &[]);
        let mut isPublicTrade: bool = is_equal(&self.safe_string_k(trade.clone(), "e", &[]), &Value::Null);
        let mut side: Value = Value::Null;
        let mut takerOrMaker: Value = Value::Null;
        if !is_equal(&isBuyerMaker, &Value::Null) {
            if is_true(&isPublicTrade) {
                takerOrMaker = Value::Str("taker".to_string());
                side = ternary(is_true(&isBuyerMaker), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
            }  else {
                takerOrMaker = ternary(is_true(&isBuyerMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
                side = self.safe_string_lower(trade.clone(), Value::Str("S".to_string()), &[]);
            }
        }
        return self.safe_trade(Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("v".to_string()), Value::Str("T".to_string()), &[]));
        m.insert("timestamp".to_string(), timestamp.clone());
        m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
        m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
        m.insert("side".to_string(), side.clone());
        m.insert("price".to_string(), self.safe_string_k(trade.clone(), "p", &[]));
        m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "q", &[]));
        m.insert("cost".to_string(), Value::Null);
        m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
        m.insert("type".to_string(), Value::Null);
        m.insert("order".to_string(), self.safe_string_k(trade.clone(), "o", &[]));
        m.insert("fee".to_string(), Value::Null);
        m.insert("info".to_string(), trade.clone());
    m
}), &[market.clone()]);

    Value::Null
}

/*
 * @method
 * @name hashkey#watchPositions
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#private-stream
 * @description watch all open positions
 * @param {string[]} [symbols] list of unified market symbols to watch positions for
 * @param {int} [since] the earliest time in ms to fetch positions for
 * @param {int} [limit] the maximum number of positions to retrieve
 * @param {object} params extra parameters specific to the exchange API endpoint
 * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
 */
    pub async fn watch_positions(&mut self, optional_args: &[Value]) -> Value {
        let mut symbols = 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
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut listenKey: Value = self.authenticate(&[]).await;
        symbols = self.market_symbols(&[symbols.clone()]);
        let mut messageHash: Value = Value::Str("positions".to_string());
        let mut messageHashes: Value = Value::List(vec![]);
        if is_equal(&symbols, &Value::Null) {
            append_to_array(&mut messageHashes, messageHash.clone());
        }  else {
            {
                                let mut i: Value = Value::Int(0);
                let mut __for_first_371: bool = true;
                while { if !__for_first_371 { i = add(&i, &Value::Int(1)); } __for_first_371 = false; is_less_than(&i, &get_array_length(&symbols)) } {
                let mut symbol: Value = get_value(&symbols, &i);
                let mut symbol: Value = get_value(&symbols, &i);
                append_to_array(&mut messageHashes, add(&add(&messageHash, &Value::Str(":".to_string())), &symbol));
            }
            }
        }
        let mut url: Value = self.get_private_url(listenKey.clone());
        let mut positions: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[Value::Null, messageHashes.clone()]).await;
        if is_true(&self.newUpdates) {
            return positions;
        }
        return self.filter_by_symbols_since_limit(self.positions.clone(), &[symbols.clone(), since.clone(), limit.clone(), Value::Bool(true)]);

    Value::Null
}

    pub fn handle_position(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "e": "outboundContractPositionInfo",
        //         "E": "1723084699801",
        //         "A": "1735619524953226496",
        //         "s": "ETHUSDT-PERPETUAL",
        //         "S": "LONG",
        //         "p": "2429.6",
        //         "P": "2",
        //         "a": "2",
        //         "f": "10760.14",
        //         "m": "1.0085",
        //         "r": "-0.0029",
        //         "up": "0.0478",
        //         "pr": "0.0492",
        //         "pv": "4.8592",
        //         "v": "5.00",
        //         "mt": "CROSS",
        //         "mm": "0.0367"
        //     }
        //
        if is_equal(&self.positions, &Value::Null) {
            self.positions = ArrayCacheBySymbolBySide::new(Value::Null);
        }
        let mut positions: Value = self.positions.clone();
        let mut parsed: Value = self.parse_ws_position(message.clone(), &[]);
        positions.append(parsed.clone());
        let mut messageHash: Value = Value::Str("positions".to_string());
        client.resolve(&[parsed.clone(), messageHash.clone()]);
        let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
        client.resolve(&[parsed.clone(), add(&add(&messageHash, &Value::Str(":".to_string())), &symbol)]);
}

    pub fn parse_ws_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
        let mut market = get_arg(optional_args, 0, Value::Null);
        let mut marketId: Value = self.safe_string_k(position.clone(), "s", &[]);
        market = self.safe_market(&[marketId.clone()]);
        let mut timestamp: Value = self.safe_integer_k(position.clone(), "E", &[]);
        return self.safe_position(Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
        m.insert("id".to_string(), Value::Null);
        m.insert("timestamp".to_string(), timestamp.clone());
        m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
        m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "P", &[]));
        m.insert("contractSize".to_string(), Value::Null);
        m.insert("side".to_string(), self.safe_string_lower(position.clone(), Value::Str("S".to_string()), &[]));
        m.insert("notional".to_string(), self.safe_number_k(position.clone(), "pv", &[]));
        m.insert("leverage".to_string(), self.safe_integer_k(position.clone(), "v", &[]));
        m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "up", &[]));
        m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "r", &[]));
        m.insert("collateral".to_string(), Value::Null);
        m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "p", &[]));
        m.insert("markPrice".to_string(), Value::Null);
        m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "f", &[]));
        m.insert("marginMode".to_string(), self.safe_string_lower(position.clone(), Value::Str("mt".to_string()), &[]));
        m.insert("hedged".to_string(), Value::Bool(true));
        m.insert("maintenanceMargin".to_string(), self.safe_number_k(position.clone(), "mm", &[]));
        m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
        m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "m", &[]));
        m.insert("initialMarginPercentage".to_string(), Value::Null);
        m.insert("marginRatio".to_string(), Value::Null);
        m.insert("lastUpdateTimestamp".to_string(), Value::Null);
        m.insert("lastPrice".to_string(), Value::Null);
        m.insert("stopLossPrice".to_string(), Value::Null);
        m.insert("takeProfitPrice".to_string(), Value::Null);
        m.insert("percentage".to_string(), Value::Null);
        m.insert("info".to_string(), position.clone());
    m
}));

    Value::Null
}

/*
 * @method
 * @name hashkey#watchBalance
 * @description watch balance and get the amount of funds available for trading or funds locked in orders
 * @see https://hashkeyglobal-apidoc.readme.io/reference/websocket-api#private-stream
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @param {string} [params.type] 'spot' or 'swap' - the type of the market to watch balance for (default 'spot')
 * @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
}));
        let mut listenKey: Value = self.authenticate(&[]).await;
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut type_var: Value = Value::Str("spot".to_string());
        { let __destr_tmp = self.handle_market_type_and_params(Value::Str("watchBalance".to_string()), &[Value::Null, params.clone(), type_var.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
        let mut messageHash: Value = add(&Value::Str("balance:".to_string()), &type_var);
        let mut url: Value = self.get_private_url(listenKey.clone());
        let mut client: Value = self.client(&[url.clone()]);
        self.set_balance_cache(client.clone(), type_var.clone(), messageHash.clone());
        let mut fetchBalanceSnapshot: Value = Value::Null;
        let mut awaitBalanceSnapshot: Value = Value::Null;
        { let __destr_tmp = self.handle_option_and_params(self.options.clone(), Value::Str("watchBalance".to_string()), Value::Str("fetchBalanceSnapshot".to_string()), &[Value::Bool(true)]); fetchBalanceSnapshot = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
        { let __destr_tmp = self.handle_option_and_params(self.options.clone(), Value::Str("watchBalance".to_string()), Value::Str("awaitBalanceSnapshot".to_string()), &[Value::Bool(false)]); awaitBalanceSnapshot = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
        if is_true(&fetchBalanceSnapshot) && is_true(&awaitBalanceSnapshot) {
            crate::exchange_stubs::ws_await_flight(&client.future(&[add(&type_var, &Value::Str(":fetchBalanceSnapshot".to_string()))])).await;
        }
        return self.watch(url.clone(), messageHash.clone(), &[Value::Null, messageHash.clone()]).await;

    Value::Null
}

    pub fn set_balance_cache(&mut self, mut client: Value, mut type_var: Value, mut subscribeHash: Value) {
        if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &subscribeHash))) {
            return;
        }
        let mut options: Value = self.safe_dict_k(self.options.clone(), "watchBalance", &[]);
        let mut snapshot: Value = self.safe_bool_k(options.clone(), "fetchBalanceSnapshot", &[Value::Bool(true)]);
        if is_equal(&snapshot, &Value::Bool(true)) {
            let mut messageHash: Value = add(&add(&type_var, &Value::Str(":".to_string())), &Value::Str("fetchBalanceSnapshot".to_string()));
            if !is_true(&(Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &messageHash)))) {
                client.future(&[messageHash.clone()]);
                self.spawn(&[Value::Str("load_balance_snapshot".to_string()).clone(), client.clone(), messageHash.clone(), type_var.clone()]);
            }
        }
        add_element_to_object(&mut self.balance, &type_var, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
}

    pub async fn load_balance_snapshot(&mut self, mut client: Value, mut messageHash: Value, mut type_var: Value) -> Value {
        let mut response: Value = self.fetch_balance(&[Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("type".to_string(), type_var.clone());
            m
        })]).await;
        let __ws_arg_1 = self.safe_value(self.balance.clone(), type_var.clone(), &[Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
})]);
        { let __be_tmp = self.extend(response.clone(), &[__ws_arg_1]); add_element_to_object(&mut self.balance, &type_var, __be_tmp); };
        // don't remove the future from the .futures cache
        if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &messageHash))) {
            let mut future: Value = get_value(&get_value(&client, &Value::Str("futures".to_string())), &messageHash);
            future.resolve(&[]);
            client.resolve(&[get_value(&self.balance, &type_var), add(&Value::Str("balance:".to_string()), &type_var)]);
        }

    Value::Null
}

    pub fn handle_balance(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "e": "outboundContractAccountInfo",        // event type
        //                                                    // outboundContractAccountInfo
        //         "E": "1714717314118",                      // event time
        //         "T": true,                                 // can trade
        //         "W": true,                                 // can withdraw
        //         "D": true,                                 // can deposit
        //         "B": [                                     // balances changed
        //             {
        //                 "a": "USDT",                       // asset
        //                 "f": "474960.65",                  // free amount
        //                 "l": "24835.178056020383226869",   // locked amount
        //                 "r": ""                            // to be released
        //             }
        //         ]
        //     }
        //
        let mut event: Value = self.safe_string_k(message.clone(), "e", &[]);
        let mut data: Value = self.safe_list_k(message.clone(), "B", &[Value::List(vec![])]);
        let mut balanceUpdate: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
        let mut isSpot: bool = is_equal(&event, &Value::Str("outboundAccountInfo".to_string()));
        let mut type_var: Value = ternary(is_true(&isSpot), Value::Str("spot".to_string()), Value::Str("swap".to_string()));
        if !is_true(&(Value::Bool(in_op(&self.balance, &type_var)))) {
            add_element_to_object(&mut self.balance, &type_var, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        }
        add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.balance) }, &type_var), &Value::Str("info".to_string()), message.clone());
        let mut currencyId: Value = self.safe_string_k(balanceUpdate.clone(), "a", &[]);
        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(balanceUpdate.clone(), "f", &[]));
        add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balanceUpdate.clone(), "l", &[]));
        if is_true(&(!is_equal(&type_var, &Value::Null))) && is_true(&(!is_equal(&code, &Value::Null))) {
            add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.balance) }, &type_var), &code, account.clone());
        }
        { let __be_tmp = self.safe_balance(get_value(&self.balance, &type_var)); add_element_to_object(&mut self.balance, &type_var, __be_tmp); };
        let mut messageHash: Value = add(&Value::Str("balance:".to_string()), &type_var);
        client.resolve(&[get_value(&self.balance, &type_var), messageHash.clone()]);
}

    pub async fn authenticate(&mut self, optional_args: &[Value]) -> Value {
        let mut params = get_arg(optional_args, 0, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        let mut listenKey: Value = self.safe_string_k(self.options.clone(), "listenKey", &[]);
        if !is_equal(&listenKey, &Value::Null) {
            return listenKey;
        }
        // single-flight leader election on a never-dialed client, see
        // https://github.com/ccxt/ccxt/issues/29393: racing cold callers each
        // mint their own listenKey and each schedules its own
        // keepAliveListenKey timer, and the key rides the private url built by
        // getPrivateUrl (), so every loser dials .../ws/<orphaned-key> and its
        // subscriptions never deliver. the flight is registered in
        // client.futures and settled through client.resolve () /
        // client.reject (), so every mutation of the futures map goes through
        // the client's own accessors
        let mut messageHash: Value = Value::Str("authenticateFlight".to_string());
        let mut client: Value = self.client(&[Value::Str("authenticationFlights".to_string())]);
        if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &messageHash))) {
            // a flight is already in progress - wake when the leader
            // settles it: the listenKey is then in the bucket
            crate::exchange_stubs::ws_await_flight(&client.future(&[messageHash.clone()])).await;
            return self.safe_string_k(self.options.clone(), "listenKey", &[]);
        }
        // register the flight BEFORE the first await, so a caller arriving
        // during the fetch below finds it and waits instead of re-leading
        let mut future: Value = client.reusable_future(messageHash.clone());
        let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
            let mut response: Value = self.parent.private_post_api_v1_user_data_stream(&[params.clone()]).await;
            //
            //    {
            //        "listenKey": "atbNEcWnBqnmgkfmYQeTuxKTpTStlZzgoPLJsZhzAOZTbAlxbHqGNWiYaUQzMtDz"
            //    }
            //
            listenKey = self.safe_string_k(response.clone(), "listenKey", &[]);
            if is_equal(&listenKey, &Value::Null) {
                panic!("{}", crate::exchange_errors::authentication_error(add(&self.id, &Value::Str(" authenticate() received an empty listenKey".to_string()))));
            }
            add_element_to_object(&mut self.options, &Value::Str("listenKey".to_string()), listenKey.clone());
            let mut listenKeyRefreshRate: Value = self.safe_integer_k(self.options.clone(), "listenKeyRefreshRate", &[Value::Int(3600000)]);
            self.delay(listenKeyRefreshRate.clone(), &[Value::Str("keep_alive_listen_key".to_string()).clone(), listenKey.clone(), params.clone()]).await;
            // settle the flight: client.resolve () wakes every waiter and
            // drops the future from the map
            client.resolve(&[listenKey.clone(), messageHash.clone()]);
         #[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
            // reject the flight - all waiters throw and the next caller
            // re-leads instead of deadlocking on a dead flight
            client.reject(&[e.clone(), messageHash.clone()]);
        }
        // rethrows the failure to the leader and attaches the handler that
        // keeps an alone-leader rejection from crashing the process
        crate::exchange_stubs::ws_await_flight(&future).await;
        return listenKey;

    Value::Null
}

    pub async fn keep_alive_listen_key(&mut self, mut listenKey: 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(&listenKey, &Value::Null) {
            return Value::Null;
        }
        let mut request: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("listenKey".to_string(), listenKey.clone());
            m
        });
        let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
            let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
            self.parent.private_put_api_v1_user_data_stream(&[__ws_arg_2]).await;
            let mut listenKeyRefreshRate: Value = self.safe_integer_k(self.options.clone(), "listenKeyRefreshRate", &[Value::Int(1200000)]);
            self.delay(listenKeyRefreshRate.clone(), &[Value::Str("keep_alive_listen_key".to_string()).clone(), listenKey.clone(), params.clone()]).await;
         #[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let error: Value = panic_to_value(_try_err);
            let mut url: Value = self.get_private_url(listenKey.clone());
            let mut client: Value = self.client(&[url.clone()]);
            add_element_to_object(&mut self.options, &Value::Str("listenKey".to_string()), Value::Null);
            client.reject(&[Value::from(error.clone())]);
            remove(&mut self.clients, &url);
        }

    Value::Null
}

    pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
        if is_true(&Value::Bool(is_array(&message))) {
            message = self.safe_dict(message.clone(), Value::Int(0), &[Value::Map({
                let mut m = indexmap::IndexMap::new();
                m
            })]);
        }
        let mut topic: Value = self.safe_string2(message.clone(), Value::Str("topic".to_string()), Value::Str("e".to_string()), &[]);
        if is_equal(&topic, &Value::Str("kline".to_string())) {
            self.handle_ohlcv(client.clone(), message.clone());
        }  else if is_equal(&topic, &Value::Str("realtimes".to_string())) {
            self.handle_ticker(client.clone(), message.clone());
        }  else if is_equal(&topic, &Value::Str("trade".to_string())) {
            self.handle_trades(client.clone(), message.clone());
        }  else if is_equal(&topic, &Value::Str("depth".to_string())) {
            self.handle_order_book(client.clone(), message.clone());
        }  else if is_true(&(is_equal(&topic, &Value::Str("contractExecutionReport".to_string())))) || is_true(&(is_equal(&topic, &Value::Str("executionReport".to_string())))) {
            self.handle_order(client.clone(), message.clone());
        }  else if is_equal(&topic, &Value::Str("ticketInfo".to_string())) {
            self.handle_my_trade(client.clone(), message.clone(), &[]);
        }  else if is_equal(&topic, &Value::Str("outboundContractPositionInfo".to_string())) {
            self.handle_position(client.clone(), message.clone());
        }  else if is_true(&(is_equal(&topic, &Value::Str("outboundAccountInfo".to_string())))) || is_true(&(is_equal(&topic, &Value::Str("outboundContractAccountInfo".to_string())))) {
            self.handle_balance(client.clone(), message.clone());
        }
}
}