#![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 OkxCore {
pub parent: crate::exchanges::okx::OkxCore,
}
impl OkxCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { parent: crate::exchanges::okx::OkxCore::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = OkxCore::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 OkxCore {
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 OkxCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"authenticate" => self.authenticate(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders_ws" => self.cancel_all_orders_ws(&args.get(0..).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,
"cancel_orders_ws" => self.cancel_orders_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"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,
"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_url" => self.get_url(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_order_book" => self.handle_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_order_book_message" => self.handle_order_book_message(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()[..]),
"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)),
"order_to_trade" => self.order_to_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_my_liquidation" => self.parse_ws_my_liquidation(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(),
"subscribe" => self.subscribe(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,
"subscribe_multiple" => self.subscribe_multiple(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).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_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_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_funding_rate" => self.watch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_funding_rates" => self.watch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_liquidations_for_symbols" => self.watch_liquidations_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_mark_price" => self.watch_mark_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_mark_prices" => self.watch_mark_prices(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_my_liquidations_for_symbols" => self.watch_my_liquidations_for_symbols(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_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 OkxCore {
#[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_all_orders_ws" => { crate::exchange_stubs::enqueue_spawn("cancel_all_orders_ws", args.to_vec()); crate::Value::Null },
"cancel_order_ws" => { crate::exchange_stubs::enqueue_spawn("cancel_order_ws", args.to_vec()); crate::Value::Null },
"cancel_orders_ws" => { crate::exchange_stubs::enqueue_spawn("cancel_orders_ws", args.to_vec()); crate::Value::Null },
"create_order_ws" => { crate::exchange_stubs::enqueue_spawn("create_order_ws", args.to_vec()); crate::Value::Null },
"edit_order_ws" => { crate::exchange_stubs::enqueue_spawn("edit_order_ws", args.to_vec()); crate::Value::Null },
"get_url" => self.get_url(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"handle_authenticate" => { self.handle_authenticate(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_balance" => { self.handle_balance(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_balance_and_position" => { self.handle_balance_and_position(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_bid_ask" => { self.handle_bid_ask(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_cancel_all_orders" => { self.handle_cancel_all_orders(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_funding_rate" => { self.handle_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); 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_liquidation" => { self.handle_my_liquidation(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_book" => self.handle_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_order_book_message" => self.handle_order_book_message(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()[..]),
"handle_orders" => { self.handle_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_place_orders" => { self.handle_place_orders(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_subscription_trades" => { self.handle_un_subscription_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_unsubscription" => { self.handle_unsubscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_unsubscription_ohlcv" => { self.handle_unsubscription_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_unsubscription_order_book" => { self.handle_unsubscription_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_unsubscription_ticker" => { self.handle_unsubscription_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"order_to_trade" => self.order_to_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_my_liquidation" => self.parse_ws_my_liquidation(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(),
"subscribe" => { crate::exchange_stubs::enqueue_spawn("subscribe", args.to_vec()); crate::Value::Null },
"subscribe_multiple" => { crate::exchange_stubs::enqueue_spawn("subscribe_multiple", 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_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_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_funding_rate" => { crate::exchange_stubs::enqueue_spawn("watch_funding_rate", args.to_vec()); crate::Value::Null },
"watch_funding_rates" => { crate::exchange_stubs::enqueue_spawn("watch_funding_rates", args.to_vec()); crate::Value::Null },
"watch_liquidations_for_symbols" => { crate::exchange_stubs::enqueue_spawn("watch_liquidations_for_symbols", args.to_vec()); crate::Value::Null },
"watch_mark_price" => { crate::exchange_stubs::enqueue_spawn("watch_mark_price", args.to_vec()); crate::Value::Null },
"watch_mark_prices" => { crate::exchange_stubs::enqueue_spawn("watch_mark_prices", args.to_vec()); crate::Value::Null },
"watch_my_liquidations_for_symbols" => { crate::exchange_stubs::enqueue_spawn("watch_my_liquidations_for_symbols", 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_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 OkxCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { std::ops::Deref::deref(&self.parent) }
}
impl std::ops::DerefMut for OkxCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { std::ops::DerefMut::deref_mut(&mut self.parent) }
}
impl OkxCore {
pub fn describe(&self) -> Value {
return self.deep_extend(self.parent.describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Bool(true));
m.insert("watchTicker".to_string(), Value::Bool(true));
m.insert("watchMarkPrice".to_string(), Value::Bool(true));
m.insert("watchMarkPrices".to_string(), Value::Bool(true));
m.insert("watchTickers".to_string(), Value::Bool(true));
m.insert("watchBidsAsks".to_string(), Value::Bool(true));
m.insert("watchOrderBook".to_string(), Value::Bool(true));
m.insert("watchTrades".to_string(), Value::Bool(true));
m.insert("watchTradesForSymbols".to_string(), Value::Bool(true));
m.insert("watchOrderBookForSymbols".to_string(), Value::Bool(true));
m.insert("watchBalance".to_string(), Value::Bool(true));
m.insert("watchLiquidations".to_string(), Value::Str("emulated".to_string()));
m.insert("watchLiquidationsForSymbols".to_string(), Value::Bool(true));
m.insert("watchMyLiquidations".to_string(), Value::Str("emulated".to_string()));
m.insert("watchMyLiquidationsForSymbols".to_string(), Value::Bool(true));
m.insert("watchOHLCV".to_string(), Value::Bool(true));
m.insert("watchOHLCVForSymbols".to_string(), Value::Bool(true));
m.insert("watchOrders".to_string(), Value::Bool(true));
m.insert("watchMyTrades".to_string(), Value::Bool(true));
m.insert("watchPositions".to_string(), Value::Bool(true));
m.insert("watchFundingRate".to_string(), Value::Bool(true));
m.insert("watchFundingRates".to_string(), Value::Bool(true));
m.insert("createOrderWs".to_string(), Value::Bool(true));
m.insert("editOrderWs".to_string(), Value::Bool(true));
m.insert("cancelOrderWs".to_string(), Value::Bool(true));
m.insert("cancelOrdersWs".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersWs".to_string(), Value::Bool(true));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Str("wss://ws.okx.com:8443/ws/v5".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Str("wss://wspap.okx.com:8443/ws/v5".to_string()));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("watchOrderBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("checksum".to_string(), Value::Bool(true));
m.insert("depth".to_string(), Value::Str("books".to_string()));
m
}));
m.insert("watchBalance".to_string(), Value::Str("spot".to_string()));
m.insert("watchTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), Value::Str("tickers".to_string()));
m
}));
m.insert("watchTickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), Value::Str("tickers".to_string()));
m
}));
m.insert("watchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("ANY".to_string()));
m
}));
m.insert("watchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("ANY".to_string()));
m
}));
m.insert("createOrderWs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("batch-orders".to_string()));
m
}));
m.insert("editOrderWs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("amend-order".to_string()));
m
}));
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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 get_url(&self, mut channel: Value, optional_args: &[Value]) -> Value {
let mut access = get_arg(optional_args, 0, Value::Str("public".to_string()));
if is_equal(&channel, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" getUrl() requires a channel argument".to_string()))));
}
let mut isSandbox: Value = get_value(&self.options, &Value::Str("sandboxMode".to_string()));
let mut sandboxSuffix: Value = ternary(is_true(&(is_equal(&isSandbox, &Value::Bool(true)))), Value::Str("?brokerId=9999".to_string()), Value::Str("".to_string()));
let mut isBusiness: bool = is_equal(&access, &Value::Str("business".to_string()));
let mut isPublic: bool = is_equal(&access, &Value::Str("public".to_string()));
let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string()));
if is_true(&isBusiness) || is_true(&(is_greater_than(&get_index_of(&channel, &Value::Str("candle".to_string())), &negate(&Value::Int(1))))) || is_true(&(is_equal(&channel, &Value::Str("orders-algo".to_string())))) {
return add(&add(&url, &Value::Str("/business".to_string())), &sandboxSuffix);
} else if is_true(&isPublic) {
return add(&add(&url, &Value::Str("/public".to_string())), &sandboxSuffix);
}
return add(&add(&url, &Value::Str("/private".to_string())), &sandboxSuffix);
Value::Null
}
pub async fn subscribe_multiple(&mut self, mut access: Value, mut channel: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&symbols, &Value::Null) {
symbols = self.symbols.clone();
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut url: Value = self.get_url(channel.clone(), &[access.clone()]);
let mut messageHashes: Value = Value::List(vec![]);
let mut args: Value = Value::List(vec![]);
if is_equal(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" subscribeMultiple() symbols is required".to_string()))));
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_524: bool = true;
while { if !__for_first_524 { i = add(&i, &Value::Int(1)); } __for_first_524 = false; is_less_than(&i, &get_array_length(&symbols)) } {
if is_equal(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" subscribeMultiple() symbols is required".to_string()))));
}
let mut marketId: Value = self.market_id(get_value(&symbols, &i));
let mut arg: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut args, self.extend(arg.clone(), &[params.clone()]));
if is_equal(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" subscribeMultiple() symbols is required".to_string()))));
}
append_to_array(&mut messageHashes, add(&add(&channel, &Value::Str("::".to_string())), &get_value(&symbols, &i)));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), args.clone());
m
});
return self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
Value::Null
}
pub async fn subscribe(&mut self, mut access: Value, mut messageHash: Value, mut channel: Value, 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 url: Value = self.get_url(channel.clone(), &[access.clone()]);
let mut firstArgument: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m
});
if !is_equal(&symbol, &Value::Null) {
let mut market: Value = self.market(symbol.clone());
messageHash = add(&messageHash, &add(&Value::Str(":".to_string()), &get_value(&market, &Value::Str("id".to_string()))));
add_element_to_object(&mut firstArgument, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), Value::List(vec![self.deep_extend(firstArgument.clone(), &[params.clone()])]));
m
});
return self.watch(url.clone(), messageHash.clone(), &[request.clone(), messageHash.clone()]).await;
Value::Null
}
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
}));
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()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTrades".to_string()), Value::Str("channel".to_string()), &[Value::Str("trades".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
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_525: bool = true;
while { if !__for_first_525 { i = add(&i, &Value::Int(1)); } __for_first_525 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut messageHashes, add(&add(&channel, &Value::Str(":".to_string())), &symbol));
let mut marketId: Value = self.market_id(symbol.clone());
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut access: Value = Value::Str("public".to_string());
if is_equal(&channel, &Value::Str("trades-all".to_string())) {
access = Value::Str("business".to_string());
self.authenticate(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access".to_string(), access.clone());
m
})]).await;
}
let mut url: Value = self.get_url(channel.clone(), &[access.clone()]);
let mut trades: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.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)]);
let mut channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTrades".to_string()), Value::Str("channel".to_string()), &[Value::Str("trades".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
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_526: bool = true;
while { if !__for_first_526 { i = add(&i, &Value::Int(1)); } __for_first_526 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut messageHashes, add(&add(&add(&Value::Str("unsubscribe:".to_string()), &channel), &Value::Str(":".to_string())), &symbol));
let mut marketId: Value = self.market_id(symbol.clone());
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut access: Value = Value::Str("public".to_string());
if is_equal(&channel, &Value::Str("trades-all".to_string())) {
access = Value::Str("business".to_string());
self.authenticate(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access".to_string(), access.clone());
m
})]).await;
}
let mut url: Value = self.get_url(channel.clone(), &[access.clone()]);
return self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.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 arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
let mut marketId: Value = self.safe_string_k(arg.clone(), "instId", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[]);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut tradesLimit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_527: bool = true;
while { if !__for_first_527 { i = add(&i, &Value::Int(1)); } __for_first_527 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut trade: Value = self.parse_trade(get_value(&data, &i), &[]);
let mut messageHash: Value = add(&add(&channel, &Value::Str(":".to_string())), &symbol);
let mut stored: Value = self.safe_value(self.trades.clone(), symbol.clone(), &[]);
if is_equal(&stored, &Value::Null) {
stored = ArrayCache::new(tradesLimit.clone());
add_element_to_object(&mut self.trades, &symbol, stored.clone());
}
stored.append(trade.clone());
client.resolve(&[stored.clone(), messageHash.clone()]);
}
}
}
pub async fn watch_funding_rate(&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
}));
symbol = self.symbol(symbol.clone());
let mut fr: Value = self.watch_funding_rates(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return get_value(&fr, &symbol);
Value::Null
}
pub async fn watch_funding_rates(&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(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchFundingRates() requires an array of symbols".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut channel: Value = Value::Str("funding-rate".to_string());
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_528: bool = true;
while { if !__for_first_528 { i = add(&i, &Value::Int(1)); } __for_first_528 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut messageHashes, add(&add(&channel, &Value::Str(":".to_string())), &symbol));
let mut marketId: Value = self.market_id(symbol.clone());
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut url: Value = self.get_url(channel.clone(), &[Value::Str("public".to_string())]);
let mut fundingRate: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
if is_true(&self.newUpdates) {
let mut symbol: Value = self.safe_string_k(fundingRate.clone(), "symbol", &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut result, &symbol, fundingRate.clone());
}
return result;
}
return self.filter_by_array(self.fundingRates.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub fn handle_funding_rate(&mut self, mut client: Value, mut message: Value) {
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_529: bool = true;
while { if !__for_first_529 { i = add(&i, &Value::Int(1)); } __for_first_529 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rawfr: Value = get_value(&data, &i);
let mut rawfr: Value = get_value(&data, &i);
let mut fundingRate: Value = self.parse_funding_rate(rawfr.clone(), &[]);
let mut symbol: Value = get_value(&fundingRate, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut self.fundingRates, &symbol, fundingRate.clone());
}
client.resolve(&[fundingRate.clone(), add(&add(&Value::Str("funding-rate".to_string()), &Value::Str(":".to_string())), &get_value(&fundingRate, &Value::Str("symbol".to_string())))]);
}
}
}
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
}));
let mut channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTicker".to_string()), Value::Str("channel".to_string()), &[Value::Str("tickers".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut params, &Value::Str("channel".to_string()), channel.clone());
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut ticker: Value = self.watch_tickers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return self.safe_value(ticker.clone(), symbol.clone(), &[]);
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 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 channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTickers".to_string()), Value::Str("channel".to_string()), &[Value::Str("tickers".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut newTickers: Value = self.subscribe_multiple(Value::Str("public".to_string()), channel.clone(), &[symbols.clone(), params.clone()]).await;
if is_true(&self.newUpdates) {
return newTickers;
}
return self.filter_by_array(self.tickers.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub async fn watch_mark_price(&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
}));
let mut channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchMarkPrice".to_string()), Value::Str("channel".to_string()), &[Value::Str("mark-price".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut params, &Value::Str("channel".to_string()), channel.clone());
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut ticker: Value = self.watch_mark_prices(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return get_value(&ticker, &symbol);
Value::Null
}
pub async fn watch_mark_prices(&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 channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchMarkPrices".to_string()), Value::Str("channel".to_string()), &[Value::Str("mark-price".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut newTickers: Value = self.subscribe_multiple(Value::Str("public".to_string()), channel.clone(), &[symbols.clone(), params.clone()]).await;
if is_true(&self.newUpdates) {
return newTickers;
}
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 channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTickers".to_string()), Value::Str("channel".to_string()), &[Value::Str("tickers".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
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_530: bool = true;
while { if !__for_first_530 { i = add(&i, &Value::Int(1)); } __for_first_530 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut messageHashes, add(&Value::Str("unsubscribe:ticker:".to_string()), &symbol));
let mut marketId: Value = self.market_id(symbol.clone());
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut url: Value = self.get_url(channel.clone(), &[Value::Str("public".to_string())]);
return self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
Value::Null
}
pub fn handle_ticker(&mut self, mut client: Value, mut message: Value) {
self.handle_bid_ask(client.clone(), message.clone());
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(arg.clone(), "instId", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("-".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut newTickers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_531: bool = true;
while { if !__for_first_531 { i = add(&i, &Value::Int(1)); } __for_first_531 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut ticker: Value = self.parse_ticker(get_value(&data, &i), &[]);
add_element_to_object(&mut self.tickers, &symbol, ticker.clone());
add_element_to_object(&mut newTickers, &symbol, ticker.clone());
}
}
let mut messageHash: Value = add(&add(&channel, &Value::Str("::".to_string())), &symbol);
client.resolve(&[newTickers.clone(), 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 channel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchBidsAsks".to_string()), Value::Str("channel".to_string()), &[Value::Str("tickers".to_string())]); channel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut url: Value = self.get_url(channel.clone(), &[Value::Str("public".to_string())]);
let mut messageHashes: Value = Value::List(vec![]);
let mut args: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_532: bool = true;
while { if !__for_first_532 { i = add(&i, &Value::Int(1)); } __for_first_532 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut marketId: Value = self.market_id(get_value(&symbols, &i));
let mut arg: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut args, self.extend(arg.clone(), &[params.clone()]));
append_to_array(&mut messageHashes, add(&Value::Str("bidask::".to_string()), &get_value(&symbols, &i)));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), args.clone());
m
});
let mut newTickers: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
if is_true(&self.newUpdates) {
let mut tickers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut tickers, &get_value(&newTickers, &Value::Str("symbol".to_string())), newTickers.clone());
return tickers;
}
return self.filter_by_array(self.bidsasks.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub fn handle_bid_ask(&mut self, mut client: Value, mut message: Value) {
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut ticker: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut parsedTicker: Value = self.parse_ws_bid_ask(ticker.clone(), &[]);
let mut symbol: Value = get_value(&parsedTicker, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut self.bidsasks, &symbol, parsedTicker.clone());
}
let mut messageHash: Value = add(&Value::Str("bidask::".to_string()), &symbol);
client.resolve(&[parsedTicker.clone(), messageHash.clone()]);
}
pub fn parse_ws_bid_ask(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "ts", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "askPx", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "askSz", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "bidPx", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bidSz", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
pub async fn watch_liquidations_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(), Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut messageHash: Value = Value::Str("liquidations".to_string());
let mut messageHashes: Value = Value::List(vec![]);
if !is_equal(&symbols, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_533: bool = true;
while { if !__for_first_533 { i = add(&i, &Value::Int(1)); } __for_first_533 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut messageHashes, add(&add(&messageHash, &Value::Str("::".to_string())), &symbol));
}
}
} else {
append_to_array(&mut messageHashes, messageHash.clone());
}
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("watchliquidationsForSymbols".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut channel: Value = Value::Str("liquidation-orders".to_string());
if is_equal(&type_var, &Value::Str("spot".to_string())) {
type_var = Value::Str("SWAP".to_string());
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
type_var = Value::Str("futures".to_string());
}
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchLiquidationsForSymbols() type is required".to_string()))));
}
let mut uppercaseType: Value = to_upper(&type_var);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instType".to_string(), uppercaseType.clone());
m
})]));
m
});
let mut url: Value = self.get_url(channel.clone(), &[Value::Str("public".to_string())]);
let mut newLiquidations: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
if is_true(&self.newUpdates) {
return newLiquidations;
}
return self.filter_by_symbols_since_limit(self.liquidations.clone(), &[symbols.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_liquidation(&mut self, mut client: Value, mut message: Value) {
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_534: bool = true;
while { if !__for_first_534 { i = add(&i, &Value::Int(1)); } __for_first_534 = 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 liquidation: Value = self.parse_ws_liquidation(rawLiquidation.clone(), &[]);
let mut symbol: Value = self.safe_string_k(liquidation.clone(), "symbol", &[]);
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 async fn watch_my_liquidations_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;
}
let mut isTrigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut accessType: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("business".to_string()), Value::Str("private".to_string()));
self.authenticate(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access".to_string(), accessType.clone());
m
})]).await;
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut messageHash: Value = Value::Str("myLiquidations".to_string());
let mut messageHashes: Value = Value::List(vec![]);
if !is_equal(&symbols, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_535: bool = true;
while { if !__for_first_535 { i = add(&i, &Value::Int(1)); } __for_first_535 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut messageHashes, add(&add(&messageHash, &Value::Str("::".to_string())), &symbol));
}
}
} else {
append_to_array(&mut messageHashes, messageHash.clone());
}
let mut channel: Value = Value::Str("balance_and_position".to_string());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m
})]));
m
});
let mut url: Value = self.get_url(channel.clone(), &[Value::Str("private".to_string())]);
let __ws_arg_0 = self.deep_extend(request.clone(), &[params.clone()]);
let mut newLiquidations: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[__ws_arg_0, messageHashes.clone()]).await;
if is_true(&self.newUpdates) {
return newLiquidations;
}
return self.filter_by_symbols_since_limit(self.liquidations.clone(), &[symbols.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_my_liquidation(&mut self, mut client: Value, mut message: Value) {
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_536: bool = true;
while { if !__for_first_536 { i = add(&i, &Value::Int(1)); } __for_first_536 = 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 eventType: Value = self.safe_string_k(rawLiquidation.clone(), "eventType", &[]);
if !is_equal(&eventType, &Value::Str("liquidation".to_string())) {
return;
}
let mut liquidation: Value = self.parse_ws_my_liquidation(rawLiquidation.clone(), &[]);
let mut symbol: Value = self.safe_string_k(liquidation.clone(), "symbol", &[]);
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("myLiquidations".to_string())]);
client.resolve(&[Value::List(vec![liquidation.clone()]), add(&Value::Str("myLiquidations::".to_string()), &symbol)]);
}
}
}
pub fn parse_ws_my_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut posData: Value = self.safe_list_k(liquidation.clone(), "posData", &[Value::List(vec![])]);
let mut firstPosData: Value = self.safe_dict(posData.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(firstPosData.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(firstPosData.clone(), "uTIme", &[]);
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), liquidation.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("contracts".to_string(), self.safe_number_k(firstPosData.clone(), "pos", &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("price".to_string(), self.safe_number_k(liquidation.clone(), "avgPx", &[]));
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 fn parse_ws_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut details: Value = self.safe_list_k(liquidation.clone(), "details", &[Value::List(vec![])]);
let mut liquidationDetails: Value = self.safe_dict(details.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(liquidation.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(liquidationDetails.clone(), "ts", &[]);
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), liquidation.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("contracts".to_string(), self.safe_number_k(liquidationDetails.clone(), "sz", &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("price".to_string(), self.safe_number_k(liquidationDetails.clone(), "bkPx", &[]));
m.insert("side".to_string(), self.safe_string_k(liquidationDetails.clone(), "side", &[]));
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_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbol = self.symbol(symbol.clone());
let mut interval: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
let mut name: Value = add(&Value::Str("candle".to_string()), &interval);
let mut ohlcv: Value = self.subscribe(Value::Str("public".to_string()), name.clone(), name.clone(), symbol.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
limit = ohlcv.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_since_limit(ohlcv.clone(), &[since.clone(), limit.clone(), Value::Int(0), Value::Bool(true)]);
Value::Null
}
pub 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
}));
return self.un_watch_ohlcv_for_symbols(Value::List(vec![Value::List(vec![symbol.clone(), timeframe.clone()])]), &[params.clone()]).await;
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
}));
let mut symbolsLength: Value = get_array_length(&symbolsAndTimeframes);
if is_equal(&symbolsLength, &Value::Int(0)) || !is_true(&Value::Bool(is_array(&get_value(&symbolsAndTimeframes, &Value::Int(0))))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).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_537: bool = true;
while { if !__for_first_537 { i = add(&i, &Value::Int(1)); } __for_first_537 = false; is_less_than(&i, &get_array_length(&symbolsAndTimeframes)) } {
let mut symbolAndTimeframe: Value = get_value(&symbolsAndTimeframes, &i);
let mut symbolAndTimeframe: Value = get_value(&symbolsAndTimeframes, &i);
let mut sym: Value = get_value(&symbolAndTimeframe, &Value::Int(0));
let mut tf: Value = get_value(&symbolAndTimeframe, &Value::Int(1));
let mut marketId: Value = self.market_id(sym.clone());
let mut interval: Value = self.safe_string(self.timeframes.clone(), tf.clone(), &[tf.clone()]);
let mut channel: Value = add(&Value::Str("candle".to_string()), &interval);
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
append_to_array(&mut messageHashes, add(&add(&add(&Value::Str("multi:".to_string()), &channel), &Value::Str(":".to_string())), &sym));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut url: Value = self.get_url(Value::Str("candle".to_string()), &[Value::Str("public".to_string())]);
let mut symboltimeframecandlesVariable = self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
let mut symbol: Value = get_value(&symboltimeframecandlesVariable, &Value::Int(0));
let mut timeframe: Value = get_value(&symboltimeframecandlesVariable, &Value::Int(1));
let mut candles: Value = get_value(&symboltimeframecandlesVariable, &Value::Int(2));
if is_true(&self.newUpdates) {
limit = candles.get_limit(symbol.clone(), limit.clone());
}
let mut filtered: Value = self.filter_by_since_limit(candles.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
}));
let mut symbolsLength: Value = get_array_length(&symbolsAndTimeframes);
if is_equal(&symbolsLength, &Value::Int(0)) || !is_true(&Value::Bool(is_array(&get_value(&symbolsAndTimeframes, &Value::Int(0))))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).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_538: bool = true;
while { if !__for_first_538 { i = add(&i, &Value::Int(1)); } __for_first_538 = false; is_less_than(&i, &get_array_length(&symbolsAndTimeframes)) } {
let mut symbolAndTimeframe: Value = get_value(&symbolsAndTimeframes, &i);
let mut symbolAndTimeframe: Value = get_value(&symbolsAndTimeframes, &i);
let mut sym: Value = get_value(&symbolAndTimeframe, &Value::Int(0));
let mut tf: Value = get_value(&symbolAndTimeframe, &Value::Int(1));
let mut marketId: Value = self.market_id(sym.clone());
let mut interval: Value = self.safe_string(self.timeframes.clone(), tf.clone(), &[tf.clone()]);
let mut channel: Value = add(&Value::Str("candle".to_string()), &interval);
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), channel.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
append_to_array(&mut messageHashes, add(&add(&add(&Value::Str("unsubscribe:multi:".to_string()), &channel), &Value::Str(":".to_string())), &sym));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut url: Value = self.get_url(Value::Str("candle".to_string()), &[Value::Str("public".to_string())]);
return self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.clone()]).await;
Value::Null
}
pub fn handle_ohlcv(&mut self, mut client: Value, mut message: Value) {
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
if is_equal(&channel, &Value::Null) {
return;
}
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut marketId: Value = self.safe_string_k(arg.clone(), "instId", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut interval: Value = replace_str(&channel, &Value::Str("candle".to_string()), &Value::Str("".to_string()));
let mut timeframe: Value = self.find_timeframe(interval.clone(), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_539: bool = true;
while { if !__for_first_539 { i = add(&i, &Value::Int(1)); } __for_first_539 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut parsed: Value = self.parse_ohlcv(get_value(&data, &i), &[market.clone()]);
{ let __be_tmp = self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]); add_element_to_object(&mut self.ohlcvs, &symbol, __be_tmp); };
let mut stored: Value = self.safe_value(self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[]), timeframe.clone(), &[]);
if is_equal(&stored, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "OHLCVLimit", &[Value::Int(1000)]);
stored = ArrayCacheByTimestamp::new(limit.clone());
if !is_equal(&symbol, &Value::Null) && !is_equal(&timeframe, &Value::Null) {
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.ohlcvs) }, &symbol), &timeframe, stored.clone());
}
}
stored.append(parsed.clone());
let mut messageHash: Value = add(&add(&channel, &Value::Str(":".to_string())), &get_value(&market, &Value::Str("id".to_string())));
client.resolve(&[stored.clone(), messageHash.clone()]);
let mut messageHashForMulti: Value = add(&add(&add(&Value::Str("multi:".to_string()), &channel), &Value::Str(":".to_string())), &symbol);
client.resolve(&[Value::List(vec![symbol.clone(), timeframe.clone(), stored.clone()]), messageHashForMulti.clone()]);
}
}
}
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;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut depth: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOrderBook".to_string()), Value::Str("depth".to_string()), &[Value::Str("books".to_string())]); depth = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
if is_equal(&limit, &Value::Int(1)) {
depth = Value::Str("bbo-tbt".to_string());
} else if is_greater_than(&limit, &Value::Int(1)) && is_less_than_or_equal(&limit, &Value::Int(5)) {
depth = Value::Str("books5".to_string());
} else if is_equal(&limit, &Value::Int(50)) {
depth = Value::Str("books50-l2-tbt".to_string()); } else if is_equal(&limit, &Value::Int(400)) {
depth = Value::Str("books".to_string());
}
}
if is_true(&(is_equal(&depth, &Value::Str("books-l2-tbt".to_string())))) || is_true(&(is_equal(&depth, &Value::Str("books50-l2-tbt".to_string())))) {
if !is_true(&self.check_required_credentials(&[Value::Bool(false)])) {
panic!("{}", crate::exchange_errors::authentication_error(add(&self.id, &Value::Str(" watchOrderBook/watchOrderBookForSymbols requires authentication for this depth. Add credentials or change the depth option to books or books5".to_string()))));
}
self.authenticate(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access".to_string(), Value::Str("public".to_string()));
m
})]).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_540: bool = true;
while { if !__for_first_540 { i = add(&i, &Value::Int(1)); } __for_first_540 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut messageHashes, add(&add(&depth, &Value::Str(":".to_string())), &symbol));
let mut marketId: Value = self.market_id(symbol.clone());
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), depth.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut url: Value = self.get_url(depth.clone(), &[Value::Str("public".to_string())]);
let mut orderbook: Value = self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.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 depth: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOrderBook".to_string()), Value::Str("depth".to_string()), &[Value::Str("books".to_string())]); depth = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut limit: Value = self.safe_integer_k(params.clone(), "limit", &[]);
if !is_equal(&limit, &Value::Null) {
if is_equal(&limit, &Value::Int(1)) {
depth = Value::Str("bbo-tbt".to_string());
} else if is_greater_than(&limit, &Value::Int(1)) && is_less_than_or_equal(&limit, &Value::Int(5)) {
depth = Value::Str("books5".to_string());
} else if is_equal(&limit, &Value::Int(50)) {
depth = Value::Str("books50-l2-tbt".to_string()); } else if is_equal(&limit, &Value::Int(400)) {
depth = Value::Str("books".to_string());
}
}
let mut topics: 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_541: bool = true;
while { if !__for_first_541 { i = add(&i, &Value::Int(1)); } __for_first_541 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
append_to_array(&mut subMessageHashes, add(&add(&depth, &Value::Str(":".to_string())), &symbol));
append_to_array(&mut messageHashes, add(&Value::Str("unsubscribe:orderbook:".to_string()), &symbol));
let mut marketId: Value = self.market_id(symbol.clone());
let mut topic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), depth.clone());
m.insert("instId".to_string(), marketId.clone());
m
});
append_to_array(&mut topics, topic.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("args".to_string(), topics.clone());
m
});
let mut url: Value = self.get_url(depth.clone(), &[Value::Str("public".to_string())]);
return self.watch_multiple(url.clone(), messageHashes.clone(), &[request.clone(), messageHashes.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_delta(&self, mut bookside: Value, mut delta: Value) {
let mut price: Value = self.safe_float(delta.clone(), Value::Int(0), &[]);
let mut amount: Value = self.safe_float(delta.clone(), Value::Int(1), &[]);
bookside.store(price.clone(), amount.clone());
}
pub fn handle_deltas(&self, mut bookside: Value, mut deltas: Value) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_542: bool = true;
while { if !__for_first_542 { i = add(&i, &Value::Int(1)); } __for_first_542 = false; is_less_than(&i, &get_array_length(&deltas)) } {
self.handle_delta(bookside.clone(), get_value(&deltas, &i));
}
}
}
pub fn handle_order_book_message(&mut self, mut client: Value, mut message: Value, mut orderbook: Value, mut messageHash: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut asks: Value = self.safe_value_k(message.clone(), "asks", &[Value::List(vec![])]);
let mut bids: Value = self.safe_value_k(message.clone(), "bids", &[Value::List(vec![])]);
let mut storedAsks: Value = get_value(&orderbook, &Value::Str("asks".to_string()));
let mut storedBids: Value = get_value(&orderbook, &Value::Str("bids".to_string()));
self.handle_deltas(storedAsks.clone(), asks.clone());
self.handle_deltas(storedBids.clone(), bids.clone());
let mut marketId: Value = self.safe_string_k(message.clone(), "instId", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut seqId: Value = self.safe_integer_k(message.clone(), "seqId", &[]);
let mut prevSeqId: Value = self.safe_integer_k(message.clone(), "prevSeqId", &[]);
let mut nonce: Value = get_value(&orderbook, &Value::Str("nonce".to_string()));
let mut error: Value = Value::Null;
if !is_equal(&prevSeqId, &Value::Null) && !is_equal(&prevSeqId, &negate(&Value::Int(1))) && !is_equal(&nonce, &prevSeqId) {
error = Value::from(crate::exchange_errors::invalid_nonce(add(&self.id, &Value::Str(" watchOrderBook received invalid nonce".to_string()))));
}
if !is_equal(&error, &Value::Null) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash);
if !is_equal(&symbol, &Value::Null) {
remove(&mut self.orderbooks, &symbol);
}
client.reject(&[Value::from(error.clone()), messageHash.clone()]);
}
let mut timestamp: Value = self.safe_integer_k(message.clone(), "ts", &[]);
add_element_to_object(&mut orderbook, &Value::Str("nonce".to_string()), seqId.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()));
return orderbook;
Value::Null
}
pub fn handle_order_book(&mut self, mut client: Value, mut message: Value) -> Value {
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
let mut action: Value = self.safe_string_k(message.clone(), "action", &[]);
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut marketId: Value = self.safe_string_k(arg.clone(), "instId", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut depths: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bbo-tbt".to_string(), Value::Int(1));
m.insert("books".to_string(), Value::Int(400));
m.insert("books5".to_string(), Value::Int(5));
m.insert("books-rpi".to_string(), Value::Int(400));
m.insert("books-l2-tbt".to_string(), Value::Int(400));
m.insert("books50-l2-tbt".to_string(), Value::Int(50));
m
});
let mut limit: Value = self.safe_integer(depths.clone(), channel.clone(), &[]);
let mut messageHash: Value = add(&add(&channel, &Value::Str(":".to_string())), &symbol);
if is_equal(&action, &Value::Str("snapshot".to_string())) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_543: bool = true;
while { if !__for_first_543 { i = add(&i, &Value::Int(1)); } __for_first_543 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut update: Value = get_value(&data, &i);
let mut update: Value = get_value(&data, &i);
let mut orderbook: Value = self.order_book(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), limit.clone()]);
add_element_to_object(&mut self.orderbooks, &symbol, orderbook.clone());
add_element_to_object(&mut orderbook, &Value::Str("symbol".to_string()), symbol.clone());
self.handle_order_book_message(client.clone(), update.clone(), orderbook.clone(), messageHash.clone(), &[]);
client.resolve(&[orderbook.clone(), messageHash.clone()]);
}
}
} else if is_equal(&action, &Value::Str("update".to_string())) {
if is_true(&Value::Bool(in_op(&self.orderbooks, &symbol))) {
let mut orderbook: Value = get_value(&self.orderbooks, &symbol);
{
let mut i: Value = Value::Int(0);
let mut __for_first_544: bool = true;
while { if !__for_first_544 { i = add(&i, &Value::Int(1)); } __for_first_544 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut update: Value = get_value(&data, &i);
let mut update: Value = get_value(&data, &i);
self.handle_order_book_message(client.clone(), update.clone(), orderbook.clone(), messageHash.clone(), &[market.clone()]);
client.resolve(&[orderbook.clone(), messageHash.clone()]);
}
}
}
} else if is_true(&(is_equal(&channel, &Value::Str("books5".to_string())))) || is_true(&(is_equal(&channel, &Value::Str("bbo-tbt".to_string())))) {
if !is_true(&(Value::Bool(in_op(&self.orderbooks, &symbol)))) {
{ let __be_tmp = self.order_book(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), limit.clone()]); add_element_to_object(&mut self.orderbooks, &symbol, __be_tmp); };
}
let mut orderbook: Value = get_value(&self.orderbooks, &symbol);
{
let mut i: Value = Value::Int(0);
let mut __for_first_545: bool = true;
while { if !__for_first_545 { i = add(&i, &Value::Int(1)); } __for_first_545 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut update: Value = get_value(&data, &i);
let mut update: Value = get_value(&data, &i);
let mut timestamp: Value = self.safe_integer_k(update.clone(), "ts", &[]);
let mut snapshot: Value = self.parse_order_book(update.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Int(0), Value::Int(1)]);
orderbook.reset(snapshot.clone());
client.resolve(&[orderbook.clone(), messageHash.clone()]);
}
}
}
return message;
Value::Null
}
pub async fn authenticate(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_required_credentials(&[]);
let mut access: Value = self.safe_string_k(params.clone(), "access", &[Value::Str("private".to_string())]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("access".to_string())]), &[]);
let mut url: Value = self.get_url(Value::Str("users".to_string()), &[access.clone()]);
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 timestamp: Value = to_string_val(&self.seconds());
let mut method: Value = Value::Str("GET".to_string());
let mut path: Value = Value::Str("/users/self/verify".to_string());
let mut auth: Value = add(&add(×tamp, &method), &path);
let mut signature: Value = self.hmac(self.encode(auth.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
let mut operation: Value = Value::Str("login".to_string());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), operation.clone());
m.insert("args".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), self.apiKey.clone());
m.insert("passphrase".to_string(), self.password.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("sign".to_string(), signature.clone());
m
})]));
m
});
if is_true(&Value::Bool(in_op(¶ms, &Value::Str("access".to_string())))) {
add_element_to_object(&mut request, &Value::Str("access".to_string()), get_value(¶ms, &Value::Str("access".to_string())));
}
self.watch(url.clone(), messageHash.clone(), &[request.clone(), messageHash.clone()]).await;
}
return crate::exchange_stubs::ws_await_flight(&future).await;
Value::Null
}
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;
}
self.authenticate(&[]).await;
return self.subscribe(Value::Str("private".to_string()), Value::Str("account".to_string()), Value::Str("account".to_string()), Value::Null, &[params.clone()]).await;
Value::Null
}
pub fn handle_balance_and_position(&mut self, mut client: Value, mut message: Value) {
self.handle_my_liquidation(client.clone(), message.clone());
}
pub fn handle_balance(&mut self, mut client: Value, mut message: Value) {
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
let mut balance: Value = self.parent.parse_trading_balance(message.clone());
let mut newBalance: Value = self.deep_extend(self.balance.clone(), &[balance.clone()]);
{ let __t = self.safe_balance(newBalance.clone()); self.balance = __t; }
client.resolve(&[self.balance.clone(), channel.clone()]);
}
pub fn order_to_trade(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut info: Value = self.safe_value_k(order.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "fillTime", &[]);
let mut feeMarketId: Value = self.safe_string_k(info.clone(), "fillFeeCcy", &[]);
let mut isTaker: Value = Value::Bool(is_equal(&self.safe_string_k(info.clone(), "execType", &[Value::Str("".to_string())]), &Value::Str("T".to_string())));
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), self.safe_string_k(order.clone(), "symbol", &[]));
m.insert("id".to_string(), self.safe_string_k(info.clone(), "tradeId", &[]));
m.insert("order".to_string(), self.safe_string_k(order.clone(), "id", &[]));
m.insert("type".to_string(), self.safe_string_k(order.clone(), "type", &[]));
m.insert("takerOrMaker".to_string(), ternary(is_true(&(isTaker)), Value::Str("taker".to_string()), Value::Str("maker".to_string())));
m.insert("side".to_string(), self.safe_string_k(order.clone(), "side", &[]));
m.insert("price".to_string(), self.safe_number_k(info.clone(), "fillPx", &[]));
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "fillSz", &[]));
m.insert("cost".to_string(), self.safe_number_k(order.clone(), "cost", &[]));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.safe_number_k(info.clone(), "fillFee", &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeMarketId.clone(), &[]));
m
}));
m
}), &[market.clone()]);
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 type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchMyTrades".to_string()), Value::Str("type".to_string()), &[Value::Str("ANY".to_string())]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut access: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("business".to_string()), Value::Str("private".to_string()));
self.authenticate(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access".to_string(), access.clone());
m
})]).await;
let mut channel: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("orders-algo".to_string()), Value::Str("orders".to_string()));
let mut messageHash: Value = add(&channel, &Value::Str("::myTrades".to_string()));
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
type_var = get_value(&market, &Value::Str("type".to_string()));
messageHash = add(&add(&messageHash, &Value::Str("::".to_string())), &symbol);
}
if is_equal(&type_var, &Value::Str("future".to_string())) {
type_var = Value::Str("futures".to_string());
}
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchMyTrades() type is required".to_string()))));
}
let mut uppercaseType: Value = to_upper(&type_var);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("watchMyTrades".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&uppercaseType, &Value::Str("SPOT".to_string())) {
if !is_equal(&marginMode, &Value::Null) {
uppercaseType = Value::Str("MARGIN".to_string());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), uppercaseType.clone());
m
});
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut orders: Value = self.subscribe(Value::Str("private".to_string()), messageHash.clone(), channel.clone(), Value::Null, &[__ws_arg_1]).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 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;
}
self.authenticate(&[params.clone()]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), Value::Str("ANY".to_string()));
m
});
let mut channel: Value = Value::Str("positions".to_string());
let mut newPositions: Value = Value::Null;
if is_equal(&symbols, &Value::Null) {
let mut arg: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("channel".to_string(), Value::Str("positions".to_string()));
m.insert("instType".to_string(), Value::Str("ANY".to_string()));
m
});
let mut args: Value = Value::List(vec![self.extend(arg.clone(), &[params.clone()])]);
let mut nonSymbolRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op".to_string(), Value::Str("subscribe".to_string()));
m.insert("args".to_string(), args.clone());
m
});
let mut url: Value = self.get_url(channel.clone(), &[Value::Str("private".to_string())]);
newPositions = self.watch(url.clone(), channel.clone(), &[nonSymbolRequest.clone(), channel.clone()]).await;
} else {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
newPositions = self.subscribe_multiple(Value::Str("private".to_string()), channel.clone(), &[symbols.clone(), __ws_arg_2]).await;
}
if is_true(&self.newUpdates) {
return ternary(is_true(&(is_equal(&newPositions, &Value::Null))), Value::List(vec![]), newPositions.clone());
}
return self.filter_by_symbols_since_limit(self.positions.clone(), &[symbols.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_positions(&mut self, mut client: Value, mut message: Value) {
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(arg.clone(), "instId", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("-".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[Value::Str("".to_string())]);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
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 i: Value = Value::Int(0);
let mut __for_first_546: bool = true;
while { if !__for_first_546 { i = add(&i, &Value::Int(1)); } __for_first_546 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rawPosition: Value = get_value(&data, &i);
let mut rawPosition: Value = get_value(&data, &i);
let mut position: Value = self.parse_position(rawPosition.clone(), &[]);
if is_equal(&get_value(&position, &Value::Str("contracts".to_string())), &Value::Int(0)) && is_equal(&get_value(&rawPosition, &Value::Str("posSide".to_string())), &Value::Str("net".to_string())) {
add_element_to_object(&mut position, &Value::Str("side".to_string()), Value::Str("long".to_string()));
let mut shortPosition: Value = self.clone_value(position.clone());
add_element_to_object(&mut shortPosition, &Value::Str("side".to_string()), Value::Str("short".to_string()));
cache.append(shortPosition.clone());
append_to_array(&mut newPositions, shortPosition.clone());
}
append_to_array(&mut newPositions, position.clone());
cache.append(position.clone());
}
}
let mut messageHash: Value = channel.clone();
if !is_equal(&symbol, &Value::Null) {
messageHash = add(&add(&channel, &Value::Str("::".to_string())), &symbol);
}
client.resolve(&[newPositions.clone(), messageHash.clone()]);
}
pub async fn watch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOrders".to_string()), Value::Str("type".to_string()), &[Value::Str("ANY".to_string())]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isTrigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accessType: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("business".to_string()), Value::Str("private".to_string()));
self.authenticate(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access".to_string(), accessType.clone());
m
})]).await;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
type_var = get_value(&market, &Value::Str("type".to_string()));
}
if is_equal(&type_var, &Value::Str("future".to_string())) {
type_var = Value::Str("futures".to_string());
}
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" watchOrders() type is required".to_string()))));
}
let mut uppercaseType: Value = to_upper(&type_var);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("watchOrders".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&uppercaseType, &Value::Str("SPOT".to_string())) {
if !is_equal(&marginMode, &Value::Null) {
uppercaseType = Value::Str("MARGIN".to_string());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), uppercaseType.clone());
m
});
let mut channel: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("orders-algo".to_string()), Value::Str("orders".to_string()));
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut orders: Value = self.subscribe(Value::Str("private".to_string()), channel.clone(), channel.clone(), symbol.clone(), &[__ws_arg_3]).await;
if is_true(&self.newUpdates) {
limit = orders.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_symbol_since_limit(orders.clone(), &[symbol.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_orders(&mut self, mut client: Value, mut message: Value) {
self.handle_my_trades(client.clone(), message.clone());
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
let mut orders: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut ordersLength: Value = get_array_length(&orders);
if is_greater_than(&ordersLength, &Value::Int(0)) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "ordersLimit", &[Value::Int(1000)]);
if is_equal(&self.orders, &Value::Null) {
self.orders = ArrayCacheBySymbolById::new(limit.clone());
self.triggerOrders = ArrayCacheBySymbolById::new(limit.clone());
}
let mut stored: Value = ternary(is_true(&(is_equal(&channel, &Value::Str("orders-algo".to_string())))), self.triggerOrders.clone(), self.orders.clone());
let mut marketIds: Value = Value::List(vec![]);
let mut parsed: Value = self.parse_orders(orders.clone(), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_547: bool = true;
while { if !__for_first_547 { i = add(&i, &Value::Int(1)); } __for_first_547 = false; is_less_than(&i, &get_array_length(&parsed)) } {
let mut order: Value = get_value(&parsed, &i);
let mut order: Value = get_value(&parsed, &i);
stored.append(order.clone());
let mut symbol: Value = get_value(&order, &Value::Str("symbol".to_string()));
let mut market: Value = self.market(symbol.clone());
append_to_array(&mut marketIds, get_value(&market, &Value::Str("id".to_string())));
}
}
client.resolve(&[stored.clone(), channel.clone()]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_548: bool = true;
while { if !__for_first_548 { i = add(&i, &Value::Int(1)); } __for_first_548 = false; is_less_than(&i, &get_array_length(&marketIds)) } {
let mut messageHash: Value = add(&add(&channel, &Value::Str(":".to_string())), &get_value(&marketIds, &i));
client.resolve(&[stored.clone(), messageHash.clone()]);
}
}
}
}
pub fn handle_my_trades(&mut self, mut client: Value, mut message: Value) {
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
let mut rawOrders: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut filteredOrders: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_549: bool = true;
while { if !__for_first_549 { i = add(&i, &Value::Int(1)); } __for_first_549 = false; is_less_than(&i, &get_array_length(&rawOrders)) } {
let mut rawOrder: Value = get_value(&rawOrders, &i);
let mut rawOrder: Value = get_value(&rawOrders, &i);
let mut tradeId: Value = self.safe_string_k(rawOrder.clone(), "tradeId", &[Value::Str("".to_string())]);
if is_greater_than(&get_array_length(&tradeId), &Value::Int(0)) {
let mut order: Value = self.parse_order(rawOrder.clone(), &[]);
append_to_array(&mut filteredOrders, order.clone());
}
}
}
let mut tradesLength: Value = get_array_length(&filteredOrders);
if is_equal(&tradesLength, &Value::Int(0)) {
return;
}
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 myTrades: Value = self.myTrades.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_550: bool = true;
while { if !__for_first_550 { i = add(&i, &Value::Int(1)); } __for_first_550 = false; is_less_than(&i, &get_array_length(&filteredOrders)) } {
let mut rawTrade: Value = get_value(&filteredOrders, &i);
let mut rawTrade: Value = get_value(&filteredOrders, &i);
let mut trade: Value = self.order_to_trade(rawTrade.clone(), &[]);
myTrades.append(trade.clone());
let mut symbol: Value = get_value(&trade, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut symbols, &symbol, Value::Bool(true));
}
}
}
let mut messageHash: Value = add(&channel, &Value::Str("::myTrades".to_string()));
client.resolve(&[self.myTrades.clone(), messageHash.clone()]);
let mut tradeSymbols: Value = object_keys(&symbols);
{
let mut i: Value = Value::Int(0);
let mut __for_first_551: bool = true;
while { if !__for_first_551 { i = add(&i, &Value::Int(1)); } __for_first_551 = false; is_less_than(&i, &get_array_length(&tradeSymbols)) } {
let mut symbolMessageHash: Value = add(&add(&messageHash, &Value::Str("::".to_string())), &get_value(&tradeSymbols, &i));
client.resolve(&[self.myTrades.clone(), symbolMessageHash.clone()]);
}
}
}
pub fn request_id(&self) -> Value {
let mut ts: Value = to_string_val(&self.milliseconds());
let mut randomNumber: Value = self.rand_number(Value::Int(4));
let mut randomPart: Value = to_string_val(&randomNumber);
return add(&ts, &randomPart);
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;
}
self.authenticate(&[]).await;
let mut url: Value = self.get_url(Value::Str("private".to_string()), &[Value::Str("private".to_string())]);
let mut messageHash: Value = self.request_id();
let mut op: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrderWs".to_string()), Value::Str("op".to_string()), &[Value::Str("batch-orders".to_string())]); op = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = self.parent.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut market: Value = self.market(symbol.clone());
let mut instIdCode: Value = self.safe_integer_k(market.clone(), "instIdCode", &[]);
if !is_equal(&instIdCode, &Value::Null) {
remove(&mut args, &Value::Str("instId".to_string()));
add_element_to_object(&mut args, &Value::Str("instIdCode".to_string()), instIdCode.clone());
}
let mut ordType: Value = self.safe_string_k(args.clone(), "ordType", &[]);
if is_true(&(is_equal(&ordType, &Value::Str("trigger".to_string())))) || is_true(&(is_equal(&ordType, &Value::Str("conditional".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("oco".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("move_order_stop".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("iceberg".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("twap".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrderWs() does not support algo trading. this.options[\"createOrderWs\"][\"op\"] must be either order or batch-order".to_string()))));
}
if is_true(&(!is_equal(&op, &Value::Str("order".to_string())))) && is_true(&(!is_equal(&op, &Value::Str("batch-orders".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrderWs() does not support algo trading. this.options[\"createOrderWs\"][\"op\"] must be either order or privatePostTradeOrder or privatePostTradeOrderAlgo".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), messageHash.clone());
m.insert("op".to_string(), op.clone());
m.insert("args".to_string(), Value::List(vec![args.clone()]));
m
});
return self.watch(url.clone(), messageHash.clone(), &[request.clone(), messageHash.clone()]).await;
Value::Null
}
pub fn handle_place_orders(&self, mut client: Value, mut message: Value) {
let mut messageHash: Value = self.safe_string_k(message.clone(), "id", &[]);
let mut args: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
args = self.filter_by(args.clone(), Value::Str("sCode".to_string()), Value::Str("0".to_string()), &[]);
if is_true(&self.is_empty(args.clone())) {
let mut method: Value = self.safe_string_k(message.clone(), "op", &[]);
let mut stringMsg: Value = self.json(message.clone());
self.handle_errors(Value::Int(1), Value::Str("".to_string()), get_value(&client, &Value::Str("url".to_string())), method.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), stringMsg.clone(), message.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
let mut orders: Value = self.parse_orders(args.clone(), &[Value::Null, Value::Null, Value::Null]);
let mut first: Value = self.safe_dict(orders.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
client.resolve(&[first.clone(), messageHash.clone()]);
}
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;
}
self.authenticate(&[]).await;
let mut url: Value = self.get_url(Value::Str("private".to_string()), &[Value::Str("private".to_string())]);
let mut messageHash: Value = self.request_id();
let mut op: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("editOrderWs".to_string()), Value::Str("op".to_string()), &[Value::Str("amend-order".to_string())]); op = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = self.parent.edit_order_request(id.clone(), symbol.clone(), type_var.clone(), side.clone(), &[amount.clone(), price.clone(), params.clone()]);
let mut market: Value = self.market(symbol.clone());
let mut instIdCode: Value = self.safe_integer_k(market.clone(), "instIdCode", &[]);
if !is_equal(&instIdCode, &Value::Null) {
remove(&mut args, &Value::Str("instId".to_string()));
add_element_to_object(&mut args, &Value::Str("instIdCode".to_string()), instIdCode.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), messageHash.clone());
m.insert("op".to_string(), op.clone());
m.insert("args".to_string(), Value::List(vec![args.clone()]));
m
});
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[__ws_arg_4, messageHash.clone()]).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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelOrderWs() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.authenticate(&[]).await;
let mut url: Value = self.get_url(Value::Str("private".to_string()), &[Value::Str("private".to_string())]);
let mut messageHash: Value = self.request_id();
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("clOrdId".to_string())]), &[]);
let mut market: Value = self.market(symbol.clone());
let mut instIdCode: Value = self.safe_integer_k(market.clone(), "instIdCode", &[]);
let mut arg: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instIdCode".to_string(), instIdCode.clone());
m
});
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut arg, &Value::Str("clOrdId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut arg, &Value::Str("ordId".to_string()), id.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), messageHash.clone());
m.insert("op".to_string(), Value::Str("cancel-order".to_string()));
m.insert("args".to_string(), Value::List(vec![self.extend(arg.clone(), &[params.clone()])]));
m
});
return self.watch(url.clone(), messageHash.clone(), &[request.clone(), messageHash.clone()]).await;
Value::Null
}
pub async fn cancel_orders_ws(&mut self, mut ids: 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
}));
let mut idsLength: Value = get_array_length(&ids);
if is_greater_than(&idsLength, &Value::Int(20)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelOrdersWs() accepts up to 20 ids at a time".to_string()))));
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelOrdersWs() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.authenticate(&[]).await;
let mut url: Value = self.get_url(Value::Str("private".to_string()), &[Value::Str("private".to_string())]);
let mut messageHash: Value = self.request_id();
let mut args: Value = Value::List(vec![]);
let mut market: Value = self.market(symbol.clone());
let mut instIdCode: Value = self.safe_integer_k(market.clone(), "instIdCode", &[]);
let mut instParams: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instIdCode".to_string(), instIdCode.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_552: bool = true;
while { if !__for_first_552 { i = add(&i, &Value::Int(1)); } __for_first_552 = false; is_less_than(&i, &idsLength) } {
let mut arg: Value = self.extend(instParams.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ordId".to_string(), get_value(&ids, &i));
m
})]);
append_to_array(&mut args, arg.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), messageHash.clone());
m.insert("op".to_string(), Value::Str("batch-cancel-orders".to_string()));
m.insert("args".to_string(), args.clone());
m
});
let __ws_arg_5 = self.deep_extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[__ws_arg_5, messageHash.clone()]).await;
Value::Null
}
pub async fn cancel_all_orders_ws(&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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelAllOrdersWs() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.authenticate(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("option".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelAllOrdersWs is only applicable to Option in Portfolio Margin mode, and MMP privilege is required.".to_string()))));
}
let mut url: Value = self.get_url(Value::Str("private".to_string()), &[Value::Str("private".to_string())]);
let mut messageHash: Value = self.request_id();
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), messageHash.clone());
m.insert("op".to_string(), Value::Str("mass-cancel".to_string()));
m.insert("args".to_string(), Value::List(vec![self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), Value::Str("OPTION".to_string()));
m.insert("instFamily".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
}), &[params.clone()])]));
m
});
return self.watch(url.clone(), messageHash.clone(), &[request.clone(), messageHash.clone()]).await;
Value::Null
}
pub fn handle_cancel_all_orders(&self, mut client: Value, mut message: Value) {
let mut messageHash: Value = self.safe_string_k(message.clone(), "id", &[]);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
client.resolve(&[data.clone(), messageHash.clone()]);
}
pub fn handle_subscription_status(&self, mut client: Value, mut message: Value) -> Value {
return message;
Value::Null
}
pub fn handle_authenticate(&self, mut client: Value, mut message: Value) {
let mut future: Value = self.safe_value(get_value(&client, &Value::Str("futures".to_string())), Value::Str("authenticated".to_string()), &[]);
future.resolve(&[Value::Bool(true)]);
}
pub fn ping(&self, mut client: Value) -> Value {
return Value::Str("ping".to_string());
Value::Null
}
pub fn handle_pong(&self, mut client: Value, mut message: Value) -> Value {
crate::set_value(&mut client, &Value::Str("lastPong".to_string()), self.milliseconds());
return message;
Value::Null
}
pub fn handle_error_message(&self, mut client: Value, mut message: Value) -> Value {
let mut errorCode: Value = self.safe_string_k(message.clone(), "code", &[]);
let _try_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
if is_true(&(!is_equal(&errorCode, &Value::Null) && !is_equal(&errorCode, &Value::Str("".to_string())))) && !is_equal(&errorCode, &Value::Str("0".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &self.json(message.clone()));
if !is_equal(&errorCode, &Value::Str("1".to_string())) {
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
}
let mut messageString: Value = self.safe_value_k(message.clone(), "msg", &[]);
if !is_equal(&messageString, &Value::Null) {
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), messageString.clone(), feedback.clone());
} else {
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_553: bool = true;
while { if !__for_first_553 { i = add(&i, &Value::Int(1)); } __for_first_553 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut d: Value = get_value(&data, &i);
let mut d: Value = get_value(&data, &i);
errorCode = self.safe_string_k(d.clone(), "sCode", &[]);
if !is_equal(&errorCode, &Value::Null) {
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
}
messageString = self.safe_value_k(d.clone(), "sMsg", &[]);
if !is_equal(&messageString, &Value::Null) {
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), messageString.clone(), feedback.clone());
}
}
}
}
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
#[allow(unreachable_code)] { Value::Null }}));
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
let mut id: Value = self.safe_string_k(message.clone(), "id", &[]);
if is_equal(&id, &Value::Null) {
let mut msg: Value = self.safe_string_k(message.clone(), "msg", &[]);
if !is_equal(&msg, &Value::Null) && is_true(&Value::Bool(starts_with(&msg, &Value::Str("Illegal request: {".to_string())))) {
let mut stringifiedJson: Value = replace_str(&msg, &Value::Str("Illegal request: ".to_string()), &Value::Str("".to_string()));
let mut parsedJson: Value = self.parse_json_value(stringifiedJson.clone());
id = self.safe_string_k(parsedJson.clone(), "id", &[]);
}
}
if !is_equal(&id, &Value::Null) {
client.reject(&[e.clone(), id.clone()]);
return Value::Bool(false);
}
client.reject(&[e.clone()]);
return Value::Bool(false);
}
return Value::Bool(true);
Value::Null
}
pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
if !is_equal(&self.handle_error_message(client.clone(), message.clone()), &Value::Bool(true)) {
return;
}
if is_equal(&message, &Value::Str("pong".to_string())) {
self.handle_pong(client.clone(), message.clone());
return;
}
let mut event: Value = self.safe_string2(message.clone(), Value::Str("event".to_string()), Value::Str("op".to_string()), &[]);
if !is_equal(&event, &Value::Null) {
let mut methods: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("login".to_string(), Value::Str("handle_authenticate".to_string()).clone());
m.insert("subscribe".to_string(), Value::Str("handle_subscription_status".to_string()).clone());
m.insert("unsubscribe".to_string(), Value::Str("handle_unsubscription".to_string()).clone());
m.insert("order".to_string(), Value::Str("handle_place_orders".to_string()).clone());
m.insert("batch-orders".to_string(), Value::Str("handle_place_orders".to_string()).clone());
m.insert("amend-order".to_string(), Value::Str("handle_place_orders".to_string()).clone());
m.insert("batch-amend-orders".to_string(), Value::Str("handle_place_orders".to_string()).clone());
m.insert("cancel-order".to_string(), Value::Str("handle_place_orders".to_string()).clone());
m.insert("mass-cancel".to_string(), Value::Str("handle_cancel_all_orders".to_string()).clone());
m
});
let mut method: Value = self.safe_value(methods.clone(), event.clone(), &[]);
if !is_equal(&method, &Value::Null) {
self.dispatch_ws_handler(&method, &[client.clone(), message.clone()]);
}
} else {
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[]);
if is_equal(&channel, &Value::Null) {
return;
}
let mut methods: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bbo-tbt".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("books".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("books5".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("books-rpi".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("books50-l2-tbt".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("books-l2-tbt".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("tickers".to_string(), Value::Str("handle_ticker".to_string()).clone());
m.insert("mark-price".to_string(), Value::Str("handle_ticker".to_string()).clone());
m.insert("positions".to_string(), Value::Str("handle_positions".to_string()).clone());
m.insert("index-tickers".to_string(), Value::Str("handle_ticker".to_string()).clone());
m.insert("sprd-tickers".to_string(), Value::Str("handle_ticker".to_string()).clone());
m.insert("block-tickers".to_string(), Value::Str("handle_ticker".to_string()).clone());
m.insert("trades".to_string(), Value::Str("handle_trades".to_string()).clone());
m.insert("trades-all".to_string(), Value::Str("handle_trades".to_string()).clone());
m.insert("account".to_string(), Value::Str("handle_balance".to_string()).clone());
m.insert("funding-rate".to_string(), Value::Str("handle_funding_rate".to_string()).clone());
m.insert("orders".to_string(), Value::Str("handle_orders".to_string()).clone());
m.insert("orders-algo".to_string(), Value::Str("handle_orders".to_string()).clone());
m.insert("liquidation-orders".to_string(), Value::Str("handle_liquidation".to_string()).clone());
m.insert("balance_and_position".to_string(), Value::Str("handle_balance_and_position".to_string()).clone());
m
});
let mut method: Value = self.safe_value(methods.clone(), channel.clone(), &[]);
if is_equal(&method, &Value::Null) {
if is_equal(&get_index_of(&channel, &Value::Str("candle".to_string())), &Value::Int(0)) {
self.handle_ohlcv(client.clone(), message.clone());
}
} else {
self.dispatch_ws_handler(&method, &[client.clone(), message.clone()]);
}
}
}
pub fn handle_un_subscription_trades(&mut self, mut client: Value, mut symbol: Value, mut channel: Value) {
let mut subMessageHash: Value = add(&add(&channel, &Value::Str(":".to_string())), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
if is_true(&Value::Bool(in_op(&self.trades, &symbol))) {
remove(&mut self.trades, &symbol);
}
}
pub fn handle_unsubscription_order_book(&mut self, mut client: Value, mut symbol: Value, mut channel: Value) {
let mut subMessageHash: Value = add(&add(&channel, &Value::Str(":".to_string())), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:orderbook:".to_string()), &symbol);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
if is_true(&Value::Bool(in_op(&self.orderbooks, &symbol))) {
remove(&mut self.orderbooks, &symbol);
}
}
pub fn handle_unsubscription_ohlcv(&mut self, mut client: Value, mut symbol: Value, mut channel: Value) {
let mut tf: Value = replace_str(&channel, &Value::Str("candle".to_string()), &Value::Str("".to_string()));
let mut timeframe: Value = self.find_timeframe(tf.clone(), &[]);
if is_equal(&timeframe, &Value::Null) {
return;
}
let mut subMessageHash: Value = add(&add(&add(&Value::Str("multi:".to_string()), &channel), &Value::Str(":".to_string())), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
if is_true(&(!is_equal(&symbol, &Value::Null))) && is_true(&(!is_equal(&timeframe, &Value::Null))) && is_true(&(Value::Bool(in_op(&get_value(&self.ohlcvs, &symbol), &timeframe)))) {
remove(&mut get_value(&self.ohlcvs, &symbol), &timeframe);
}
}
pub fn handle_unsubscription_ticker(&mut self, mut client: Value, mut symbol: Value, mut channel: Value) {
let mut subMessageHash: Value = add(&add(&channel, &Value::Str("::".to_string())), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:ticker:".to_string()), &symbol);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
if is_true(&Value::Bool(in_op(&self.tickers, &symbol))) {
remove(&mut self.tickers, &symbol);
}
}
pub fn handle_unsubscription(&mut self, mut client: Value, mut message: Value) {
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut channel: Value = self.safe_string_k(arg.clone(), "channel", &[Value::Str("".to_string())]);
let mut marketId: Value = self.safe_string_k(arg.clone(), "instId", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[]);
if is_equal(&channel, &Value::Str("trades".to_string())) || is_equal(&channel, &Value::Str("trades-all".to_string())) {
self.handle_un_subscription_trades(client.clone(), symbol.clone(), channel.clone());
} else if is_true(&Value::Bool(starts_with(&channel, &Value::Str("bbo".to_string())))) || is_true(&Value::Bool(starts_with(&channel, &Value::Str("book".to_string())))) {
self.handle_unsubscription_order_book(client.clone(), symbol.clone(), channel.clone());
} else if is_greater_than(&get_index_of(&channel, &Value::Str("tickers".to_string())), &negate(&Value::Int(1))) {
self.handle_unsubscription_ticker(client.clone(), symbol.clone(), channel.clone());
} else if is_true(&Value::Bool(starts_with(&channel, &Value::Str("candle".to_string())))) {
self.handle_unsubscription_ohlcv(client.clone(), symbol.clone(), channel.clone());
}
}
}