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
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
// 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 GeminiCore {
    pub parent: crate::exchanges::gemini::GeminiCore,
}

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

    pub fn init(&mut self) {
        let described = GeminiCore::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 GeminiCore {
    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 GeminiCore {
    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,
                "handle_heartbeat" => self.handle_heartbeat(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).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 },
                "handle_ohlcv" => self.handle_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
                "handle_subscription" => self.handle_subscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
                "helper_for_watch_multiple_construct" => self.helper_for_watch_multiple_construct(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                "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_order_status" => self.parse_ws_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
                "parse_ws_order_type" => self.parse_ws_order_type(args.get(0).cloned().unwrap_or(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_bids_asks" => self.watch_bids_asks(&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_order_book_for_symbols" => self.watch_order_book_for_symbols(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_trades" => self.watch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_trades_for_symbols" => self.watch_trades_for_symbols(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 GeminiCore {
    /// 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 },
            "handle_bids_asks_for_multidata" => { self.handle_bids_asks_for_multidata(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).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_error" => { self.handle_error(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_heartbeat" => self.handle_heartbeat(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
            "handle_l2_updates" => { self.handle_l2_updates(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_ohlcv" => self.handle_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(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_order_book_for_multidata" => { self.handle_order_book_for_multidata(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).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
            "handle_subscription" => self.handle_subscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(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 },
            "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 },
            "handle_trades_for_multidata" => { self.handle_trades_for_multidata(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 },
            "helper_for_watch_multiple_construct" => { crate::exchange_stubs::enqueue_spawn("helper_for_watch_multiple_construct", args.to_vec()); crate::Value::Null },
            "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_order_status" => self.parse_ws_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
            "parse_ws_order_type" => self.parse_ws_order_type(args.get(0).cloned().unwrap_or(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_bids_asks" => { crate::exchange_stubs::enqueue_spawn("watch_bids_asks", 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_order_book_for_symbols" => { crate::exchange_stubs::enqueue_spawn("watch_order_book_for_symbols", args.to_vec()); crate::Value::Null },
            "watch_orders" => { crate::exchange_stubs::enqueue_spawn("watch_orders", args.to_vec()); crate::Value::Null },
            "watch_trades" => { crate::exchange_stubs::enqueue_spawn("watch_trades", args.to_vec()); crate::Value::Null },
            "watch_trades_for_symbols" => { crate::exchange_stubs::enqueue_spawn("watch_trades_for_symbols", args.to_vec()); crate::Value::Null },
            _ => crate::Value::Null,
        }
    }
}

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

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

impl GeminiCore {
    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(false));
        m.insert("watchTicker".to_string(), Value::Bool(false));
        m.insert("watchTickers".to_string(), Value::Bool(false));
        m.insert("watchBidsAsks".to_string(), Value::Bool(true));
        m.insert("watchTrades".to_string(), Value::Bool(true));
        m.insert("watchTradesForSymbols".to_string(), Value::Bool(true));
        m.insert("watchMyTrades".to_string(), Value::Bool(false));
        m.insert("watchOrders".to_string(), Value::Bool(true));
        m.insert("watchOrderBook".to_string(), Value::Bool(true));
        m.insert("watchOrderBookForSymbols".to_string(), Value::Bool(true));
        m.insert("watchOHLCV".to_string(), Value::Bool(true));
    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::Str("wss://api.gemini.com".to_string()));
    m
}));
        m.insert("test".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("ws".to_string(), Value::Str("wss://api.sandbox.gemini.com".to_string()));
    m
}));
    m
}));
    m
})]);

    Value::Null
}

