#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
use crate::pro::*;
pub struct BybitCore {
pub parent: crate::exchanges::bybit::BybitCore,
}
impl BybitCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { parent: crate::exchanges::bybit::BybitCore::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = BybitCore::describe(self);
self.initialize_properties(described);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for BybitCore {
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 BybitCore {
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).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order_ws" => self.cancel_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"clean_params" => self.clean_params(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"create_order_ws" => self.create_order_ws(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), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"describe_data" => self.describe_data(),
"edit_order_ws" => self.edit_order_ws(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), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"get_private_type" => self.get_private_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"get_url_by_market_type" => self.get_url_by_market_type(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"handle_authenticate" => self.handle_authenticate(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"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)),
"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_pong" => self.handle_pong(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_subscription_status" => self.handle_subscription_status(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_un_subscribe" => self.handle_un_subscribe(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"load_positions_snapshot" => self.load_positions_snapshot(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)).await,
"parse_ws_bid_ask" => self.parse_ws_bid_ask(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_liquidation" => self.parse_ws_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_ohlcv" => self.parse_ws_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"request_id" => self.request_id(),
"un_watch_my_trades" => self.un_watch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_ohlcv" => self.un_watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_ohlcv_for_symbols" => self.un_watch_ohlcv_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_order_book" => self.un_watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_order_book_for_symbols" => self.un_watch_order_book_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_orders" => self.un_watch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_positions" => self.un_watch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_ticker" => self.un_watch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_tickers" => self.un_watch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_topics" => self.un_watch_topics(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), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), &args.get(6..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_trades" => self.un_watch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_trades_for_symbols" => self.un_watch_trades_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_balance" => self.watch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_bids_asks" => self.watch_bids_asks(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_liquidations" => self.watch_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_my_trades" => self.watch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_ohlcv" => self.watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_ohlcv_for_symbols" => self.watch_ohlcv_for_symbols(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_positions" => self.watch_positions(&args.get(0..).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,
"watch_topics" => self.watch_topics(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"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,
_ => crate::exchange_generated::ExchangeBase::call_dynamic(&mut self.parent, method, args).await,
}
})
}
}
impl BybitCore {
#[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 },
"cancel_order_ws" => { crate::exchange_stubs::enqueue_spawn("cancel_order_ws", args.to_vec()); crate::Value::Null },
"clean_params" => self.clean_params(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"create_order_ws" => { crate::exchange_stubs::enqueue_spawn("create_order_ws", args.to_vec()); crate::Value::Null },
"describe_data" => self.describe_data(),
"edit_order_ws" => { crate::exchange_stubs::enqueue_spawn("edit_order_ws", args.to_vec()); crate::Value::Null },
"get_private_type" => self.get_private_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"get_url_by_market_type" => { crate::exchange_stubs::enqueue_spawn("get_url_by_market_type", args.to_vec()); crate::Value::Null },
"handle_authenticate" => self.handle_authenticate(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_balance" => { self.handle_balance(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_delta" => { self.handle_delta(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_deltas" => { self.handle_deltas(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"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)),
"handle_liquidation" => { self.handle_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_my_trades" => { self.handle_my_trades(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_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_ws" => { self.handle_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_pong" => self.handle_pong(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_positions" => { self.handle_positions(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_subscription_status" => self.handle_subscription_status(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_ticker" => { self.handle_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_trades" => { self.handle_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_un_subscribe" => self.handle_un_subscribe(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"load_positions_snapshot" => { crate::exchange_stubs::enqueue_spawn("load_positions_snapshot", args.to_vec()); crate::Value::Null },
"parse_ws_balance" => { self.parse_ws_balance(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]); crate::Value::Null },
"parse_ws_bid_ask" => self.parse_ws_bid_ask(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_liquidation" => self.parse_ws_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_ohlcv" => self.parse_ws_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"request_id" => self.request_id(),
"set_positions_cache" => { self.set_positions_cache(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]); crate::Value::Null },
"un_watch_my_trades" => { crate::exchange_stubs::enqueue_spawn("un_watch_my_trades", args.to_vec()); crate::Value::Null },
"un_watch_ohlcv" => { crate::exchange_stubs::enqueue_spawn("un_watch_ohlcv", args.to_vec()); crate::Value::Null },
"un_watch_ohlcv_for_symbols" => { crate::exchange_stubs::enqueue_spawn("un_watch_ohlcv_for_symbols", args.to_vec()); crate::Value::Null },
"un_watch_order_book" => { crate::exchange_stubs::enqueue_spawn("un_watch_order_book", args.to_vec()); crate::Value::Null },
"un_watch_order_book_for_symbols" => { crate::exchange_stubs::enqueue_spawn("un_watch_order_book_for_symbols", args.to_vec()); crate::Value::Null },
"un_watch_orders" => { crate::exchange_stubs::enqueue_spawn("un_watch_orders", args.to_vec()); crate::Value::Null },
"un_watch_positions" => { crate::exchange_stubs::enqueue_spawn("un_watch_positions", args.to_vec()); crate::Value::Null },
"un_watch_ticker" => { crate::exchange_stubs::enqueue_spawn("un_watch_ticker", args.to_vec()); crate::Value::Null },
"un_watch_tickers" => { crate::exchange_stubs::enqueue_spawn("un_watch_tickers", args.to_vec()); crate::Value::Null },
"un_watch_topics" => { crate::exchange_stubs::enqueue_spawn("un_watch_topics", args.to_vec()); crate::Value::Null },
"un_watch_trades" => { crate::exchange_stubs::enqueue_spawn("un_watch_trades", args.to_vec()); crate::Value::Null },
"un_watch_trades_for_symbols" => { crate::exchange_stubs::enqueue_spawn("un_watch_trades_for_symbols", args.to_vec()); crate::Value::Null },
"watch_balance" => { crate::exchange_stubs::enqueue_spawn("watch_balance", args.to_vec()); crate::Value::Null },
"watch_bids_asks" => { crate::exchange_stubs::enqueue_spawn("watch_bids_asks", args.to_vec()); crate::Value::Null },
"watch_liquidations" => { crate::exchange_stubs::enqueue_spawn("watch_liquidations", args.to_vec()); crate::Value::Null },
"watch_my_trades" => { crate::exchange_stubs::enqueue_spawn("watch_my_trades", args.to_vec()); crate::Value::Null },
"watch_ohlcv" => { crate::exchange_stubs::enqueue_spawn("watch_ohlcv", args.to_vec()); crate::Value::Null },
"watch_ohlcv_for_symbols" => { crate::exchange_stubs::enqueue_spawn("watch_ohlcv_for_symbols", 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_positions" => { crate::exchange_stubs::enqueue_spawn("watch_positions", 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 },
"watch_topics" => { crate::exchange_stubs::enqueue_spawn("watch_topics", 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 BybitCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { std::ops::Deref::deref(&self.parent) }
}
impl std::ops::DerefMut for BybitCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { std::ops::DerefMut::deref_mut(&mut self.parent) }
}
impl BybitCore {
pub fn describe(&self) -> Value {
let mut superDescribe: Value = self.parent.describe();
return self.deep_extend(superDescribe.clone(), &[self.describe_data()]);
Value::Null
}
pub fn describe_data(&self) -> Value {
return 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("createOrderWs".to_string(), Value::Bool(true));
m.insert("editOrderWs".to_string(), Value::Bool(true));
m.insert("fetchOpenOrdersWs".to_string(), Value::Bool(false));
m.insert("fetchOrderWs".to_string(), Value::Bool(false));
m.insert("cancelOrderWs".to_string(), Value::Bool(true));
m.insert("cancelOrdersWs".to_string(), Value::Bool(false));
m.insert("cancelAllOrdersWs".to_string(), Value::Bool(false));
m.insert("fetchTradesWs".to_string(), Value::Bool(false));
m.insert("fetchBalanceWs".to_string(), Value::Bool(false));
m.insert("watchBalance".to_string(), Value::Bool(true));
m.insert("watchBidsAsks".to_string(), Value::Bool(true));
m.insert("watchLiquidations".to_string(), Value::Bool(true));
m.insert("watchLiquidationsForSymbols".to_string(), Value::Bool(false));
m.insert("watchMyLiquidations".to_string(), Value::Bool(false));
m.insert("watchMyLiquidationsForSymbols".to_string(), Value::Bool(false));
m.insert("watchMyTrades".to_string(), Value::Bool(true));
m.insert("watchOHLCV".to_string(), Value::Bool(true));
m.insert("watchOHLCVForSymbols".to_string(), Value::Bool(true));
m.insert("watchOrderBook".to_string(), Value::Bool(true));
m.insert("watchOrderBookForSymbols".to_string(), Value::Bool(true));
m.insert("watchOrders".to_string(), Value::Bool(true));
m.insert("watchTicker".to_string(), Value::Bool(true));
m.insert("watchTickers".to_string(), Value::Bool(true));
m.insert("watchTrades".to_string(), Value::Bool(true));
m.insert("watchPositions".to_string(), Value::Bool(true));
m.insert("watchTradesForSymbols".to_string(), Value::Bool(true));
m.insert("unWatchTicker".to_string(), Value::Bool(true));
m.insert("unWatchTickers".to_string(), Value::Bool(true));
m.insert("unWatchOHLCV".to_string(), Value::Bool(true));
m.insert("unWatchOHLCVForSymbols".to_string(), Value::Bool(true));
m.insert("unWatchOrderBook".to_string(), Value::Bool(true));
m.insert("unWatchOrderBookForSymbols".to_string(), Value::Bool(true));
m.insert("unWatchTrades".to_string(), Value::Bool(true));
m.insert("unWatchTradesForSymbols".to_string(), Value::Bool(true));
m.insert("unWatchMyTrades".to_string(), Value::Bool(true));
m.insert("unWatchOrders".to_string(), Value::Bool(true));
m.insert("unWatchPositions".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::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("wss://stream.{hostname}/v5/public/spot".to_string()));
m.insert("inverse".to_string(), Value::Str("wss://stream.{hostname}/v5/public/inverse".to_string()));
m.insert("option".to_string(), Value::Str("wss://stream.{hostname}/v5/public/option".to_string()));
m.insert("linear".to_string(), Value::Str("wss://stream.{hostname}/v5/public/linear".to_string()));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unified".to_string(), Value::Str("wss://stream.{hostname}/v5/private".to_string()));
m.insert("nonUnified".to_string(), Value::Str("wss://stream.{hostname}/spot/private/v3".to_string()));
m
}));
m.insert("contract".to_string(), Value::Str("wss://stream.{hostname}/v5/private".to_string()));
m.insert("usdc".to_string(), Value::Str("wss://stream.{hostname}/trade/option/usdc/private/v1".to_string()));
m.insert("trade".to_string(), Value::Str("wss://stream.bybit.com/v5/trade".to_string()));
m
}));
m
}));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("wss://stream-testnet.{hostname}/v5/public/spot".to_string()));
m.insert("inverse".to_string(), Value::Str("wss://stream-testnet.{hostname}/v5/public/inverse".to_string()));
m.insert("linear".to_string(), Value::Str("wss://stream-testnet.{hostname}/v5/public/linear".to_string()));
m.insert("option".to_string(), Value::Str("wss://stream-testnet.{hostname}/v5/public/option".to_string()));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unified".to_string(), Value::Str("wss://stream-testnet.{hostname}/v5/private".to_string()));
m.insert("nonUnified".to_string(), Value::Str("wss://stream-testnet.{hostname}/spot/private/v3".to_string()));
m
}));
m.insert("contract".to_string(), Value::Str("wss://stream-testnet.{hostname}/v5/private".to_string()));
m.insert("usdc".to_string(), Value::Str("wss://stream-testnet.{hostname}/trade/option/usdc/private/v1".to_string()));
m.insert("trade".to_string(), Value::Str("wss://stream-testnet.bybit.com/v5/trade".to_string()));
m
}));
m
}));
m
}));
m.insert("demotrading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("wss://stream.{hostname}/v5/public/spot".to_string()));
m.insert("inverse".to_string(), Value::Str("wss://stream.{hostname}/v5/public/inverse".to_string()));
m.insert("option".to_string(), Value::Str("wss://stream.{hostname}/v5/public/option".to_string()));
m.insert("linear".to_string(), Value::Str("wss://stream.{hostname}/v5/public/linear".to_string()));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unified".to_string(), Value::Str("wss://stream-demo.{hostname}/v5/private".to_string()));
m.insert("nonUnified".to_string(), Value::Str("wss://stream-demo.{hostname}/spot/private/v3".to_string()));
m
}));
m.insert("contract".to_string(), Value::Str("wss://stream-demo.{hostname}/v5/private".to_string()));
m.insert("usdc".to_string(), Value::Str("wss://stream-demo.{hostname}/trade/option/usdc/private/v1".to_string()));
m.insert("trade".to_string(), Value::Str("wss://stream-demo.bybit.com/v5/trade".to_string()));
m
}));
m
}));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("watchTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("tickers".to_string()));
m
}));
m.insert("watchPositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fetchPositionsSnapshot".to_string(), Value::Bool(true));
m.insert("awaitPositionsSnapshot".to_string(), Value::Bool(true));
m
}));
m.insert("watchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("execType".to_string(), Value::List(vec![Value::Str("Trade".to_string()), Value::Str("AdlTrade".to_string()), Value::Str("BustTrade".to_string()), Value::Str("Settle".to_string())]));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("3m".to_string(), Value::Str("3m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
m
}));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1".to_string()));
m.insert("3m".to_string(), Value::Str("3".to_string()));
m.insert("5m".to_string(), Value::Str("5".to_string()));
m.insert("15m".to_string(), Value::Str("15".to_string()));
m.insert("30m".to_string(), Value::Str("30".to_string()));
m.insert("1h".to_string(), Value::Str("60".to_string()));
m.insert("2h".to_string(), Value::Str("120".to_string()));
m.insert("4h".to_string(), Value::Str("240".to_string()));
m.insert("6h".to_string(), Value::Str("360".to_string()));
m.insert("12h".to_string(), Value::Str("720".to_string()));
m.insert("1d".to_string(), Value::Str("D".to_string()));
m.insert("1w".to_string(), Value::Str("W".to_string()));
m.insert("1M".to_string(), Value::Str("M".to_string()));
m
}));
m
}));
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(18000));
m
}));
m
});
Value::Null
}
pub fn request_id(&mut self) -> Value {
self.lock_id(&[]);
let mut requestId: Value = self.sum(&[self.safe_integer_k(self.options.clone(), "requestId", &[Value::Int(0)]), Value::Int(1)]);
add_element_to_object(&mut self.options, &Value::Str("requestId".to_string()), requestId.clone());
self.unlock_id(&[]);
return requestId;
Value::Null
}
pub async fn get_url_by_market_type(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut isPrivate = get_arg(optional_args, 1, Value::Bool(false));
let mut method = 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 accessibility: Value = ternary(is_true(&isPrivate), Value::Str("private".to_string()), Value::Str("public".to_string()));
if is_equal(&method, &Value::Null) {
method = Value::Str("".to_string());
}
let mut isUsdcSettled: Value = Value::Null;
let mut isSpot: Value = Value::Null;
let mut type_var: Value = Value::Null;
let mut market: Value = Value::Null;
let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string()));
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
isUsdcSettled = Value::Bool(is_equal(&get_value(&market, &Value::Str("settle".to_string())), &Value::Str("USDC".to_string())));
type_var = get_value(&market, &Value::Str("type".to_string()));
} else {
{ let __destr_tmp = self.handle_market_type_and_params(method.clone(), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut defaultSettle: Value = self.safe_string_k(self.options.clone(), "defaultSettle", &[]);
defaultSettle = self.safe_string2(params.clone(), Value::Str("settle".to_string()), Value::Str("defaultSettle".to_string()), &[defaultSettle.clone()]);
isUsdcSettled = Value::Bool(is_equal(&defaultSettle, &Value::Str("USDC".to_string())));
}
isSpot = Value::Bool(is_equal(&type_var, &Value::Str("spot".to_string())));
if is_true(&isPrivate) {
let mut unified: Value = self.parent.is_unified_enabled(&[]).await;
let mut isUnifiedMargin: Value = self.safe_bool(unified.clone(), Value::Int(0), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = self.safe_bool(unified.clone(), Value::Int(1), &[Value::Bool(false)]);
if is_true(&isUsdcSettled) && is_true(&(!is_equal(&isUnifiedMargin, &Value::Bool(true)))) && is_true(&(!is_equal(&isUnifiedAccount, &Value::Bool(true)))) {
url = get_value(&get_value(&url, &accessibility), &Value::Str("usdc".to_string()));
} else {
url = get_value(&get_value(&url, &accessibility), &Value::Str("contract".to_string()));
}
} else {
if is_true(&isSpot) {
url = get_value(&get_value(&url, &accessibility), &Value::Str("spot".to_string()));
} else if is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(method.clone(), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
url = get_value(&get_value(&url, &accessibility), &subType);
} else {
url = get_value(&get_value(&url, &accessibility), &Value::Str("option".to_string()));
}
}
url = self.implode_hostname(url.clone());
return url;
Value::Null
}
pub fn clean_params(&self, mut params: Value) -> Value {
params = self.omit(params.clone(), Value::List(vec![Value::Str("type".to_string()), Value::Str("subType".to_string()), Value::Str("settle".to_string()), Value::Str("defaultSettle".to_string()), Value::Str("unifiedMargin".to_string())]), &[]);
return params;
Value::Null
}
pub async fn create_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = 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 orderRequest: Value = self.parent.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone(), Value::Bool(true)]);
let mut url: Value = get_value(&get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("private".to_string())), &Value::Str("trade".to_string()));
self.authenticate(url.clone(), &[]).await;
let mut requestId: Value = to_string_val(&self.request_id());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("order.create".to_string()));
m.insert("reqId".to_string(), requestId.clone());
m.insert("args".to_string(), Value::List(vec![orderRequest.clone()]));
m.insert("header".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-BAPI-TIMESTAMP".to_string(), to_string_val(&self.milliseconds()));
m.insert("X-BAPI-RECV-WINDOW".to_string(), to_string_val(&get_value(&self.options, &Value::Str("recvWindow".to_string()))));
m
}));
m
});
return self.watch(url.clone(), requestId.clone(), &[request.clone(), requestId.clone(), Value::Bool(true)]).await;
Value::Null
}
pub async fn edit_order_ws(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = 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 orderRequest: Value = self.parent.edit_order_request(id.clone(), symbol.clone(), type_var.clone(), side.clone(), &[amount.clone(), price.clone(), params.clone()]);
let mut url: Value = get_value(&get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("private".to_string())), &Value::Str("trade".to_string()));
self.authenticate(url.clone(), &[]).await;
let mut requestId: Value = to_string_val(&self.request_id());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("order.amend".to_string()));
m.insert("reqId".to_string(), requestId.clone());
m.insert("args".to_string(), Value::List(vec![orderRequest.clone()]));
m.insert("header".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-BAPI-TIMESTAMP".to_string(), to_string_val(&self.milliseconds()));
m.insert("X-BAPI-RECV-WINDOW".to_string(), to_string_val(&get_value(&self.options, &Value::Str("recvWindow".to_string()))));
m
}));
m
});
return self.watch(url.clone(), requestId.clone(), &[request.clone(), requestId.clone(), Value::Bool(true)]).await;
Value::Null
}
pub async fn cancel_order_ws(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = 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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrderWs() requires a symbol argument".to_string()))));
}
let mut orderRequest: Value = self.parent.cancel_order_request(id.clone(), &[symbol.clone(), params.clone()]);
let mut url: Value = get_value(&get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("private".to_string())), &Value::Str("trade".to_string()));
self.authenticate(url.clone(), &[]).await;
let mut requestId: Value = to_string_val(&self.request_id());
if is_true(&Value::Bool(in_op(&orderRequest, &Value::Str("orderFilter".to_string())))) {
remove(&mut orderRequest, &Value::Str("orderFilter".to_string()));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("order.cancel".to_string()));
m.insert("reqId".to_string(), requestId.clone());
m.insert("args".to_string(), Value::List(vec![orderRequest.clone()]));
m.insert("header".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-BAPI-TIMESTAMP".to_string(), to_string_val(&self.milliseconds()));
m.insert("X-BAPI-RECV-WINDOW".to_string(), to_string_val(&get_value(&self.options, &Value::Str("recvWindow".to_string()))));
m
}));
m
});
return self.watch(url.clone(), requestId.clone(), &[request.clone(), requestId.clone(), Value::Bool(true)]).await;
Value::Null
}
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 = self.get_url_by_market_type(&[symbol.clone(), Value::Bool(false), Value::Str("watchTicker".to_string()), params.clone()]).await;
params = self.clean_params(params.clone());
let mut options: Value = self.safe_value_k(self.options.clone(), "watchTicker", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut topic: Value = self.safe_string_k(options.clone(), "name", &[Value::Str("tickers".to_string())]);
if is_true(&(!is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && !is_equal(&topic, &Value::Str("tickers".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" watchTicker() only supports name tickers for contract markets".to_string()))));
}
topic = add(&topic, &add(&Value::Str(".".to_string()), &get_value(&market, &Value::Str("id".to_string()))));
let mut topics: Value = Value::List(vec![topic.clone()]);
return self.watch_topics(url.clone(), Value::List(vec![messageHash.clone()]), topics.clone(), &[params.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(), Value::Null, Value::Bool(false)]);
let mut messageHashes: Value = Value::List(vec![]);
let mut url: Value = self.get_url_by_market_type(&[get_value(&symbols, &Value::Int(0)), Value::Bool(false), Value::Str("watchTickers".to_string()), params.clone()]).await;
params = self.clean_params(params.clone());
let mut options: Value = self.safe_value_k(self.options.clone(), "watchTickers", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut topic: Value = self.safe_string_k(options.clone(), "name", &[Value::Str("tickers".to_string())]);
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
let mut topics: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_201: bool = true;
while { if !__for_first_201 { i = add(&i, &Value::Int(1)); } __for_first_201 = false; is_less_than(&i, &get_array_length(&marketIds)) } {
let mut marketId: Value = get_value(&marketIds, &i);
let mut marketId: Value = get_value(&marketIds, &i);
append_to_array(&mut topics, add(&add(&topic, &Value::Str(".".to_string())), &marketId));
append_to_array(&mut messageHashes, add(&Value::Str("ticker:".to_string()), &get_value(&symbols, &i)));
}
}
let mut ticker: Value = self.watch_topics(url.clone(), messageHashes.clone(), topics.clone(), &[params.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(self.tickers.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub async fn un_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(), Value::Null, Value::Bool(false)]);
let mut options: Value = self.safe_value_k(self.options.clone(), "watchTickers", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut topic: Value = self.safe_string_k(options.clone(), "name", &[Value::Str("tickers".to_string())]);
let mut messageHashes: Value = Value::List(vec![]);
let mut subMessageHashes: Value = Value::List(vec![]);
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
let mut topics: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_202: bool = true;
while { if !__for_first_202 { i = add(&i, &Value::Int(1)); } __for_first_202 = false; is_less_than(&i, &get_array_length(&marketIds)) } {
let mut marketId: Value = get_value(&marketIds, &i);
let mut marketId: Value = get_value(&marketIds, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut topics, add(&add(&topic, &Value::Str(".".to_string())), &marketId));
append_to_array(&mut subMessageHashes, add(&Value::Str("ticker:".to_string()), &symbol));
append_to_array(&mut messageHashes, add(&Value::Str("unsubscribe:ticker:".to_string()), &symbol));
}
}
let mut url: Value = self.get_url_by_market_type(&[get_value(&symbols, &Value::Int(0)), Value::Bool(false), Value::Str("watchTickers".to_string()), params.clone()]).await;
return self.un_watch_topics(url.clone(), Value::Str("ticker".to_string()), symbols.clone(), messageHashes.clone(), subMessageHashes.clone(), topics.clone(), &[params.clone()]).await;
Value::Null
}
pub async fn un_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
}));
return self.un_watch_tickers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
Value::Null
}
pub fn handle_ticker(&mut self, mut client: Value, mut message: Value) {
let mut topic: Value = self.safe_string_k(message.clone(), "topic", &[Value::Str("".to_string())]);
let mut updateType: Value = self.safe_string_k(message.clone(), "type", &[Value::Str("".to_string())]);
let mut data: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut isSpot: bool = !is_equal(&self.safe_string_k(data.clone(), "usdIndexPrice", &[]), &Value::Null);
let mut type_var: Value = ternary(is_true(&isSpot), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut symbol: Value = Value::Null;
let mut parsed: Value = Value::Null;
if is_true(&(is_equal(&updateType, &Value::Str("snapshot".to_string())))) {
parsed = self.parse_ticker(data.clone(), &[]);
symbol = get_value(&parsed, &Value::Str("symbol".to_string()));
} else if is_equal(&updateType, &Value::Str("delta".to_string())) {
let mut topicParts: Value = split(&topic, &Value::Str(".".to_string()));
let mut topicLength: Value = get_array_length(&topicParts);
let mut marketId: Value = self.safe_string(topicParts.clone(), subtract(&topicLength, &Value::Int(1)), &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, type_var.clone()]);
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut ticker: Value = self.safe_dict(self.tickers.clone(), symbol.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rawTicker: Value = self.safe_dict_k(ticker.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut merged: Value = self.extend(rawTicker.clone(), &[data.clone()]);
parsed = self.parse_ticker(merged.clone(), &[]);
}
if is_true(&(is_equal(&parsed, &Value::Null))) || is_true(&(is_equal(&symbol, &Value::Null))) {
return;
}
let mut timestamp: Value = self.safe_integer_k(message.clone(), "ts", &[]);
add_element_to_object(&mut parsed, &Value::Str("timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut parsed, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
add_element_to_object(&mut self.tickers, &symbol, parsed.clone());
let mut messageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
client.resolve(&[get_value(&self.tickers, &symbol), messageHash.clone()]);
}
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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false)]);
let mut messageHashes: Value = Value::List(vec![]);
let mut url: Value = self.get_url_by_market_type(&[get_value(&symbols, &Value::Int(0)), Value::Bool(false), Value::Str("watchBidsAsks".to_string()), params.clone()]).await;
params = self.clean_params(params.clone());
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
let mut topics: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_203: bool = true;
while { if !__for_first_203 { i = add(&i, &Value::Int(1)); } __for_first_203 = false; is_less_than(&i, &get_array_length(&marketIds)) } {
let mut marketId: Value = get_value(&marketIds, &i);
let mut marketId: Value = get_value(&marketIds, &i);
let mut topic: Value = add(&Value::Str("orderbook.1.".to_string()), &marketId);
append_to_array(&mut topics, topic.clone());
append_to_array(&mut messageHashes, add(&Value::Str("bidask:".to_string()), &get_value(&symbols, &i)));
}
}
let mut ticker: Value = self.watch_topics(url.clone(), messageHashes.clone(), topics.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
return ticker;
}
return self.filter_by_array(self.bidsasks.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub fn parse_ws_bid_ask(&self, mut orderbook: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.safe_integer_k(orderbook.clone(), "timestamp", &[]);
let mut bids: Value = self.sort_by(self.aggregate(get_value(&orderbook, &Value::Str("bids".to_string()))), Value::Int(0), &[]);
let mut asks: Value = self.sort_by(self.aggregate(get_value(&orderbook, &Value::Str("asks".to_string()))), Value::Int(0), &[]);
let mut bestBid: Value = self.safe_list(bids.clone(), Value::Int(0), &[Value::List(vec![])]);
let mut bestAsk: Value = self.safe_list(asks.clone(), Value::Int(0), &[Value::List(vec![])]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("ask".to_string(), self.safe_number(bestAsk.clone(), Value::Int(0), &[]));
m.insert("askVolume".to_string(), self.safe_number(bestAsk.clone(), Value::Int(1), &[]));
m.insert("bid".to_string(), self.safe_number(bestBid.clone(), Value::Int(0), &[]));
m.insert("bidVolume".to_string(), self.safe_number(bestBid.clone(), Value::Int(1), &[]));
m.insert("info".to_string(), orderbook.clone());
m
}), &[market.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
}));
add_element_to_object(&mut params, &Value::Str("callerMethodName".to_string()), Value::Str("watchOHLCV".to_string()));
let mut result: Value = self.watch_ohlcv_for_symbols(Value::List(vec![Value::List(vec![symbol.clone(), timeframe.clone()])]), &[since.clone(), limit.clone(), params.clone()]).await;
return get_value(&get_value(&result, &symbol), &timeframe);
Value::Null
}
pub async fn watch_ohlcv_for_symbols(&mut self, mut symbolsAndTimeframes: 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 symbols: Value = self.get_list_from_object_values(symbolsAndTimeframes.clone(), Value::Int(0));
let mut marketSymbols: Value = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut firstSymbol: Value = get_value(&marketSymbols, &Value::Int(0));
let mut url: Value = self.get_url_by_market_type(&[firstSymbol.clone(), Value::Bool(false), Value::Str("watchOHLCVForSymbols".to_string()), params.clone()]).await;
let mut rawHashes: Value = Value::List(vec![]);
let mut messageHashes: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_204: bool = true;
while { if !__for_first_204 { i = add(&i, &Value::Int(1)); } __for_first_204 = false; is_less_than(&i, &get_array_length(&symbolsAndTimeframes)) } {
let mut data: Value = get_value(&symbolsAndTimeframes, &i);
let mut data: Value = get_value(&symbolsAndTimeframes, &i);
let mut market: Value = self.market(get_value(&data, &Value::Int(0)));
let mut symbolString: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut unfiedTimeframe: Value = get_value(&data, &Value::Int(1));
let mut timeframeId: Value = self.safe_string(self.timeframes.clone(), unfiedTimeframe.clone(), &[unfiedTimeframe.clone()]);
append_to_array(&mut rawHashes, add(&add(&add(&Value::Str("kline.".to_string()), &timeframeId), &Value::Str(".".to_string())), &get_value(&market, &Value::Str("id".to_string()))));
append_to_array(&mut messageHashes, add(&add(&add(&Value::Str("ohlcv::".to_string()), &symbolString), &Value::Str("::".to_string())), &unfiedTimeframe));
}
}
let mut symboltimeframestoredVariable = self.watch_topics(url.clone(), messageHashes.clone(), rawHashes.clone(), &[params.clone()]).await;
let mut symbol: Value = get_value(&symboltimeframestoredVariable, &Value::Int(0));
let mut timeframe: Value = get_value(&symboltimeframestoredVariable, &Value::Int(1));
let mut stored: Value = get_value(&symboltimeframestoredVariable, &Value::Int(2));
if is_true(&self.newUpdates) {
limit = stored.get_limit(symbol.clone(), limit.clone());
}
let mut filtered: Value = self.filter_by_since_limit(stored.clone(), &[since.clone(), limit.clone(), Value::Int(0), Value::Bool(true)]);
return self.create_ohlcv_object(symbol.clone(), timeframe.clone(), filtered.clone());
Value::Null
}
pub async fn un_watch_ohlcv_for_symbols(&mut self, mut symbolsAndTimeframes: 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 symbols: Value = self.get_list_from_object_values(symbolsAndTimeframes.clone(), Value::Int(0));
let mut marketSymbols: Value = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut firstSymbol: Value = get_value(&marketSymbols, &Value::Int(0));
let mut url: Value = self.get_url_by_market_type(&[firstSymbol.clone(), Value::Bool(false), Value::Str("watchOHLCVForSymbols".to_string()), params.clone()]).await;
let mut rawHashes: Value = Value::List(vec![]);
let mut subMessageHashes: Value = Value::List(vec![]);
let mut messageHashes: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_205: bool = true;
while { if !__for_first_205 { i = add(&i, &Value::Int(1)); } __for_first_205 = false; is_less_than(&i, &get_array_length(&symbolsAndTimeframes)) } {
let mut data: Value = get_value(&symbolsAndTimeframes, &i);
let mut data: Value = get_value(&symbolsAndTimeframes, &i);
let mut market: Value = self.market(get_value(&data, &Value::Int(0)));
let mut symbolString: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut unfiedTimeframe: Value = get_value(&data, &Value::Int(1));
let mut timeframeId: Value = self.safe_string(self.timeframes.clone(), unfiedTimeframe.clone(), &[unfiedTimeframe.clone()]);
append_to_array(&mut rawHashes, add(&add(&add(&Value::Str("kline.".to_string()), &timeframeId), &Value::Str(".".to_string())), &get_value(&market, &Value::Str("id".to_string()))));
append_to_array(&mut subMessageHashes, add(&add(&add(&Value::Str("ohlcv::".to_string()), &symbolString), &Value::Str("::".to_string())), &unfiedTimeframe));
append_to_array(&mut messageHashes, add(&add(&add(&Value::Str("unsubscribe::ohlcv::".to_string()), &symbolString), &Value::Str("::".to_string())), &unfiedTimeframe));
}
}
let mut subExtension: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbolsAndTimeframes".to_string(), symbolsAndTimeframes.clone());
m
});
return self.un_watch_topics(url.clone(), Value::Str("ohlcv".to_string()), symbols.clone(), messageHashes.clone(), subMessageHashes.clone(), rawHashes.clone(), &[params.clone(), subExtension.clone()]).await;
Value::Null
}
pub async fn un_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 params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
add_element_to_object(&mut params, &Value::Str("callerMethodName".to_string()), Value::Str("watchOHLCV".to_string()));
return self.un_watch_ohlcv_for_symbols(Value::List(vec![Value::List(vec![symbol.clone(), timeframe.clone()])]), &[params.clone()]).await;
Value::Null
}
pub fn handle_ohlcv(&mut self, mut client: Value, mut message: Value) {
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut topic: Value = self.safe_string_k(message.clone(), "topic", &[Value::Str("".to_string())]);
let mut topicParts: Value = split(&topic, &Value::Str(".".to_string()));
let mut topicLength: Value = get_array_length(&topicParts);
let mut timeframeId: Value = self.safe_string(topicParts.clone(), Value::Int(1), &[]);
let mut timeframe: Value = self.find_timeframe(timeframeId.clone(), &[]);
if is_equal(&timeframe, &Value::Null) {
return;
}
let mut marketId: Value = self.safe_string(topicParts.clone(), subtract(&topicLength, &Value::Int(1)), &[]);
let mut isSpot: bool = is_greater_than(&get_index_of(&get_value(&client, &Value::Str("url".to_string())), &Value::Str("spot".to_string())), &negate(&Value::Int(1)));
let mut marketType: Value = ternary(is_true(&isSpot), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut ohlcvsByTimeframe: Value = self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[]);
if is_equal(&ohlcvsByTimeframe, &Value::Null) {
add_element_to_object(&mut self.ohlcvs, &symbol, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
if is_equal(&self.safe_value(ohlcvsByTimeframe.clone(), timeframe.clone(), &[]), &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "OHLCVLimit", &[Value::Int(1000)]);
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.ohlcvs) }, &symbol), &timeframe, ArrayCacheByTimestamp::new(limit.clone()));
}
let mut stored: Value = get_value(&get_value(&self.ohlcvs, &symbol), &timeframe);
{
let mut i: Value = Value::Int(0);
let mut __for_first_206: bool = true;
while { if !__for_first_206 { i = add(&i, &Value::Int(1)); } __for_first_206 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut parsed: Value = self.parse_ws_ohlcv(get_value(&data, &i), &[market.clone()]);
stored.append(parsed.clone());
}
}
let mut messageHash: Value = add(&add(&add(&Value::Str("ohlcv::".to_string()), &symbol), &Value::Str("::".to_string())), &timeframe);
let mut resolveData: Value = Value::List(vec![symbol.clone(), timeframe.clone(), stored.clone()]);
client.resolve(&[resolveData.clone(), messageHash.clone()]);
}
pub fn parse_ws_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut isInverse: bool = is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true));
let mut volumeIndex: Value = ternary(is_true(&isInverse), Value::Str("turnover".to_string()), Value::Str("volume".to_string()));
return Value::List(vec![self.safe_integer_k(ohlcv.clone(), "start", &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number(ohlcv.clone(), volumeIndex.clone(), &[])]);
Value::Null
}
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
}));
return self.watch_order_book_for_symbols(Value::List(vec![symbol.clone()]), &[limit.clone(), params.clone()]).await;
Value::Null
}
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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsLength: Value = get_array_length(&symbols);
if is_equal(&symbolsLength, &Value::Int(0)) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchOrderBookForSymbols() requires a non-empty array of symbols".to_string()))));
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut url: Value = self.get_url_by_market_type(&[get_value(&symbols, &Value::Int(0)), Value::Bool(false), Value::Str("watchOrderBook".to_string()), params.clone()]).await;
params = self.clean_params(params.clone());
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
if is_equal(&limit, &Value::Null) {
limit = Value::Int(50);
if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
limit = Value::Int(100);
}
} else {
let mut limits: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::List(vec![Value::Int(1), Value::Int(50), Value::Int(200), Value::Int(1000)]));
m.insert("option".to_string(), Value::List(vec![Value::Int(25), Value::Int(100)]));
m.insert("default".to_string(), Value::List(vec![Value::Int(1), Value::Int(50), Value::Int(200), Value::Int(1000)]));
m
});
let mut selectedLimits: Value = self.safe_list2(limits.clone(), get_value(&market, &Value::Str("type".to_string())), Value::Str("default".to_string()), &[Value::List(vec![])]);
if !is_true(&self.in_array(limit.clone(), selectedLimits.clone())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&self.id, &Value::Str(" watchOrderBookForSymbols(): for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" markets limit can be one of: ".to_string())), &self.json(selectedLimits.clone()))));
}
}
let mut topics: Value = Value::List(vec![]);
let mut messageHashes: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_207: bool = true;
while { if !__for_first_207 { i = add(&i, &Value::Int(1)); } __for_first_207 = 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 marketId: Value = self.market_id(symbol.clone());
let mut topic: Value = add(&add(&add(&Value::Str("orderbook.".to_string()), &to_string_val(&limit)), &Value::Str(".".to_string())), &marketId);
append_to_array(&mut topics, topic.clone());
let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
append_to_array(&mut messageHashes, messageHash.clone());
}
}
let mut orderbook: Value = self.watch_topics(url.clone(), messageHashes.clone(), topics.clone(), &[params.clone()]).await;
return orderbook.limit();
Value::Null
}
pub async fn un_watch_order_book_for_symbols(&mut self, mut symbols: 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;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false)]);
let mut channel: Value = Value::Str("orderbook.".to_string());
let mut limit: Value = self.safe_integer_k(params.clone(), "limit", &[]);
if !is_equal(&limit, &Value::Null) {
params = self.omit(params.clone(), Value::Str("limit".to_string()), &[]);
} else {
let mut firstMarket: Value = self.market(get_value(&symbols, &Value::Int(0)));
limit = ternary(is_true(&(is_equal(&get_value(&firstMarket, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Int(50), Value::Int(500));
}
channel = add(&channel, &to_string_val(&limit));
let mut subMessageHashes: Value = Value::List(vec![]);
let mut messageHashes: Value = Value::List(vec![]);
let mut topics: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_208: bool = true;
while { if !__for_first_208 { i = add(&i, &Value::Int(1)); } __for_first_208 = 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 market: Value = self.market(symbol.clone());
let mut marketId: Value = get_value(&market, &Value::Str("id".to_string()));
let mut topic: Value = add(&add(&channel, &Value::Str(".".to_string())), &marketId);
append_to_array(&mut messageHashes, add(&Value::Str("unsubscribe:orderbook:".to_string()), &symbol));
append_to_array(&mut subMessageHashes, add(&Value::Str("orderbook:".to_string()), &symbol));
append_to_array(&mut topics, topic.clone());
}
}
let mut url: Value = self.get_url_by_market_type(&[get_value(&symbols, &Value::Int(0)), Value::Bool(false), Value::Str("watchOrderBook".to_string()), params.clone()]).await;
return self.un_watch_topics(url.clone(), Value::Str("orderbook".to_string()), symbols.clone(), messageHashes.clone(), subMessageHashes.clone(), topics.clone(), &[params.clone()]).await;
Value::Null
}
pub async fn un_watch_order_book(&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
}));
return self.un_watch_order_book_for_symbols(Value::List(vec![symbol.clone()]), &[params.clone()]).await;
Value::Null
}
pub fn handle_order_book(&mut self, mut client: Value, mut message: Value) {
let mut topic: Value = self.safe_string_k(message.clone(), "topic", &[Value::Str("".to_string())]);
let mut limit: Value = get_value(&split(&topic, &Value::Str(".".to_string())), &Value::Int(1));
let mut isSpot: bool = is_greater_than_or_equal(&get_index_of(&get_value(&client, &Value::Str("url".to_string())), &Value::Str("spot".to_string())), &Value::Int(0));
let mut type_var: Value = self.safe_string_k(message.clone(), "type", &[]);
let mut isSnapshot: bool = is_equal(&type_var, &Value::Str("snapshot".to_string()));
let mut data: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(data.clone(), "s", &[]);
let mut marketType: Value = ternary(is_true(&isSpot), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer_k(message.clone(), "ts", &[]);
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); };
}
let mut orderbook: Value = get_value(&self.orderbooks, &symbol);
add_element_to_object(&mut orderbook, &Value::Str("symbol".to_string()), symbol.clone());
if is_true(&isSnapshot) {
let mut snapshot: Value = self.parse_order_book(data.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("b".to_string()), Value::Str("a".to_string())]);
orderbook.reset(snapshot.clone());
} else {
let mut asks: Value = self.safe_list_k(data.clone(), "a", &[Value::List(vec![])]);
let mut bids: Value = self.safe_list_k(data.clone(), "b", &[Value::List(vec![])]);
self.handle_deltas(get_value(&orderbook, &Value::Str("asks".to_string())), asks.clone());
self.handle_deltas(get_value(&orderbook, &Value::Str("bids".to_string())), bids.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()));
}
let mut messageHash: Value = add(&add(&Value::Str("orderbook".to_string()), &Value::Str(":".to_string())), &symbol);
add_element_to_object(&mut self.orderbooks, &symbol, orderbook.clone());
client.resolve(&[orderbook.clone(), messageHash.clone()]);
if is_equal(&limit, &Value::Str("1".to_string())) {
let mut bidask: Value = self.parse_ws_bid_ask(get_value(&self.orderbooks, &symbol), &[market.clone()]);
let mut newBidsAsks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut newBidsAsks, &symbol, bidask.clone());
add_element_to_object(&mut self.bidsasks, &symbol, bidask.clone());
client.resolve(&[newBidsAsks.clone(), add(&Value::Str("bidask:".to_string()), &symbol)]);
}
}
pub fn handle_delta(&self, mut bookside: Value, mut delta: Value) {
let mut bidAsk: Value = self.parse_order_book_bid_ask(delta.clone(), &[Value::Int(0), Value::Int(1)]);
bookside.store_array(bidAsk.clone());
}
pub fn handle_deltas(&self, mut bookside: Value, mut deltas: Value) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_209: bool = true;
while { if !__for_first_209 { i = add(&i, &Value::Int(1)); } __for_first_209 = false; is_less_than(&i, &get_array_length(&deltas)) } {
self.handle_delta(bookside.clone(), get_value(&deltas, &i));
}
}
}
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
}));
return self.watch_trades_for_symbols(Value::List(vec![symbol.clone()]), &[since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut symbolsLength: Value = get_array_length(&symbols);
if is_equal(&symbolsLength, &Value::Int(0)) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchTradesForSymbols() requires a non-empty array of symbols".to_string()))));
}
params = self.clean_params(params.clone());
let mut url: Value = self.get_url_by_market_type(&[get_value(&symbols, &Value::Int(0)), Value::Bool(false), Value::Str("watchTrades".to_string()), params.clone()]).await;
let mut topics: Value = Value::List(vec![]);
let mut messageHashes: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_210: bool = true;
while { if !__for_first_210 { i = add(&i, &Value::Int(1)); } __for_first_210 = 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 market: Value = self.market(symbol.clone());
let mut topic: Value = add(&Value::Str("publicTrade.".to_string()), &get_value(&market, &Value::Str("id".to_string())));
append_to_array(&mut topics, topic.clone());
let mut messageHash: Value = add(&Value::Str("trade:".to_string()), &symbol);
append_to_array(&mut messageHashes, messageHash.clone());
}
}
let mut trades: Value = self.watch_topics(url.clone(), messageHashes.clone(), topics.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
let mut first: Value = self.safe_value(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 async fn un_watch_trades_for_symbols(&mut self, mut symbols: 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;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true)]);
let mut url: Value = self.get_url_by_market_type(&[get_value(&symbols, &Value::Int(0)), Value::Bool(false), Value::Str("unWatchTradesForSymbols".to_string()), params.clone()]).await;
let mut messageHashes: Value = Value::List(vec![]);
let mut topics: Value = Value::List(vec![]);
let mut subMessageHashes: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_211: bool = true;
while { if !__for_first_211 { i = add(&i, &Value::Int(1)); } __for_first_211 = 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 market: Value = self.market(symbol.clone());
let mut topic: Value = add(&Value::Str("publicTrade.".to_string()), &get_value(&market, &Value::Str("id".to_string())));
append_to_array(&mut topics, topic.clone());
let mut messageHash: Value = add(&Value::Str("unsubscribe:trade:".to_string()), &symbol);
append_to_array(&mut messageHashes, messageHash.clone());
append_to_array(&mut subMessageHashes, add(&Value::Str("trade:".to_string()), &symbol));
}
}
return self.un_watch_topics(url.clone(), Value::Str("trades".to_string()), symbols.clone(), messageHashes.clone(), subMessageHashes.clone(), topics.clone(), &[params.clone()]).await;
Value::Null
}
pub async fn un_watch_trades(&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
}));
return self.un_watch_trades_for_symbols(Value::List(vec![symbol.clone()]), &[params.clone()]).await;
Value::Null
}
pub fn handle_trades(&mut self, mut client: Value, mut message: Value) {
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut topic: Value = self.safe_string_k(message.clone(), "topic", &[Value::Str("".to_string())]);
let mut trades: Value = data.clone();
let mut parts: Value = split(&topic, &Value::Str(".".to_string()));
let mut isSpot: Value = Value::Bool(is_greater_than_or_equal(&get_index_of(&get_value(&client, &Value::Str("url".to_string())), &Value::Str("spot".to_string())), &Value::Int(0)));
let mut marketType: Value = ternary(is_true(&(isSpot)), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut marketId: Value = self.safe_string(parts.clone(), Value::Int(1), &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut stored: Value = self.safe_value(self.trades.clone(), symbol.clone(), &[]);
if is_equal(&stored, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
stored = ArrayCache::new(limit.clone());
add_element_to_object(&mut self.trades, &symbol, stored.clone());
}
{
let mut j: Value = Value::Int(0);
let mut __for_first_212: bool = true;
while { if !__for_first_212 { j = add(&j, &Value::Int(1)); } __for_first_212 = false; is_less_than(&j, &get_array_length(&trades)) } {
let mut parsed: Value = self.parse_ws_trade(get_value(&trades, &j), &[market.clone()]);
stored.append(parsed.clone());
}
}
let mut messageHash: Value = add(&add(&Value::Str("trade".to_string()), &Value::Str(":".to_string())), &symbol);
client.resolve(&[stored.clone(), messageHash.clone()]);
}
pub fn parse_ws_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut id: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("i".to_string()), Value::Str("T".to_string()), Value::Str("v".to_string())]), &[]);
let mut isContract: Value = (Value::Bool(in_op(&trade, &Value::Str("BT".to_string()))));
let mut marketType: Value = ternary(is_true(&isContract), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
if !is_equal(&market, &Value::Null) {
marketType = get_value(&market, &Value::Str("type".to_string()));
}
let mut marketId: Value = self.safe_string_k(trade.clone(), "s", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer2(trade.clone(), Value::Str("t".to_string()), Value::Str("T".to_string()), &[]);
let mut side: Value = self.safe_string_lower(trade.clone(), Value::Str("S".to_string()), &[]);
let mut takerOrMaker: Value = Value::Null;
let mut m: Value = self.safe_value_k(trade.clone(), "m", &[]);
if is_equal(&side, &Value::Null) {
side = ternary(is_true(&(is_equal(&m, &Value::Bool(true)))), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
} else {
takerOrMaker = m.clone();
}
let mut price: Value = self.safe_string_k(trade.clone(), "p", &[]);
let mut amount: Value = self.safe_string2(trade.clone(), Value::Str("q".to_string()), Value::Str("v".to_string()), &[]);
let mut orderId: Value = self.safe_string_k(trade.clone(), "o", &[]);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("order".to_string(), orderId.clone());
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), price.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
pub fn get_private_type(&self, mut url: Value) -> Value {
if is_greater_than_or_equal(&get_index_of(&url, &Value::Str("spot".to_string())), &Value::Int(0)) {
return Value::Str("spot".to_string());
} else if is_greater_than_or_equal(&get_index_of(&url, &Value::Str("v5/private".to_string())), &Value::Int(0)) {
return Value::Str("unified".to_string());
} else {
return Value::Str("usdc".to_string());
}
Value::Null
}
pub async fn watch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut method: Value = Value::Str("watchMyTrades".to_string());
let mut messageHash: Value = Value::Str("myTrades".to_string());
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if !is_equal(&symbol, &Value::Null) {
symbol = self.symbol(symbol.clone());
messageHash = add(&messageHash, &add(&Value::Str(":".to_string()), &symbol));
}
let mut url: Value = self.get_url_by_market_type(&[symbol.clone(), Value::Bool(true), method.clone(), params.clone()]).await;
self.authenticate(url.clone(), &[]).await;
let mut topicByMarket: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("ticketInfo".to_string()));
m.insert("unified".to_string(), Value::Str("execution".to_string()));
m.insert("usdc".to_string(), Value::Str("user.openapi.perp.trade".to_string()));
m
});
let mut topic: Value = self.safe_value(topicByMarket.clone(), self.get_private_type(url.clone()), &[]);
let mut executionFast: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchMyTrades".to_string()), Value::Str("executionFast".to_string()), &[Value::Bool(false)]); executionFast = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&executionFast) {
topic = Value::Str("execution.fast".to_string());
}
let mut trades: Value = self.watch_topics(url.clone(), Value::List(vec![messageHash.clone()]), Value::List(vec![topic.clone()]), &[params.clone()]).await;
if is_true(&self.newUpdates) {
limit = trades.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_symbol_since_limit(trades.clone(), &[symbol.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub async fn un_watch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = 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 method: Value = Value::Str("watchMyTrades".to_string());
let mut messageHash: Value = Value::Str("unsubscribe:myTrades".to_string());
let mut subHash: Value = Value::Str("myTrades".to_string());
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if !is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" unWatchMyTrades() does not support a symbol parameter, you must unwatch all my trades".to_string()))));
}
let mut url: Value = self.get_url_by_market_type(&[symbol.clone(), Value::Bool(true), method.clone(), params.clone()]).await;
self.authenticate(url.clone(), &[]).await;
let mut topicByMarket: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("ticketInfo".to_string()));
m.insert("unified".to_string(), Value::Str("execution".to_string()));
m.insert("usdc".to_string(), Value::Str("user.openapi.perp.trade".to_string()));
m
});
let mut topic: Value = self.safe_value(topicByMarket.clone(), self.get_private_type(url.clone()), &[]);
let mut executionFast: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchMyTrades".to_string()), Value::Str("executionFast".to_string()), &[Value::Bool(false)]); executionFast = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&executionFast) {
topic = Value::Str("execution.fast".to_string());
}
return self.un_watch_topics(url.clone(), Value::Str("myTrades".to_string()), Value::List(vec![]), Value::List(vec![messageHash.clone()]), Value::List(vec![subHash.clone()]), Value::List(vec![topic.clone()]), &[params.clone()]).await;
Value::Null
}
pub fn handle_my_trades(&mut self, mut client: Value, mut message: Value) {
let mut topic: Value = self.safe_string_k(message.clone(), "topic", &[Value::Str("".to_string())]);
let mut spot: bool = is_equal(&topic, &Value::Str("ticketInfo".to_string()));
let mut executionFast: bool = is_equal(&topic, &Value::Str("execution.fast".to_string()));
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
if !is_true(&Value::Bool(is_array(&data))) {
data = self.safe_value_k(data.clone(), "result", &[Value::List(vec![])]);
}
if is_equal(&self.myTrades, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
self.myTrades = ArrayCacheBySymbolById::new(limit.clone());
}
let mut trades: Value = self.myTrades.clone();
let mut symbols: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut execTypeOption: Value = self.handle_option(Value::Str("watchMyTrades".to_string()), Value::Str("execType".to_string()), &[]);
if is_equal(&execTypeOption, &Value::Null) {
execTypeOption = self.handle_option(Value::Str("watchMyTrades".to_string()), Value::Str("filterExecTypes".to_string()), &[]);
}
let mut execTypes: Value = Value::Null;
if is_string(&execTypeOption) {
execTypes = Value::List(vec![execTypeOption.clone()]);
} else {
execTypes = execTypeOption.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_213: bool = true;
while { if !__for_first_213 { i = add(&i, &Value::Int(1)); } __for_first_213 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rawTrade: Value = get_value(&data, &i);
let mut rawTrade: Value = get_value(&data, &i);
let mut parsed: Value = Value::Null;
if is_true(&spot) && !is_true(&executionFast) {
parsed = self.parse_ws_trade(rawTrade.clone(), &[]);
} else {
let mut execType: Value = self.safe_string_k(rawTrade.clone(), "execType", &[Value::Str("".to_string())]);
if is_true(&executionFast) {
execType = Value::Str("Trade".to_string());
}
if is_true(&(!is_equal(&execTypes, &Value::Null))) && !is_true(&self.in_array(execType.clone(), execTypes.clone())) {
continue;
}
parsed = self.parse_trade(rawTrade.clone(), &[]);
}
let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
if is_equal(&symbol, &Value::Null) {
continue;
}
add_element_to_object(&mut symbols, &symbol, Value::Bool(true));
trades.append(parsed.clone());
}
}
let mut keys: Value = object_keys(&symbols);
{
let mut i: Value = Value::Int(0);
let mut __for_first_214: bool = true;
while { if !__for_first_214 { i = add(&i, &Value::Int(1)); } __for_first_214 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut currentMessageHash: Value = add(&Value::Str("myTrades:".to_string()), &get_value(&keys, &i));
client.resolve(&[trades.clone(), currentMessageHash.clone()]);
}
}
let mut messageHash: Value = Value::Str("myTrades".to_string());
client.resolve(&[trades.clone(), messageHash.clone()]);
}
pub async fn watch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut method: Value = Value::Str("watchPositions".to_string());
let mut messageHash: Value = Value::Str("".to_string());
if is_true(&(!is_equal(&symbols, &Value::Null))) && !is_true(&self.is_empty(symbols.clone())) {
symbols = self.market_symbols(&[symbols.clone()]);
messageHash = add(&Value::Str("::".to_string()), &join(&symbols, &Value::Str(",".to_string())));
}
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
let mut url: Value = self.get_url_by_market_type(&[firstSymbol.clone(), Value::Bool(true), method.clone(), params.clone()]).await;
messageHash = add(&Value::Str("positions".to_string()), &messageHash);
let mut client: Value = self.client(&[url.clone()]);
self.authenticate(url.clone(), &[]).await;
self.set_positions_cache(client.clone(), &[symbols.clone()]);
let mut cache: Value = self.positions.clone();
let mut fetchPositionsSnapshot: Value = self.handle_option(Value::Str("watchPositions".to_string()), Value::Str("fetchPositionsSnapshot".to_string()), &[Value::Bool(true)]);
let mut awaitPositionsSnapshot: Value = self.handle_option(Value::Str("watchPositions".to_string()), Value::Str("awaitPositionsSnapshot".to_string()), &[Value::Bool(true)]);
if is_true(&(is_equal(&fetchPositionsSnapshot, &Value::Bool(true)))) && is_true(&(is_equal(&awaitPositionsSnapshot, &Value::Bool(true)))) && is_true(&(is_equal(&cache, &Value::Null))) {
let mut snapshot: Value = crate::exchange_stubs::ws_await_flight(&client.future(&[Value::Str("fetchPositionsSnapshot".to_string())])).await;
return self.filter_by_symbols_since_limit(snapshot.clone(), &[symbols.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
}
let mut topics: Value = Value::List(vec![Value::Str("position".to_string())]);
let mut newPositions: Value = self.watch_topics(url.clone(), Value::List(vec![messageHash.clone()]), topics.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
return newPositions;
}
return self.filter_by_symbols_since_limit(cache.clone(), &[symbols.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn set_positions_cache(&mut self, mut client: Value, optional_args: &[Value]) {
let mut symbols = get_arg(optional_args, 0, Value::Null);
if !is_equal(&self.positions, &Value::Null) {
return;
}
let mut fetchPositionsSnapshot: Value = self.handle_option(Value::Str("watchPositions".to_string()), Value::Str("fetchPositionsSnapshot".to_string()), &[Value::Bool(true)]);
if is_equal(&fetchPositionsSnapshot, &Value::Bool(true)) {
let mut messageHash: Value = Value::Str("fetchPositionsSnapshot".to_string());
if !is_true(&(Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &messageHash)))) {
client.future(&[messageHash.clone()]);
self.spawn(&[Value::Str("load_positions_snapshot".to_string()).clone(), client.clone(), messageHash.clone()]);
}
} else {
self.positions = ArrayCacheBySymbolBySide::new(Value::Null);
}
}
pub async fn load_positions_snapshot(&mut self, mut client: Value, mut messageHash: Value) -> Value {
let mut fetchFunctions: Value = Value::List(vec![self.fetch_positions(&[Value::Null, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("swap".to_string()));
m.insert("subType".to_string(), Value::Str("linear".to_string()));
m
})]).await, self.fetch_positions(&[Value::Null, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("swap".to_string()));
m.insert("subType".to_string(), Value::Str("inverse".to_string()));
m
})]).await]);
let mut promises: Value = promise_all(&fetchFunctions).await;
self.positions = ArrayCacheBySymbolBySide::new(Value::Null);
let mut cache: Value = self.positions.clone();
{
let mut i: Value = Value::Int(0);
let mut __for_first_216: bool = true;
while { if !__for_first_216 { i = add(&i, &Value::Int(1)); } __for_first_216 = false; is_less_than(&i, &get_array_length(&promises)) } {
let mut positions: Value = get_value(&promises, &i);
let mut positions: Value = get_value(&promises, &i);
{
let mut ii: Value = Value::Int(0);
let mut __for_first_215: bool = true;
while { if !__for_first_215 { ii = add(&ii, &Value::Int(1)); } __for_first_215 = false; is_less_than(&ii, &get_array_length(&positions)) } {
let mut position: Value = get_value(&positions, &ii);
let mut position: Value = get_value(&positions, &ii);
cache.append(position.clone());
}
}
}
}
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &messageHash))) {
let mut future: Value = get_value(&get_value(&client, &Value::Str("futures".to_string())), &messageHash);
future.resolve(&[cache.clone()]);
client.resolve(&[cache.clone(), Value::Str("position".to_string())]);
}
Value::Null
}
pub fn handle_positions(&mut self, mut client: Value, mut message: Value) {
if is_equal(&self.positions, &Value::Null) {
self.positions = ArrayCacheBySymbolBySide::new(Value::Null);
}
let mut cache: Value = self.positions.clone();
let mut newPositions: Value = Value::List(vec![]);
let mut rawPositions: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_217: bool = true;
while { if !__for_first_217 { i = add(&i, &Value::Int(1)); } __for_first_217 = false; is_less_than(&i, &get_array_length(&rawPositions)) } {
let mut rawPosition: Value = get_value(&rawPositions, &i);
let mut rawPosition: Value = get_value(&rawPositions, &i);
let mut position: Value = self.parse_position(rawPosition.clone(), &[]);
let mut side: Value = self.safe_string_k(position.clone(), "side", &[]);
append_to_array(&mut newPositions, position.clone());
if is_equal(&side, &Value::Null) || is_equal(&side, &Value::Str("".to_string())) {
add_element_to_object(&mut position, &Value::Str("side".to_string()), Value::Str("long".to_string()));
cache.append(position.clone());
add_element_to_object(&mut position, &Value::Str("side".to_string()), Value::Str("short".to_string()));
cache.append(position.clone());
add_element_to_object(&mut position, &Value::Str("side".to_string()), Value::Null);
} else {
cache.append(position.clone());
}
}
}
let mut messageHashes: Value = self.find_message_hashes(client.clone(), Value::Str("positions::".to_string()));
{
let mut i: Value = Value::Int(0);
let mut __for_first_218: bool = true;
while { if !__for_first_218 { i = add(&i, &Value::Int(1)); } __for_first_218 = false; is_less_than(&i, &get_array_length(&messageHashes)) } {
let mut messageHash: Value = get_value(&messageHashes, &i);
let mut messageHash: Value = get_value(&messageHashes, &i);
let mut parts: Value = split(&messageHash, &Value::Str("::".to_string()));
let mut symbolsString: Value = get_value(&parts, &Value::Int(1));
let mut symbols: Value = split(&symbolsString, &Value::Str(",".to_string()));
let mut positions: Value = self.filter_by_array(newPositions.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
if !is_true(&self.is_empty(positions.clone())) {
client.resolve(&[positions.clone(), messageHash.clone()]);
}
}
}
client.resolve(&[newPositions.clone(), Value::Str("positions".to_string())]);
}
pub async fn un_watch_positions(&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;
}
let mut method: Value = Value::Str("watchPositions".to_string());
let mut messageHash: Value = Value::Str("unsubscribe:positions".to_string());
let mut subHash: Value = Value::Str("positions".to_string());
if is_true(&(!is_equal(&symbols, &Value::Null))) && !is_true(&self.is_empty(symbols.clone())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" unWatchPositions() does not support a symbol parameter, you must unwatch all orders".to_string()))));
}
let mut url: Value = self.get_url_by_market_type(&[Value::Null, Value::Bool(true), method.clone(), params.clone()]).await;
self.authenticate(url.clone(), &[]).await;
let mut topics: Value = Value::List(vec![Value::Str("position".to_string())]);
return self.un_watch_topics(url.clone(), Value::Str("positions".to_string()), symbols.clone(), Value::List(vec![messageHash.clone()]), Value::List(vec![subHash.clone()]), topics.clone(), &[params.clone()]).await;
Value::Null
}
pub async fn watch_liquidations(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut url: Value = self.get_url_by_market_type(&[symbol.clone(), Value::Bool(false), Value::Str("watchLiquidations".to_string()), params.clone()]).await;
params = self.clean_params(params.clone());
let mut method: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchLiquidations".to_string()), Value::Str("method".to_string()), &[Value::Str("allLiquidation".to_string())]); method = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut messageHash: Value = add(&Value::Str("liquidations::".to_string()), &symbol);
let mut topic: Value = add(&add(&method, &Value::Str(".".to_string())), &get_value(&market, &Value::Str("id".to_string())));
let mut newLiquidation: Value = self.watch_topics(url.clone(), Value::List(vec![messageHash.clone()]), Value::List(vec![topic.clone()]), &[params.clone()]).await;
if is_true(&self.newUpdates) {
return newLiquidation;
}
return self.filter_by_symbols_since_limit(self.liquidations.clone(), &[Value::List(vec![symbol.clone()]), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_liquidation(&mut self, mut client: Value, mut message: Value) {
if is_true(&Value::Bool(is_array(&get_value(&message, &Value::Str("data".to_string()))))) {
let mut rawLiquidations: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_219: bool = true;
while { if !__for_first_219 { i = add(&i, &Value::Int(1)); } __for_first_219 = false; is_less_than(&i, &get_array_length(&rawLiquidations)) } {
let mut rawLiquidation: Value = get_value(&rawLiquidations, &i);
let mut rawLiquidation: Value = get_value(&rawLiquidations, &i);
let mut marketId: Value = self.safe_string_k(rawLiquidation.clone(), "s", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("".to_string()), Value::Str("contract".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut liquidation: Value = self.parse_ws_liquidation(rawLiquidation.clone(), &[market.clone()]);
if is_equal(&self.liquidations, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "liquidationsLimit", &[Value::Int(1000)]);
self.liquidations = ArrayCache::new(limit.clone());
}
let mut cache: Value = self.liquidations.clone();
cache.append(liquidation.clone());
client.resolve(&[Value::List(vec![liquidation.clone()]), Value::Str("liquidations".to_string())]);
client.resolve(&[Value::List(vec![liquidation.clone()]), add(&Value::Str("liquidations::".to_string()), &symbol)]);
}
}
} else {
let mut rawLiquidation: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(rawLiquidation.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("".to_string()), Value::Str("contract".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut liquidation: Value = self.parse_ws_liquidation(rawLiquidation.clone(), &[market.clone()]);
if is_equal(&self.liquidations, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "liquidationsLimit", &[Value::Int(1000)]);
self.liquidations = ArrayCache::new(limit.clone());
}
let mut cache: Value = self.liquidations.clone();
cache.append(liquidation.clone());
client.resolve(&[Value::List(vec![liquidation.clone()]), Value::Str("liquidations".to_string())]);
client.resolve(&[Value::List(vec![liquidation.clone()]), add(&Value::Str("liquidations::".to_string()), &symbol)]);
}
}
pub fn parse_ws_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string2(liquidation.clone(), Value::Str("symbol".to_string()), Value::Str("s".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("".to_string()), Value::Str("contract".to_string())]);
let mut timestamp: Value = self.safe_integer2(liquidation.clone(), Value::Str("updatedTime".to_string()), Value::Str("T".to_string()), &[]);
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), liquidation.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("contracts".to_string(), self.safe_number2(liquidation.clone(), Value::Str("size".to_string()), Value::Str("v".to_string()), &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("price".to_string(), self.safe_number2(liquidation.clone(), Value::Str("price".to_string()), Value::Str("p".to_string()), &[]));
m.insert("side".to_string(), self.safe_string_lower2(liquidation.clone(), Value::Str("side".to_string()), Value::Str("S".to_string()), &[]));
m.insert("baseValue".to_string(), Value::Null);
m.insert("quoteValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}), &[]);
Value::Null
}
pub async fn watch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut method: Value = Value::Str("watchOrders".to_string());
let mut messageHash: Value = Value::Str("orders".to_string());
if !is_equal(&symbol, &Value::Null) {
symbol = self.symbol(symbol.clone());
messageHash = add(&messageHash, &add(&Value::Str(":".to_string()), &symbol));
}
let mut url: Value = self.get_url_by_market_type(&[symbol.clone(), Value::Bool(true), method.clone(), params.clone()]).await;
self.authenticate(url.clone(), &[]).await;
let mut topicsByMarket: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::List(vec![Value::Str("order".to_string()), Value::Str("stopOrder".to_string())]));
m.insert("unified".to_string(), Value::List(vec![Value::Str("order".to_string())]));
m.insert("usdc".to_string(), Value::List(vec![Value::Str("user.openapi.perp.order".to_string())]));
m
});
let mut topics: Value = self.safe_value(topicsByMarket.clone(), self.get_private_type(url.clone()), &[]);
let mut orders: Value = self.watch_topics(url.clone(), Value::List(vec![messageHash.clone()]), topics.clone(), &[params.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 async fn un_watch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = 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 method: Value = Value::Str("watchOrders".to_string());
let mut messageHash: Value = Value::Str("unsubscribe:orders".to_string());
let mut subHash: Value = Value::Str("orders".to_string());
if !is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" unWatchOrders() does not support a symbol parameter, you must unwatch all orders".to_string()))));
}
let mut url: Value = self.get_url_by_market_type(&[symbol.clone(), Value::Bool(true), method.clone(), params.clone()]).await;
self.authenticate(url.clone(), &[]).await;
let mut topicsByMarket: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::List(vec![Value::Str("order".to_string()), Value::Str("stopOrder".to_string())]));
m.insert("unified".to_string(), Value::List(vec![Value::Str("order".to_string())]));
m.insert("usdc".to_string(), Value::List(vec![Value::Str("user.openapi.perp.order".to_string())]));
m
});
let mut topics: Value = self.safe_value(topicsByMarket.clone(), self.get_private_type(url.clone()), &[]);
return self.un_watch_topics(url.clone(), Value::Str("orders".to_string()), Value::List(vec![]), Value::List(vec![messageHash.clone()]), Value::List(vec![subHash.clone()]), topics.clone(), &[params.clone()]).await;
Value::Null
}
pub fn handle_order_ws(&self, mut client: Value, mut message: Value) {
let mut messageHash: Value = self.safe_string_k(message.clone(), "reqId", &[]);
let mut data: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(data.clone(), &[]);
client.resolve(&[order.clone(), messageHash.clone()]);
}
pub fn handle_order(&mut self, mut client: Value, mut message: Value) {
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 rawOrders: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_value(rawOrders.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut category: Value = self.safe_string_k(first.clone(), "category", &[]);
let mut isSpot: bool = is_equal(&category, &Value::Str("spot".to_string()));
if !is_true(&isSpot) {
rawOrders = self.safe_value_k(rawOrders.clone(), "result", &[rawOrders.clone()]);
}
let mut symbols: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_220: bool = true;
while { if !__for_first_220 { i = add(&i, &Value::Int(1)); } __for_first_220 = false; is_less_than(&i, &get_array_length(&rawOrders)) } {
let mut parsed: Value = self.parse_order(get_value(&rawOrders, &i), &[]);
let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
if is_equal(&symbol, &Value::Null) {
continue;
}
add_element_to_object(&mut symbols, &symbol, Value::Bool(true));
orders.append(parsed.clone());
}
}
let mut symbolsArray: Value = object_keys(&symbols);
{
let mut i: Value = Value::Int(0);
let mut __for_first_221: bool = true;
while { if !__for_first_221 { i = add(&i, &Value::Int(1)); } __for_first_221 = false; is_less_than(&i, &get_array_length(&symbolsArray)) } {
let mut currentMessageHash: Value = add(&Value::Str("orders:".to_string()), &get_value(&symbolsArray, &i));
client.resolve(&[orders.clone(), currentMessageHash.clone()]);
}
}
let mut messageHash: Value = Value::Str("orders".to_string());
client.resolve(&[orders.clone(), messageHash.clone()]);
}
pub async fn watch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut method: Value = Value::Str("watchBalance".to_string());
let mut messageHash: Value = Value::Str("balances".to_string());
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("watchBalance".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("watchBalance".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut unified: Value = self.parent.is_unified_enabled(&[]).await;
let mut isUnifiedMargin: Value = self.safe_bool(unified.clone(), Value::Int(0), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = self.safe_bool(unified.clone(), Value::Int(1), &[Value::Bool(false)]);
let mut url: Value = self.get_url_by_market_type(&[Value::Null, Value::Bool(true), method.clone(), params.clone()]).await;
self.authenticate(url.clone(), &[]).await;
let mut topicByMarket: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("outboundAccountInfo".to_string()));
m.insert("unified".to_string(), Value::Str("wallet".to_string()));
m
});
if is_equal(&isUnifiedAccount, &Value::Bool(true)) {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
messageHash = add(&messageHash, &Value::Str(":contract".to_string()));
} else {
messageHash = add(&messageHash, &Value::Str(":unified".to_string()));
}
}
if is_true(&(!is_equal(&isUnifiedMargin, &Value::Bool(true)))) && is_true(&(!is_equal(&isUnifiedAccount, &Value::Bool(true)))) {
if is_equal(&type_var, &Value::Str("spot".to_string())) {
messageHash = add(&messageHash, &Value::Str(":spot".to_string()));
} else {
messageHash = add(&messageHash, &Value::Str(":contract".to_string()));
}
}
if is_equal(&isUnifiedMargin, &Value::Bool(true)) {
if is_equal(&type_var, &Value::Str("spot".to_string())) {
messageHash = add(&messageHash, &Value::Str(":spot".to_string()));
} else {
if is_equal(&subType, &Value::Str("linear".to_string())) {
messageHash = add(&messageHash, &Value::Str(":unified".to_string()));
} else {
messageHash = add(&messageHash, &Value::Str(":contract".to_string()));
}
}
}
let mut topics: Value = Value::List(vec![self.safe_value(topicByMarket.clone(), self.get_private_type(url.clone()), &[])]);
return self.watch_topics(url.clone(), Value::List(vec![messageHash.clone()]), topics.clone(), &[params.clone()]).await;
Value::Null
}
pub fn handle_balance(&mut self, mut client: Value, mut message: Value) {
if is_equal(&self.balance, &Value::Null) {
self.balance = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut messageHash: Value = Value::Str("balance".to_string());
let mut topic: Value = self.safe_value_k(message.clone(), "topic", &[]);
let mut info: Value = Value::Null;
let mut rawBalances: Value = Value::List(vec![]);
let mut account: Value = Value::Null;
if is_equal(&topic, &Value::Str("outboundAccountInfo".to_string())) {
account = Value::Str("spot".to_string());
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_222: bool = true;
while { if !__for_first_222 { i = add(&i, &Value::Int(1)); } __for_first_222 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut B: Value = self.safe_value_k(get_value(&data, &i), "B", &[Value::List(vec![])]);
rawBalances = self.array_concat(rawBalances.clone(), B.clone());
}
}
info = rawBalances.clone();
}
if is_equal(&topic, &Value::Str("wallet".to_string())) {
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_223: bool = true;
while { if !__for_first_223 { i = add(&i, &Value::Int(1)); } __for_first_223 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut result: Value = self.safe_value(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
account = self.safe_string_lower(result.clone(), Value::Str("accountType".to_string()), &[]);
rawBalances = self.array_concat(rawBalances.clone(), self.safe_value_k(result.clone(), "coin", &[Value::List(vec![])]));
}
}
info = data.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_224: bool = true;
while { if !__for_first_224 { i = add(&i, &Value::Int(1)); } __for_first_224 = false; is_less_than(&i, &get_array_length(&rawBalances)) } {
self.parse_ws_balance(get_value(&rawBalances, &i), &[account.clone()]);
}
}
if !is_equal(&account, &Value::Null) {
if is_equal(&self.safe_value(self.balance.clone(), account.clone(), &[]), &Value::Null) {
add_element_to_object(&mut self.balance, &account, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.balance) }, &account), &Value::Str("info".to_string()), info.clone());
let mut timestamp: Value = self.safe_integer_k(message.clone(), "ts", &[]);
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.balance) }, &account), &Value::Str("timestamp".to_string()), timestamp.clone());
{ let __be_tmp = self.iso8601(timestamp.clone()); add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.balance) }, &account), &Value::Str("datetime".to_string()), __be_tmp); };
{ let __be_tmp = self.safe_balance(get_value(&self.balance, &account)); add_element_to_object(&mut self.balance, &account, __be_tmp); };
messageHash = add(&Value::Str("balances:".to_string()), &account);
client.resolve(&[get_value(&self.balance, &account), messageHash.clone()]);
} else {
add_element_to_object(&mut self.balance, &Value::Str("info".to_string()), info.clone());
let mut timestamp: Value = self.safe_integer_k(message.clone(), "ts", &[]);
add_element_to_object(&mut self.balance, &Value::Str("timestamp".to_string()), timestamp.clone());
{ let __be_tmp = self.iso8601(timestamp.clone()); add_element_to_object(&mut self.balance, &Value::Str("datetime".to_string()), __be_tmp); };
{ let __t = self.safe_balance(self.balance.clone()); self.balance = __t; }
messageHash = Value::Str("balances".to_string());
client.resolve(&[self.balance.clone(), messageHash.clone()]);
}
}
pub fn parse_ws_balance(&mut self, mut balance: Value, optional_args: &[Value]) {
let mut accountType = get_arg(optional_args, 0, Value::Null);
let mut account: Value = self.account();
let mut currencyId: Value = self.safe_string2(balance.clone(), Value::Str("a".to_string()), Value::Str("coin".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_n(balance.clone(), Value::List(vec![Value::Str("availableToWithdraw".to_string()), Value::Str("f".to_string()), Value::Str("free".to_string())]), &[]));
let mut used: Value = self.safe_string2(balance.clone(), Value::Str("l".to_string()), Value::Str("locked".to_string()), &[]);
if !is_equal(&used, &Value::Null) {
add_element_to_object(&mut account, &Value::Str("used".to_string()), used.clone());
} else {
let mut totalPositionIm: Value = self.safe_string_k(balance.clone(), "totalPositionIM", &[Value::Str("0".to_string())]);
let mut totalOrderIm: Value = self.safe_string_k(balance.clone(), "totalOrderIM", &[Value::Str("0".to_string())]);
add_element_to_object(&mut account, &Value::Str("used".to_string()), crate::precise::Precise::stringAdd(&totalPositionIm, &totalOrderIm));
}
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string2(balance.clone(), Value::Str("equity".to_string()), Value::Str("walletBalance".to_string()), &[]));
if !is_equal(&accountType, &Value::Null) {
if is_equal(&self.safe_value(self.balance.clone(), accountType.clone(), &[]), &Value::Null) {
add_element_to_object(&mut self.balance, &accountType, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
if is_true(&(!is_equal(&accountType, &Value::Null))) && is_true(&(!is_equal(&code, &Value::Null))) {
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.balance) }, &accountType), &code, account.clone());
}
} else {
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut self.balance, &code, account.clone());
}
}
}
pub async fn watch_topics(&mut self, mut url: Value, mut messageHashes: Value, mut topics: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("req_id".to_string(), self.request_id());
m.insert("args".to_string(), topics.clone());
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch_multiple(url.clone(), messageHashes.clone(), &[message.clone(), messageHashes.clone()]).await;
Value::Null
}
pub async fn un_watch_topics(&mut self, mut url: Value, mut topic: Value, mut symbols: Value, mut messageHashes: Value, mut subMessageHashes: Value, mut topics: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut subExtension = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut reqId: Value = self.request_id();
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("req_id".to_string(), reqId.clone());
m.insert("args".to_string(), topics.clone());
m
});
let mut subscription: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), reqId.clone());
m.insert("topic".to_string(), topic.clone());
m.insert("messageHashes".to_string(), messageHashes.clone());
m.insert("subMessageHashes".to_string(), subMessageHashes.clone());
m.insert("symbols".to_string(), symbols.clone());
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
let __ws_arg_0 = self.extend(subscription.clone(), &[subExtension.clone()]);
return self.watch_multiple(url.clone(), messageHashes.clone(), &[message.clone(), messageHashes.clone(), __ws_arg_0]).await;
Value::Null
}
pub async fn authenticate(&mut self, mut url: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_required_credentials(&[]);
let mut messageHash: Value = Value::Str("authenticated".to_string());
let mut client: Value = self.client(&[url.clone()]);
let mut future: Value = client.reusable_future(messageHash.clone());
let mut authenticated: Value = self.safe_value(get_value(&client, &Value::Str("subscriptions".to_string())), messageHash.clone(), &[]);
if is_equal(&authenticated, &Value::Null) {
let mut expiresInt: Value = add(&self.milliseconds(), &Value::Int(10000));
let mut expires: Value = self.number_to_string(expiresInt.clone());
let mut path: Value = Value::Str("GET/realtime".to_string());
let mut auth: Value = add(&path, &expires);
let mut signature: Value = self.hmac(self.encode(auth.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("hex".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("auth".to_string()));
m.insert("args".to_string(), Value::List(vec![self.apiKey.clone(), expires.clone(), signature.clone()]));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
}
return crate::exchange_stubs::ws_await_flight(&future).await;
Value::Null
}
pub fn handle_error_message(&self, mut client: Value, mut message: Value) -> Value {
let mut code: Value = self.safe_string_n(message.clone(), Value::List(vec![Value::Str("code".to_string()), Value::Str("ret_code".to_string()), Value::Str("retCode".to_string())]), &[]);
let _try_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
if !is_equal(&code, &Value::Null) && !is_equal(&code, &Value::Str("0".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &self.json(message.clone()));
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
let mut msg: Value = self.safe_string2(message.clone(), Value::Str("retMsg".to_string()), Value::Str("ret_msg".to_string()), &[]);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), msg.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut success: Value = self.safe_value_k(message.clone(), "success", &[]);
if is_true(&(!is_equal(&success, &Value::Null))) && is_true(&(!is_equal(&success, &Value::Bool(true)))) {
let mut ret_msg: Value = self.safe_string_k(message.clone(), "ret_msg", &[]);
let mut request: Value = self.safe_value_k(message.clone(), "request", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut op: Value = self.safe_string_k(request.clone(), "op", &[]);
if is_equal(&op, &Value::Str("auth".to_string())) {
panic!("{}", crate::exchange_errors::authentication_error(add(&Value::Str("Authentication failed: ".to_string()), &ret_msg)));
} else {
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" ".to_string())), &ret_msg)));
}
}
return Value::Bool(false);
#[allow(unreachable_code)] { Value::Null }}));
match _try_result { Ok(__try_ok) => { if !matches!(__try_ok, Value::Null) { return __try_ok; } return Value::Null; } Err(_try_err) => { let error: Value = panic_to_value(_try_err);
let mut messageHash: Value = self.safe_string2(message.clone(), Value::Str("req_id".to_string()), Value::Str("reqId".to_string()), &[]);
if !is_equal(&messageHash, &Value::Null) {
client.reject(&[Value::from(error.clone()), messageHash.clone()]);
} else if is_true(&is_instance(&error, &Value::Str("AuthenticationError".to_string()))) {
let mut authenticatedHash: Value = Value::Str("authenticated".to_string());
client.reject(&[Value::from(error.clone()), authenticatedHash.clone()]);
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &authenticatedHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &authenticatedHash);
}
let mut op: Value = self.safe_string_k(message.clone(), "op", &[]);
if is_true(&(!is_equal(&op, &Value::Null))) && is_true(&(!is_equal(&op, &Value::Str("auth".to_string())))) {
client.reject(&[Value::from(error.clone())]);
}
} else {
client.reject(&[Value::from(error.clone()), messageHash.clone()]);
}
return Value::Bool(true);
} }
Value::Null
}
pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
let mut topic: Value = self.safe_string2(message.clone(), Value::Str("topic".to_string()), Value::Str("op".to_string()), &[Value::Str("".to_string())]);
if is_equal(&self.handle_error_message(client.clone(), message.clone()), &Value::Bool(true)) {
return;
}
let mut ret_msg: Value = self.safe_string_k(message.clone(), "ret_msg", &[]);
if is_true(&(is_equal(&ret_msg, &Value::Str("pong".to_string())))) || is_true(&(is_equal(&topic, &Value::Str("pong".to_string())))) {
self.handle_pong(client.clone(), message.clone());
return;
}
let mut pong: Value = self.safe_integer_k(message.clone(), "pong", &[]);
if !is_equal(&pong, &Value::Null) {
self.handle_pong(client.clone(), message.clone());
return;
}
let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
if is_equal(&event, &Value::Str("sub".to_string())) || is_true(&(is_equal(&topic, &Value::Str("subscribe".to_string())))) {
self.handle_subscription_status(client.clone(), message.clone());
return;
}
let mut methods: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderbook".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("kline".to_string(), Value::Str("handle_ohlcv".to_string()).clone());
m.insert("order".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("stopOrder".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("ticker".to_string(), Value::Str("handle_ticker".to_string()).clone());
m.insert("trade".to_string(), Value::Str("handle_trades".to_string()).clone());
m.insert("publicTrade".to_string(), Value::Str("handle_trades".to_string()).clone());
m.insert("depth".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("wallet".to_string(), Value::Str("handle_balance".to_string()).clone());
m.insert("outboundAccountInfo".to_string(), Value::Str("handle_balance".to_string()).clone());
m.insert("execution".to_string(), Value::Str("handle_my_trades".to_string()).clone());
m.insert("execution.fast".to_string(), Value::Str("handle_my_trades".to_string()).clone());
m.insert("ticketInfo".to_string(), Value::Str("handle_my_trades".to_string()).clone());
m.insert("user.openapi.perp.trade".to_string(), Value::Str("handle_my_trades".to_string()).clone());
m.insert("position".to_string(), Value::Str("handle_positions".to_string()).clone());
m.insert("liquidation".to_string(), Value::Str("handle_liquidation".to_string()).clone());
m.insert("allLiquidation".to_string(), Value::Str("handle_liquidation".to_string()).clone());
m.insert("pong".to_string(), Value::Str("handle_pong".to_string()).clone());
m.insert("order.create".to_string(), Value::Str("handle_order_ws".to_string()).clone());
m.insert("order.amend".to_string(), Value::Str("handle_order_ws".to_string()).clone());
m.insert("order.cancel".to_string(), Value::Str("handle_order_ws".to_string()).clone());
m.insert("auth".to_string(), Value::Str("handle_authenticate".to_string()).clone());
m.insert("unsubscribe".to_string(), Value::Str("handle_un_subscribe".to_string()).clone());
m
});
let mut exacMethod: Value = self.safe_value(methods.clone(), topic.clone(), &[]);
if !is_equal(&exacMethod, &Value::Null) {
self.dispatch_ws_handler(&exacMethod, &[client.clone(), message.clone()]);
return;
}
if is_greater_than_or_equal(&get_index_of(&topic, &Value::Str("orderbook".to_string())), &Value::Int(0)) {
self.handle_order_book(client.clone(), message.clone());
return;
}
let mut keys: Value = object_keys(&methods);
{
let mut i: Value = Value::Int(0);
let mut __for_first_225: bool = true;
while { if !__for_first_225 { i = add(&i, &Value::Int(1)); } __for_first_225 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
if is_greater_than_or_equal(&get_index_of(&topic, &key), &Value::Int(0)) {
let mut method: Value = get_value(&methods, &key);
let mut method: Value = get_value(&methods, &key);
self.dispatch_ws_handler(&method, &[client.clone(), message.clone()]);
return;
}
}
}
let mut type_var: Value = self.safe_string_k(message.clone(), "type", &[]);
if is_equal(&type_var, &Value::Str("AUTH_RESP".to_string())) {
self.handle_authenticate(client.clone(), message.clone());
}
}
pub fn ping(&mut self, mut client: Value) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("req_id".to_string(), self.request_id());
m.insert("op".to_string(), Value::Str("ping".to_string()));
m
});
Value::Null
}
pub fn handle_pong(&self, mut client: Value, mut message: Value) -> Value {
let __ws_arg_1 = self.milliseconds();
crate::set_value(&mut client, &Value::Str("lastPong".to_string()), self.safe_integer_k(message.clone(), "pong", &[__ws_arg_1]));
return message;
Value::Null
}
pub fn handle_authenticate(&self, mut client: Value, mut message: Value) -> Value {
let mut success: Value = self.safe_value_k(message.clone(), "success", &[]);
let mut code: Value = self.safe_integer_k(message.clone(), "retCode", &[]);
let mut messageHash: Value = Value::Str("authenticated".to_string());
if is_true(&(is_equal(&success, &Value::Bool(true)))) || is_true(&(is_equal(&code, &Value::Int(0)))) {
let mut future: Value = self.safe_value(get_value(&client, &Value::Str("futures".to_string())), messageHash.clone(), &[]);
future.resolve(&[Value::Bool(true)]);
} else {
let mut error = Value::from(crate::exchange_errors::authentication_error(add(&add(&self.id, &Value::Str(" ".to_string())), &self.json(message.clone()))));
client.reject(&[Value::from(error.clone()), messageHash.clone()]);
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash);
}
}
return message;
Value::Null
}
pub fn handle_subscription_status(&self, mut client: Value, mut message: Value) -> Value {
return message;
Value::Null
}
pub fn handle_un_subscribe(&mut self, mut client: Value, mut message: Value) -> Value {
let mut reqId: Value = self.safe_string_k(message.clone(), "req_id", &[]);
let mut keys: Value = object_keys(&get_value(&client, &Value::Str("subscriptions".to_string())));
{
let mut i: Value = Value::Int(0);
let mut __for_first_227: bool = true;
while { if !__for_first_227 { i = add(&i, &Value::Int(1)); } __for_first_227 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut messageHash: Value = get_value(&keys, &i);
let mut messageHash: Value = get_value(&keys, &i);
if !is_true(&(Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash)))) {
continue;
}
if is_true(&Value::Bool(starts_with(&messageHash, &Value::Str("unsubscribe".to_string())))) {
let mut subscription: Value = get_value(&get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash);
let mut subId: Value = self.safe_string_k(subscription.clone(), "id", &[]);
if !is_equal(&reqId, &subId) {
continue;
}
let mut messageHashes: Value = self.safe_list_k(subscription.clone(), "messageHashes", &[Value::List(vec![])]);
let mut subMessageHashes: Value = self.safe_list_k(subscription.clone(), "subMessageHashes", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_226: bool = true;
while { if !__for_first_226 { j = add(&j, &Value::Int(1)); } __for_first_226 = false; is_less_than(&j, &get_array_length(&messageHashes)) } {
let mut unsubHash: Value = get_value(&messageHashes, &j);
let mut unsubHash: Value = get_value(&messageHashes, &j);
let mut subHash: Value = get_value(&subMessageHashes, &j);
let mut subHash: Value = get_value(&subMessageHashes, &j);
let mut usePrefix: Value = Value::Bool(is_true(&(is_equal(&subHash, &Value::Str("orders".to_string())))) || is_true(&(is_equal(&subHash, &Value::Str("myTrades".to_string())))) || is_true(&(is_equal(&subHash, &Value::Str("positions".to_string())))));
self.clean_unsubscription(client.clone(), subHash.clone(), unsubHash.clone(), &[usePrefix.clone()]);
}
}
self.clean_cache(subscription.clone());
}
}
}
return message;
Value::Null
}
}