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
// 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 MudrexCore {
    pub parent: crate::exchanges::mudrex::MudrexCore,
}

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

    pub fn init(&mut self) {
        let described = MudrexCore::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 MudrexCore {
    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 MudrexCore {
    fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
        -> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
    {
        Box::pin(async move {
            match method {
                "handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
                "ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
                "request_id" => self.request_id(),
                "watch_ohlcv" => self.watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_ticker" => self.watch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
                "watch_tickers" => self.watch_tickers(&args.get(0..).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 MudrexCore {
    /// 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 {
            "handle_error_message" => { self.handle_error_message(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)); 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 },
            "ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
            "request_id" => self.request_id(),
            "set_broker_headers" => { self.set_broker_headers(); crate::Value::Null },
            "watch_ohlcv" => { crate::exchange_stubs::enqueue_spawn("watch_ohlcv", args.to_vec()); crate::Value::Null },
            "watch_ticker" => { crate::exchange_stubs::enqueue_spawn("watch_ticker", args.to_vec()); crate::Value::Null },
            "watch_tickers" => { crate::exchange_stubs::enqueue_spawn("watch_tickers", args.to_vec()); crate::Value::Null },
            _ => crate::Value::Null,
        }
    }
}

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

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

impl MudrexCore {
    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("watchOHLCV".to_string(), Value::Bool(true));
        m.insert("watchTicker".to_string(), Value::Bool(true));
        m.insert("watchTickers".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://trade.mudrex.com/fapi/v1/price/ws/linear".to_string()));
    m
}));
    m
}));
        m.insert("options".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("broker".to_string(), Value::Str("42ce8902-8585-448c-a1e8-0371a6ca7ca8".to_string()));
    m
}));
        m.insert("streaming".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("ping".to_string(), Value::Str("ping".to_string()).clone());
        m.insert("keepAlive".to_string(), Value::Int(20000));
    m
}));
    m
})]);

    Value::Null
}

    pub fn ping(&mut self, mut client: Value) -> Value {
        return Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("id".to_string(), self.request_id());
        m.insert("method".to_string(), Value::Str("PING".to_string()));
    m
});

    Value::Null
}

    pub fn request_id(&mut self) -> Value {
        let mut reqid: Value = self.sum(&[self.safe_integer_k(self.options.clone(), "correlationId", &[Value::Int(0)]), Value::Int(1)]);
        add_element_to_object(&mut self.options, &Value::Str("correlationId".to_string()), reqid.clone());
        return reqid;

    Value::Null
}