/*
 * @method
 * @name gemini#watchTrades
 * @description watch the list of most recent trades for a particular symbol
 * @see https://docs.gemini.com/websocket-api/#market-data-version-2
 * @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());
        let mut messageHash: Value = add(&Value::Str("trades:".to_string()), &get_value(&market, &Value::Str("symbol".to_string())));
        let mut marketId: Value = get_value(&market, &Value::Str("id".to_string()));
        if is_equal(&marketId, &Value::Null) {
            panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchTrades() marketId is required".to_string()))));
        }
        let mut request: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("type".to_string(), Value::Str("subscribe".to_string()));
                m.insert("subscriptions".to_string(), Value::List(vec![Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("name".to_string(), Value::Str("l2".to_string()));
        m.insert("symbols".to_string(), Value::List(vec![to_upper(&marketId)]));
    m
})]));
            m
        });
        let mut subscribeHash: Value = add(&Value::Str("l2:".to_string()), &get_value(&market, &Value::Str("symbol".to_string())));
        let mut url: Value = add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("/v2/marketdata".to_string()));
        let mut trades: Value = self.watch(url.clone(), messageHash.clone(), &[request.clone(), subscribeHash.clone()]).await;
        if is_true(&self.newUpdates) {
            limit = trades.get_limit(get_value(&market, &Value::Str("symbol".to_string())), limit.clone());
        }
        return self.filter_by_since_limit(trades.clone(), &[since.clone(), limit.clone(), Value::Str("timestamp".to_string()), Value::Bool(true)]);

    Value::Null
}

/*
 * @method
 * @name gemini#watchTradesForSymbols
 * @see https://docs.gemini.com/websocket-api/#multi-market-data
 * @description get the list of most recent trades for a list of symbols
 * @param {string[]} symbols 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_for_symbols(&mut self, mut symbols: 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
}));
        let mut trades: Value = self.helper_for_watch_multiple_construct(Value::Str("trades".to_string()), &[symbols.clone(), params.clone()]).await;
        if is_true(&self.newUpdates) {
            let mut first: Value = self.safe_list(trades.clone(), Value::Int(0), &[]);
            let mut tradeSymbol: Value = self.safe_string_k(first.clone(), "symbol", &[]);
            limit = trades.get_limit(tradeSymbol.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 parse_ws_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
        let mut market = get_arg(optional_args, 0, Value::Null);
        //
        // regular v2 trade
        //
        //     {
        //         "type": "trade",
        //         "symbol": "BTCUSD",
        //         "event_id": 122258166738,
        //         "timestamp": 1655330221424,
        //         "price": "22269.14",
        //         "quantity": "0.00004473",
        //         "side": "buy"
        //     }
        //
        // multi data trade
        //
        //    {
        //        "type": "trade",
        //        "symbol": "ETHUSD",
        //        "tid": "1683002242170204", // this is not TS, but somewhat ID
        //        "price": "2299.24",
        //        "amount": "0.002662",
        //        "makerSide": "bid"
        //    }
        //
        let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
        let mut id: Value = self.safe_string2(trade.clone(), Value::Str("event_id".to_string()), Value::Str("tid".to_string()), &[]);
        let mut priceString: Value = self.safe_string_k(trade.clone(), "price", &[]);
        let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("quantity".to_string()), Value::Str("amount".to_string()), &[]);
        let mut side: Value = self.safe_string_lower(trade.clone(), Value::Str("side".to_string()), &[]);
        if is_equal(&side, &Value::Null) {
            let mut marketSide: Value = self.safe_string_lower(trade.clone(), Value::Str("makerSide".to_string()), &[]);
            if is_equal(&marketSide, &Value::Str("bid".to_string())) {
                side = Value::Str("sell".to_string());
            }  else if is_equal(&marketSide, &Value::Str("ask".to_string())) {
                side = Value::Str("buy".to_string());
            }
        }
        let mut marketId: Value = self.safe_string_lower(trade.clone(), Value::Str("symbol".to_string()), &[]);
        let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
        return self.safe_trade(Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("id".to_string(), id.clone());
        m.insert("order".to_string(), Value::Null);
        m.insert("info".to_string(), trade.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("type".to_string(), Value::Null);
        m.insert("side".to_string(), side.clone());
        m.insert("takerOrMaker".to_string(), Value::Null);
        m.insert("price".to_string(), priceString.clone());
        m.insert("cost".to_string(), Value::Null);
        m.insert("amount".to_string(), amountString.clone());
        m.insert("fee".to_string(), Value::Null);
    m
}), &[market.clone()]);

    Value::Null
}

    pub fn handle_trade(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "type": "trade",
        //         "symbol": "BTCUSD",
        //         "event_id": 122278173770,
        //         "timestamp": 1655335880981,
        //         "price": "22530.80",
        //         "quantity": "0.04",
        //         "side": "buy"
        //     }
        //
        let mut trade: Value = self.parse_ws_trade(message.clone(), &[]);
        let mut symbol: Value = get_value(&trade, &Value::Str("symbol".to_string()));
        let mut tradesLimit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
        let mut stored: Value = self.safe_value(self.trades.clone(), symbol.clone(), &[]);
        if is_equal(&stored, &Value::Null) {
            stored = ArrayCache::new(tradesLimit.clone());
            if !is_equal(&symbol, &Value::Null) {
                add_element_to_object(&mut self.trades, &symbol, stored.clone());
            }
        }
        stored.append(trade.clone());
        let mut messageHash: Value = add(&Value::Str("trades:".to_string()), &symbol);
        client.resolve(&[stored.clone(), messageHash.clone()]);
}

    pub fn handle_trades(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "type": "l2_updates",
        //         "symbol": "BTCUSD",
        //         "changes": [
        //             [ "buy", '22252.37', "0.02" ],
        //             [ "buy", '22251.61', "0.04" ],
        //             [ "buy", '22251.60', "0.04" ],
        //             // some asks as well
        //         ],
        //         "trades": [
        //             { type: 'trade', symbol: 'BTCUSD', event_id: 122258166738, timestamp: 1655330221424, price: '22269.14', quantity: "0.00004473", side: "buy" },
        //             { type: 'trade', symbol: 'BTCUSD', event_id: 122258141090, timestamp: 1655330213216, price: '22250.00', quantity: "0.00704098", side: "buy" },
        //             { type: 'trade', symbol: 'BTCUSD', event_id: 122258118291, timestamp: 1655330206753, price: '22250.00', quantity: "0.03", side: "buy" },
        //         ],
        //         "auction_events": [
        //             {
        //                 "type": "auction_result",
        //                 "symbol": "BTCUSD",
        //                 "time_ms": 1655323200000,
        //                 "result": "failure",
        //                 "highest_bid_price": "21590.88",
        //                 "lowest_ask_price": "21602.30",
        //                 "collar_price": "21634.73"
        //             },
        //             {
        //                 "type": "auction_indicative",
        //                 "symbol": "BTCUSD",
        //                 "time_ms": 1655323185000,
        //                 "result": "failure",
        //                 "highest_bid_price": "21661.90",
        //                 "lowest_ask_price": "21663.78",
        //                 "collar_price": "21662.845"
        //             },
        //         ]
        //     }
        //
        let mut marketId: Value = self.safe_string_lower(message.clone(), Value::Str("symbol".to_string()), &[]);
        let mut market: Value = self.safe_market(&[marketId.clone()]);
        let mut trades: Value = self.safe_value_k(message.clone(), "trades", &[]);
        if !is_equal(&trades, &Value::Null) {
            let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
            let mut tradesLimit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
            let mut stored: Value = self.safe_value(self.trades.clone(), symbol.clone(), &[]);
            if is_equal(&stored, &Value::Null) {
                stored = ArrayCache::new(tradesLimit.clone());
                add_element_to_object(&mut self.trades, &symbol, stored.clone());
            }
            {
                                let mut i: Value = Value::Int(0);
                let mut __for_first_354: bool = true;
                while { if !__for_first_354 { i = add(&i, &Value::Int(1)); } __for_first_354 = false; is_less_than(&i, &get_array_length(&trades)) } {
                let mut trade: Value = self.parse_ws_trade(get_value(&trades, &i), &[market.clone()]);
                stored.append(trade.clone());
            }
            }
            let mut messageHash: Value = add(&Value::Str("trades:".to_string()), &symbol);
            client.resolve(&[stored.clone(), messageHash.clone()]);
        }
}

    pub fn handle_trades_for_multidata(&mut self, mut client: Value, mut trades: Value, mut timestamp: Value) {
        if !is_equal(&trades, &Value::Null) {
            let mut tradesLimit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
            let mut storesForSymbols: Value = Value::Map({
                let mut m = indexmap::IndexMap::new();
                m
            });
            {
                                let mut i: Value = Value::Int(0);
                let mut __for_first_355: bool = true;
                while { if !__for_first_355 { i = add(&i, &Value::Int(1)); } __for_first_355 = false; is_less_than(&i, &get_array_length(&trades)) } {
                let mut marketId: Value = get_value(&get_value(&trades, &i), &Value::Str("symbol".to_string()));
                let mut market: Value = self.safe_market(&[to_lower(&marketId)]);
                let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
                let mut trade: Value = self.parse_ws_trade(get_value(&trades, &i), &[market.clone()]);
                add_element_to_object(&mut trade, &Value::Str("timestamp".to_string()), timestamp.clone());
                add_element_to_object(&mut trade, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
                let mut stored: Value = self.safe_value(self.trades.clone(), symbol.clone(), &[]);
                if is_equal(&stored, &Value::Null) {
                    stored = ArrayCache::new(tradesLimit.clone());
                    add_element_to_object(&mut self.trades, &symbol, stored.clone());
                }
                stored.append(trade.clone());
                add_element_to_object(&mut storesForSymbols, &symbol, stored.clone());
            }
            }
            let mut symbols: Value = object_keys(&storesForSymbols);
            {
                                let mut i: Value = Value::Int(0);
                let mut __for_first_356: bool = true;
                while { if !__for_first_356 { i = add(&i, &Value::Int(1)); } __for_first_356 = 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);
                let mut stored: Value = get_value(&storesForSymbols, &symbol);
                let mut stored: Value = get_value(&storesForSymbols, &symbol);
                let mut messageHash: Value = add(&Value::Str("trades:".to_string()), &symbol);
                client.resolve(&[stored.clone(), messageHash.clone()]);
            }
            }
        }
}

/*
 * @method
 * @name gemini#watchOHLCV
 * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
 * @see https://docs.gemini.com/websocket-api/#candles-data-feed
 * @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
 * @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());
        let mut timeframeId: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
        let mut request: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("type".to_string(), Value::Str("subscribe".to_string()));
                m.insert("subscriptions".to_string(), Value::List(vec![Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("name".to_string(), add(&Value::Str("candles_".to_string()), &timeframeId));
        m.insert("symbols".to_string(), Value::List(vec![self.safe_string_upper(market.clone(), Value::Str("id".to_string()), &[])]));
    m
})]));
            m
        });
        let mut messageHash: Value = add(&add(&add(&Value::Str("ohlcv:".to_string()), &get_value(&market, &Value::Str("symbol".to_string()))), &Value::Str(":".to_string())), &timeframeId);
        let mut url: Value = add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("/v2/marketdata".to_string()));
        let mut ohlcv: Value = self.watch(url.clone(), messageHash.clone(), &[request.clone(), messageHash.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) -> Value {
        //
        //     {
        //         "type": "candles_15m_updates",
        //         "symbol": "BTCUSD",
        //         "changes": [
        //             [
        //                 1561054500000,
        //                 9350.18,
        //                 9358.35,
        //                 9350.18,
        //                 9355.51,
        //                 2.07
        //             ],
        //             [
        //                 1561053600000,
        //                 9357.33,
        //                 9357.33,
        //                 9350.18,
        //                 9350.18,
        //                 1.5900161
        //             ]
        //             ...
        //         ]
        //     }
        //
        let mut type_var: Value = self.safe_string_k(message.clone(), "type", &[Value::Str("".to_string())]);
        let mut timeframeId: Value = slice(&type_var, &Value::Int(8), &Value::Null);
        let mut timeframeEndIndex: Value = get_index_of(&timeframeId, &Value::Str("_".to_string()));
        timeframeId = slice(&timeframeId, &Value::Int(0), &timeframeEndIndex);
        let mut marketId: Value = to_lower(&self.safe_string_k(message.clone(), "symbol", &[Value::Str("".to_string())]));
        let mut market: Value = self.safe_market(&[marketId.clone()]);
        let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
        let mut changes: Value = self.safe_value_k(message.clone(), "changes", &[Value::List(vec![])]);
        let mut timeframe: Value = self.find_timeframe(timeframeId.clone(), &[]);
        let mut ohlcvsBySymbol: Value = self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[]);
        if is_equal(&ohlcvsBySymbol, &Value::Null) {
            add_element_to_object(&mut self.ohlcvs, &symbol, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        }
        let mut stored: Value = self.safe_value(self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[]), timeframe.clone(), &[]);
        if is_equal(&stored, &Value::Null) {
            let mut limit: Value = self.safe_integer_k(self.options.clone(), "OHLCVLimit", &[Value::Int(1000)]);
            stored = ArrayCacheByTimestamp::new(limit.clone());
            if !is_equal(&symbol, &Value::Null) && !is_equal(&timeframe, &Value::Null) {
                add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.ohlcvs) }, &symbol), &timeframe, stored.clone());
            }
        }
        let mut changesLength: Value = get_array_length(&changes);
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_357: bool = true;
            while { if !__for_first_357 { i = add(&i, &Value::Int(1)); } __for_first_357 = false; is_less_than(&i, &changesLength) } {
            let mut index: Value = subtract(&subtract(&changesLength, &i), &Value::Int(1));
            let mut parsed: Value = self.parse_ohlcv(get_value(&changes, &index), &[market.clone()]);
            stored.append(parsed.clone());
        }
        }
        let mut messageHash: Value = add(&add(&add(&Value::Str("ohlcv:".to_string()), &symbol), &Value::Str(":".to_string())), &timeframeId);
        client.resolve(&[stored.clone(), messageHash.clone()]);
        return message;

    Value::Null
}

/*
 * @method
 * @name gemini#watchOrderBook
 * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
 * @see https://docs.gemini.com/websocket-api/#market-data-version-2
 * @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());
        let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &get_value(&market, &Value::Str("symbol".to_string())));
        let mut marketId: Value = get_value(&market, &Value::Str("id".to_string()));
        if is_equal(&marketId, &Value::Null) {
            panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchOrderBook() marketId is required".to_string()))));
        }
        let mut request: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("type".to_string(), Value::Str("subscribe".to_string()));
                m.insert("subscriptions".to_string(), Value::List(vec![Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("name".to_string(), Value::Str("l2".to_string()));
        m.insert("symbols".to_string(), Value::List(vec![to_upper(&marketId)]));
    m
})]));
            m
        });
        let mut subscribeHash: Value = add(&Value::Str("l2:".to_string()), &get_value(&market, &Value::Str("symbol".to_string())));
        let mut url: Value = add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("/v2/marketdata".to_string()));
        let mut orderbook: Value = self.watch(url.clone(), messageHash.clone(), &[request.clone(), subscribeHash.clone()]).await;
        return orderbook.limit();

    Value::Null
}

    pub fn handle_order_book(&mut self, mut client: Value, mut message: Value) {
        let mut isInitial: bool = is_true(&(Value::Bool(in_op(&message, &Value::Str("auction_events".to_string()))))) && is_true(&(Value::Bool(in_op(&message, &Value::Str("trades".to_string()))))) && is_true(&(Value::Bool(in_op(&message, &Value::Str("changes".to_string())))));
        let mut changes: Value = self.safe_value_k(message.clone(), "changes", &[Value::List(vec![])]);
        let mut marketId: Value = self.safe_string_lower(message.clone(), Value::Str("symbol".to_string()), &[]);
        let mut market: Value = self.safe_market(&[marketId.clone()]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
        // let orderbook = this.safeValue (this.orderbooks, symbol);
        if !is_true(&(Value::Bool(in_op(&self.orderbooks, &symbol)))) {
            { let __be_tmp = self.order_book(&[]); add_element_to_object(&mut self.orderbooks, &symbol, __be_tmp); };
        }  else if is_true(&isInitial) {
            // handle https://github.com/ccxt/ccxt/issues/29210
            if is_true(&Value::Bool(in_op(&self.orderbooks, &symbol))) {
                remove(&mut self.orderbooks, &symbol);
            }
            { let __be_tmp = self.order_book(&[]); add_element_to_object(&mut self.orderbooks, &symbol, __be_tmp); };
        }
        let mut orderbook: Value = get_value(&self.orderbooks, &symbol);
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_358: bool = true;
            while { if !__for_first_358 { i = add(&i, &Value::Int(1)); } __for_first_358 = false; is_less_than(&i, &get_array_length(&changes)) } {
            let mut delta: Value = get_value(&changes, &i);
            let mut delta: Value = get_value(&changes, &i);
            let mut price: Value = self.safe_number(delta.clone(), Value::Int(1), &[]);
            let mut size: Value = self.safe_number(delta.clone(), Value::Int(2), &[]);
            let mut side: Value = ternary(is_true(&(is_equal(&get_value(&delta, &Value::Int(0)), &Value::Str("buy".to_string())))), Value::Str("bids".to_string()), Value::Str("asks".to_string()));
            let mut bookside: Value = get_value(&orderbook, &side);
            let mut bookside: Value = get_value(&orderbook, &side);
            bookside.store(price.clone(), size.clone());
            add_element_to_object(&mut orderbook, &side, bookside.clone());
        }
        }
        add_element_to_object(&mut orderbook, &Value::Str("symbol".to_string()), symbol.clone());
        add_element_to_object(&mut self.orderbooks, &symbol, orderbook.clone());
        client.resolve(&[orderbook.clone(), messageHash.clone()]);
}

/*
 * @method
 * @name gemini#watchOrderBookForSymbols
 * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
 * @see https://docs.gemini.com/websocket-api/#multi-market-data
 * @param {string[]} symbols unified array of symbols
 * @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_for_symbols(&mut self, mut symbols: 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
}));
        let mut orderbook: Value = self.helper_for_watch_multiple_construct(Value::Str("orderbook".to_string()), &[symbols.clone(), params.clone()]).await;
        return orderbook.limit();

    Value::Null
}

/*
 * @method
 * @name gemini#watchBidsAsks
 * @description watches best bid & ask for symbols
 * @see https://docs.gemini.com/websocket-api/#multi-market-data
 * @param {string[]} symbols 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_bids_asks(&mut self, optional_args: &[Value]) -> Value {
        let mut symbols = get_arg(optional_args, 0, Value::Null);
        let mut params = get_arg(optional_args, 1, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        return self.helper_for_watch_multiple_construct(Value::Str("bidsasks".to_string()), &[symbols.clone(), params.clone()]).await;

    Value::Null
}

    pub fn handle_bids_asks_for_multidata(&mut self, mut client: Value, mut rawBidAskChanges: Value, mut timestamp: Value, mut nonce: Value) {
        //
        // {
        //     eventId: '1683002916916153',
        //     events: [
        //       {
        //         price: '50945.37',
        //         reason: 'top-of-book',
        //         remaining: '0.0',
        //         side: 'bid',
        //         symbol: 'BTCUSDT',
        //         type: 'change'
        //       },
        //       {
        //         price: '50947.75',
        //         reason: 'top-of-book',
        //         remaining: '0.11725',
        //         side: 'bid',
        //         symbol: 'BTCUSDT',
        //         type: 'change'
        //       }
        //     ],
        //     socket_sequence: 322,
        //     timestamp: 1708674495,
        //     timestampms: 1708674495174,
        //     type: 'update'
        // }
        //
        let mut marketId: Value = get_value(&get_value(&rawBidAskChanges, &Value::Int(0)), &Value::Str("symbol".to_string()));
        let mut market: Value = self.safe_market(&[to_lower(&marketId)]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        if !is_true(&(Value::Bool(in_op(&self.bidsasks, &symbol)))) {
            { let __be_tmp = self.parse_ticker(Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}), &[]); add_element_to_object(&mut self.bidsasks, &symbol, __be_tmp); };
            add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.bidsasks) }, &symbol), &Value::Str("symbol".to_string()), symbol.clone());
        }
        let mut currentBidAsk: Value = get_value(&self.bidsasks, &symbol);
        let mut messageHash: Value = add(&Value::Str("bidsasks:".to_string()), &symbol);
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_359: bool = true;
            while { if !__for_first_359 { i = add(&i, &Value::Int(1)); } __for_first_359 = false; is_less_than(&i, &get_array_length(&rawBidAskChanges)) } {
            let mut entry: Value = get_value(&rawBidAskChanges, &i);
            let mut entry: Value = get_value(&rawBidAskChanges, &i);
            let mut rawSide: Value = self.safe_string_k(entry.clone(), "side", &[]);
            let mut price: Value = self.safe_number_k(entry.clone(), "price", &[]);
            let mut sizeString: Value = self.safe_string_k(entry.clone(), "remaining", &[]);
            if is_true(&crate::precise::Precise::stringEq(&sizeString, &Value::Str("0".to_string()))) {
                continue;
            }
            let mut size: Value = self.parse_number(sizeString.clone(), &[]);
            if is_equal(&rawSide, &Value::Str("bid".to_string())) {
                add_element_to_object(&mut currentBidAsk, &Value::Str("bid".to_string()), price.clone());
                add_element_to_object(&mut currentBidAsk, &Value::Str("bidVolume".to_string()), size.clone());
            }  else {
                add_element_to_object(&mut currentBidAsk, &Value::Str("ask".to_string()), price.clone());
                add_element_to_object(&mut currentBidAsk, &Value::Str("askVolume".to_string()), size.clone());
            }
        }
        }
        add_element_to_object(&mut currentBidAsk, &Value::Str("timestamp".to_string()), timestamp.clone());
        add_element_to_object(&mut currentBidAsk, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
        add_element_to_object(&mut currentBidAsk, &Value::Str("info".to_string()), rawBidAskChanges.clone());
        let mut bidsAsksDict: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        });
        add_element_to_object(&mut bidsAsksDict, &symbol, currentBidAsk.clone());
        add_element_to_object(&mut self.bidsasks, &symbol, currentBidAsk.clone());
        client.resolve(&[bidsAsksDict.clone(), messageHash.clone()]);
}

    pub async fn helper_for_watch_multiple_construct(&mut self, mut itemHashName: Value, optional_args: &[Value]) -> Value {
        let mut symbols = 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;
        }
        if is_equal(&symbols, &Value::Null) {
            panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchMultiple requires at least one symbol".to_string()))));
        }
        symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
        let mut firstMarket: Value = self.market(get_value(&symbols, &Value::Int(0)));
        if is_true(&(!is_equal(&get_value(&firstMarket, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&(!is_equal(&get_value(&firstMarket, &Value::Str("linear".to_string())), &Value::Bool(true)))) {
            panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchMultiple supports only spot or linear-swap symbols".to_string()))));
        }
        let mut messageHashes: Value = Value::List(vec![]);
        let mut marketIds: Value = Value::List(vec![]);
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_360: bool = true;
            while { if !__for_first_360 { i = add(&i, &Value::Int(1)); } __for_first_360 = 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);
            let mut messageHash: Value = add(&add(&itemHashName, &Value::Str(":".to_string())), &symbol);
            append_to_array(&mut messageHashes, messageHash.clone());
            let mut market: Value = self.market(symbol.clone());
            append_to_array(&mut marketIds, get_value(&market, &Value::Str("id".to_string())));
        }
        }
        let mut queryStr: Value = join(&marketIds, &Value::Str(",".to_string()));
        let mut url: Value = add(&add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("/v1/multimarketdata?symbols=".to_string())), &queryStr), &Value::Str("&heartbeat=true&".to_string()));
        if is_equal(&itemHashName, &Value::Str("orderbook".to_string())) {
            url = add(&url, &Value::Str("trades=false&bids=true&offers=true".to_string()));
        }  else if is_equal(&itemHashName, &Value::Str("bidsasks".to_string())) {
            url = add(&url, &Value::Str("trades=false&bids=true&offers=true&top_of_book=true".to_string()));
        }  else if is_equal(&itemHashName, &Value::Str("trades".to_string())) {
            url = add(&url, &Value::Str("trades=true&bids=false&offers=false".to_string()));
        }
        return self.watch_multiple(url.clone(), messageHashes.clone(), &[Value::Null]).await;

    Value::Null
}

    pub fn handle_order_book_for_multidata(&mut self, mut client: Value, mut rawOrderBookChanges: Value, mut timestamp: Value, mut nonce: Value) {
        //
        // rawOrderBookChanges
        //
        // [
        //   {
        //     delta: "4105123935484.817624",
        //     price: "0.000000001",
        //     reason: "initial", // initial|cancel|place
        //     remaining: "4105123935484.817624",
        //     side: "bid", // bid|ask
        //     symbol: "SHIBUSD",
        //     type: "change", // seems always change
        //   },
        //   ...
        //
        let mut marketId: Value = get_value(&get_value(&rawOrderBookChanges, &Value::Int(0)), &Value::Str("symbol".to_string()));
        let mut market: Value = self.safe_market(&[to_lower(&marketId)]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
        if !is_true(&(Value::Bool(in_op(&self.orderbooks, &symbol)))) {
            let mut ob: Value = self.order_book(&[]);
            add_element_to_object(&mut self.orderbooks, &symbol, ob.clone());
        }
        let mut orderbook: Value = get_value(&self.orderbooks, &symbol);
        let mut bids: Value = get_value(&orderbook, &Value::Str("bids".to_string()));
        let mut asks: Value = get_value(&orderbook, &Value::Str("asks".to_string()));
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_361: bool = true;
            while { if !__for_first_361 { i = add(&i, &Value::Int(1)); } __for_first_361 = false; is_less_than(&i, &get_array_length(&rawOrderBookChanges)) } {
            let mut entry: Value = get_value(&rawOrderBookChanges, &i);
            let mut entry: Value = get_value(&rawOrderBookChanges, &i);
            let mut price: Value = self.safe_number_k(entry.clone(), "price", &[]);
            let mut size: Value = self.safe_number_k(entry.clone(), "remaining", &[]);
            let mut rawSide: Value = self.safe_string_k(entry.clone(), "side", &[]);
            if is_equal(&rawSide, &Value::Str("bid".to_string())) {
                bids.store(price.clone(), size.clone());
            }  else {
                asks.store(price.clone(), size.clone());
            }
        }
        }
        add_element_to_object(&mut orderbook, &Value::Str("bids".to_string()), bids.clone());
        add_element_to_object(&mut orderbook, &Value::Str("asks".to_string()), asks.clone());
        add_element_to_object(&mut orderbook, &Value::Str("symbol".to_string()), symbol.clone());
        add_element_to_object(&mut orderbook, &Value::Str("nonce".to_string()), nonce.clone());
        add_element_to_object(&mut orderbook, &Value::Str("timestamp".to_string()), timestamp.clone());
        add_element_to_object(&mut orderbook, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
        add_element_to_object(&mut self.orderbooks, &symbol, orderbook.clone());
        client.resolve(&[orderbook.clone(), messageHash.clone()]);
}

    pub fn handle_l2_updates(&mut self, mut client: Value, mut message: Value) {
        //
        //     {
        //         "type": "l2_updates",
        //         "symbol": "BTCUSD",
        //         "changes": [
        //             [ "buy", '22252.37', "0.02" ],
        //             [ "buy", '22251.61', "0.04" ],
        //             [ "buy", '22251.60', "0.04" ],
        //             // some asks as well
        //         ],
        //         "trades": [
        //             { type: 'trade', symbol: 'BTCUSD', event_id: 122258166738, timestamp: 1655330221424, price: '22269.14', quantity: "0.00004473", side: "buy" },
        //             { type: 'trade', symbol: 'BTCUSD', event_id: 122258141090, timestamp: 1655330213216, price: '22250.00', quantity: "0.00704098", side: "buy" },
        //             { type: 'trade', symbol: 'BTCUSD', event_id: 122258118291, timestamp: 1655330206753, price: '22250.00', quantity: "0.03", side: "buy" },
        //         ],
        //         "auction_events": [
        //             {
        //                 "type": "auction_result",
        //                 "symbol": "BTCUSD",
        //                 "time_ms": 1655323200000,
        //                 "result": "failure",
        //                 "highest_bid_price": "21590.88",
        //                 "lowest_ask_price": "21602.30",
        //                 "collar_price": "21634.73"
        //             },
        //             {
        //                 "type": "auction_indicative",
        //                 "symbol": "BTCUSD",
        //                 "time_ms": 1655323185000,
        //                 "result": "failure",
        //                 "highest_bid_price": "21661.90",
        //                 "lowest_ask_price": "21663.79",
        //                 "collar_price": "21662.845"
        //             },
        //         ]
        //     }
        //
        self.handle_order_book(client.clone(), message.clone());
        self.handle_trades(client.clone(), message.clone());
}

/*
 * @method
 * @name gemini#fetchOrders
 * @description watches information on multiple orders made by the user
 * @see https://docs.gemini.com/websocket-api/#order-events
 * @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
}));
        let mut url: Value = add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("/v1/order/events?eventTypeFilter=initial&eventTypeFilter=accepted&eventTypeFilter=rejected&eventTypeFilter=fill&eventTypeFilter=cancelled&eventTypeFilter=booked".to_string()));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut authParams: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("url".to_string(), url.clone());
            m
        });
        self.authenticate(&[authParams.clone()]).await;
        if !is_equal(&symbol, &Value::Null) {
            let mut market: Value = self.market(symbol.clone());
            symbol = get_value(&market, &Value::Str("symbol".to_string()));
        }
        let mut messageHash: Value = Value::Str("orders".to_string());
        let mut orders: Value = self.watch(url.clone(), messageHash.clone(), &[Value::Null, 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_heartbeat(&self, mut client: Value, mut message: Value) -> Value {
        //
        //     {
        //         "type": "heartbeat",
        //         "timestampms": 1659740268958,
        //         "sequence": 7,
        //         "trace_id": "25b3d92476dd3a9a5c03c9bd9e0a0dba",
        //         "socket_sequence": 7
        //     }
        //
        crate::set_value(&mut client, &Value::Str("lastPong".to_string()), self.milliseconds());
        return message;

    Value::Null
}

    pub fn handle_subscription(&self, mut client: Value, mut message: Value) -> Value {
        return message;

    Value::Null
}

    pub fn handle_order(&mut self, mut client: Value, mut message: Value) {
        //
        //     [
        //         {
        //             "type": "accepted",
        //             "order_id": "134150423884",
        //             "event_id": "134150423886",
        //             "account_name": "primary",
        //             "client_order_id": "1659739406916",
        //             "api_session": "account-pnBFSS0XKGvDamX4uEIt",
        //             "symbol": "batbtc",
        //             "side": "sell",
        //             "order_type": "exchange limit",
        //             "timestamp": "1659739407",
        //             "timestampms": 1659739407576,
        //             "is_live": true,
        //             "is_cancelled": false,
        //             "is_hidden": false,
        //             "original_amount": "1",
        //             "price": "1",
        //             "socket_sequence": 139
        //         }
        //     ]
        //
        let mut messageHash: Value = Value::Str("orders".to_string());
        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 orders: Value = self.orders.clone();
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_362: bool = true;
            while { if !__for_first_362 { i = add(&i, &Value::Int(1)); } __for_first_362 = false; is_less_than(&i, &get_array_length(&message)) } {
            let mut order: Value = self.parse_ws_order(get_value(&message, &i), &[]);
            orders.append(order.clone());
        }
        }
        client.resolve(&[self.orders.clone(), messageHash.clone()]);
}

    pub fn parse_ws_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
        let mut market = get_arg(optional_args, 0, Value::Null);
        //
        //     {
        //         "type": "accepted",
        //         "order_id": "134150423884",
        //         "event_id": "134150423886",
        //         "account_name": "primary",
        //         "client_order_id": "1659739406916",
        //         "api_session": "account-pnBFSS0XKGvDamX4uEIt",
        //         "symbol": "batbtc",
        //         "side": "sell",
        //         "order_type": "exchange limit",
        //         "timestamp": "1659739407",
        //         "timestampms": 1659739407576,
        //         "is_live": true,
        //         "is_cancelled": false,
        //         "is_hidden": false,
        //         "original_amount": "1",
        //         "price": "1",
        //         "socket_sequence": 139
        //     }
        //
        let mut timestamp: Value = self.safe_integer_k(order.clone(), "timestampms", &[]);
        let mut status: Value = self.safe_string_k(order.clone(), "type", &[]);
        let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
        let mut typeId: Value = self.safe_string_k(order.clone(), "order_type", &[]);
        let mut behavior: Value = self.safe_string_k(order.clone(), "behavior", &[]);
        let mut timeInForce: Value = Value::Str("GTC".to_string());
        let mut postOnly: Value = Value::Bool(false);
        if is_equal(&behavior, &Value::Str("immediate-or-cancel".to_string())) {
            timeInForce = Value::Str("IOC".to_string());
        }  else if is_equal(&behavior, &Value::Str("fill-or-kill".to_string())) {
            timeInForce = Value::Str("FOK".to_string());
        }  else if is_equal(&behavior, &Value::Str("maker-or-cancel".to_string())) {
            timeInForce = Value::Str("PO".to_string());
            postOnly = Value::Bool(true);
        }
        return self.safe_order(Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
        m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client_order_id", &[]));
        m.insert("info".to_string(), order.clone());
        m.insert("timestamp".to_string(), timestamp.clone());
        m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
        m.insert("lastTradeTimestamp".to_string(), Value::Null);
        m.insert("status".to_string(), self.parse_ws_order_status(status.clone()));
        m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
        m.insert("type".to_string(), self.parse_ws_order_type(typeId.clone()));
        m.insert("timeInForce".to_string(), timeInForce.clone());
        m.insert("postOnly".to_string(), postOnly.clone());
        m.insert("side".to_string(), self.safe_string_k(order.clone(), "side", &[]));
        m.insert("price".to_string(), self.safe_number_k(order.clone(), "price", &[]));
        m.insert("stopPrice".to_string(), Value::Null);
        m.insert("average".to_string(), self.safe_number_k(order.clone(), "avg_execution_price", &[]));
        m.insert("cost".to_string(), Value::Null);
        m.insert("amount".to_string(), self.safe_number_k(order.clone(), "original_amount", &[]));
        m.insert("filled".to_string(), self.safe_number_k(order.clone(), "executed_amount", &[]));
        m.insert("remaining".to_string(), self.safe_number_k(order.clone(), "remaining_amount", &[]));
        m.insert("fee".to_string(), Value::Null);
        m.insert("trades".to_string(), Value::Null);
    m
}), &[market.clone()]);

    Value::Null
}

    pub fn parse_ws_order_status(&self, mut status: Value) -> Value {
        let mut statuses: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("accepted".to_string(), Value::Str("open".to_string()));
                m.insert("booked".to_string(), Value::Str("open".to_string()));
                m.insert("fill".to_string(), Value::Str("closed".to_string()));
                m.insert("cancelled".to_string(), Value::Str("canceled".to_string()));
                m.insert("cancel_rejected".to_string(), Value::Str("rejected".to_string()));
                m.insert("rejected".to_string(), Value::Str("rejected".to_string()));
            m
        });
        return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);

    Value::Null
}

    pub fn parse_ws_order_type(&self, mut type_var: Value) -> Value {
        let mut types: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("exchange limit".to_string(), Value::Str("limit".to_string()));
                m.insert("market buy".to_string(), Value::Str("market".to_string()));
                m.insert("market sell".to_string(), Value::Str("market".to_string()));
            m
        });
        return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);

    Value::Null
}

    pub fn handle_error(&self, mut client: Value, mut message: Value) {
        panic!("{}", crate::exchange_errors::exchange_error(self.json(message.clone())));
}

    pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
        //
        //  public
        //     {
        //         "type": "trade",
        //         "symbol": "BTCUSD",
        //         "event_id": 122278173770,
        //         "timestamp": 1655335880981,
        //         "price": "22530.80",
        //         "quantity": "0.04",
        //         "side": "buy"
        //     }
        //
        //  private
        //     [
        //         {
        //             "type": "accepted",
        //             "order_id": "134150423884",
        //             "event_id": "134150423886",
        //             "account_name": "primary",
        //             "client_order_id": "1659739406916",
        //             "api_session": "account-pnBFSS0XKGvDamX4uEIt",
        //             "symbol": "batbtc",
        //             "side": "sell",
        //             "order_type": "exchange limit",
        //             "timestamp": "1659739407",
        //             "timestampms": 1659739407576,
        //             "is_live": true,
        //             "is_cancelled": false,
        //             "is_hidden": false,
        //             "original_amount": "1",
        //             "price": "1",
        //             "socket_sequence": 139
        //         }
        //     ]
        //
        let mut isArray: bool = is_array(&message);
        if is_true(&isArray) {
            self.handle_order(client.clone(), message.clone());
            return;
        }
        let mut reason: Value = self.safe_string_k(message.clone(), "reason", &[]);
        if is_equal(&reason, &Value::Str("error".to_string())) {
            self.handle_error(client.clone(), message.clone());
        }
        let mut methods: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("l2_updates".to_string(), Value::Str("handle_l2_updates".to_string()).clone());
                m.insert("trade".to_string(), Value::Str("handle_trade".to_string()).clone());
                m.insert("subscription_ack".to_string(), Value::Str("handle_subscription".to_string()).clone());
                m.insert("heartbeat".to_string(), Value::Str("handle_heartbeat".to_string()).clone());
            m
        });
        let mut type_var: Value = self.safe_string_k(message.clone(), "type", &[Value::Str("".to_string())]);
        if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("candles".to_string())), &Value::Int(0)) {
            self.handle_ohlcv(client.clone(), message.clone());
            return;
        }
        let mut method: Value = self.safe_value(methods.clone(), type_var.clone(), &[]);
        if !is_equal(&method, &Value::Null) {
            self.dispatch_ws_handler(&method, &[client.clone(), message.clone()]);
        }
        // handle multimarketdata
        if is_equal(&type_var, &Value::Str("update".to_string())) {
            let mut ts: Value = self.safe_integer_k(message.clone(), "timestampms", &[self.milliseconds()]);
            let mut eventId: Value = self.safe_integer_k(message.clone(), "eventId", &[]);
            let mut events: Value = self.safe_list_k(message.clone(), "events", &[]);
            if is_equal(&events, &Value::Null) {
                return;
            }
            let mut orderBookItems: Value = Value::List(vec![]);
            let mut bidaskItems: Value = Value::List(vec![]);
            let mut collectedEventsOfTrades: Value = Value::List(vec![]);
            let mut eventsLength: Value = get_array_length(&events);
            {
                                let mut i: Value = Value::Int(0);
                let mut __for_first_363: bool = true;
                while { if !__for_first_363 { i = add(&i, &Value::Int(1)); } __for_first_363 = false; is_less_than(&i, &get_array_length(&events)) } {
                let mut event: Value = get_value(&events, &i);
                let mut event: Value = get_value(&events, &i);
                let mut eventType: Value = self.safe_string_k(event.clone(), "type", &[]);
                let mut isOrderBook: bool = is_true(&(is_equal(&eventType, &Value::Str("change".to_string())))) && is_true(&(Value::Bool(in_op(&event, &Value::Str("side".to_string()))))) && is_true(&self.in_array(get_value(&event, &Value::Str("side".to_string())), Value::List(vec![Value::Str("ask".to_string()), Value::Str("bid".to_string())])));
                let mut eventReason: Value = self.safe_string_k(event.clone(), "reason", &[]);
                let mut isBidAsk: bool = is_true(&(is_equal(&eventReason, &Value::Str("top-of-book".to_string())))) || is_true(&(is_true(&isOrderBook) && is_true(&(is_equal(&eventReason, &Value::Str("initial".to_string())))) && is_equal(&eventsLength, &Value::Int(2))));
                if is_true(&isBidAsk) {
                    append_to_array(&mut bidaskItems, event.clone());
                }  else if is_true(&isOrderBook) {
                    append_to_array(&mut orderBookItems, event.clone());
                }  else if is_equal(&eventType, &Value::Str("trade".to_string())) {
                    append_to_array(&mut collectedEventsOfTrades, get_value(&events, &i));
                }
            }
            }
            let mut lengthBa: Value = get_array_length(&bidaskItems);
            if is_greater_than(&lengthBa, &Value::Int(0)) {
                self.handle_bids_asks_for_multidata(client.clone(), bidaskItems.clone(), ts.clone(), eventId.clone());
            }
            let mut lengthOb: Value = get_array_length(&orderBookItems);
            if is_greater_than(&lengthOb, &Value::Int(0)) {
                self.handle_order_book_for_multidata(client.clone(), orderBookItems.clone(), ts.clone(), eventId.clone());
            }
            let mut lengthTrades: Value = get_array_length(&collectedEventsOfTrades);
            if is_greater_than(&lengthTrades, &Value::Int(0)) {
                self.handle_trades_for_multidata(client.clone(), collectedEventsOfTrades.clone(), ts.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 url: Value = self.safe_string_k(params.clone(), "url", &[]);
        if is_equal(&url, &Value::Null) {
            return Value::Null;
        }
        if is_true(&(!is_equal(&self.clients, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.clients, &url)))) {
            return Value::Null;
        }
        self.check_required_credentials(&[]);
        let mut startIndex: Value = get_array_length(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())));
        let mut urlParamsIndex: Value = get_index_of(&url, &Value::Str("?".to_string()));
        let mut urlLength: Value = get_array_length(&url);
        let mut endIndex: Value = ternary(is_true(&(is_greater_than_or_equal(&urlParamsIndex, &Value::Int(0)))), urlParamsIndex.clone(), urlLength.clone());
        let mut request: Value = slice(&url, &startIndex, &endIndex);
        let mut payload: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("request".to_string(), request.clone());
                m.insert("nonce".to_string(), self.nonce());
            m
        });
        let mut b64: Value = self.string_to_base64(self.json(payload.clone()), &[]);
        let mut signature: Value = self.hmac(self.encode(b64.clone()), self.encode(self.secret.clone()), Value::Str("sha384".to_string()), &[Value::Str("hex".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-GEMINI-APIKEY".to_string(), self.apiKey.clone());
                m.insert("X-GEMINI-PAYLOAD".to_string(), b64.clone());
                m.insert("X-GEMINI-SIGNATURE".to_string(), signature.clone());
            m
        });
        add_element_to_object(get_value_mut(get_value_mut(&mut self.options, &Value::Str("ws".to_string())), &Value::Str("options".to_string())), &Value::Str("headers".to_string()), headers.clone());
        self.client(&[url.clone()]);
        add_element_to_object(get_value_mut(get_value_mut(&mut self.options, &Value::Str("ws".to_string())), &Value::Str("options".to_string())), &Value::Str("headers".to_string()), originalHeaders.clone());

    Value::Null
}
}