// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
use crate::pro::*;
pub struct BitgetCore {
pub parent: crate::exchanges::bitget::BitgetCore,
}
impl BitgetCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { parent: crate::exchanges::bitget::BitgetCore::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = BitgetCore::describe(self);
self.initialize_properties(described);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for BitgetCore {
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 BitgetCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"authenticate" => self.authenticate(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"get_inst_type" => self.get_inst_type(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()[..]),
"handle_check_sum_error" => self.handle_check_sum_error(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)).await,
"handle_error_message" => self.handle_error_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_pong" => self.handle_pong(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_subscription_status" => self.handle_subscription_status(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_un_subscription_status" => self.handle_un_subscription_status(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ws_bid_ask" => self.parse_ws_bid_ask(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_ohlcv" => self.parse_ws_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_order" => self.parse_ws_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_order_status" => self.parse_ws_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ws_position" => self.parse_ws_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_ticker" => self.parse_ws_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"un_watch_channel" => self.un_watch_channel(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,
"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_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_public" => self.un_watch_public(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"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_trades" => self.un_watch_trades(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_my_trades" => self.watch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_ohlcv" => self.watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_order_book" => self.watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_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_private" => self.watch_private(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,
"watch_public" => self.watch_public(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"watch_public_multiple" => self.watch_public_multiple(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"watch_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,
// Go-style inheritance: an un-overridden method dispatches to the parent core.
_ => crate::exchange_generated::ExchangeBase::call_dynamic(&mut self.parent, method, args).await,
}
})
}
}
impl BitgetCore {
/// Synchronous WS handler dispatch — routes a handler-name string (from the
/// venue's handle_message dispatch table) to the real handler method.
#[allow(dead_code, unreachable_patterns, clippy::all)]
pub fn dispatch_ws_handler(&mut self, __name: &crate::Value, args: &[crate::Value]) -> crate::Value {
let __n = match __name { crate::Value::Str(s) => s.as_str(), _ => return crate::Value::Null };
match __n {
"authenticate" => { crate::exchange_stubs::enqueue_spawn("authenticate", args.to_vec()); crate::Value::Null },
"get_inst_type" => self.get_inst_type(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()[..]),
"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_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_check_sum_error" => { crate::exchange_stubs::enqueue_spawn("handle_check_sum_error", args.to_vec()); 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_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_my_trades" => { self.handle_my_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_ohlcv" => { self.handle_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_ohlcv_un_subscription" => { self.handle_ohlcv_un_subscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order" => { self.handle_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order_book" => { self.handle_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order_book_un_subscription" => { self.handle_order_book_un_subscription(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_ticker_un_subscription" => { self.handle_ticker_un_subscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_trades" => { self.handle_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_trades_un_subscription" => { self.handle_trades_un_subscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_un_subscription_status" => self.handle_un_subscription_status(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ws_bid_ask" => self.parse_ws_bid_ask(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_ohlcv" => self.parse_ws_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_order" => self.parse_ws_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_order_status" => self.parse_ws_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ws_position" => self.parse_ws_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_ticker" => self.parse_ws_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"un_watch_channel" => { crate::exchange_stubs::enqueue_spawn("un_watch_channel", 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_order_book" => { crate::exchange_stubs::enqueue_spawn("un_watch_order_book", args.to_vec()); crate::Value::Null },
"un_watch_public" => { crate::exchange_stubs::enqueue_spawn("un_watch_public", 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_trades" => { crate::exchange_stubs::enqueue_spawn("un_watch_trades", 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_my_trades" => { crate::exchange_stubs::enqueue_spawn("watch_my_trades", args.to_vec()); crate::Value::Null },
"watch_ohlcv" => { crate::exchange_stubs::enqueue_spawn("watch_ohlcv", args.to_vec()); crate::Value::Null },
"watch_order_book" => { crate::exchange_stubs::enqueue_spawn("watch_order_book", args.to_vec()); crate::Value::Null },
"watch_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_private" => { crate::exchange_stubs::enqueue_spawn("watch_private", args.to_vec()); crate::Value::Null },
"watch_public" => { crate::exchange_stubs::enqueue_spawn("watch_public", args.to_vec()); crate::Value::Null },
"watch_public_multiple" => { crate::exchange_stubs::enqueue_spawn("watch_public_multiple", 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 BitgetCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { std::ops::Deref::deref(&self.parent) }
}
impl std::ops::DerefMut for BitgetCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { std::ops::DerefMut::deref_mut(&mut self.parent) }
}
impl BitgetCore {
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("createOrderWs".to_string(), Value::Bool(false));
m.insert("editOrderWs".to_string(), Value::Bool(false));
m.insert("fetchOpenOrdersWs".to_string(), Value::Bool(false));
m.insert("fetchOrderWs".to_string(), Value::Bool(false));
m.insert("cancelOrderWs".to_string(), Value::Bool(false));
m.insert("cancelOrdersWs".to_string(), Value::Bool(false));
m.insert("cancelAllOrdersWs".to_string(), Value::Bool(false));
m.insert("watchBalance".to_string(), Value::Bool(true));
m.insert("watchMyTrades".to_string(), Value::Bool(true));
m.insert("watchOHLCV".to_string(), Value::Bool(true));
m.insert("watchOHLCVForSymbols".to_string(), Value::Bool(false));
m.insert("watchOrderBook".to_string(), Value::Bool(true));
m.insert("watchOrderBookForSymbols".to_string(), Value::Bool(true));
m.insert("watchOrders".to_string(), Value::Bool(true));
m.insert("watchTicker".to_string(), Value::Bool(true));
m.insert("watchTickers".to_string(), Value::Bool(true));
m.insert("watchBidsAsks".to_string(), Value::Bool(true));
m.insert("watchTrades".to_string(), Value::Bool(true));
m.insert("watchTradesForSymbols".to_string(), Value::Bool(true));
m.insert("watchPositions".to_string(), Value::Bool(true));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("wss://ws.bitget.com/v2/ws/public".to_string()));
m.insert("private".to_string(), Value::Str("wss://ws.bitget.com/v2/ws/private".to_string()));
m.insert("utaPublic".to_string(), Value::Str("wss://ws.bitget.com/v3/ws/public".to_string()));
m.insert("utaPrivate".to_string(), Value::Str("wss://ws.bitget.com/v3/ws/private".to_string()));
m
}));
m.insert("demo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("wss://wspap.bitget.com/v2/ws/public".to_string()));
m.insert("private".to_string(), Value::Str("wss://wspap.bitget.com/v2/ws/private".to_string()));
m.insert("utaPublic".to_string(), Value::Str("wss://wspap.bitget.com/v3/ws/public".to_string()));
m.insert("utaPrivate".to_string(), Value::Str("wss://wspap.bitget.com/v3/ws/private".to_string()));
m
}));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradesLimit".to_string(), Value::Int(1000));
m.insert("OHLCVLimit".to_string(), Value::Int(1000));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("3m".to_string(), Value::Str("3m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1H".to_string()));
m.insert("4h".to_string(), Value::Str("4H".to_string()));
m.insert("6h".to_string(), Value::Str("6H".to_string()));
m.insert("12h".to_string(), Value::Str("12H".to_string()));
m.insert("1d".to_string(), Value::Str("1D".to_string()));
m.insert("1w".to_string(), Value::Str("1W".to_string()));
m
}));
m.insert("watchTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ignoreDuplicates".to_string(), Value::Bool(true));
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
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("30001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("30003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("30005".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("30006".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("30007".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("30011".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("30012".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("30013".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("30014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30015".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("30016".to_string(), Value::Str("BadRequest".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m
})]);
Value::Null
}
pub fn get_inst_type(&self, mut methodName: Value, mut market: Value, optional_args: &[Value]) -> Value {
let mut uta = get_arg(optional_args, 0, Value::Bool(false));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut instType: Value = Value::Null;
if is_equal(&market, &Value::Null) {
{ let __destr_tmp = self.parent.handle_product_type_and_params(&[Value::Null, params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
} else if is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)))) {
{ let __destr_tmp = self.parent.handle_product_type_and_params(&[market.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
} else {
instType = Value::Str("SPOT".to_string());
}
let mut instypeAux: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("instType".to_string()), &[instType.clone()]); instypeAux = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
instType = instypeAux.clone();
if is_true(&uta) && is_true(&(!is_equal(&instType, &Value::Null))) {
instType = to_lower(&instType);
}
return Value::List(vec![instType.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name bitget#watchTicker
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Tickers-Channel
* @param {string} symbol unified symbol of the market to watch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn watch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut messageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
let mut instType: Value = Value::Null;
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTicker".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.get_inst_type(Value::Str("watchTicker".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
let mut symbolOrInstId: Value = ternary(is_true(&uta), Value::Str("symbol".to_string()), Value::Str("instId".to_string()));
add_element_to_object(&mut args, &topicOrChannel, Value::Str("ticker".to_string()));
add_element_to_object(&mut args, &symbolOrInstId, get_value(&market, &Value::Str("id".to_string())));
return self.watch_public(uta.clone(), messageHash.clone(), args.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name bitget#unWatchTicker
* @description unsubscribe from the ticker channel
* @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
* @param {string} symbol unified symbol of the market to unwatch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {any} status of the unwatch request
*/
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_channel(symbol.clone(), Value::Str("ticker".to_string()), Value::Str("ticker".to_string()), Value::Str("watchTicker".to_string()), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name bitget#watchTickers
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
* @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Tickers-Channel
* @param {string[]} symbols unified symbol of the market to watch the tickers for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
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)]);
if is_equal(&symbols, &Value::Null) {
symbols = Value::List(vec![]);
}
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
let mut instType: Value = Value::Null;
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTickers".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.get_inst_type(Value::Str("watchTickers".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = 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_110: bool = true;
while { if !__for_first_110 { i = add(&i, &Value::Int(1)); } __for_first_110 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut marketInner: Value = self.market(symbol.clone());
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
let mut symbolOrInstId: Value = ternary(is_true(&uta), Value::Str("symbol".to_string()), Value::Str("instId".to_string()));
add_element_to_object(&mut args, &topicOrChannel, Value::Str("ticker".to_string()));
add_element_to_object(&mut args, &symbolOrInstId, get_value(&marketInner, &Value::Str("id".to_string())));
append_to_array(&mut topics, args.clone());
append_to_array(&mut messageHashes, add(&Value::Str("ticker:".to_string()), &symbol));
}
}
let mut tickers: Value = self.watch_public_multiple(uta.clone(), messageHashes.clone(), topics.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut result, &get_value(&tickers, &Value::Str("symbol".to_string())), tickers.clone());
return result;
}
return self.filter_by_array(self.tickers.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub fn handle_ticker(&mut self, mut client: Value, mut message: Value) {
//
// default
//
// {
// "action": "snapshot",
// "arg": {
// "instType": "SPOT",
// "channel": "ticker",
// "instId": "BTCUSDT"
// },
// "data": [
// {
// "instId": "BTCUSDT",
// "lastPr": "43528.19",
// "open24h": "42267.78",
// "high24h": "44490.00",
// "low24h": "41401.53",
// "change24h": "0.03879",
// "bidPr": "43528",
// "askPr": "43528.01",
// "bidSz": "0.0334",
// "askSz": "0.1917",
// "baseVolume": "15002.4216",
// "quoteVolume": "648006446.7164",
// "openUtc": "44071.18",
// "changeUtc24h": "-0.01232",
// "ts": "1701842994338"
// }
// ],
// "ts": 1701842994341
// }
//
// uta
//
// {
// "action": "snapshot",
// "arg": { "instType": "spot", topic: "ticker", symbol: "BTCUSDT" },
// "data": [
// {
// "highPrice24h": "120255.61",
// "lowPrice24h": "116145.88",
// "openPrice24h": "118919.38",
// "lastPrice": "119818.83",
// "turnover24h": "215859996.272276",
// "volume24h": "1819.756798",
// "bid1Price": "119811.26",
// "ask1Price": "119831.18",
// "bid1Size": "0.008732",
// "ask1Size": "0.004297",
// "price24hPcnt": "0.02002"
// }
// ],
// "ts": 1753230479687
// }
//
self.handle_bid_ask(client.clone(), message.clone());
let mut ticker: Value = self.parse_ws_ticker(message.clone(), &[]);
let mut symbol: Value = get_value(&ticker, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut self.tickers, &symbol, ticker.clone());
}
let mut messageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
client.resolve(&[ticker.clone(), messageHash.clone()]);
}
pub fn parse_ws_ticker(&self, mut message: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// spot
//
// {
// "action": "snapshot",
// "arg": {
// "instType": "SPOT",
// "channel": "ticker",
// "instId": "BTCUSDT"
// },
// "data": [
// {
// "instId": "BTCUSDT",
// "lastPr": "43528.19",
// "open24h": "42267.78",
// "high24h": "44490.00",
// "low24h": "41401.53",
// "change24h": "0.03879",
// "bidPr": "43528",
// "askPr": "43528.01",
// "bidSz": "0.0334",
// "askSz": "0.1917",
// "baseVolume": "15002.4216",
// "quoteVolume": "648006446.7164",
// "openUtc": "44071.18",
// "changeUtc24h": "-0.01232",
// "ts": "1701842994338"
// }
// ],
// "ts": 1701842994341
// }
//
// contract
//
// {
// "action": "snapshot",
// "arg": {
// "instType": "USDT-FUTURES",
// "channel": "ticker",
// "instId": "BTCUSDT"
// },
// "data": [
// {
// "instId": "BTCUSDT",
// "lastPr": "43480.4",
// "bidPr": "43476.3",
// "askPr": "43476.8",
// "bidSz": "0.1",
// "askSz": "3.055",
// "open24h": "42252.3",
// "high24h": "44518.2",
// "low24h": "41387.0",
// "change24h": "0.03875",
// "fundingRate": "0.000096",
// "nextFundingTime": "1701849600000",
// "markPrice": "43476.4",
// "indexPrice": "43478.4",
// "holdingAmount": "50670.787",
// "baseVolume": "120187.104",
// "quoteVolume": "5167385048.693",
// "openUtc": "44071.4",
// "symbolType": "1",
// "symbol": "BTCUSDT",
// "deliveryPrice": "0",
// "ts": "1701843962811"
// }
// ],
// "ts": 1701843962812
// }
//
// uta
//
// {
// "action": "snapshot",
// "arg": { "instType": "spot", topic: "ticker", symbol: "BTCUSDT" },
// "data": [
// {
// "highPrice24h": "120255.61",
// "lowPrice24h": "116145.88",
// "openPrice24h": "118919.38",
// "lastPrice": "119818.83",
// "turnover24h": "215859996.272276",
// "volume24h": "1819.756798",
// "bid1Price": "119811.26",
// "ask1Price": "119831.18",
// "bid1Size": "0.008732",
// "ask1Size": "0.004297",
// "price24hPcnt": "0.02002"
// }
// ],
// "ts": 1753230479687
// }
//
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut ticker: Value = self.safe_value(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut utaTimestamp: Value = self.safe_integer_k(message.clone(), "ts", &[]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "ts", &[utaTimestamp.clone()]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut utaMarketId: Value = self.safe_string_k(arg.clone(), "symbol", &[]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instId", &[utaMarketId.clone()]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut close: Value = self.safe_string2(ticker.clone(), Value::Str("lastPr".to_string()), Value::Str("lastPrice".to_string()), &[]);
let mut changeCoefficient: Value = self.safe_string2(ticker.clone(), Value::Str("price24hPcnt".to_string()), Value::Str("change24h".to_string()), &[]);
let mut changePercentage: Value = crate::precise::Precise::stringMul(&changeCoefficient, &Value::Str("100".to_string()));
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string2(ticker.clone(), Value::Str("high24h".to_string()), Value::Str("highPrice24h".to_string()), &[]));
m.insert("low".to_string(), self.safe_string2(ticker.clone(), Value::Str("low24h".to_string()), Value::Str("lowPrice24h".to_string()), &[]));
m.insert("bid".to_string(), self.safe_string2(ticker.clone(), Value::Str("bidPr".to_string()), Value::Str("bid1Price".to_string()), &[]));
m.insert("bidVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("bidSz".to_string()), Value::Str("bid1Size".to_string()), &[]));
m.insert("ask".to_string(), self.safe_string2(ticker.clone(), Value::Str("askPr".to_string()), Value::Str("ask1Price".to_string()), &[]));
m.insert("askVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("askSz".to_string()), Value::Str("ask1Size".to_string()), &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string2(ticker.clone(), Value::Str("open24h".to_string()), Value::Str("openPrice24h".to_string()), &[]));
m.insert("close".to_string(), close.clone());
m.insert("last".to_string(), close.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), changePercentage.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("baseVolume".to_string()), Value::Str("volume24h".to_string()), &[]));
m.insert("quoteVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("quoteVolume".to_string()), Value::Str("turnover24h".to_string()), &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bitget#watchBidsAsks
* @description watches best bid & ask for symbols
* @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Tickers-Channel
* @param {string[]} symbols unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn watch_bids_asks(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false)]);
if is_equal(&symbols, &Value::Null) {
symbols = Value::List(vec![]);
}
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
let mut instType: Value = Value::Null;
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchBidsAsks".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.get_inst_type(Value::Str("watchBidsAsks".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = 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_111: bool = true;
while { if !__for_first_111 { i = add(&i, &Value::Int(1)); } __for_first_111 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut marketInner: Value = self.market(symbol.clone());
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
let mut symbolOrInstId: Value = ternary(is_true(&uta), Value::Str("symbol".to_string()), Value::Str("instId".to_string()));
add_element_to_object(&mut args, &topicOrChannel, Value::Str("ticker".to_string()));
add_element_to_object(&mut args, &symbolOrInstId, get_value(&marketInner, &Value::Str("id".to_string())));
append_to_array(&mut topics, args.clone());
append_to_array(&mut messageHashes, add(&Value::Str("bidask:".to_string()), &symbol));
}
}
let mut tickers: Value = self.watch_public_multiple(uta.clone(), messageHashes.clone(), topics.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut result, &get_value(&tickers, &Value::Str("symbol".to_string())), tickers.clone());
return result;
}
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 ticker: Value = self.parse_ws_bid_ask(message.clone(), &[]);
let mut symbol: Value = get_value(&ticker, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut self.bidsasks, &symbol, ticker.clone());
}
let mut messageHash: Value = add(&Value::Str("bidask:".to_string()), &symbol);
client.resolve(&[ticker.clone(), messageHash.clone()]);
}
pub fn parse_ws_bid_ask(&self, mut message: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
let mut ticker: Value = self.safe_value(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut utaTimestamp: Value = self.safe_integer_k(message.clone(), "ts", &[]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "ts", &[utaTimestamp.clone()]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut utaMarketId: Value = self.safe_string_k(arg.clone(), "symbol", &[]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instId", &[utaMarketId.clone()]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("ask".to_string(), self.safe_string2(ticker.clone(), Value::Str("askPr".to_string()), Value::Str("ask1Price".to_string()), &[]));
m.insert("askVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("askSz".to_string()), Value::Str("ask1Size".to_string()), &[]));
m.insert("bid".to_string(), self.safe_string2(ticker.clone(), Value::Str("bidPr".to_string()), Value::Str("bid1Price".to_string()), &[]));
m.insert("bidVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("bidSz".to_string()), Value::Str("bid1Size".to_string()), &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bitget#watchOHLCV
* @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
* @see https://www.bitget.com/api-doc/spot/websocket/public/Candlesticks-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Candlesticks-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Candlesticks-Channel
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn watch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut timeframes: Value = self.safe_value_k(self.options.clone(), "timeframes", &[]);
let mut interval: Value = self.safe_string(timeframes.clone(), timeframe.clone(), &[]);
let mut messageHash: Value = Value::Null;
let mut instType: Value = Value::Null;
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOHLCV".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.get_inst_type(Value::Str("watchOHLCV".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
if is_true(&uta) {
add_element_to_object(&mut args, &Value::Str("topic".to_string()), Value::Str("kline".to_string()));
add_element_to_object(&mut args, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut args, &Value::Str("interval".to_string()), interval.clone());
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
messageHash = add(&Value::Str("kline:".to_string()), &symbol);
} else {
add_element_to_object(&mut args, &Value::Str("channel".to_string()), add(&Value::Str("candle".to_string()), &interval));
add_element_to_object(&mut args, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
messageHash = add(&add(&add(&Value::Str("candles:".to_string()), &timeframe), &Value::Str(":".to_string())), &symbol);
}
let mut ohlcv: Value = self.watch_public(uta.clone(), messageHash.clone(), args.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
}
/*
* @method
* @name bitget#unWatchOHLCV
* @description unsubscribe from the ohlcv channel
* @see https://www.bitget.com/api-doc/spot/websocket/public/Candlesticks-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Candlesticks-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Candlesticks-Channel
* @param {string} symbol unified symbol of the market to unwatch the ohlcv for
* @param {string} [timeframe] the period for the ratio, default is 1 minute
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut timeframes: Value = self.safe_dict_k(self.options.clone(), "timeframes", &[]);
let mut interval: Value = self.safe_string(timeframes.clone(), timeframe.clone(), &[]);
let mut channel: Value = Value::Null;
let mut market: Value = self.market(symbol.clone());
let mut instType: Value = Value::Null;
let mut messageHash: Value = Value::Null;
let mut values: Value = self.handle_option_and_params(params.clone(), Value::Str("watchOHLCV".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]);
let mut uta: Value = get_value(&values, &Value::Int(0));
{ let __destr_tmp = self.get_inst_type(Value::Str("watchOHLCV".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
if is_true(&uta) {
channel = Value::Str("kline".to_string());
add_element_to_object(&mut args, &Value::Str("topic".to_string()), channel.clone());
add_element_to_object(&mut args, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut args, &Value::Str("interval".to_string()), interval.clone());
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
add_element_to_object(&mut params, &Value::Str("interval".to_string()), interval.clone());
messageHash = add(&channel, &symbol);
} else {
channel = add(&Value::Str("candle".to_string()), &interval);
add_element_to_object(&mut args, &Value::Str("channel".to_string()), channel.clone());
add_element_to_object(&mut args, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
messageHash = add(&Value::Str("candles:".to_string()), &interval);
}
return self.un_watch_channel(symbol.clone(), channel.clone(), messageHash.clone(), Value::Str("watchOHLCV".to_string()), &[params.clone()]).await;
Value::Null
}
pub fn handle_ohlcv(&mut self, mut client: Value, mut message: Value) {
//
// {
// "action": "snapshot",
// "arg": {
// "instType": "SPOT",
// "channel": "candle1m",
// "instId": "BTCUSDT"
// },
// "data": [
// [
// "1701871620000",
// "44080.23",
// "44080.23",
// "44028.5",
// "44028.51",
// "9.9287",
// "437404.105512",
// "437404.105512"
// ],
// [
// "1701871680000",
// "44028.51",
// "44108.11",
// "44028.5",
// "44108.11",
// "17.139",
// "755436.870643",
// "755436.870643"
// ],
// ],
// "ts": 1701901610417
// }
//
// uta
//
// {
// "action": "snapshot",
// "arg": {
// "instType": "usdt-futures",
// "topic": "kline",
// "symbol": "BTCUSDT",
// "interval": "1m"
// },
// "data": [
// {
// "start": "1755564480000",
// "open": "116286",
// "close": "116256.2",
// "high": "116310.2",
// "low": "116232.8",
// "volume": "39.7062",
// "turnover": "4616746.46654"
// },
// ],
// "ts": 1755594421877
// }
//
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut marketId: Value = self.safe_string2(arg.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
{ let __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 channel: Value = self.safe_string2(arg.clone(), Value::Str("channel".to_string()), Value::Str("topic".to_string()), &[Value::Str("".to_string())]);
let mut interval: Value = self.safe_string_k(arg.clone(), "interval", &[]);
let mut isUta: Value = Value::Null;
if is_equal(&interval, &Value::Null) {
isUta = Value::Bool(false);
interval = replace_str(&channel, &Value::Str("candle".to_string()), &Value::Str("".to_string()));
} else {
isUta = Value::Bool(true);
}
let mut timeframes: Value = self.safe_value_k(self.options.clone(), "timeframes", &[]);
let mut timeframe: Value = self.find_timeframe(interval.clone(), &[timeframes.clone()]);
if is_equal(&timeframe, &Value::Null) {
return;
}
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());
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.ohlcvs) }, &symbol), &timeframe, stored.clone());
}
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_112: bool = true;
while { if !__for_first_112 { i = add(&i, &Value::Int(1)); } __for_first_112 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut parsed: Value = self.parse_ws_ohlcv(get_value(&data, &i), &[market.clone()]);
stored.append(parsed.clone());
}
}
let mut messageHash: Value = Value::Null;
if is_true(&isUta) {
messageHash = add(&Value::Str("kline:".to_string()), &symbol);
} else {
messageHash = add(&add(&add(&Value::Str("candles:".to_string()), &timeframe), &Value::Str(":".to_string())), &symbol);
}
client.resolve(&[stored.clone(), messageHash.clone()]);
}
pub fn parse_ws_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// "1701871620000", // timestamp
// "44080.23", // open
// "44080.23", // high
// "44028.5", // low
// "44028.51", // close
// "9.9287", // base volume
// "437404.105512", // quote volume
// "437404.105512" // USDT volume
// ]
//
// uta
//
// {
// "start": "1755564480000",
// "open": "116286",
// "close": "116256.2",
// "high": "116310.2",
// "low": "116232.8",
// "volume": "39.7062",
// "turnover": "4616746.46654"
// }
//
let mut volumeIndex: Value = Value::Int(5);
if is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))) {
volumeIndex = Value::Int(6);
}
return Value::List(vec![self.safe_integer2(ohlcv.clone(), Value::Str("start".to_string()), Value::Int(0), &[]), self.safe_number2(ohlcv.clone(), Value::Str("open".to_string()), Value::Int(1), &[]), self.safe_number2(ohlcv.clone(), Value::Str("high".to_string()), Value::Int(2), &[]), self.safe_number2(ohlcv.clone(), Value::Str("low".to_string()), Value::Int(3), &[]), self.safe_number2(ohlcv.clone(), Value::Str("close".to_string()), Value::Int(4), &[]), self.safe_number2(ohlcv.clone(), Value::Str("volume".to_string()), volumeIndex.clone(), &[])]);
Value::Null
}
/*
* @method
* @name bitget#watchOrderBook
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Order-Book-Channel
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn watch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.watch_order_book_for_symbols(Value::List(vec![symbol.clone()]), &[limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name bitget#unWatchOrderBook
* @description unsubscribe from the orderbook channel
* @see https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Order-Book-Channel
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.limit] orderbook limit, default is undefined
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut channel: Value = Value::Str("books".to_string());
let mut limit: Value = self.safe_integer_k(params.clone(), "limit", &[]);
if is_true(&(is_equal(&limit, &Value::Int(1)))) || is_true(&(is_equal(&limit, &Value::Int(5)))) || is_true(&(is_equal(&limit, &Value::Int(15)))) || is_true(&(is_equal(&limit, &Value::Int(50)))) {
params = self.omit(params.clone(), Value::Str("limit".to_string()), &[]);
channel = add(&channel, &to_string_val(&limit));
}
return self.un_watch_channel(symbol.clone(), channel.clone(), Value::Str("orderbook".to_string()), Value::Str("watchOrderBook".to_string()), &[params.clone()]).await;
Value::Null
}
pub async fn un_watch_channel(&mut self, mut symbol: Value, mut channel: Value, mut messageHashTopic: Value, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut messageHash: Value = add(&add(&add(&Value::Str("unsubscribe:".to_string()), &messageHashTopic), &Value::Str(":".to_string())), &get_value(&market, &Value::Str("symbol".to_string())));
let mut instType: Value = Value::Null;
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.get_inst_type(methodName.clone(), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
if is_true(&uta) {
add_element_to_object(&mut args, &Value::Str("topic".to_string()), channel.clone());
add_element_to_object(&mut args, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut args, &Value::Str("interval".to_string()), self.safe_string_k(params.clone(), "interval", &[Value::Str("1m".to_string())]));
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
params = self.omit(params.clone(), Value::Str("interval".to_string()), &[]);
} else {
add_element_to_object(&mut args, &Value::Str("channel".to_string()), channel.clone());
add_element_to_object(&mut args, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
return self.un_watch_public(uta.clone(), messageHash.clone(), args.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name bitget#watchOrderBookForSymbols
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/Order-Book-Channel
* @param {string[]} symbols unified array of symbols
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn watch_order_book_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut channel: Value = Value::Str("books".to_string());
let mut incrementalFeed: bool = true;
if is_true(&(is_equal(&limit, &Value::Int(1)))) || is_true(&(is_equal(&limit, &Value::Int(5)))) || is_true(&(is_equal(&limit, &Value::Int(15)))) || is_true(&(is_equal(&limit, &Value::Int(50)))) {
channel = add(&channel, &to_string_val(&limit));
incrementalFeed = false;
}
let mut topics: Value = Value::List(vec![]);
let mut messageHashes: Value = Value::List(vec![]);
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOrderBookForSymbols".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{
let mut i: Value = Value::Int(0);
let mut __for_first_113: bool = true;
while { if !__for_first_113 { i = add(&i, &Value::Int(1)); } __for_first_113 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut market: Value = self.market(symbol.clone());
let mut instType: Value = Value::Null;
{ let __destr_tmp = self.get_inst_type(Value::Str("watchOrderBookForSymbols".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
let mut symbolOrInstId: Value = ternary(is_true(&uta), Value::Str("symbol".to_string()), Value::Str("instId".to_string()));
add_element_to_object(&mut args, &topicOrChannel, channel.clone());
add_element_to_object(&mut args, &symbolOrInstId, get_value(&market, &Value::Str("id".to_string())));
append_to_array(&mut topics, args.clone());
append_to_array(&mut messageHashes, add(&Value::Str("orderbook:".to_string()), &symbol));
}
}
if is_true(&uta) {
add_element_to_object(&mut params, &Value::Str("uta".to_string()), Value::Bool(true));
}
let mut orderbook: Value = self.watch_public_multiple(uta.clone(), messageHashes.clone(), topics.clone(), &[params.clone()]).await;
if is_true(&incrementalFeed) {
return orderbook.limit();
} else {
return orderbook;
}
Value::Null
}
pub fn handle_order_book(&mut self, mut client: Value, mut message: Value) {
//
// {
// "action":"snapshot",
// "arg":{
// "instType":"SPOT",
// "channel":"books5",
// "instId":"BTCUSDT"
// },
// "data":[
// {
// "asks":[
// ["21041.11","0.0445"],
// ["21041.16","0.0411"],
// ["21041.21","0.0421"],
// ["21041.26","0.0811"],
// ["21041.65","1.9465"]
// ],
// "bids":[
// ["21040.76","0.0417"],
// ["21040.71","0.0434"],
// ["21040.66","0.1141"],
// ["21040.61","0.3004"],
// ["21040.60","1.3357"]
// ],
// "checksum": -1367582038,
// "ts":"1656413855484"
// }
// ]
// }
//
// {
// "action": "snapshot",
// "arg": { "instType": "usdt-futures", "topic": "books", "symbol": "BTCUSDT" },
// "data": [
// {
// "a": [Array],
// "b": [Array],
// "checksum": 0,
// "pseq": 0,
// "seq": "1343064377779269632",
// "ts": "1755937421270"
// }
// ],
// "ts": 1755937421337
// }
//
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[]);
let mut channel: Value = self.safe_string2(arg.clone(), Value::Str("channel".to_string()), Value::Str("topic".to_string()), &[Value::Str("".to_string())]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut marketId: Value = self.safe_string2(arg.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[]);
let mut rawOrderBook: Value = self.safe_value(data.clone(), Value::Int(0), &[]);
let mut timestamp: Value = self.safe_integer_k(rawOrderBook.clone(), "ts", &[]);
let mut incrementalBook: bool = is_equal(&channel, &Value::Str("books".to_string()));
if is_true(&incrementalBook) {
// storedOrderBook = this.safeValue (this.orderbooks, symbol);
if !is_true(&(Value::Bool(in_op(&self.orderbooks, &symbol)))) {
// const ob = this.orderBook ({});
let mut ob: Value = self.counted_order_book(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
add_element_to_object(&mut ob, &Value::Str("symbol".to_string()), symbol.clone());
add_element_to_object(&mut self.orderbooks, &symbol, ob.clone());
}
let mut storedOrderBook: Value = get_value(&self.orderbooks, &symbol);
let mut asks: Value = self.safe_list2(rawOrderBook.clone(), Value::Str("asks".to_string()), Value::Str("a".to_string()), &[Value::List(vec![])]);
let mut bids: Value = self.safe_list2(rawOrderBook.clone(), Value::Str("bids".to_string()), Value::Str("b".to_string()), &[Value::List(vec![])]);
self.handle_deltas(get_value(&storedOrderBook, &Value::Str("asks".to_string())), asks.clone());
self.handle_deltas(get_value(&storedOrderBook, &Value::Str("bids".to_string())), bids.clone());
add_element_to_object(&mut storedOrderBook, &Value::Str("timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut storedOrderBook, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
let mut checksum: Value = self.handle_option(Value::Str("watchOrderBook".to_string()), Value::Str("checksum".to_string()), &[Value::Bool(true)]);
let mut isSnapshot: bool = is_equal(&self.safe_string_k(message.clone(), "action", &[]), &Value::Str("snapshot".to_string())); // snapshot does not have a checksum
// UTA order books do not provide a crc32 checksum (they rely on seq/pseq for integrity),
// so only validate the checksum when the exchange actually sends one
let mut responseChecksum: Value = self.safe_integer_k(rawOrderBook.clone(), "checksum", &[]);
if !is_true(&isSnapshot) && is_true(&(is_equal(&checksum, &Value::Bool(true)))) && is_true(&(!is_equal(&responseChecksum, &Value::Null))) {
let mut storedAsks: Value = get_value(&storedOrderBook, &Value::Str("asks".to_string()));
let mut storedBids: Value = get_value(&storedOrderBook, &Value::Str("bids".to_string()));
let mut asksLength: Value = get_array_length(&storedAsks);
let mut bidsLength: Value = get_array_length(&storedBids);
let mut payloadArray: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_114: bool = true;
while { if !__for_first_114 { i = add(&i, &Value::Int(1)); } __for_first_114 = false; is_less_than(&i, &Value::Int(25)) } {
if is_less_than(&i, &bidsLength) {
append_to_array(&mut payloadArray, get_value(&get_value(&get_value(&storedBids, &i), &Value::Int(2)), &Value::Int(0)));
append_to_array(&mut payloadArray, get_value(&get_value(&get_value(&storedBids, &i), &Value::Int(2)), &Value::Int(1)));
}
if is_less_than(&i, &asksLength) {
append_to_array(&mut payloadArray, get_value(&get_value(&get_value(&storedAsks, &i), &Value::Int(2)), &Value::Int(0)));
append_to_array(&mut payloadArray, get_value(&get_value(&get_value(&storedAsks, &i), &Value::Int(2)), &Value::Int(1)));
}
}
}
let mut payload: Value = join(&payloadArray, &Value::Str(":".to_string()));
let mut calculatedChecksum: Value = self.crc32(&[payload.clone(), Value::Bool(true)]);
if !is_equal(&calculatedChecksum, &responseChecksum) {
self.spawn(&[Value::Str("handle_check_sum_error".to_string()).clone(), client.clone(), symbol.clone(), messageHash.clone()]);
return;
}
}
} else {
let mut orderbook: Value = self.order_book(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut bidsKey: Value = Value::Str("bids".to_string());
let mut asksKey: Value = Value::Str("asks".to_string());
// bitget UTA has `a` and `b` instead of `asks` and `bids`
if is_true(&Value::Bool(in_op(&rawOrderBook, &Value::Str("a".to_string())))) {
if !is_true(&(Value::Bool(in_op(&rawOrderBook, &Value::Str("asks".to_string()))))) {
asksKey = Value::Str("a".to_string());
}
}
if is_true(&Value::Bool(in_op(&rawOrderBook, &Value::Str("b".to_string())))) {
if !is_true(&(Value::Bool(in_op(&rawOrderBook, &Value::Str("bids".to_string()))))) {
bidsKey = Value::Str("b".to_string());
}
}
let mut parsedOrderbook: Value = self.parse_order_book(rawOrderBook.clone(), symbol.clone(), &[timestamp.clone(), bidsKey.clone(), asksKey.clone()]);
orderbook.reset(parsedOrderbook.clone());
add_element_to_object(&mut self.orderbooks, &symbol, orderbook.clone());
}
client.resolve(&[get_value(&self.orderbooks, &symbol), messageHash.clone()]);
}
pub async fn handle_check_sum_error(&mut self, mut client: Value, mut symbol: Value, mut messageHash: Value) -> Value {
self.un_watch_order_book(symbol.clone(), &[]).await;
let mut error = Value::from(crate::exchange_errors::checksum_error(add(&add(&self.id, &Value::Str(" ".to_string())), &self.orderbook_checksum_message(symbol.clone()))));
client.reject(&[Value::from(error.clone()), messageHash.clone()]);
Value::Null
}
pub fn handle_delta(&self, mut bookside: Value, mut delta: Value) {
let mut bidAsk: Value = self.parse_order_book_bid_ask(delta.clone(), &[Value::Int(0), Value::Int(1)]);
// we store the string representations in the orderbook for checksum calculation
// this simplifies the code for generating checksums as we do not need to do any complex number transformations
append_to_array(&mut bidAsk, delta.clone());
bookside.store_array(bidAsk.clone());
}
pub fn handle_deltas(&self, mut bookside: Value, mut deltas: Value) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_115: bool = true;
while { if !__for_first_115 { i = add(&i, &Value::Int(1)); } __for_first_115 = false; is_less_than(&i, &get_array_length(&deltas)) } {
self.handle_delta(bookside.clone(), get_value(&deltas, &i));
}
}
}
/*
* @method
* @name bitget#watchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn watch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.watch_trades_for_symbols(Value::List(vec![symbol.clone()]), &[since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name bitget#watchTradesForSymbols
* @description get the list of most recent trades for a particular symbol
* @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
* @param {string[]} symbols unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn watch_trades_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut 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 uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchTradesForSymbols".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = 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_116: bool = true;
while { if !__for_first_116 { i = add(&i, &Value::Int(1)); } __for_first_116 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut market: Value = self.market(symbol.clone());
let mut instType: Value = Value::Null;
{ let __destr_tmp = self.get_inst_type(Value::Str("watchTradesForSymbols".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
let mut symbolOrInstId: Value = ternary(is_true(&uta), Value::Str("symbol".to_string()), Value::Str("instId".to_string()));
add_element_to_object(&mut args, &topicOrChannel, ternary(is_true(&uta), Value::Str("publicTrade".to_string()), Value::Str("trade".to_string())));
add_element_to_object(&mut args, &symbolOrInstId, get_value(&market, &Value::Str("id".to_string())));
append_to_array(&mut topics, args.clone());
append_to_array(&mut messageHashes, add(&Value::Str("trade:".to_string()), &symbol));
}
}
if is_true(&uta) {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
}
let mut trades: Value = self.watch_public_multiple(uta.clone(), messageHashes.clone(), topics.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
let mut first: Value = self.safe_value(trades.clone(), Value::Int(0), &[]);
let mut tradeSymbol: Value = self.safe_string_k(first.clone(), "symbol", &[]);
limit = trades.get_limit(tradeSymbol.clone(), limit.clone());
}
let mut result: Value = self.filter_by_since_limit(trades.clone(), &[since.clone(), limit.clone(), Value::Str("timestamp".to_string()), Value::Bool(true)]);
if is_equal(&self.handle_option(Value::Str("watchTrades".to_string()), Value::Str("ignoreDuplicates".to_string()), &[Value::Bool(true)]), &Value::Bool(true)) {
let mut filtered: Value = self.remove_repeated_trades_from_array(result.clone());
filtered = self.sort_by(filtered.clone(), Value::Str("timestamp".to_string()), &[]);
return filtered;
}
return result;
Value::Null
}
/*
* @method
* @name bitget#unWatchTrades
* @description unsubscribe from the trades channel
* @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
* @param {string} symbol unified symbol of the market to unwatch the trades for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {any} status of the unwatch request
*/
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
}));
let mut values: Value = self.handle_option_and_params(params.clone(), Value::Str("watchTrades".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]);
let mut uta: Value = get_value(&values, &Value::Int(0));
let mut channelTopic: Value = ternary(is_true(&uta), Value::Str("publicTrade".to_string()), Value::Str("trade".to_string()));
return self.un_watch_channel(symbol.clone(), channelTopic.clone(), Value::Str("trade".to_string()), Value::Str("watchTrades".to_string()), &[params.clone()]).await;
Value::Null
}
pub fn handle_trades(&mut self, mut client: Value, mut message: Value) {
//
// {
// "action": "snapshot",
// "arg": { "instType": "SPOT", "channel": "trade", "instId": "BTCUSDT" },
// "data": [
// {
// "ts": "1701910980366",
// "price": "43854.01",
// "size": "0.0535",
// "side": "buy",
// "tradeId": "1116461060594286593"
// },
// ],
// "ts": 1701910980730
// }
//
// uta
//
// {
// "action": "snapshot",
// "arg": { "instType": "spot", "topic": "publicTrade", "symbol": "BTCUSDT" },
// "data": [
// {
// "T": "1756287827920",
// "P": "110878.5",
// "v": "0.07",
// "S": "buy",
// "L": "1344534089797185550"
// "i": "1344534089797185549"
// },
// ],
// "ts": 1701910980730
// }
//
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut marketId: Value = self.safe_string2(arg.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut stored: Value = self.safe_value(self.trades.clone(), symbol.clone(), &[]);
if is_equal(&stored, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
stored = ArrayCache::new(limit.clone());
add_element_to_object(&mut self.trades, &symbol, stored.clone());
}
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut length: Value = get_array_length(&data);
{
let mut i: Value = Value::Int(0);
let mut __for_first_117: bool = true;
while { if !__for_first_117 { i = add(&i, &Value::Int(1)); } __for_first_117 = false; is_less_than(&i, &length) } {
let mut index: Value = subtract(&subtract(&length, &i), &Value::Int(1));
let mut rawTrade: Value = get_value(&data, &index);
let mut rawTrade: Value = get_value(&data, &index);
let mut parsed: Value = self.parse_ws_trade(rawTrade.clone(), &[market.clone()]);
stored.append(parsed.clone());
}
}
let mut messageHash: Value = add(&Value::Str("trade:".to_string()), &symbol);
client.resolve(&[stored.clone(), messageHash.clone()]);
}
pub fn parse_ws_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "ts": "1701910980366",
// "price": "43854.01",
// "size": "0.0535",
// "side": "buy",
// "tradeId": "1116461060594286593"
// }
// swap private
//
// {
// "orderId": "1169142761031114781",
// "tradeId": "1169142761312637004",
// "symbol": "LTCUSDT",
// "orderType": "market",
// "side": "buy",
// "price": "80.87",
// "baseVolume": "0.1",
// "quoteVolume": "8.087",
// "profit": "0",
// "tradeSide": "open",
// "posMode": "hedge_mode",
// "tradeScope": "taker",
// "feeDetail": [
// {
// "feeCoin": "USDT",
// "deduction": "no",
// "totalDeductionFee": "0",
// "totalFee": "-0.0048522"
// }
// ],
// "cTime": "1714471276596",
// "uTime": "1714471276596"
// }
// spot private
// {
// "orderId": "1169142457356959747",
// "tradeId": "1169142457636958209",
// "symbol": "LTCUSDT",
// "orderType": "market",
// "side": "buy",
// "priceAvg": "81.069",
// "size": "0.074",
// "amount": "5.999106",
// "tradeScope": "taker",
// "feeDetail": [
// {
// "feeCoin": "LTC",
// "deduction": "no",
// "totalDeductionFee": "0",
// "totalFee": "0.000074"
// }
// ],
// "cTime": "1714471204194",
// "uTime": "1714471204194"
// }
//
// uta private
//
// {
// "symbol": "BTCUSDT",
// "orderType": "market",
// "updatedTime": "1736378720623",
// "side": "buy",
// "orderId": "1288888888888888888",
// "execPnl": "0",
// "feeDetail": [
// {
// "feeCoin": "USDT",
// "fee": "0.569958"
// }
// ],
// "execTime": "1736378720623",
// "tradeScope": "taker",
// "tradeSide": "open",
// "execId": "1288888888888888888",
// "execLinkId": "1288888888888888888",
// "execPrice": "94993",
// "holdSide": "long",
// "execValue": "949.93",
// "category": "USDT-FUTURES",
// "execQty": "0.01",
// "clientOid": "1288888888888888889"
// uta
//
// {
// "i": "1344534089797185549", // Fill execution ID
// "L": "1344534089797185550", // Execution correlation ID
// "p": "110878.5", // Fill price
// "v": "0.07", // Fill size
// "S": "buy", // Fill side
// "T": "1756287827920" // Fill timestamp
// }
//
let mut instId: Value = self.safe_string2(trade.clone(), Value::Str("symbol".to_string()), Value::Str("instId".to_string()), &[]);
let mut posMode: Value = self.safe_string_k(trade.clone(), "posMode", &[]);
let mut category: Value = self.safe_string_k(trade.clone(), "category", &[]);
let mut defaultType: Value = Value::Null;
if !is_equal(&category, &Value::Null) {
defaultType = ternary(is_true(&(!is_equal(&category, &Value::Str("SPOT".to_string())))), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
} else {
defaultType = ternary(is_true(&(!is_equal(&posMode, &Value::Null))), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
}
if is_equal(&market, &Value::Null) {
market = self.safe_market(&[instId.clone(), Value::Null, Value::Null, defaultType.clone()]);
}
let mut timestamp: Value = self.safe_integer_n(trade.clone(), Value::List(vec![Value::Str("uTime".to_string()), Value::Str("cTime".to_string()), Value::Str("ts".to_string()), Value::Str("T".to_string()), Value::Str("execTime".to_string())]), &[]);
let mut feeDetail: Value = self.safe_list_k(trade.clone(), "feeDetail", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(feeDetail.clone(), Value::Int(0), &[]);
let mut fee: Value = Value::Null;
if !is_equal(&first, &Value::Null) {
let mut feeCurrencyId: Value = self.safe_string_k(first.clone(), "feeCoin", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), crate::precise::Precise::stringAbs(&self.safe_string2(first.clone(), Value::Str("totalFee".to_string()), Value::Str("fee".to_string()), &[])));
m.insert("currency".to_string(), feeCurrencyCode.clone());
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("tradeId".to_string()), Value::Str("i".to_string()), Value::Str("execId".to_string())]), &[]));
m.insert("order".to_string(), self.safe_string2(trade.clone(), Value::Str("orderId".to_string()), Value::Str("L".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), self.safe_string_k(trade.clone(), "orderType", &[]));
m.insert("side".to_string(), self.safe_string2(trade.clone(), Value::Str("side".to_string()), Value::Str("S".to_string()), &[]));
m.insert("takerOrMaker".to_string(), self.safe_string_k(trade.clone(), "tradeScope", &[]));
m.insert("price".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("priceAvg".to_string()), Value::Str("price".to_string()), Value::Str("execPrice".to_string()), Value::Str("P".to_string())]), &[]));
m.insert("amount".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("size".to_string()), Value::Str("baseVolume".to_string()), Value::Str("execQty".to_string()), Value::Str("v".to_string())]), &[]));
m.insert("cost".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("amount".to_string()), Value::Str("quoteVolume".to_string()), Value::Str("execValue".to_string())]), &[]));
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bitget#watchPositions
* @description watch all open positions
* @see https://www.bitget.com/api-doc/contract/websocket/private/Positions-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/private/Positions-Channel
* @param {string[]|undefined} symbols list of unified market symbols
* @param {int} [since] the earliest time in ms to fetch positions for
* @param {int} [limit] the maximum number of positions to retrieve
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} [params.instType] one of 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES', default is 'USDT-FUTURES'
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
*/
pub async fn watch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut messageHash: Value = Value::Str("".to_string());
let mut subscriptionHash: Value = Value::Str("positions".to_string());
let mut instType: Value = Value::Str("USDT-FUTURES".to_string());
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchPositions".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
symbols = self.market_symbols(&[symbols.clone()]);
if is_true(&(!is_equal(&symbols, &Value::Null))) && !is_true(&self.is_empty(symbols.clone())) {
market = self.get_market_from_symbols(&[symbols.clone()]);
{ let __destr_tmp = self.get_inst_type(Value::Str("watchPositions".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
}
if is_true(&uta) {
instType = Value::Str("UTA".to_string());
}
messageHash = add(&add(&instType, &Value::Str(":positions".to_string())), &messageHash);
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
let mut channel: Value = ternary(is_true(&uta), Value::Str("position".to_string()), Value::Str("positions".to_string()));
add_element_to_object(&mut args, &topicOrChannel, channel.clone());
if !is_true(&uta) {
add_element_to_object(&mut args, &Value::Str("instId".to_string()), Value::Str("default".to_string()));
} else {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
}
let mut newPositions: Value = self.watch_private(uta.clone(), messageHash.clone(), subscriptionHash.clone(), args.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
return newPositions;
}
return self.filter_by_symbols_since_limit(newPositions.clone(), &[symbols.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_positions(&mut self, mut client: Value, mut message: Value) {
//
// {
// "action": "snapshot",
// "arg": {
// "instType": "USDT-FUTURES",
// "channel": "positions",
// "instId": "default"
// },
// "data": [
// {
// "posId": "926036334386778112",
// "instId": "BTCUSDT",
// "marginCoin": "USDT",
// "marginSize": "2.19245",
// "marginMode": "crossed",
// "holdSide": "long",
// "posMode": "hedge_mode",
// "total": "0.001",
// "available": "0.001",
// "frozen": "0",
// "openPriceAvg": "43849",
// "leverage": 20,
// "achievedProfits": "0",
// "unrealizedPL": "-0.0032",
// "unrealizedPLR": "-0.00145955438",
// "liquidationPrice": "17629.684814834",
// "keepMarginRate": "0.004",
// "marginRate": "0.007634649185",
// "cTime": "1652331666985",
// "uTime": "1701913016923",
// "autoMargin": "off"
// },
// ...
// ]
// "ts": 1701913043767
// }
//
// uta
//
// {
// "data": [
// {
// "symbol": "BTCUSDT",
// "leverage": "20",
// "openFeeTotal": "",
// "mmr": "",
// "breakEvenPrice": "",
// "available": "0",
// "liqPrice": "",
// "marginMode": "crossed",
// "unrealisedPnl": "0",
// "markPrice": "94987.1",
// "createdTime": "1736378720620",
// "avgPrice": "0",
// "totalFundingFee": "0",
// "updatedTime": "1736378720620",
// "marginCoin": "USDT",
// "frozen": "0",
// "profitRate": "",
// "closeFeeTotal": "",
// "marginSize": "0",
// "curRealisedPnl": "0",
// "size": "0",
// "positionStatus": "ended",
// "posSide": "long",
// "holdMode": "hedge_mode"
// }
// ],
// "arg": {
// "instType": "UTA",
// "topic": "position"
// },
// "action": "snapshot",
// "ts": 1730711666652
// }
//
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_k(arg.clone(), "instType", &[Value::Str("".to_string())]);
if is_equal(&self.positions, &Value::Null) {
self.positions = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut action: Value = self.safe_string_k(message.clone(), "action", &[]);
if !is_true(&(Value::Bool(in_op(&self.positions, &instType)))) || is_true(&(is_equal(&action, &Value::Str("snapshot".to_string())))) {
add_element_to_object(&mut self.positions, &instType, ArrayCacheBySymbolBySide::new(Value::Null));
}
let mut cache: Value = get_value(&self.positions, &instType);
let mut rawPositions: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut newPositions: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_118: bool = true;
while { if !__for_first_118 { i = add(&i, &Value::Int(1)); } __for_first_118 = false; is_less_than(&i, &get_array_length(&rawPositions)) } {
let mut rawPosition: Value = get_value(&rawPositions, &i);
let mut rawPosition: Value = get_value(&rawPositions, &i);
let mut marketId: Value = self.safe_string2(rawPosition.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, Value::Str("contract".to_string())]);
let mut position: Value = self.parse_ws_position(rawPosition.clone(), &[market.clone()]);
append_to_array(&mut newPositions, position.clone());
cache.append(position.clone());
}
}
let mut messageHashes: Value = self.find_message_hashes(client.clone(), add(&instType, &Value::Str(":positions::".to_string())));
{
let mut i: Value = Value::Int(0);
let mut __for_first_119: bool = true;
while { if !__for_first_119 { i = add(&i, &Value::Int(1)); } __for_first_119 = false; is_less_than(&i, &get_array_length(&messageHashes)) } {
let mut messageHash: Value = get_value(&messageHashes, &i);
let mut messageHash: Value = get_value(&messageHashes, &i);
let mut parts: Value = split(&messageHash, &Value::Str("::".to_string()));
let mut symbolsString: Value = get_value(&parts, &Value::Int(1));
let mut symbols: Value = split(&symbolsString, &Value::Str(",".to_string()));
let mut positions: Value = self.filter_by_array(newPositions.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
if !is_true(&self.is_empty(positions.clone())) {
client.resolve(&[positions.clone(), messageHash.clone()]);
}
}
}
client.resolve(&[newPositions.clone(), add(&instType, &Value::Str(":positions".to_string()))]);
}
pub fn parse_ws_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "posId": "926036334386778112",
// "instId": "BTCUSDT",
// "marginCoin": "USDT",
// "marginSize": "2.19245",
// "marginMode": "crossed",
// "holdSide": "long",
// "posMode": "hedge_mode",
// "total": "0.001",
// "available": "0.001",
// "frozen": "0",
// "openPriceAvg": "43849",
// "leverage": 20,
// "achievedProfits": "0",
// "unrealizedPL": "-0.0032",
// "unrealizedPLR": "-0.00145955438",
// "liquidationPrice": "17629.684814834",
// "keepMarginRate": "0.004",
// "marginRate": "0.007634649185",
// "cTime": "1652331666985",
// "uTime": "1701913016923",
// "autoMargin": "off"
// }
//
// uta
//
// {
// "symbol": "BTCUSDT",
// "leverage": "20",
// "openFeeTotal": "",
// "mmr": "",
// "breakEvenPrice": "",
// "available": "0",
// "liqPrice": "",
// "marginMode": "crossed",
// "unrealisedPnl": "0",
// "markPrice": "94987.1",
// "createdTime": "1736378720620",
// "avgPrice": "0",
// "totalFundingFee": "0",
// "updatedTime": "1736378720620",
// "marginCoin": "USDT",
// "frozen": "0",
// "profitRate": "",
// "closeFeeTotal": "",
// "marginSize": "0",
// "curRealisedPnl": "0",
// "size": "0",
// "positionStatus": "ended",
// "posSide": "long",
// "holdMode": "hedge_mode"
// }
//
let mut marketId: Value = self.safe_string2(position.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut marginModeId: Value = self.safe_string_k(position.clone(), "marginMode", &[]);
let mut marginMode: Value = self.get_supported_mapping(marginModeId.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("crossed".to_string(), Value::Str("cross".to_string()));
m.insert("isolated".to_string(), Value::Str("isolated".to_string()));
m
})]);
let mut hedgedId: Value = self.safe_string2(position.clone(), Value::Str("posMode".to_string()), Value::Str("holdMode".to_string()), &[]);
let mut hedged: Value = ternary(is_true(&(is_equal(&hedgedId, &Value::Str("hedge_mode".to_string())))), Value::Bool(true), Value::Bool(false));
let mut timestamp: Value = self.safe_integer_n(position.clone(), Value::List(vec![Value::Str("updatedTime".to_string()), Value::Str("uTime".to_string()), Value::Str("cTime".to_string()), Value::Str("createdTime".to_string())]), &[]);
let mut percentageDecimal: Value = self.safe_string2(position.clone(), Value::Str("unrealizedPLR".to_string()), Value::Str("profitRate".to_string()), &[]);
let mut percentage: Value = crate::precise::Precise::stringMul(&percentageDecimal, &Value::Str("100".to_string()));
let mut contractSize: Value = Value::Null;
if !is_equal(&market, &Value::Null) {
contractSize = get_value(&market, &Value::Str("contractSize".to_string()));
}
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_k(position.clone(), "posId", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("notional".to_string(), Value::Null);
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("liquidationPrice".to_string(), self.safe_number2(position.clone(), Value::Str("liquidationPrice".to_string()), Value::Str("liqPrice".to_string()), &[]));
m.insert("entryPrice".to_string(), self.safe_number2(position.clone(), Value::Str("openPriceAvg".to_string()), Value::Str("avgPrice".to_string()), &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number2(position.clone(), Value::Str("unrealizedPL".to_string()), Value::Str("unrealisedPnl".to_string()), &[]));
m.insert("percentage".to_string(), self.parse_number(percentage.clone(), &[]));
m.insert("contracts".to_string(), self.safe_number2(position.clone(), Value::Str("total".to_string()), Value::Str("size".to_string()), &[]));
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "markPrice", &[]));
m.insert("side".to_string(), self.safe_string2(position.clone(), Value::Str("holdSide".to_string()), Value::Str("posSide".to_string()), &[]));
m.insert("hedged".to_string(), hedged.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), self.safe_number2(position.clone(), Value::Str("keepMarginRate".to_string()), Value::Str("mmr".to_string()), &[]));
m.insert("collateral".to_string(), self.safe_number_k(position.clone(), "available", &[]));
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "marginSize", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("marginRatio".to_string(), self.safe_number_k(position.clone(), "marginRate", &[]));
m
}));
Value::Null
}
/*
* @method
* @name bitget#watchOrders
* @description watches information on multiple orders made by the user
* @see https://www.bitget.com/api-doc/spot/websocket/private/Order-Channel
* @see https://www.bitget.com/api-doc/spot/websocket/private/Plan-Order-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/private/Order-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/private/Plan-Order-Channel
* @see https://www.bitget.com/api-doc/margin/cross/websocket/private/Cross-Orders
* @see https://www.bitget.com/api-doc/margin/isolated/websocket/private/Isolate-Orders
* @see https://www.bitget.com/api-doc/uta/websocket/private/Order-Channel
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] *contract only* set to true for watching trigger orders
* @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin orders]
* @param {string} [params.type] 'spot', 'swap'
* @param {string} [params.subType] 'linear', 'inverse'
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn watch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut marketId: Value = Value::Null;
let mut isTrigger: Value = Value::Null;
{ let __destr_tmp = self.is_trigger_order(params.clone()); isTrigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut messageHash: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("triggerOrder".to_string()), Value::Str("order".to_string()));
let mut subscriptionHash: Value = Value::Str("order:trades".to_string());
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
marketId = get_value(&market, &Value::Str("id".to_string()));
messageHash = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
}
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOrders".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut productType: Value = self.safe_string_k(params.clone(), "productType", &[]);
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("watchOrders".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 subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("watchOrders".to_string()), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())))) && is_true(&(is_equal(&symbol, &Value::Null))) {
marketId = Value::Str("default".to_string());
}
if is_true(&(is_equal(&productType, &Value::Null))) && is_true(&(!is_equal(&type_var, &Value::Str("spot".to_string())))) && is_true(&(is_equal(&symbol, &Value::Null))) {
messageHash = add(&add(&messageHash, &Value::Str(":".to_string())), &subType);
} else if is_equal(&productType, &Value::Str("USDT-FUTURES".to_string())) {
messageHash = add(&messageHash, &Value::Str(":linear".to_string()));
} else if is_equal(&productType, &Value::Str("COIN-FUTURES".to_string())) {
messageHash = add(&messageHash, &Value::Str(":inverse".to_string()));
} else if is_equal(&productType, &Value::Str("USDC-FUTURES".to_string())) {
messageHash = add(&messageHash, &Value::Str(":usdcfutures".to_string())); // non unified channel
}
let mut instType: Value = Value::Null;
if is_equal(&market, &Value::Null) && is_equal(&type_var, &Value::Str("spot".to_string())) {
instType = Value::Str("SPOT".to_string());
} else {
{ let __destr_tmp = self.get_inst_type(Value::Str("watchOrders".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
}
if is_equal(&type_var, &Value::Str("spot".to_string())) && is_true(&(!is_equal(&symbol, &Value::Null))) {
subscriptionHash = add(&add(&subscriptionHash, &Value::Str(":".to_string())), &symbol);
}
if is_equal(&isTrigger, &Value::Bool(true)) {
subscriptionHash = add(&subscriptionHash, &Value::Str(":stop".to_string())); // we don't want to re-use the same subscription hash for stop orders
}
let mut instId: Value = ternary(is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())))), marketId.clone(), Value::Str("default".to_string())); // different from other streams here the 'rest' id is required for spot markets, contract markets require default here
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 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(&marginMode, &Value::Null) {
instType = Value::Str("MARGIN".to_string());
messageHash = add(&add(&messageHash, &Value::Str(":".to_string())), &marginMode);
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
channel = Value::Str("orders-isolated".to_string());
} else {
channel = Value::Str("orders-crossed".to_string());
}
}
if is_true(&uta) {
instType = Value::Str("UTA".to_string());
channel = Value::Str("order".to_string());
}
subscriptionHash = add(&add(&subscriptionHash, &Value::Str(":".to_string())), &instType);
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
add_element_to_object(&mut args, &topicOrChannel, channel.clone());
if !is_true(&uta) {
add_element_to_object(&mut args, &Value::Str("instId".to_string()), instId.clone());
} else {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
}
let mut orders: Value = self.watch_private(uta.clone(), messageHash.clone(), subscriptionHash.clone(), args.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
limit = orders.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_symbol_since_limit(orders.clone(), &[symbol.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_order(&mut self, mut client: Value, mut message: Value) {
//
// spot
//
// {
// "action": "snapshot",
// "arg": { "instType": "SPOT", "channel": "orders", "instId": "BTCUSDT" },
// "data": [
// // see all examples in parseWsOrder
// ],
// "ts": 1701923297285
// }
//
// contract
//
// {
// "action": "snapshot",
// "arg": { "instType": "USDT-FUTURES", "channel": "orders", "instId": "default" },
// "data": [
// // see all examples in parseWsOrder
// ],
// "ts": 1701920595879
// }
//
// isolated and cross margin
//
// {
// "action": "snapshot",
// "arg": { "instType": "MARGIN", "channel": "orders-crossed", "instId": "BTCUSDT" },
// "data": [
// // see examples in parseWsOrder
// ],
// "ts": 1701923982497
// }
//
// uta
//
// {
// "action": "snapshot",
// "arg": {
// "instType": "UTA",
// "topic": "order"
// },
// "data": [
// {
// "category": "usdt-futures",
// "symbol": "BTCUSDT",
// "orderId": "xxx",
// "clientOid": "xxx",
// "price": "",
// "qty": "0.001",
// "amount": "1000",
// "holdMode": "hedge_mode",
// "holdSide": "long",
// "tradeSide": "open",
// "orderType": "market",
// "timeInForce": "gtc",
// "side": "buy",
// "marginMode": "crossed",
// "marginCoin": "USDT",
// "reduceOnly": "no",
// "cumExecQty": "0.001",
// "cumExecValue": "83.1315",
// "avgPrice": "83131.5",
// "totalProfit": "0",
// "orderStatus": "filled",
// "cancelReason": "",
// "leverage": "20",
// "feeDetail": [
// {
// "feeCoin": "USDT",
// "fee": "0.0332526"
// }
// ],
// "createdTime": "1742367838101",
// "updatedTime": "1742367838115",
// "stpMode": "none"
// }
// ],
// "ts": 1742367838124
// }
//
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_string2(arg.clone(), Value::Str("channel".to_string()), Value::Str("topic".to_string()), &[Value::Str("".to_string())]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut argInstId: Value = self.safe_string_k(arg.clone(), "instId", &[]);
let mut marketType: Value = Value::Null;
if is_equal(&instType, &Value::Str("spot".to_string())) {
marketType = Value::Str("spot".to_string());
} else if is_equal(&instType, &Value::Str("margin".to_string())) {
marketType = Value::Str("spot".to_string());
} else {
marketType = Value::Str("contract".to_string());
}
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut category: Value = self.safe_string_lower(first.clone(), Value::Str("category".to_string()), &[instType.clone()]);
let mut isLinearSwap: bool = is_equal(&category, &Value::Str("usdt-futures".to_string()));
let mut isInverseSwap: bool = is_equal(&category, &Value::Str("coin-futures".to_string()));
let mut isUSDCFutures: bool = is_equal(&category, &Value::Str("usdc-futures".to_string()));
if is_equal(&instType, &Value::Str("uta".to_string())) {
// UTA order/fill pushes carry the real product in 'category' (spot / *-futures);
// the instType->marketType mapping above defaults UTA to 'contract', which
// mis-resolves a UTA SPOT order to the swap market and yields a messageHash the
// watcher never matches. Derive marketType from category for UTA.
if is_true(&(is_equal(&category, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&category, &Value::Str("margin".to_string())))) {
marketType = Value::Str("spot".to_string());
} else {
marketType = Value::Str("contract".to_string());
}
}
if is_equal(&self.orders, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "ordersLimit", &[Value::Int(1000)]);
self.orders = ArrayCacheBySymbolById::new(limit.clone());
self.triggerOrders = ArrayCacheBySymbolById::new(limit.clone());
}
let mut isTrigger: bool = is_true(&(is_equal(&channel, &Value::Str("orders-algo".to_string())))) || is_true(&(is_equal(&channel, &Value::Str("ordersAlgo".to_string()))));
let mut stored: Value = ternary(is_true(&isTrigger), self.triggerOrders.clone(), self.orders.clone());
let mut messageHash: Value = ternary(is_true(&isTrigger), Value::Str("triggerOrder".to_string()), Value::Str("order".to_string()));
let mut marketSymbols: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_120: bool = true;
while { if !__for_first_120 { i = add(&i, &Value::Int(1)); } __for_first_120 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut order: Value = get_value(&data, &i);
let mut order: Value = get_value(&data, &i);
let mut marketId: Value = self.safe_string2(order.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[argInstId.clone()]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let mut parsed: Value = self.parse_ws_order(order.clone(), &[market.clone()]);
stored.append(parsed.clone());
let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut marketSymbols, &symbol, Value::Bool(true));
}
}
}
let mut keys: Value = object_keys(&marketSymbols);
{
let mut i: Value = Value::Int(0);
let mut __for_first_121: bool = true;
while { if !__for_first_121 { i = add(&i, &Value::Int(1)); } __for_first_121 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut symbol: Value = get_value(&keys, &i);
let mut symbol: Value = get_value(&keys, &i);
let mut innerMessageHash: Value = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
if is_equal(&channel, &Value::Str("orders-crossed".to_string())) {
innerMessageHash = add(&innerMessageHash, &Value::Str(":cross".to_string()));
} else if is_equal(&channel, &Value::Str("orders-isolated".to_string())) {
innerMessageHash = add(&innerMessageHash, &Value::Str(":isolated".to_string()));
}
client.resolve(&[stored.clone(), innerMessageHash.clone()]);
}
}
client.resolve(&[stored.clone(), messageHash.clone()]);
if is_true(&isLinearSwap) {
client.resolve(&[stored.clone(), Value::Str("order:linear".to_string())]);
}
if is_true(&isInverseSwap) {
client.resolve(&[stored.clone(), Value::Str("order:inverse".to_string())]);
}
if is_true(&isUSDCFutures) {
client.resolve(&[stored.clone(), Value::Str("order:usdcfutures".to_string())]);
}
}
pub fn parse_ws_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// spot
//
// {
// instId: 'EOSUSDT',
// orderId: '1171779081105780739',
// price: '0.81075', // limit price, field not present for market orders
// clientOid: 'a2330139-1d04-4d78-98be-07de3cfd1055',
// notional: '5.675250', // this is not cost! but notional
// newSize: '7.0000', // this is not cost! quantity (for limit order or market sell) or cost (for market buy order)
// size: '5.6752', // this is not cost, neither quantity, but notional! this field for "spot" can be ignored at all
// // Note: for limit order (even filled) we don't have cost value in response, only in market order
// orderType: 'limit', // limit, market
// force: 'gtc',
// side: 'buy',
// accBaseVolume: '0.0000', // in case of 'filled', this would be set (for limit orders, this is the only indicator of the amount filled)
// priceAvg: '0.00000', // in case of 'filled', this would be set
// status: 'live', // live, filled, partially_filled
// cTime: '1715099824215',
// uTime: '1715099824215',
// feeDetail: [],
// enterPointSource: 'API'
// #### trigger order has these additional fields: ####
// "triggerPrice": "35100",
// "price": "35100", // this is same as trigger price
// "executePrice": "35123", // this is limit price
// "triggerType": "fill_price",
// "planType": "amount",
// #### in case order had a partial fill: ####
// fillPrice: '35123',
// tradeId: '1171775539946528779',
// baseVolume: '7', // field present in market order
// fillTime: '1715098979937',
// fillFee: '-0.0069987',
// fillFeeCoin: 'BTC',
// tradeScope: 'T',
// }
//
// contract
//
// {
// accBaseVolume: '0', // total amount filled during lifetime for order
// cTime: '1715065875539',
// clientOid: '1171636690041344003',
// enterPointSource: 'API',
// feeDetail: [ {
// "feeCoin": "USDT",
// "fee": "-0.162003"
// } ],
// force: 'gtc',
// instId: 'SEOSSUSDT',
// leverage: '10',
// marginCoin: 'USDT',
// marginMode: 'crossed',
// notionalUsd: '10.4468',
// orderId: '1171636690028761089',
// orderType: 'market',
// posMode: 'hedge_mode', // one_way_mode, hedge_mode
// posSide: 'short', // short, long, net
// price: '0', // zero for market order
// reduceOnly: 'no',
// side: 'sell',
// size: '13', // this is contracts amount
// status: 'live', // live, filled, cancelled
// tradeSide: 'open',
// uTime: '1715065875539'
// #### when filled order is incoming, these additional fields are present too: ###
// baseVolume: '9', // amount filled for the incoming update/trade
// accBaseVolume: '13', // i.e. 9 has been filled from 13 amount (this value is same as 'size')
// fillFee: '-0.0062712',
// fillFeeCoin: 'SUSDT',
// fillNotionalUsd: '10.452',
// fillPrice: '0.804',
// fillTime: '1715065875605',
// pnl: '0',
// priceAvg: '0.804',
// tradeId: '1171636690314407937',
// tradeScope: 'T',
// #### trigger order has these additional fields:
// "triggerPrice": "0.800000000",
// "price": "0.800000000", // <-- this is same as trigger price, actual limit-price is not present in initial response
// "triggerType": "mark_price",
// "triggerTime": "1715082796679",
// "planType": "pl",
// "actualSize": "0.000000000",
// "stopSurplusTriggerType": "fill_price",
// "stopLossTriggerType": "fill_price",
// }
//
// isolated and cross margin
//
// {
// enterPointSource: "web",
// feeDetail: [
// {
// feeCoin: "AAVE",
// deduction: "no",
// totalDeductionFee: "0",
// totalFee: "-0.00010740",
// },
// ],
// force: "gtc",
// orderType: "limit",
// price: "93.170000000",
// fillPrice: "93.170000000",
// baseSize: "0.110600000", // total amount of order
// quoteSize: "10.304602000", // total cost of order (independently if order is filled or pending)
// baseVolume: "0.107400000", // filled amount of order (during order's lifecycle, and not for this specific incoming update)
// fillTotalAmount: "10.006458000", // filled cost of order (during order's lifecycle, and not for this specific incoming update)
// side: "buy",
// status: "partially_filled",
// cTime: "1717875017306",
// clientOid: "b57afe789a06454e9c560a2aab7f7201",
// loanType: "auto-loan",
// orderId: "1183419084588060673",
// }
//
// uta
//
// {
// "category": "usdt-futures",
// "symbol": "BTCUSDT",
// "orderId": "xxx",
// "clientOid": "xxx",
// "price": "",
// "qty": "0.001",
// "amount": "1000",
// "holdMode": "hedge_mode",
// "holdSide": "long",
// "tradeSide": "open",
// "orderType": "market",
// "timeInForce": "gtc",
// "side": "buy",
// "marginMode": "crossed",
// "marginCoin": "USDT",
// "reduceOnly": "no",
// "cumExecQty": "0.001",
// "cumExecValue": "83.1315",
// "avgPrice": "83131.5",
// "totalProfit": "0",
// "orderStatus": "filled",
// "cancelReason": "",
// "leverage": "20",
// "feeDetail": [
// {
// "feeCoin": "USDT",
// "fee": "0.0332526"
// }
// ],
// "createdTime": "1742367838101",
// "updatedTime": "1742367838115",
// "stpMode": "none"
// }
//
let mut isSpot: bool = !is_true(&(Value::Bool(in_op(&order, &Value::Str("posMode".to_string())))));
let mut isMargin: Value = (Value::Bool(in_op(&order, &Value::Str("loanType".to_string()))));
let mut category: Value = self.safe_string_lower(order.clone(), Value::Str("category".to_string()), &[]);
if is_equal(&category, &Value::Str("spot".to_string())) {
isSpot = true;
}
if is_equal(&category, &Value::Str("margin".to_string())) {
isMargin = Value::Bool(true);
}
let mut marketId: Value = self.safe_string2(order.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("cTime".to_string()), Value::Str("createdTime".to_string()), &[]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut rawStatus: Value = self.safe_string2(order.clone(), Value::Str("status".to_string()), Value::Str("orderStatus".to_string()), &[]);
let mut orderFee: Value = self.safe_value_k(order.clone(), "feeDetail", &[Value::List(vec![])]);
let mut fee: Value = self.safe_value(orderFee.clone(), Value::Int(0), &[]);
let mut feeAmount: Value = self.safe_string_k(fee.clone(), "fee", &[]);
let mut feeObject: Value = Value::Null;
if !is_equal(&feeAmount, &Value::Null) {
let mut feeCurrency: Value = self.safe_string_k(fee.clone(), "feeCoin", &[]);
feeObject = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&feeAmount), &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCurrency.clone(), &[]));
m
});
}
let mut triggerPrice: Value = self.safe_number_k(order.clone(), "triggerPrice", &[]);
let mut isTriggerOrder: bool = !is_equal(&triggerPrice, &Value::Null);
let mut price: Value = Value::Null;
if !is_true(&isTriggerOrder) {
price = self.safe_number_k(order.clone(), "price", &[]);
} else if is_true(&isSpot) && is_true(&isTriggerOrder) {
// for spot trigger order, limit price is this
price = self.safe_number_k(order.clone(), "executePrice", &[]);
}
let mut avgPriceString: Value = self.safe_string_lower_n(order.clone(), Value::List(vec![Value::Str("priceAvg".to_string()), Value::Str("fillPrice".to_string()), Value::Str("avgPrice".to_string())]), &[]);
let mut avgPrice: Value = ternary(is_true(&(is_equal(&avgPriceString, &Value::Null))), Value::Null, self.omit_zero(avgPriceString.clone()));
let mut side: Value = self.safe_string_k(order.clone(), "side", &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "orderType", &[]);
let mut accBaseVolume: Value = self.omit_zero(self.safe_string2(order.clone(), Value::Str("accBaseVolume".to_string()), Value::Str("cumExecQty".to_string()), &[]));
let mut newSizeValue: Value = self.omit_zero(self.safe_string2(order.clone(), Value::Str("newSize".to_string()), Value::Str("cumExecValue".to_string()), &[]));
let mut isMarketOrder: bool = is_equal(&type_var, &Value::Str("market".to_string()));
let mut isBuy: bool = is_equal(&side, &Value::Str("buy".to_string()));
let mut totalAmount: Value = Value::Null;
let mut filledAmount: Value = Value::Null;
let mut cost: Value = Value::Null;
let mut remaining: Value = Value::Null;
let mut totalFilled: Value = self.safe_string2(order.clone(), Value::Str("accBaseVolume".to_string()), Value::Str("cumExecQty".to_string()), &[]);
if is_true(&isSpot) {
if is_true(&isMargin) {
totalAmount = self.safe_string2(order.clone(), Value::Str("baseSize".to_string()), Value::Str("qty".to_string()), &[]);
totalFilled = self.safe_string2(order.clone(), Value::Str("baseVolume".to_string()), Value::Str("cumExecQty".to_string()), &[]);
cost = self.safe_string2(order.clone(), Value::Str("fillTotalAmount".to_string()), Value::Str("cumExecValue".to_string()), &[]);
} else {
let mut partialFillAmount: Value = self.safe_string_k(order.clone(), "baseVolume", &[]);
if !is_equal(&partialFillAmount, &Value::Null) {
filledAmount = partialFillAmount.clone();
} else {
filledAmount = totalFilled.clone();
}
if is_true(&isMarketOrder) {
if is_true(&isBuy) {
totalAmount = accBaseVolume.clone();
cost = newSizeValue.clone();
} else {
totalAmount = newSizeValue.clone();
}
} else {
totalAmount = self.safe_string2(order.clone(), Value::Str("newSize".to_string()), Value::Str("qty".to_string()), &[]);
}
}
} else {
// baseVolume should not be used for "amount" for contracts !
filledAmount = self.safe_string2(order.clone(), Value::Str("baseVolume".to_string()), Value::Str("cumExecQty".to_string()), &[]);
totalAmount = self.safe_string2(order.clone(), Value::Str("size".to_string()), Value::Str("qty".to_string()), &[]);
cost = self.safe_string2(order.clone(), Value::Str("fillNotionalUsd".to_string()), Value::Str("cumExecValue".to_string()), &[]);
}
remaining = crate::precise::Precise::stringSub(&totalAmount, &totalFilled);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("id".to_string(), self.safe_string_k(order.clone(), "orderId", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "clientOid", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), self.safe_integer2(order.clone(), Value::Str("uTime".to_string()), Value::Str("updatedTime".to_string()), &[]));
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), self.safe_string_upper2(order.clone(), Value::Str("force".to_string()), Value::Str("timeInForce".to_string()), &[]));
m.insert("postOnly".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("amount".to_string(), totalAmount.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("average".to_string(), avgPrice.clone());
m.insert("filled".to_string(), filledAmount.clone());
m.insert("remaining".to_string(), remaining.clone());
m.insert("status".to_string(), self.parse_ws_order_status(rawStatus.clone()));
m.insert("fee".to_string(), feeObject.clone());
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_ws_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("new".to_string(), Value::Str("open".to_string()));
m.insert("live".to_string(), Value::Str("open".to_string()));
m.insert("partially_filled".to_string(), Value::Str("open".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("cancelled".to_string(), Value::Str("canceled".to_string()));
m.insert("not_trigger".to_string(), Value::Str("open".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name bitget#watchMyTrades
* @description watches trades made by the user
* @see https://www.bitget.com/api-doc/contract/websocket/private/Fill-Channel
* @see https://www.bitget.com/api-doc/uta/websocket/private/Fill-Channel
* @param {str} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn watch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut messageHash: Value = Value::Str("myTrades".to_string());
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
messageHash = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("watchMyTrades".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 instType: Value = Value::Null;
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchMyTrades".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&market, &Value::Null) && is_equal(&type_var, &Value::Str("spot".to_string())) {
instType = Value::Str("SPOT".to_string());
} else {
{ let __destr_tmp = self.get_inst_type(Value::Str("watchMyTrades".to_string()), market.clone(), &[uta.clone(), params.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
}
if is_true(&uta) {
instType = Value::Str("UTA".to_string());
}
let mut subscriptionHash: Value = add(&Value::Str("fill:".to_string()), &instType);
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
add_element_to_object(&mut args, &topicOrChannel, Value::Str("fill".to_string()));
if !is_true(&uta) {
add_element_to_object(&mut args, &Value::Str("instId".to_string()), Value::Str("default".to_string()));
} else {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
}
let mut trades: Value = self.watch_private(uta.clone(), messageHash.clone(), subscriptionHash.clone(), args.clone(), &[params.clone()]).await;
if is_true(&self.newUpdates) {
limit = trades.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_symbol_since_limit(trades.clone(), &[symbol.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
pub fn handle_my_trades(&mut self, mut client: Value, mut message: Value) {
//
// spot
// {
// "action": "snapshot",
// "arg": {
// "instType": "SPOT",
// "channel": "fill",
// "instId": "default"
// },
// "data": [
// {
// "orderId": "1169142457356959747",
// "tradeId": "1169142457636958209",
// "symbol": "LTCUSDT",
// "orderType": "market",
// "side": "buy",
// "priceAvg": "81.069",
// "size": "0.074",
// "amount": "5.999106",
// "tradeScope": "taker",
// "feeDetail": [
// {
// "feeCoin": "LTC",
// "deduction": "no",
// "totalDeductionFee": "0",
// "totalFee": "0.000074"
// }
// ],
// "cTime": "1714471204194",
// "uTime": "1714471204194"
// }
// ],
// "ts": 1714471204270
// }
// swap
// {
// "action": "snapshot",
// "arg": {
// "instType": "USDT-FUTURES",
// "channel": "fill",
// "instId": "default"
// },
// "data": [
// {
// "orderId": "1169142761031114781",
// "tradeId": "1169142761312637004",
// "symbol": "LTCUSDT",
// "orderType": "market",
// "side": "buy",
// "price": "80.87",
// "baseVolume": "0.1",
// "quoteVolume": "8.087",
// "profit": "0",
// "tradeSide": "open",
// "posMode": "hedge_mode",
// "tradeScope": "taker",
// "feeDetail": [
// {
// "feeCoin": "USDT",
// "deduction": "no",
// "totalDeductionFee": "0",
// "totalFee": "-0.0048522"
// }
// ],
// "cTime": "1714471276596",
// "uTime": "1714471276596"
// }
// ],
// "ts": 1714471276629
// }
//
// uta
//
// {
// "data": [
// {
// "symbol": "BTCUSDT",
// "orderType": "market",
// "updatedTime": "1736378720623",
// "side": "buy",
// "orderId": "1288888888888888888",
// "execPnl": "0",
// "feeDetail": [
// {
// "feeCoin": "USDT",
// "fee": "0.569958"
// }
// ],
// "execTime": "1736378720623",
// "tradeScope": "taker",
// "tradeSide": "open",
// "execId": "1288888888888888888",
// "execLinkId": "1288888888888888888",
// "execPrice": "94993",
// "holdSide": "long",
// "execValue": "949.93",
// "category": "USDT-FUTURES",
// "execQty": "0.01",
// "clientOid": "1288888888888888889"
// }
// ],
// "arg": {
// "instType": "UTA",
// "topic": "fill"
// },
// "action": "snapshot",
// "ts": 1733904123981
// }
//
if is_equal(&self.myTrades, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
self.myTrades = ArrayCache::new(limit.clone());
}
let mut stored: Value = self.myTrades.clone();
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut length: Value = get_array_length(&data);
let mut messageHash: Value = Value::Str("myTrades".to_string());
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_122: bool = true;
while { if !__for_first_122 { i = add(&i, &Value::Int(1)); } __for_first_122 = false; is_less_than(&i, &length) } {
let mut trade: Value = get_value(&data, &i);
let mut trade: Value = get_value(&data, &i);
let mut market: Value = Value::Null;
if is_equal(&instType, &Value::Str("uta".to_string())) {
// UTA fills carry the product in 'category'; resolve the matching
// market so parseWsTrade yields the correct symbol (a UTA SPOT fill
// otherwise resolves to the swap market and the messageHash never matches).
let mut category: Value = self.safe_string_lower(trade.clone(), Value::Str("category".to_string()), &[]);
let mut marketType: Value = Value::Str("contract".to_string());
if is_true(&(is_equal(&category, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&category, &Value::Str("margin".to_string())))) {
marketType = Value::Str("spot".to_string());
}
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
}
let mut parsed: Value = self.parse_ws_trade(trade.clone(), &[market.clone()]);
stored.append(parsed.clone());
let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
let mut symbolSpecificMessageHash: Value = add(&Value::Str("myTrades:".to_string()), &symbol);
client.resolve(&[stored.clone(), symbolSpecificMessageHash.clone()]);
}
}
client.resolve(&[stored.clone(), messageHash.clone()]);
}
/*
* @method
* @name bitget#watchBalance
* @description watch balance and get the amount of funds available for trading or funds locked in orders
* @see https://www.bitget.com/api-doc/spot/websocket/private/Account-Channel
* @see https://www.bitget.com/api-doc/contract/websocket/private/Account-Channel
* @see https://www.bitget.com/api-doc/margin/cross/websocket/private/Margin-Cross-Account-Assets
* @see https://www.bitget.com/api-doc/margin/isolated/websocket/private/Margin-isolated-account-assets
* @see https://www.bitget.com/api-doc/uta/websocket/private/Account-Channel
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {str} [params.type] spot or contract if not provided this.options['defaultType'] is used
* @param {string} [params.instType] one of 'SPOT', 'MARGIN', 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
* @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin balances
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn watch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut uta: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchBalance".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("watchBalance".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("watchBalance".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut instType: Value = Value::Null;
let mut channel: Value = Value::Str("account".to_string());
if is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
instType = Value::Str("USDT-FUTURES".to_string());
} else if !is_equal(&marginMode, &Value::Null) {
instType = Value::Str("MARGIN".to_string());
if !is_true(&uta) {
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
channel = Value::Str("account-isolated".to_string());
} else {
channel = Value::Str("account-crossed".to_string());
}
}
} else if !is_true(&uta) {
instType = Value::Str("SPOT".to_string());
}
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchBalance".to_string()), Value::Str("instType".to_string()), &[instType.clone()]); instType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
instType = Value::Str("UTA".to_string());
}
let mut args: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut topicOrChannel: Value = ternary(is_true(&uta), Value::Str("topic".to_string()), Value::Str("channel".to_string()));
add_element_to_object(&mut args, &topicOrChannel, channel.clone());
if !is_true(&uta) {
add_element_to_object(&mut args, &Value::Str("coin".to_string()), Value::Str("default".to_string()));
} else {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
}
let mut instTypeLower: Value = ternary(is_true(&(is_equal(&instType, &Value::Null))), Value::Str("".to_string()), to_lower(&instType));
let mut messageHash: Value = add(&Value::Str("balance:".to_string()), &instTypeLower);
return self.watch_private(uta.clone(), messageHash.clone(), messageHash.clone(), args.clone(), &[params.clone()]).await;
Value::Null
}
pub fn handle_balance(&mut self, mut client: Value, mut message: Value) {
//
// spot
//
// {
// "action": "snapshot",
// "arg": { "instType": "SPOT", "channel": "account", "coin": "default" },
// "data": [
// {
// "coin": "USDT",
// "available": "19.1430952856087",
// "frozen": "7",
// "locked": "0",
// "limitAvailable": "0",
// "uTime": "1701931970487"
// },
// ],
// "ts": 1701931970487
// }
//
// swap
//
// {
// "action": "snapshot",
// "arg": { "instType": "USDT-FUTURES", "channel": "account", "coin": "default" },
// "data": [
// {
// "marginCoin": "USDT",
// "frozen": "5.36581500",
// "available": "26.14309528",
// "maxOpenPosAvailable": "20.77728028",
// "maxTransferOut": "20.77728028",
// "equity": "26.14309528",
// "usdtEquity": "26.143095285166"
// }
// ],
// "ts": 1701932570822
// }
//
// margin
//
// {
// "action": "snapshot",
// "arg": { "instType": "MARGIN", "channel": "account-crossed", "coin": "default" },
// "data": [
// {
// "uTime": "1701933110544",
// "id": "1096916799926710272",
// "coin": "USDT",
// "available": "16.24309528",
// "borrow": "0.00000000",
// "frozen": "9.90000000",
// "interest": "0.00000000",
// "coupon": "0.00000000"
// }
// ],
// "ts": 1701933110544
// }
//
// uta
//
// {
// "data": [{
// "unrealisedPnL": "-10116.55",
// "totalEquity": "4976919.05",
// "positionMgnRatio": "0",
// "mmr": "408.08",
// "effEquity": "4847952.35",
// "imr": "17795.97",
// "mgnRatio": "0",
// "coin": [{
// "debts": "0",
// "balance": "0.9992",
// "available": "0.9992",
// "borrow": "0",
// "locked": "0",
// "equity": "0.9992",
// "coin": "ETH",
// "usdValue": "2488.667472"
// }]
// }],
// "arg": {
// "instType": "UTA",
// "topic": "account"
// },
// "action": "snapshot",
// "ts": 1740546523244
// }
//
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut data: Value = self.safe_value_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_124: bool = true;
while { if !__for_first_124 { i = add(&i, &Value::Int(1)); } __for_first_124 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rawBalance: Value = get_value(&data, &i);
let mut rawBalance: Value = get_value(&data, &i);
if is_equal(&instType, &Value::Str("uta".to_string())) {
let mut coins: Value = self.safe_list_k(rawBalance.clone(), "coin", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_123: bool = true;
while { if !__for_first_123 { j = add(&j, &Value::Int(1)); } __for_first_123 = false; is_less_than(&j, &get_array_length(&coins)) } {
let mut entry: Value = get_value(&coins, &j);
let mut entry: Value = get_value(&coins, &j);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.balance, &code)))) {
account = get_value(&self.balance, &code);
}
let mut borrow: Value = self.safe_string_k(entry.clone(), "borrow", &[]);
let mut debts: Value = self.safe_string_k(entry.clone(), "debts", &[]);
if is_true(&(!is_equal(&borrow, &Value::Null))) || is_true(&(!is_equal(&debts, &Value::Null))) {
add_element_to_object(&mut account, &Value::Str("debt".to_string()), crate::precise::Precise::stringAdd(&borrow, &debts));
}
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(entry.clone(), "available", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(entry.clone(), "locked", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(entry.clone(), "balance", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut self.balance, &code, account.clone());
}
}
}
} else {
let mut currencyId: Value = self.safe_string2(rawBalance.clone(), Value::Str("coin".to_string()), Value::Str("marginCoin".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.balance, &code)))) {
account = get_value(&self.balance, &code);
}
let mut borrow: Value = self.safe_string_k(rawBalance.clone(), "borrow", &[]);
if !is_equal(&borrow, &Value::Null) {
let mut interest: Value = self.safe_string_k(rawBalance.clone(), "interest", &[]);
add_element_to_object(&mut account, &Value::Str("debt".to_string()), crate::precise::Precise::stringAdd(&borrow, &interest));
}
let mut freeQuery: Value = ternary(is_true(&(Value::Bool(in_op(&rawBalance, &Value::Str("maxTransferOut".to_string()))))), Value::Str("maxTransferOut".to_string()), Value::Str("available".to_string()));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string(rawBalance.clone(), freeQuery.clone(), &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(rawBalance.clone(), "equity", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(rawBalance.clone(), "frozen", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut self.balance, &code, account.clone());
}
}
}
}
// REST parseBalance sets info, keep the ws structure at parity,
// see https://github.com/ccxt/ccxt/issues/21973
add_element_to_object(&mut self.balance, &Value::Str("info".to_string()), message.clone());
{ let __t = self.safe_balance(self.balance.clone()); self.balance = __t; }
let mut messageHash: Value = add(&Value::Str("balance:".to_string()), &instType);
client.resolve(&[self.balance.clone(), messageHash.clone()]);
}
pub async fn watch_public(&mut self, mut uta: Value, mut messageHash: Value, mut args: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut url: Value = ternary(is_true(&(is_equal(&uta, &Value::Bool(true)))), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("utaPublic".to_string())), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("public".to_string())));
let mut sandboxMode: Value = self.safe_bool2(self.options.clone(), Value::Str("sandboxMode".to_string()), Value::Str("sandbox".to_string()), &[Value::Bool(false)]);
if is_equal(&sandboxMode, &Value::Bool(true)) {
let mut instType: Value = self.safe_string_k(args.clone(), "instType", &[]);
if is_true(&(!is_equal(&instType, &Value::Str("SCOIN-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDT-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDC-FUTURES".to_string())))) {
if is_equal(&uta, &Value::Bool(true)) {
url = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("utaPublic".to_string()));
} else {
url = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("public".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![args.clone()]));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
Value::Null
}
pub async fn un_watch_public(&mut self, mut uta: Value, mut messageHash: Value, mut args: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut url: Value = ternary(is_true(&(is_equal(&uta, &Value::Bool(true)))), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("utaPublic".to_string())), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("public".to_string())));
let mut sandboxMode: Value = self.safe_bool2(self.options.clone(), Value::Str("sandboxMode".to_string()), Value::Str("sandbox".to_string()), &[Value::Bool(false)]);
if is_equal(&sandboxMode, &Value::Bool(true)) {
let mut instType: Value = self.safe_string_k(args.clone(), "instType", &[]);
if is_true(&(!is_equal(&instType, &Value::Str("SCOIN-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDT-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDC-FUTURES".to_string())))) {
if is_equal(&uta, &Value::Bool(true)) {
url = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("utaPublic".to_string()));
} else {
url = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("public".to_string()));
}
}
}
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(), Value::List(vec![args.clone()]));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
Value::Null
}
pub async fn watch_public_multiple(&mut self, mut uta: Value, mut messageHashes: Value, mut argsArray: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut url: Value = ternary(is_true(&(is_equal(&uta, &Value::Bool(true)))), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("utaPublic".to_string())), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("public".to_string())));
let mut sandboxMode: Value = self.safe_bool2(self.options.clone(), Value::Str("sandboxMode".to_string()), Value::Str("sandbox".to_string()), &[Value::Bool(false)]);
if is_equal(&sandboxMode, &Value::Bool(true)) {
let mut argsArrayFirst: Value = self.safe_dict(argsArray.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_k(argsArrayFirst.clone(), "instType", &[]);
if is_true(&(!is_equal(&instType, &Value::Str("SCOIN-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDT-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDC-FUTURES".to_string())))) {
url = ternary(is_true(&(is_equal(&uta, &Value::Bool(true)))), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("utaPublic".to_string())), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("public".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(), argsArray.clone());
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch_multiple(url.clone(), messageHashes.clone(), &[message.clone(), messageHashes.clone()]).await;
Value::Null
}
pub async fn 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 url: Value = self.safe_string_k(params.clone(), "url", &[Value::Str("".to_string())]);
let mut client: Value = self.client(&[url.clone()]);
let mut messageHash: Value = Value::Str("authenticated".to_string());
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 auth: Value = add(&add(×tamp, &Value::Str("GET".to_string())), &Value::Str("/user/verify".to_string()));
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
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
}
return crate::exchange_stubs::ws_await_flight(&future).await;
Value::Null
}
pub async fn watch_private(&mut self, mut uta: Value, mut messageHash: Value, mut subscriptionHash: Value, mut args: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut url: Value = ternary(is_true(&(is_equal(&uta, &Value::Bool(true)))), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("utaPrivate".to_string())), get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("ws".to_string())), &Value::Str("private".to_string())));
let mut sandboxMode: Value = self.safe_bool2(self.options.clone(), Value::Str("sandboxMode".to_string()), Value::Str("sandbox".to_string()), &[Value::Bool(false)]);
if is_equal(&sandboxMode, &Value::Bool(true)) {
let mut instType: Value = self.safe_string_k(args.clone(), "instType", &[]);
if is_true(&(!is_equal(&instType, &Value::Str("SCOIN-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDT-FUTURES".to_string())))) && is_true(&(!is_equal(&instType, &Value::Str("SUSDC-FUTURES".to_string())))) {
if is_equal(&uta, &Value::Bool(true)) {
url = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("utaPrivate".to_string()));
} else {
url = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("demo".to_string())), &Value::Str("private".to_string()));
}
}
}
self.authenticate(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m
})]).await;
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![args.clone()]));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[message.clone(), subscriptionHash.clone()]).await;
Value::Null
}
pub fn handle_authenticate(&self, mut client: Value, mut message: Value) {
//
// { event: "login", code: 0 }
//
let mut messageHash: Value = Value::Str("authenticated".to_string());
let mut future: Value = self.safe_value(get_value(&client, &Value::Str("futures".to_string())), messageHash.clone(), &[]);
future.resolve(&[Value::Bool(true)]);
}
pub fn handle_error_message(&self, mut client: Value, mut message: Value) -> Value {
//
// { event: "error", code: 30015, msg: "Invalid sign" }
//
let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
let _try_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
if is_equal(&event, &Value::Str("error".to_string())) {
let mut code: Value = self.safe_string_k(message.clone(), "code", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &self.json(message.clone()));
self.throw_exactly_matched_exception(get_value(&get_value(&self.exceptions, &Value::Str("ws".to_string())), &Value::Str("exact".to_string())), code.clone(), feedback.clone());
let mut msg: Value = self.safe_string_k(message.clone(), "msg", &[Value::Str("".to_string())]);
self.throw_broadly_matched_exception(get_value(&get_value(&self.exceptions, &Value::Str("ws".to_string())), &Value::Str("broad".to_string())), msg.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Bool(false);
#[allow(unreachable_code)] { Value::Null }}));
match _try_result { Ok(__try_ok) => { if !matches!(__try_ok, Value::Null) { return __try_ok; } return Value::Null; } Err(_try_err) => { let e: Value = panic_to_value(_try_err);
if is_true(&is_instance(&e, &Value::Str("AuthenticationError".to_string()))) {
let mut messageHash: Value = Value::Str("authenticated".to_string());
client.reject(&[e.clone(), messageHash.clone()]);
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash);
}
} else {
// Note: if error happens on a subscribe event, user will have to close exchange to resubscribe. Issue #19041
client.reject(&[e.clone()]);
}
return Value::Bool(true);
} }
Value::Null
}
pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
//
// {
// "action": "snapshot",
// "arg": { instType: 'SPOT', channel: "ticker", instId: "BTCUSDT" },
// "data": [
// {
// "instId": "BTCUSDT",
// "last": "21150.53",
// "open24h": "20759.65",
// "high24h": "21202.29",
// "low24h": "20518.82",
// "bestBid": "21150.500000",
// "bestAsk": "21150.600000",
// "baseVolume": "25402.1961",
// "quoteVolume": "530452554.2156",
// "ts": 1656408934044,
// "labeId": 0
// }
// ]
// }
// pong message
// "pong"
//
// login
//
// { event: "login", code: 0 }
//
// subscribe
//
// {
// "event": "subscribe",
// "arg": { instType: 'SPOT', channel: "account", instId: "default" }
// }
// unsubscribe
// {
// "op":"unsubscribe",
// "args":[
// {
// "instType":"USDT-FUTURES",
// "channel":"ticker",
// "instId":"BTCUSDT"
// }
// ]
// }
//
// uta
//
// {
// "action": "snapshot",
// "arg": { "instType": "spot", topic: "ticker", symbol: "BTCUSDT" },
// "data": [
// {
// "highPrice24h": "120255.61",
// "lowPrice24h": "116145.88",
// "openPrice24h": "118919.38",
// "lastPrice": "119818.83",
// "turnover24h": "215859996.272276",
// "volume24h": "1819.756798",
// "bid1Price": "119811.26",
// "ask1Price": "119831.18",
// "bid1Size": "0.008732",
// "ask1Size": "0.004297",
// "price24hPcnt": "0.02002"
// }
// ],
// "ts": 1753230479687
// }
//
// unsubscribe
//
// {
// "event": "unsubscribe",
// "arg": {
// "instType": "spot",
// "topic": "kline",
// "symbol": "BTCUSDT",
// "interval": "1m"
// }
// }
//
if is_equal(&self.handle_error_message(client.clone(), message.clone()), &Value::Bool(true)) {
return;
}
let mut content: Value = self.safe_string_k(message.clone(), "message", &[]);
if is_equal(&content, &Value::Str("pong".to_string())) {
self.handle_pong(client.clone(), message.clone());
return;
}
if is_equal(&message, &Value::Str("pong".to_string())) {
self.handle_pong(client.clone(), message.clone());
return;
}
let mut event: Value = self.safe_string_k(message.clone(), "event", &[]);
if is_equal(&event, &Value::Str("login".to_string())) {
self.handle_authenticate(client.clone(), message.clone());
return;
}
if is_equal(&event, &Value::Str("subscribe".to_string())) {
self.handle_subscription_status(client.clone(), message.clone());
return;
}
if is_equal(&event, &Value::Str("unsubscribe".to_string())) {
self.handle_un_subscription_status(client.clone(), message.clone());
return;
}
let mut methods: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ticker".to_string(), Value::Str("handle_ticker".to_string()).clone());
m.insert("trade".to_string(), Value::Str("handle_trades".to_string()).clone());
m.insert("publicTrade".to_string(), Value::Str("handle_trades".to_string()).clone());
m.insert("fill".to_string(), Value::Str("handle_my_trades".to_string()).clone());
m.insert("order".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("orders".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("ordersAlgo".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("orders-algo".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("orders-crossed".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("orders-isolated".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("account".to_string(), Value::Str("handle_balance".to_string()).clone());
m.insert("position".to_string(), Value::Str("handle_positions".to_string()).clone());
m.insert("positions".to_string(), Value::Str("handle_positions".to_string()).clone());
m.insert("account-isolated".to_string(), Value::Str("handle_balance".to_string()).clone());
m.insert("account-crossed".to_string(), Value::Str("handle_balance".to_string()).clone());
m.insert("kline".to_string(), Value::Str("handle_ohlcv".to_string()).clone());
m
});
let mut arg: Value = self.safe_value_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut topic: Value = self.safe_value2(arg.clone(), Value::Str("channel".to_string()), Value::Str("topic".to_string()), &[Value::Str("".to_string())]);
let mut method: Value = self.safe_value(methods.clone(), topic.clone(), &[]);
if !is_equal(&method, &Value::Null) {
self.dispatch_ws_handler(&method, &[client.clone(), message.clone()]);
}
if is_greater_than_or_equal(&get_index_of(&topic, &Value::Str("candle".to_string())), &Value::Int(0)) {
self.handle_ohlcv(client.clone(), message.clone());
}
if is_greater_than_or_equal(&get_index_of(&topic, &Value::Str("books".to_string())), &Value::Int(0)) {
self.handle_order_book(client.clone(), message.clone());
}
}
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_subscription_status(&self, mut client: Value, mut message: Value) -> Value {
return message;
Value::Null
}
pub fn handle_order_book_un_subscription(&mut self, mut client: Value, mut message: Value) {
//
// {"event":"unsubscribe","arg":{"instType":"SPOT","channel":"books","instId":"BTCUSDT"}}
//
// UTA
//
// {"event":"unsubscribe","arg":{"instType":"spot","topic":"books","symbol":"BTCUSDT"}}
//
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut instId: Value = self.safe_string2(arg.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut market: Value = self.safe_market(&[instId.clone(), Value::Null, Value::Null, type_var.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut messageHash: Value = add(&Value::Str("unsubscribe:orderbook:".to_string()), &get_value(&market, &Value::Str("symbol".to_string())));
let mut subMessageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
if is_true(&Value::Bool(in_op(&self.orderbooks, &symbol))) {
remove(&mut self.orderbooks, &symbol);
}
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &subMessageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &subMessageHash);
}
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash);
}
let mut error = Value::from(crate::exchange_errors::unsubscribe_error(add(&add(&self.id, &Value::Str(" orderbook ".to_string())), &symbol)));
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &subMessageHash))) {
client.reject(&[Value::from(error.clone()), subMessageHash.clone()]);
}
client.resolve(&[Value::Bool(true), messageHash.clone()]);
}
pub fn handle_trades_un_subscription(&mut self, mut client: Value, mut message: Value) {
//
// {"event":"unsubscribe","arg":{"instType":"SPOT","channel":"trade","instId":"BTCUSDT"}}
//
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut instId: Value = self.safe_string2(arg.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut market: Value = self.safe_market(&[instId.clone(), Value::Null, Value::Null, type_var.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut messageHash: Value = add(&Value::Str("unsubscribe:trade:".to_string()), &get_value(&market, &Value::Str("symbol".to_string())));
let mut subMessageHash: Value = add(&Value::Str("trade:".to_string()), &symbol);
if is_true(&Value::Bool(in_op(&self.trades, &symbol))) {
remove(&mut self.trades, &symbol);
}
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &subMessageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &subMessageHash);
}
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash);
}
let mut error = Value::from(crate::exchange_errors::unsubscribe_error(add(&add(&self.id, &Value::Str(" trades ".to_string())), &symbol)));
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &subMessageHash))) {
client.reject(&[Value::from(error.clone()), subMessageHash.clone()]);
}
client.resolve(&[Value::Bool(true), messageHash.clone()]);
}
pub fn handle_ticker_un_subscription(&mut self, mut client: Value, mut message: Value) {
//
// {"event":"unsubscribe","arg":{"instType":"SPOT","channel":"trade","instId":"BTCUSDT"}}
//
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut instId: Value = self.safe_string2(arg.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut market: Value = self.safe_market(&[instId.clone(), Value::Null, Value::Null, type_var.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut messageHash: Value = add(&Value::Str("unsubscribe:ticker:".to_string()), &get_value(&market, &Value::Str("symbol".to_string())));
let mut subMessageHash: Value = add(&Value::Str("ticker:".to_string()), &symbol);
if is_true(&Value::Bool(in_op(&self.tickers, &symbol))) {
remove(&mut self.tickers, &symbol);
}
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &subMessageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &subMessageHash);
}
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".to_string())), &messageHash);
}
let mut error = Value::from(crate::exchange_errors::unsubscribe_error(add(&add(&self.id, &Value::Str(" ticker ".to_string())), &symbol)));
if is_true(&Value::Bool(in_op(&get_value(&client, &Value::Str("futures".to_string())), &subMessageHash))) {
client.reject(&[Value::from(error.clone()), subMessageHash.clone()]);
}
client.resolve(&[Value::Bool(true), messageHash.clone()]);
}
pub fn handle_ohlcv_un_subscription(&mut self, mut client: Value, mut message: Value) {
//
// {"event":"unsubscribe","arg":{"instType":"SPOT","channel":"candle1m","instId":"BTCUSDT"}}
//
// UTA
//
// {"event":"unsubscribe","arg":{"instType":"spot","topic":"kline","symbol":"BTCUSDT","interval":"1m"}}
//
let mut arg: Value = self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instType: Value = self.safe_string_lower(arg.clone(), Value::Str("instType".to_string()), &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&instType, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
let mut instId: Value = self.safe_string2(arg.clone(), Value::Str("instId".to_string()), Value::Str("symbol".to_string()), &[]);
let mut channel: Value = self.safe_string2(arg.clone(), Value::Str("channel".to_string()), Value::Str("topic".to_string()), &[Value::Str("".to_string())]);
let mut interval: Value = self.safe_string_k(arg.clone(), "interval", &[]);
let mut isUta: Value = Value::Null;
if is_equal(&interval, &Value::Null) {
isUta = Value::Bool(false);
interval = replace_str(&channel, &Value::Str("candle".to_string()), &Value::Str("".to_string()));
} else {
isUta = Value::Bool(true);
}
let mut timeframes: Value = self.safe_value_k(self.options.clone(), "timeframes", &[]);
let mut timeframe: Value = self.find_timeframe(interval.clone(), &[timeframes.clone()]);
let mut market: Value = self.safe_market(&[instId.clone(), Value::Null, Value::Null, type_var.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut messageHash: Value = Value::Null;
let mut subMessageHash: Value = Value::Null;
if is_true(&isUta) {
messageHash = add(&Value::Str("unsubscribe:kline:".to_string()), &symbol);
subMessageHash = add(&Value::Str("kline:".to_string()), &symbol);
} else {
messageHash = add(&add(&add(&Value::Str("unsubscribe:candles:".to_string()), &timeframe), &Value::Str(":".to_string())), &symbol);
subMessageHash = add(&add(&add(&Value::Str("candles:".to_string()), &timeframe), &Value::Str(":".to_string())), &symbol);
}
if is_true(&Value::Bool(in_op(&self.ohlcvs, &symbol))) {
if 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);
}
}
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
}
pub fn handle_un_subscription_status(&mut self, mut client: Value, mut message: Value) -> Value {
//
// {
// "op":"unsubscribe",
// "args":[
// {
// "instType":"USDT-FUTURES",
// "channel":"ticker",
// "instId":"BTCUSDT"
// },
// {
// "instType":"USDT-FUTURES",
// "channel":"candle1m",
// "instId":"BTCUSDT"
// }
// ]
// }
// or
// {"event":"unsubscribe","arg":{"instType":"SPOT","channel":"books","instId":"BTCUSDT"}}
//
let mut argsList: Value = self.safe_list_k(message.clone(), "args", &[]);
if is_equal(&argsList, &Value::Null) {
argsList = Value::List(vec![self.safe_dict_k(message.clone(), "arg", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})])]);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_125: bool = true;
while { if !__for_first_125 { i = add(&i, &Value::Int(1)); } __for_first_125 = false; is_less_than(&i, &get_array_length(&argsList)) } {
let mut arg: Value = get_value(&argsList, &i);
let mut arg: Value = get_value(&argsList, &i);
let mut channel: Value = self.safe_string2(arg.clone(), Value::Str("channel".to_string()), Value::Str("topic".to_string()), &[Value::Str("".to_string())]);
if is_greater_than_or_equal(&get_index_of(&channel, &Value::Str("books".to_string())), &Value::Int(0)) {
// for now only unWatchOrderBook is supported
self.handle_order_book_un_subscription(client.clone(), message.clone());
} else if is_true(&(is_greater_than_or_equal(&get_index_of(&channel, &Value::Str("trade".to_string())), &Value::Int(0)))) || is_true(&(is_greater_than_or_equal(&get_index_of(&channel, &Value::Str("publicTrade".to_string())), &Value::Int(0)))) {
self.handle_trades_un_subscription(client.clone(), message.clone());
} else if is_greater_than_or_equal(&get_index_of(&channel, &Value::Str("ticker".to_string())), &Value::Int(0)) {
self.handle_ticker_un_subscription(client.clone(), message.clone());
} else if is_greater_than_or_equal(&get_index_of(&channel, &Value::Str("candle".to_string())), &Value::Int(0)) {
self.handle_ohlcv_un_subscription(client.clone(), message.clone());
} else if is_greater_than_or_equal(&get_index_of(&channel, &Value::Str("kline".to_string())), &Value::Int(0)) {
self.handle_ohlcv_un_subscription(client.clone(), message.clone());
}
}
}
return message;
Value::Null
}
}