/*
 * @ignore
 * @method
 * @description injects the broker Partner-Id into the websocket connection headers
 */
    pub fn set_broker_headers(&mut self) {
        let mut brokerId: Value = self.safe_string_k(self.options.clone(), "broker", &[]);
        if is_equal(&brokerId, &Value::Null) {
            return;
        }
        let mut wsOptions: Value = self.safe_dict_k(self.options.clone(), "ws", &[Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        })]);
        let mut innerOptions: Value = self.safe_dict_k(wsOptions.clone(), "options", &[Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        })]);
        let mut headers: Value = self.safe_dict_k(innerOptions.clone(), "headers", &[Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        })]);
        add_element_to_object(&mut headers, &Value::Str("Partner-Id".to_string()), brokerId.clone());
        add_element_to_object(&mut innerOptions, &Value::Str("headers".to_string()), headers.clone());
        add_element_to_object(&mut wsOptions, &Value::Str("options".to_string()), innerOptions.clone());
        add_element_to_object(&mut self.options, &Value::Str("ws".to_string()), wsOptions.clone());
}

    pub async fn watch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
        let mut params = get_arg(optional_args, 0, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut market: Value = self.market(symbol.clone());
        symbol = get_value(&market, &Value::Str("symbol".to_string()));
        let mut messageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
        let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string()));
        self.set_broker_headers();
        let mut baseIdString: Value = ternary(is_true(&(!is_equal(&get_value(&market, &Value::Str("baseId".to_string())), &Value::Null))), get_value(&market, &Value::Str("baseId".to_string())), Value::Str("".to_string()));
        let mut quoteIdString: Value = ternary(is_true(&(!is_equal(&get_value(&market, &Value::Str("quoteId".to_string())), &Value::Null))), get_value(&market, &Value::Str("quoteId".to_string())), Value::Str("".to_string()));
        let mut assetId: Value = add(&to_lower(&baseIdString), &to_lower(&quoteIdString));
        let mut subscribe: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("id".to_string(), self.request_id());
                m.insert("method".to_string(), Value::Str("SUBSCRIBE".to_string()));
                m.insert("params".to_string(), Value::List(vec![Value::Str("ticker@1s".to_string())]));
                m.insert("assets".to_string(), Value::List(vec![assetId.clone()]));
            m
        });
        let mut request: Value = self.extend(subscribe.clone(), &[params.clone()]);
        return self.watch(url.clone(), messageHash.clone(), &[request.clone(), messageHash.clone()]).await;

    Value::Null
}

    pub async fn watch_tickers(&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
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        symbols = self.market_symbols(&[symbols.clone()]);
        let mut messageHashes: Value = Value::List(vec![]);
        let mut assets: Value = Value::List(vec![]);
        if !is_equal(&symbols, &Value::Null) {
            {
                                let mut i: Value = Value::Int(0);
                let mut __for_first_499: bool = true;
                while { if !__for_first_499 { i = add(&i, &Value::Int(1)); } __for_first_499 = false; is_less_than(&i, &get_array_length(&symbols)) } {
                let mut market: Value = self.market(get_value(&symbols, &i));
                append_to_array(&mut messageHashes, add(&Value::Str("ticker:".to_string()), &get_value(&market, &Value::Str("symbol".to_string()))));
                let mut baseIdString: Value = ternary(is_true(&(!is_equal(&get_value(&market, &Value::Str("baseId".to_string())), &Value::Null))), get_value(&market, &Value::Str("baseId".to_string())), Value::Str("".to_string()));
                let mut quoteIdString: Value = ternary(is_true(&(!is_equal(&get_value(&market, &Value::Str("quoteId".to_string())), &Value::Null))), get_value(&market, &Value::Str("quoteId".to_string())), Value::Str("".to_string()));
                append_to_array(&mut assets, add(&to_lower(&baseIdString), &to_lower(&quoteIdString)));
            }
            }
        }
        let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string()));
        self.set_broker_headers();
        let mut subscribe: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("id".to_string(), self.request_id());
                m.insert("method".to_string(), Value::Str("SUBSCRIBE".to_string()));
                m.insert("params".to_string(), Value::List(vec![Value::Str("ticker@1s".to_string())]));
                m.insert("assets".to_string(), assets.clone());
            m
        });
        let mut request: Value = self.extend(subscribe.clone(), &[params.clone()]);
        let mut ticker: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
        if is_true(&self.newUpdates) {
            let mut result: Value = Value::Map({
                let mut m = indexmap::IndexMap::new();
                m
            });
            add_element_to_object(&mut result, &get_value(&ticker, &Value::Str("symbol".to_string())), ticker.clone());
            return result;
        }
        return self.filter_by_array_tickers(self.tickers.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);

    Value::Null
}

    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 priceType: Value = self.safe_string_k(params.clone(), "price", &[]);
        params = self.omit(params.clone(), Value::Str("price".to_string()), &[]);
        let mut interval: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
        if !is_equal(&interval, &Value::Str("1s".to_string())) && !is_equal(&interval, &Value::Str("1m".to_string())) {
            panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchOHLCV() supports 1s and 1m timeframes only".to_string()))));
        }
        let mut prefix: Value = Value::Str("kline".to_string());
        if is_equal(&priceType, &Value::Str("mark".to_string())) {
            prefix = Value::Str("markKline".to_string());
        }
        let mut streamBaseId: Value = ternary(is_true(&(!is_equal(&get_value(&market, &Value::Str("baseId".to_string())), &Value::Null))), get_value(&market, &Value::Str("baseId".to_string())), Value::Str("".to_string()));
        let mut streamQuoteId: Value = ternary(is_true(&(!is_equal(&get_value(&market, &Value::Str("quoteId".to_string())), &Value::Null))), get_value(&market, &Value::Str("quoteId".to_string())), Value::Str("".to_string()));
        let mut stream: Value = add(&add(&add(&add(&add(&prefix, &Value::Str("@".to_string())), &interval), &Value::Str("@".to_string())), &to_lower(&streamBaseId)), &to_lower(&streamQuoteId));
        let mut messageHash: Value = stream.clone();
        let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string()));
        self.set_broker_headers();
        let mut subscribe: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("id".to_string(), self.request_id());
                m.insert("method".to_string(), Value::Str("SUBSCRIBE".to_string()));
                m.insert("params".to_string(), Value::List(vec![stream.clone()]));
            m
        });
        let mut request: Value = self.extend(subscribe.clone(), &[params.clone()]);
        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_message(&mut self, mut client: Value, mut message: Value) {
        if is_equal(&self.safe_string_k(message.clone(), "method", &[]), &Value::Str("PONG".to_string())) {
            return;
        }
        let mut error: Value = self.safe_dict_k(message.clone(), "error", &[]);
        if !is_equal(&error, &Value::Null) {
            self.handle_error_message(client.clone(), message.clone());
            return;
        }
        let mut stream: Value = self.safe_string_k(message.clone(), "stream", &[]);
        if !is_equal(&stream, &Value::Null) {
            if is_greater_than_or_equal(&get_index_of(&stream, &Value::Str("kline".to_string())), &Value::Int(0)) || is_greater_than_or_equal(&get_index_of(&stream, &Value::Str("markKline".to_string())), &Value::Int(0)) {
                self.handle_ohlcv(client.clone(), message.clone());
            }  else if is_greater_than_or_equal(&get_index_of(&stream, &Value::Str("ticker".to_string())), &Value::Int(0)) {
                self.handle_ticker(client.clone(), message.clone());
            }
        }
}

    pub fn handle_error_message(&self, mut client: Value, mut message: Value) {
        let mut error: Value = self.safe_dict_k(message.clone(), "error", &[Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        })]);
        let mut code: Value = self.safe_string_k(error.clone(), "code", &[]);
        let mut msg: Value = self.safe_string_k(error.clone(), "msg", &[]);
        let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &msg);
        if is_equal(&code, &Value::Str("429".to_string())) {
            panic!("{}", crate::exchange_errors::rate_limit_exceeded(feedback));
        }
        panic!("{}", crate::exchange_errors::exchange_error(feedback));
}

    pub fn handle_ohlcv(&mut self, mut client: Value, mut message: Value) {
        let mut stream: Value = self.safe_string_k(message.clone(), "stream", &[]);
        if is_equal(&stream, &Value::Null) {
            return;
        }
        let mut parts: Value = split(&stream, &Value::Str("@".to_string()));
        let mut interval: Value = get_value(&parts, &Value::Int(1));
        let mut tf: Value = self.find_timeframe(interval.clone(), &[]);
        let mut data: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        })]);
        let mut s: Value = self.safe_string_k(data.clone(), "s", &[]);
        if is_equal(&s, &Value::Null) {
            return;
        }
        let mut market: Value = self.safe_market(&[to_upper(&s)]);
        let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
        let mut parsed: Value = Value::List(vec![self.safe_timestamp(data.clone(), Value::Str("t".to_string()), &[]), self.safe_number_k(data.clone(), "o", &[]), self.safe_number_k(data.clone(), "h", &[]), self.safe_number_k(data.clone(), "l", &[]), self.safe_number_k(data.clone(), "c", &[]), self.safe_number_k(data.clone(), "v", &[])]);
        { let __be_tmp = self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
})]); add_element_to_object(&mut self.ohlcvs, &symbol, __be_tmp); };
        let mut stored: Value = self.safe_value(self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[]), tf.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(&tf, &Value::Null) {
                add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.ohlcvs) }, &symbol), &tf, stored.clone());
            }
        }
        stored.append(parsed.clone());
        let mut messageHash: Value = stream.clone();
        client.resolve(&[stored.clone(), messageHash.clone()]);
}

    pub fn handle_ticker(&mut self, mut client: Value, mut message: Value) {
        let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
        {
                        let mut i: Value = Value::Int(0);
            let mut __for_first_500: bool = true;
            while { if !__for_first_500 { i = add(&i, &Value::Int(1)); } __for_first_500 = false; is_less_than(&i, &get_array_length(&data)) } {
            let mut t: Value = get_value(&data, &i);
            let mut t: Value = get_value(&data, &i);
            let mut s: Value = self.safe_string_k(t.clone(), "s", &[]);
            if is_equal(&s, &Value::Null) {
                continue;
            }
            let mut market: Value = self.safe_market(&[to_upper(&s)]);
            let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
            let mut timestamp: Value = self.milliseconds();
            let mut last: Value = self.safe_number_k(t.clone(), "p", &[]);
            let mut result: Value = self.safe_ticker(Value::Map({
                let mut m = indexmap::IndexMap::new();
                    m.insert("symbol".to_string(), symbol.clone());
                    m.insert("timestamp".to_string(), timestamp.clone());
                    m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
                    m.insert("last".to_string(), last.clone());
                    m.insert("close".to_string(), last.clone());
                    m.insert("info".to_string(), t.clone());
                m
            }), &[]);
            add_element_to_object(&mut self.tickers, &symbol, result.clone());
            let mut messageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
            client.resolve(&[result.clone(), messageHash.clone()]);
            client.resolve(&[result.clone(), Value::Str("tickers".to_string())]);
        }
        }
}
}