// 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;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct ToobitCore {
pub exchange: crate::exchange::Exchange,
}
impl ToobitCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { exchange: crate::exchange::Exchange::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = ToobitCore::describe(self);
self.initialize_properties(described);
// compatibility for sandbox/testnet options in userConfig
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
/// 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 ToobitCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_position(self, position, &[market])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_funding_rate(self, rate, &[market])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_deposit_address(self, depositAddress, &[currency])
}
fn parse_last_price(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_last_price(self, entry, &[market])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_transfer(self, transfer, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_currency(self, currency)
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_funding_rate_history(self, entry, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_transaction(self, transaction, &[currency])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::parse_leverage(self, leverage, &[market])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on ToobitCore.
ToobitCore::sign(self, 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 {
// Forward to the inherent method on ToobitCore.
ToobitCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for ToobitCore {
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 {
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_contract_order_request" => self.create_contract_order_request(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[4.min(args.len())..]),
"create_order" => self.create_order(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[4.min(args.len())..]).await,
"create_order_request" => self.create_order_request(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[4.min(args.len())..]),
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_deposits_or_withdrawals_helper" => self.fetch_deposits_or_withdrawals_helper(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[4.min(args.len())..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args[..]).await,
"fetch_last_prices" => self.fetch_last_prices(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_status" => self.fetch_status(&args[..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_bid_ask_custom" => self.parse_bid_ask_custom(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_bids_asks_custom" => self.parse_bids_asks_custom(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_last_price" => self.parse_last_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction_with_type" => self.parse_transaction_with_type(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"transfer" => self.transfer(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[4.min(args.len())..]).await,
"withdraw" => self.withdraw(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[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for ToobitCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for ToobitCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl ToobitCore {
pub fn describe(&self) -> Value {
return self.deep_extend(self.super_describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("toobit".into()));
m.insert("name".to_string(), Value::Str("Toobit".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("KY".into())]));
m.insert("version".to_string(), Value::Str("v1".into()));
m.insert("rateLimit".to_string(), Value::Int(20));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLastPrices".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/58e1b718-c6fd-49e2-8a49-797da6b9c008".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("common".to_string(), Value::Str("https://api.toobit.com".into()));
m.insert("private".to_string(), Value::Str("https://api.toobit.com".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.toobit.com/".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://api-docs.toobit.com/".into())]));
m.insert("referral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Str("https://www.toobit.com/en-US/r?i=dvCpJj".into()));
m
}));
m.insert("fees".to_string(), Value::Str("https://www.toobit.com/fee".into()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("common".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/exchangeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/depth/merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/index/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/indexPriceComponents".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/markPrice/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/markPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("quote/v1/index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("quote/v1/contract/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("quote/v1/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/contract/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/contract/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/fundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/historyFundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/riskLimits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/checkApiKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/spot/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/spot/tradeOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/historyOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/account/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/account/balanceFlow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/depositOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/withdrawOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/subAccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/subAccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/subAccount/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/accountLeverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/historyPositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/balanceFlow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/todayPnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/download/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("api/v1/agent/inviteUserList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/commissionDataList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/commissionDataInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/inviteRelationCheck".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/depositDetailList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/querySubAgentData".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/spotOrdersList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/futuresOrdersList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/futuresPositionsList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/invite-commission-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/user/export".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/export-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/agent/export-url".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v2/account/balance-flow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v2/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v2/futures/open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v2/futures/history-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v2/futures/user-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v2/futures/algo-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v2/futures/open-algo-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v2/futures/history-algo-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v2/futures/voucher/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/spot/orderTest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/spot/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(2)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/subAccount/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(2)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/position/trading-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(3)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/positionMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/order/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(2)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/autoAddMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/flashClose".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/reversePosition".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/download/apply".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1000));
m
}));
m.insert("api/v1/userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(1)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/spot/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(3)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/spot/cancelOrderByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(5)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/futures/cancelOrderByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Int(3)), &(Value::Float(1.67))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("api/v1/userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".into()));
m.insert("3m".to_string(), Value::Str("3m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15m".to_string(), Value::Str("15m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("2h".to_string(), Value::Str("2h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("8h".to_string(), Value::Str("8h".into()));
m.insert("12h".to_string(), Value::Str("12h".into()));
m.insert("1d".to_string(), Value::Str("1d".into()));
m.insert("1w".to_string(), Value::Str("1w".into()));
m.insert("1M".to_string(), Value::Str("1M".into()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("exceptions".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("-1000".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1001".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1002".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1003".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("-1004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1005".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1006".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1007".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1014".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1015".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("-1016".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1020".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1021".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1022".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1023".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1031".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1100".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1101".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1102".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1103".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1104".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1105".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1106".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1107".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1111".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1112".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1114".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1115".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1116".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1117".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1118".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1119".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1120".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1121".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("-1125".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1127".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1128".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1129".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1130".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1131".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-1132".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1133".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1134".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1135".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1136".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1137".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1138".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1139".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1140".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1141".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1142".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1143".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("-1144".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1145".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1146".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1147".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1148".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1149".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1150".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1151".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1153".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1156".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1157".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1158".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1161".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1164".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1165".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1166".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1170".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1171".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-1172".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1181".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1182".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1193".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1194".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1195".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1196".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1197".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1198".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1199".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1200".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1201".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1202".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1203".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1204".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1205".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1206".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1207".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1208".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1209".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1210".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1211".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1212".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1213".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("-1214".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1215".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1216".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1217".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1300".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1400".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1401".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1402".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1403".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1404".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-1405".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-1406".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1407".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1408".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-1409".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1410".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-1411".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1412".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1413".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1414".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1415".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1416".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-1417".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2010".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-2011".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-2013".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("-2014".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-2015".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-2016".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2017".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-2018".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-3000".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-3001".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3002".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3050".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-3051".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3052".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-3101".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3102".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3103".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-3105".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3107".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3108".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3109".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3110".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-3116".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3117".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3120".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3124".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3125".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3126".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3127".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-3128".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3129".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-3130".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3131".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-3132".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3133".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3136".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3137".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3138".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3139".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3140".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3141".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3142".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3143".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3144".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3145".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3147".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-3148".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3149".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-3150".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-3151".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-3152".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-3153".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-32045".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-32090".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-32093".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-120041".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-120047".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-120055".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-120067".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-120072".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-120073".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-120078".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-120510".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-120511".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-120512".to_string(), Value::Str("BadRequest".into()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Unknown order sent".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("Duplicate order sent".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("Market is closed".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Account has insufficient balance for requested action".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("Market orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Iceberg orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Stop loss orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Stop loss limit orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Take profit orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Take profit limit orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("QTY is zero or less".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("IcebergQty exceeds QTY".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("This action disabled is on this account".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("Unsupported order combination".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("Order would trigger immediately".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Cancel order is invalid. Check origClOrdId and orderId".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("Order would immediately match and take".to_string(), Value::Str("OperationRejected".into()).clone());
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("spot".into()));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("MAIN".into()));
m.insert("swap".to_string(), Value::Str("FUTURES".into()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".into()));
m.insert("ERC20".to_string(), Value::Str("ETH".into()));
m.insert("BEP20".to_string(), Value::Str("BSC".into()));
m.insert("TRC20".to_string(), Value::Str("TRX".into()));
m.insert("SOL".to_string(), Value::Str("SOL".into()));
m.insert("MATIC".to_string(), Value::Str("MATIC".into()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBITRUM".into()));
m.insert("BASE".to_string(), Value::Str("BASE".into()));
m.insert("TON".to_string(), Value::Str("TON".into()));
m.insert("AVAXC".to_string(), Value::Str("AVAXC".into()));
m.insert("DOGE".to_string(), Value::Str("DOGE".into()));
m.insert("XRP".to_string(), Value::Str("XRP".into()));
m.insert("DOT".to_string(), Value::Str("DOT".into()));
m.insert("ADA".to_string(), Value::Str("ADA".into()));
m.insert("LTC".to_string(), Value::Str("LTC".into()));
m.insert("APT".to_string(), Value::Str("APT".into()));
m.insert("ATOM".to_string(), Value::Str("ATOM".into()));
m.insert("ALGO".to_string(), Value::Str("ALGO".into()));
m.insert("NEAR".to_string(), Value::Str("NEAR".into()));
m.insert("XLM".to_string(), Value::Str("XLM".into()));
m.insert("SUI".to_string(), Value::Str("SUI".into()));
m.insert("ETC".to_string(), Value::Str("ETC".into()));
m.insert("EOS".to_string(), Value::Str("EOS".into()));
m.insert("WAVES".to_string(), Value::Str("WAVES".into()));
m.insert("ICP".to_string(), Value::Str("ICP".into()));
m.insert("ONE".to_string(), Value::Str("ONE".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ETH".to_string(), Value::Str("ERC20".into()));
m.insert("ERC20".to_string(), Value::Str("ERC20".into()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(500));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Null);
m
}));
m.insert("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("createOrders".to_string(), Value::Null);
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name toobit#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://toobit-docs.github.io/apidocs/spot/v1/en/#test-connectivity
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&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 response: Value = self.common_get_api_v1_ping(&[params]).await;
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("ok".into()));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response);
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://api-docs.toobit.com/api/spot-market-data.html#check-server-time
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
pub async fn fetch_time(&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 response: Value = self.common_get_api_v1_time(&[params]).await;
return self.safe_integer_k(response, "serverTime", &[]);
Value::Null
}
/*
* @method
* @name toobit#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://api-docs.toobit.com/api/spot-market-data.html#exchange-information
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&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 response: Value = self.common_get_api_v1_exchange_info(&[params]).await;
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("exchangeInfo".into(), response.clone()); }; // we store it in options for later use in fetchMarkets
//
// {
// "timezone": "UTC",
// "serverTime": "1755583099926",
// "brokerFilters": [],
// "symbols": [
// {
// "filters": [
// {
// "minPrice": "0.01",
// "maxPrice": "10000000.00000000",
// "tickSize": "0.01",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.0001",
// "maxQty": "4000",
// "stepSize": "0.0001",
// "filterType": "LOT_SIZE"
// },
// {
// "minNotional": "5",
// "filterType": "MIN_NOTIONAL"
// },
// {
// "minAmount": "5",
// "maxAmount": "6600000",
// "minBuyPrice": "0.01",
// "filterType": "TRADE_AMOUNT"
// },
// {
// "maxSellPrice": "99999999",
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "LIMIT_TRADING"
// },
// {
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "MARKET_TRADING"
// },
// {
// "noAllowMarketStartTime": "0",
// "noAllowMarketEndTime": "0",
// "limitOrderStartTime": "0",
// "limitOrderEndTime": "0",
// "limitMinPrice": "0",
// "limitMaxPrice": "0",
// "filterType": "OPEN_QUOTE"
// }
// ],
// "exchangeId": "301",
// "symbol": "ETHUSDT",
// "symbolName": "ETHUSDT",
// "status": "TRADING",
// "baseAsset": "ETH",
// "baseAssetName": "ETH",
// "baseAssetPrecision": "0.0001",
// "quoteAsset": "USDT",
// "quoteAssetName": "USDT",
// "quotePrecision": "0.01",
// "icebergAllowed": false,
// "isAggregate": false,
// "allowMargin": true,
// }
// ],
// "options": [],
// "contracts": [
// {
// "filters": [ ... ],
// "exchangeId": "301",
// "symbol": "BTC-SWAP-USDT",
// "symbolName": "BTC-SWAP-USDTUSDT",
// "status": "TRADING",
// "baseAsset": "BTC-SWAP-USDT",
// "baseAssetPrecision": "0.001",
// "quoteAsset": "USDT",
// "quoteAssetPrecision": "0.1",
// "icebergAllowed": false,
// "inverse": false,
// "index": "BTC",
// "indexToken": "BTCUSDT",
// "marginToken": "USDT",
// "marginPrecision": "0.0001",
// "contractMultiplier": "0.001",
// "underlying": "BTC",
// "riskLimits": [
// {
// "riskLimitId": "200020911",
// "quantity": "42000.0",
// "initialMargin": "0.02",
// "maintMargin": "0.01",
// "isWhite": false
// },
// {
// "riskLimitId": "200020912",
// "quantity": "84000.0",
// "initialMargin": "0.04",
// "maintMargin": "0.02",
// "isWhite": false
// },
// ...
// ]
// },
// ],
// "coins": [
// {
// "orgId": "9001",
// "coinId": "TCOM",
// "coinName": "TCOM",
// "coinFullName": "TCOM",
// "allowWithdraw": true,
// "allowDeposit": true,
// "chainTypes": [
// {
// "chainType": "BSC",
// "withdrawFee": "49.55478",
// "minWithdrawQuantity": "77",
// "maxWithdrawQuantity": "0",
// "minDepositQuantity": "48",
// "allowDeposit": true,
// "allowWithdraw": false
// }
// ],
// "isVirtual": false
// },
// ...
//
let mut coins: Value = self.safe_list_k(response, "coins", &[Value::from(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1116: bool = true;
while { if !__for_first_1116 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_1116 = false; i.as_f64().unwrap_or(f64::NAN) < ((coins.len() as i64) as f64) } {
let mut coin: Value = coins.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut parsed: Value = self.parse_currency(coin);
if (parsed != Value::Null) {
let mut code: Value = parsed.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), parsed); }
}
}
}
return result;
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut id: Value = self.safe_string_k(rawCurrency.clone(), "coinId", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut rawNetworks: Value = self.safe_list_k(rawCurrency.clone(), "chainTypes", &[Value::from(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_1117: bool = true;
while { if !__for_first_1117 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_1117 = false; j.as_f64().unwrap_or(f64::NAN) < ((rawNetworks.len() as i64) as f64) } {
let mut rawNetwork: Value = rawNetworks.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.safe_string_k(rawNetwork.clone(), "chainType", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut networks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId);
m.insert("network".to_string(), networkCode.clone());
m.insert("margin".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(rawNetwork.clone(), "allowDeposit", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(rawNetwork.clone(), "allowWithdraw", &[]));
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), self.safe_number_k(rawNetwork.clone(), "withdrawFee", &[]));
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(rawNetwork.clone(), "minDepositQuantity", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(rawNetwork.clone(), "minWithdrawQuantity", &[]));
m.insert("max".to_string(), self.safe_number_k(rawNetwork.clone(), "maxWithdrawQuantity", &[]));
m
}));
m
}));
m.insert("info".to_string(), rawNetwork);
m
})); }
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("code".to_string(), code);
m.insert("name".to_string(), self.safe_string_k(rawCurrency.clone(), "coinFullName", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(rawCurrency.clone(), "allowDeposit", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(rawCurrency.clone(), "allowWithdraw", &[]));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), networks);
m.insert("info".to_string(), rawCurrency);
m
}));
Value::Null
}
/*
* @method
* @name toobit#fetchMarkets
* @description retrieves data on all markets for toobit
* @see https://api-docs.toobit.com/api/spot-market-data.html#exchange-information
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#exchange-information
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&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 cachedInfo: Value = self.safe_dict_k(self.options.clone(), "exchangeInfo", &[]);
let mut response: Value = cachedInfo.clone();
if (cachedInfo != Value::Null) {
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("exchangeInfo".into(), Value::Null); }; // reset it to avoid using old cached data
} else {
response = self.common_get_api_v1_exchange_info(&[params]).await;
}
//
// {
// "timezone": "UTC",
// "serverTime": "1755583099926",
// "brokerFilters": [],
// "symbols": [
// {
// "filters": [
// {
// "minPrice": "0.01",
// "maxPrice": "10000000.00000000",
// "tickSize": "0.01",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.0001",
// "maxQty": "4000",
// "stepSize": "0.0001",
// "filterType": "LOT_SIZE"
// },
// {
// "minNotional": "5",
// "filterType": "MIN_NOTIONAL"
// },
// {
// "minAmount": "5",
// "maxAmount": "6600000",
// "minBuyPrice": "0.01",
// "filterType": "TRADE_AMOUNT"
// },
// {
// "maxSellPrice": "99999999",
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "LIMIT_TRADING"
// },
// {
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "MARKET_TRADING"
// },
// {
// "noAllowMarketStartTime": "0",
// "noAllowMarketEndTime": "0",
// "limitOrderStartTime": "0",
// "limitOrderEndTime": "0",
// "limitMinPrice": "0",
// "limitMaxPrice": "0",
// "filterType": "OPEN_QUOTE"
// }
// ],
// "exchangeId": "301",
// "symbol": "ETHUSDT",
// "symbolName": "ETHUSDT",
// "status": "TRADING",
// "baseAsset": "ETH",
// "baseAssetName": "ETH",
// "baseAssetPrecision": "0.0001",
// "quoteAsset": "USDT",
// "quoteAssetName": "USDT",
// "quotePrecision": "0.01",
// "icebergAllowed": false,
// "isAggregate": false,
// "allowMargin": true,
// }
// ],
// "options": [],
// "contracts": [
// {
// "filters": [ ... ],
// "exchangeId": "301",
// "symbol": "BTC-SWAP-USDT",
// "symbolName": "BTC-SWAP-USDTUSDT",
// "status": "TRADING",
// "baseAsset": "BTC-SWAP-USDT",
// "baseAssetPrecision": "0.001",
// "quoteAsset": "USDT",
// "quoteAssetPrecision": "0.1",
// "icebergAllowed": false,
// "inverse": false,
// "index": "BTC",
// "indexToken": "BTCUSDT",
// "marginToken": "USDT",
// "marginPrecision": "0.0001",
// "contractMultiplier": "0.001",
// "underlying": "BTC",
// "riskLimits": [
// {
// "riskLimitId": "200020911",
// "quantity": "42000.0",
// "initialMargin": "0.02",
// "maintMargin": "0.01",
// "isWhite": false
// },
// {
// "riskLimitId": "200020912",
// "quantity": "84000.0",
// "initialMargin": "0.04",
// "maintMargin": "0.02",
// "isWhite": false
// },
// ...
// ]
// },
// ],
// "coins": [
// {
// "orgId": "9001",
// "coinId": "TCOM",
// "coinName": "TCOM",
// "coinFullName": "TCOM",
// "allowWithdraw": true,
// "allowDeposit": true,
// "chainTypes": [
// {
// "chainType": "BSC",
// "withdrawFee": "49.55478",
// "minWithdrawQuantity": "77",
// "maxWithdrawQuantity": "0",
// "minDepositQuantity": "48",
// "allowDeposit": true,
// "allowWithdraw": false
// }
// ],
// "isVirtual": false
// },
// ...
//
let mut symbols: Value = self.safe_list_k(response.clone(), "symbols", &[Value::from(vec![])]);
let mut contracts: Value = self.safe_list_k(response, "contracts", &[Value::from(vec![])]);
let mut all: Value = self.array_concat(symbols, contracts);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_1118: bool = true;
while { if !__for_first_1118 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_1118 = false; i.as_f64().unwrap_or(f64::NAN) < ((all.len() as i64) as f64) } {
let mut market: Value = all.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut parsed: Value = self.parse_market(market);
if (parsed != Value::Null) {
result.push(parsed);
}
}
}
return Value::from(result);
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseAsset", &[Value::Str("".into())]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteAsset", &[]);
let mut baseParts: Value = Value::Array(baseId.as_str().map(|__s| __s.split("-").map(|__p| Value::Str(__p.to_string().into())).collect()).unwrap_or_default());
let mut baseIdClean: Value = baseParts.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut base: Value = self.safe_currency_code(baseIdClean, &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut settleId: Value = self.safe_string_k(market.clone(), "marginToken", &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut status: Option<String> = self.safe_string_k(market.clone(), "status", &[]).as_str().map(str::to_owned);
let mut active: Value = (Value::Bool(status.as_deref() == Some("TRADING")));
let mut filters: Value = self.safe_list_k(market.clone(), "filters", &[Value::from(vec![])]);
let mut filtersByType: Value = self.index_by(filters, Value::Str("filterType".into()));
let mut priceFilter: Value = self.safe_dict_k(filtersByType.clone(), "PRICE_FILTER", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut lotSizeFilter: Value = self.safe_dict_k(filtersByType.clone(), "LOT_SIZE", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut minNotionalFilter: Value = self.safe_dict_k(filtersByType, "MIN_NOTIONAL", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut isContract: Value = (Value::Bool(matches!(&market, Value::Dict(__d) if __d.contains_key("contractMultiplier"))));
let mut inverse: Value = self.safe_bool2(market.clone(), Value::Str("isInverse".into()), Value::Str("inverse".into()), &[]);
if matches!(&isContract, Value::Bool(true)) {
symbol = Value::Str(format!("{}{}", symbol, Value::Str(format!("{}{}", Value::Str(":".into()), settle).into())).into());
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), settle);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), (if matches!(&isContract, Value::Bool(true)) { Value::Str("swap".into()) } else { Value::Str("spot".into()) }));
m.insert("spot".to_string(), Value::Bool(!(matches!(&isContract, Value::Bool(true)))));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), isContract.clone());
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active);
m.insert("contract".to_string(), isContract.clone());
m.insert("linear".to_string(), (if matches!(&isContract, Value::Bool(true)) { (Value::Bool(inverse.as_bool() != Some(true))) } else { Value::Null }));
m.insert("inverse".to_string(), (if matches!(&isContract, Value::Bool(true)) { inverse } else { Value::Null }));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractMultiplier", &[]));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(lotSizeFilter.clone(), "stepSize", &[]));
m.insert("price".to_string(), self.safe_number_k(priceFilter.clone(), "tickSize", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(lotSizeFilter.clone(), "minQty", &[]));
m.insert("max".to_string(), self.safe_number_k(lotSizeFilter, "maxQty", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(priceFilter.clone(), "minPrice", &[]));
m.insert("max".to_string(), self.safe_number_k(priceFilter, "maxPrice", &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(minNotionalFilter, "minNotional", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
/*
* @method
* @name toobit#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://api-docs.toobit.com/api/spot-market-data.html#order-book
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#order-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit); }
}
let __ws_arg_0 = self.extend(request, &[params]);
let mut response: Value = self.common_get_quote_v1_depth(&[__ws_arg_0]).await;
//
// {
// "t": "1755593995237",
// "b": [
// [
// "115186.47",
// "4.184864"
// ],
// [
// "115186.46",
// "0.002756"
// ],
// ...
// ],
// "a": [
// [
// "115186.48",
// "6.137369"
// ],
// [
// "115186.49",
// "0.002914"
// ],
// ...
// ]
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "t", &[]);
return self.parse_order_book(response, market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), &[timestamp, Value::Str("b".into()), Value::Str("a".into())]);
Value::Null
}
/*
* @method
* @name toobit#fetchTrades
* @description get a list of the most recent trades for a particular symbol
* @see https://api-docs.toobit.com/api/spot-market-data.html#recent-trades-list
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#recent-trades-list
* @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 number of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_1 = self.extend(request, &[params]);
let mut response: Value = self.common_get_quote_v1_trades(&[__ws_arg_1]).await;
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades
//
// {
// "t": "1755594277287",
// "p": "115276.99",
// "q": "0.001508",
// "ibm": true
// },
// // watchTrades have also an additional fields:
// "v": "4864732022868004630", // trade id
// "m": true, // is the buyer taker
//
// fetchMyTrades
//
// {
// "id": "2024934575206059008",
// "symbol": "ETHUSDT",
// "orderId": "2024934575097029888",
// "ticketId": "4864450547563401875",
// "price": "4641.21",
// "qty": "0.001",
// "time": "1756127012094",
// "isMaker": false,
// "commission": "0.00464121",
// "commissionAsset": "USDT",
// "makerRebate": "0",
// "symbolName": "ETHUSDT", // only in SPOT
// "isBuyer": false, // only in SPOT
// "feeAmount": "0.00464121", // only in SPOT
// "feeCoinId": "USDT", // only in SPOT
// "fee": { // only in SPOT
// "feeCoinId": "USDT",
// "feeCoinName": "USDT",
// "fee": "0.00464121"
// },
// "type": "LIMIT", // only in CONTRACT
// "side": "BUY_OPEN", // only in CONTRACT
// "realizedPnl": "0", // only in CONTRACT
// },
//
let mut timestamp: Value = self.safe_integer2(trade.clone(), Value::Str("t".into()), Value::Str("time".into()), &[]);
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("p".into()), Value::Str("price".into()), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("q".into()), Value::Str("qty".into()), &[]);
let mut isBuyer: Value = self.safe_bool_k(trade.clone(), "isBuyer", &[]);
let mut side: Value = Value::Null;
let mut isBuyerMaker: Value = self.safe_bool_k(trade.clone(), "ibm", &[]);
let mut isBuyerTaker: Value = self.safe_bool_k(trade.clone(), "m", &[]);
if (isBuyerMaker != Value::Null) {
side = (if (isBuyerMaker.as_bool() == Some(true)) { Value::Str("sell".into()) } else { Value::Str("buy".into()) });
} else if (isBuyerTaker != Value::Null) {
side = (if (isBuyerTaker.as_bool() == Some(true)) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
} else {
if (isBuyer.as_bool() == Some(true)) {
side = Value::Str("buy".into());
} else {
side = Value::Str("sell".into());
}
}
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "feeCoinId", &[]);
let mut feeAmount: Value = self.safe_string_k(trade.clone(), "feeAmount", &[]);
let mut fee: Value = Value::Null;
if (feeAmount != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(feeCurrencyId, &[]));
m.insert("cost".to_string(), feeAmount);
m
});
}
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "isMaker", &[]);
let mut takerOrMaker: Value = Value::Null;
if (isMaker != Value::Null) {
takerOrMaker = (if isMaker.as_bool() == Some(true) { Value::Str("maker".into()) } else { Value::Str("taker".into()) });
}
let mut marketResolved: Value = self.safe_market(&[Value::Null, market]);
let mut symbol: Value = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), symbol);
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("id".into()), Value::Str("v".into()), &[]));
m.insert("order".to_string(), self.safe_string_k(trade, "orderId", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("amount".to_string(), amountString);
m.insert("price".to_string(), priceString);
m.insert("cost".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("fee".to_string(), fee);
m
}), &[marketResolved]);
Value::Null
}
/*
* @method
* @name toobit#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://api-docs.toobit.com/api/spot-market-data.html#kline-candlestick-data
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#kline-candlestick-data
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#index-price-kline-candlestick-data
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#mark-price-kline-candlestick-data
* @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 {string} [params.price] "mark" or "index" for mark price and index price candles
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut paramsOmitted: Value = (if (until != Value::Null) { self.omit(params.clone(), Value::Str("until".into()), &[]) } else { params });
let mut endpointparamsPriceVariable = self.handle_option_string_and_params(paramsOmitted, Value::Str("fetchOHLCV".into()), Value::Str("price".into()), &[]);
let mut endpoint: Value = endpointparamsPriceVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPrice: Value = endpointparamsPriceVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut isPriceKlines: bool = (endpoint.as_str() == Some("index")) || (endpoint.as_str() == Some("mark"));
let mut startKey: Value = Value::Str("startTime".into());
let mut endKey: Value = Value::Str("endTime".into());
if isPriceKlines {
startKey = Value::Str("from".into());
endKey = Value::Str("to".into());
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&startKey), since.clone()); }
}
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&endKey), until); }
} else if isPriceKlines && (since != Value::Null) {
// mark and index klines walk backwards from `to` and ignore a lone `from`
let mut duration: Value = self.parse_timeframe(timeframe.clone());
if (limit == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("to".into(), self.sum(&[since.clone(), (match (&((match (&(duration), &(Value::Int(2000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })])); }; // exchange default limit
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("to".into(), self.sum(&[since.clone(), (match (&((match (&(duration), &(limit)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })])); }
}
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut response: Value = Value::from(vec![]);
if (endpoint.as_str() == Some("index")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("indexToken".into()), &[])); }; // index klines take the index id instead of the market id
let __ws_arg_2 = self.extend(request.clone(), &[paramsPrice.clone()]);
response = self.common_get_quote_v1_index_klines(&[__ws_arg_2]).await;
} else if (endpoint.as_str() == Some("mark")) {
let __ws_arg_3 = self.extend(request.clone(), &[paramsPrice.clone()]);
response = self.common_get_quote_v1_mark_price_klines(&[__ws_arg_3]).await;
} else {
let __ws_arg_4 = self.extend(request, &[paramsPrice]);
response = self.common_get_quote_v1_klines(&[__ws_arg_4]).await;
}
let mut candles: Value = Value::from(vec![]);
if (matches!(&response, Value::Arr(_))) {
candles = response.clone();
} else {
candles = self.safe_list_k(response, "data", &[Value::from(vec![])]);
}
return self.parse_ohlc_vs(candles, &[market, timeframe, since, limit]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_integer_n(ohlcv.clone(), Value::from(vec![Value::Int(0), Value::Str("time".into()), Value::Str("t".into())]), &[]), self.safe_number_n(ohlcv.clone(), Value::from(vec![Value::Int(1), Value::Str("open".into()), Value::Str("o".into())]), &[]), self.safe_number_n(ohlcv.clone(), Value::from(vec![Value::Int(2), Value::Str("high".into()), Value::Str("h".into())]), &[]), self.safe_number_n(ohlcv.clone(), Value::from(vec![Value::Int(3), Value::Str("low".into()), Value::Str("l".into())]), &[]), self.safe_number_n(ohlcv.clone(), Value::from(vec![Value::Int(4), Value::Str("close".into()), Value::Str("c".into())]), &[]), self.safe_number_n(ohlcv, Value::from(vec![Value::Int(5), Value::Str("volume".into()), Value::Str("v".into())]), &[])]);
Value::Null
}
/*
* @method
* @name toobit#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://api-docs.toobit.com/api/spot-market-data.html#_24hr-ticker-price-change-statistics
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#_24hr-ticker-price-change-statistics
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbolsNormalized != Value::Null) {
let mut symbol: Value = self.safe_string(symbolsNormalized.clone(), Value::Int(0), &[]);
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut length: f64 = ((symbolsNormalized.len() as i64) as f64);
if (length == 1.0) && (market != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
}
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchTickers".into()), &[market, params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("spot")) {
let __ws_arg_5 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.common_get_quote_v1_ticker24hr(&[__ws_arg_5]).await;
} else {
let __ws_arg_6 = self.extend(request, &[paramsMarketType.clone()]);
response = self.common_get_quote_v1_contract_ticker24hr(&[__ws_arg_6]).await;
}
//
// [
// {
// "t": "1755601440162",
// "s": "GRDRUSDT",
// "o": "0.38",
// "h": "0.38",
// "l": "0.38",
// "c": "0.38",
// "v": "0",
// "qv": "0",
// "pc": "0",
// "pcp": "0"
// },
// ...
//
let mut rows: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_1119: bool = true;
while { if !__for_first_1119 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_1119 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut ticker: Value = response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "s", &[]);
if (marketId != Value::Null) && (self.markets_by_id.clone() != Value::Null) && (matches!((&self.markets_by_id, &marketId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
rows.push(ticker);
}
}
}
return self.parse_tickers(Value::from(rows), &[symbolsNormalized, paramsMarketType]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "s", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
let mut last: Value = self.safe_string_k(ticker.clone(), "c", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "v", &[]);
let mut contractSize: Value = self.safe_number_k(marketResolved.clone(), "contractSize", &[]);
if (marketResolved.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) && (contractSize != Value::Null) {
// 'v' counts contracts, and a ticker reports base volume
baseVolume = crate::precise::Precise::stringMul(&baseVolume, &self.number_to_string(contractSize));
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "h", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "l", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "b", &[]));
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "a", &[]));
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "o", &[]));
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "pc", &[]));
m.insert("percentage".to_string(), crate::precise::Precise::stringMul(&self.safe_string_k(ticker.clone(), "pcp", &[]), &Value::Str("100".into())));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume);
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "qv", &[]));
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
/*
* @method
* @name toobit#fetchLastPrices
* @description fetches the last price for multiple markets
* @see https://api-docs.toobit.com/api/spot-market-data.html#symbol-price-ticker
* @see https://toobit-docs.github.io/apidocs/usdt_swap/v1/en/#symbol-price-ticker
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the last prices
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of lastprices structures
*/
pub async fn fetch_last_prices(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbolsNormalized != Value::Null) {
let mut length: f64 = ((symbolsNormalized.len() as i64) as f64);
if (length == 1.0) {
let mut market: Value = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
}
let __ws_arg_7 = self.extend(request, &[params]);
let mut response: Value = self.common_get_quote_v1_ticker_price(&[__ws_arg_7]).await;
return self.parse_last_prices(response, &[symbolsNormalized]);
Value::Null
}
pub fn parse_last_price(&self, mut entry: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(entry.clone(), "s", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("price".to_string(), self.safe_number_omit_zero(entry.clone(), Value::Str("p".into()), &[]));
m.insert("side".to_string(), Value::Null);
m.insert("info".to_string(), entry);
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchBidsAsks
* @description fetches the bid and ask price and volume for multiple markets
* @see https://api-docs.toobit.com/api/spot-market-data.html#symbol-order-book-ticker
* @see https://toobit-docs.github.io/apidocs/usdt_swap/v1/en/#symbol-order-book-ticker
* @param {string[]} [symbols] unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbolsNormalized != Value::Null) {
let mut length: f64 = ((symbolsNormalized.len() as i64) as f64);
if (length == 1.0) {
let mut market: Value = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
}
let __ws_arg_8 = self.extend(request, &[params]);
let mut response: Value = self.common_get_quote_v1_ticker_book_ticker(&[__ws_arg_8]).await;
return self.parse_bids_asks_custom(response, &[symbolsNormalized]);
Value::Null
}
pub fn parse_bids_asks_custom(&self, mut tickers: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut results: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_1120: bool = true;
while { if !__for_first_1120 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_1120 = false; i.as_f64().unwrap_or(f64::NAN) < ((tickers.len() as i64) as f64) } {
let mut parsedTicker: Value = self.parse_bid_ask_custom(tickers.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
let mut ticker: Value = self.extend(parsedTicker, &[params.clone()]);
results.push(ticker);
}
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
return self.filter_by_array_tickers(Value::from(results), Value::Str("symbol".into()), &[symbolsNormalized]);
Value::Null
}
pub fn parse_bid_ask_custom(&self, mut ticker: Value) -> Value {
// 's' is the exchange id and 't' a millisecond integer, the pair parseTicker
// reads through safeMarket and safeInteger. The caller filters on a unified symbol.
let mut marketId: Value = self.safe_string_k(ticker.clone(), "s", &[]);
let mut market: Value = self.safe_market(&[marketId]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("bid".to_string(), self.safe_number_k(ticker.clone(), "b", &[]));
m.insert("bidVolume".to_string(), self.safe_number_k(ticker.clone(), "bq", &[]));
m.insert("ask".to_string(), self.safe_number_k(ticker.clone(), "a", &[]));
m.insert("askVolume".to_string(), self.safe_number_k(ticker.clone(), "aq", &[]));
m.insert("info".to_string(), ticker);
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchFundingRates
* @description fetch the funding rate for multiple markets
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#funding-rate
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rates structures]{@link https://docs.ccxt.com/?id=funding-rates-structure}, indexed by market symbols
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbolsNormalized != Value::Null) {
let mut length: f64 = ((symbolsNormalized.len() as i64) as f64);
if (length == 1.0) {
let mut market: Value = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
}
let __ws_arg_9 = self.extend(request, &[params]);
let mut response: Value = self.common_get_api_v1_futures_funding_rate(&[__ws_arg_9]).await;
return self.parse_funding_rates(response, &[symbolsNormalized]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId, &[market]);
let mut nextFundingRate: Value = self.safe_number_k(contract.clone(), "rate", &[]);
let mut nextFundingRateTimestamp: Value = self.safe_integer_k(contract.clone(), "nextFundingTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract);
m.insert("symbol".to_string(), symbol);
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("nextFundingDatetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), nextFundingRate);
m.insert("fundingTimestamp".to_string(), nextFundingRateTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(nextFundingRateTimestamp));
m.insert("interval".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://api-docs.toobit.com/api/usdt-m-market-data.html#get-funding-rate-history
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest funding rate to fetch
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone()]).await;
}
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_10 = self.extend(request, &[paramsPaginate]);
let mut response: Value = self.common_get_api_v1_futures_history_funding_rate(&[__ws_arg_10]).await;
return self.parse_funding_rate_histories(response, &[market, since, limit]);
Value::Null
}
pub fn parse_funding_rate_history(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "settleTime", &[]);
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("fundingRate".to_string(), self.safe_number_k(contract, "settleRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#account-information-user-data
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#futures-account-balance-user-data
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
let mut marketType: Value = self.handle_market_type_and_params(Value::Str("fetchBalance".into()), &[Value::Null, params]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
if self.in_array(marketType, Value::from(vec![Value::Str("swap".into()), Value::Str("future".into())])).as_bool() == Some(true) {
response = self.private_get_api_v1_futures_balance(&[]).await;
} else {
response = self.private_get_api_v1_account(&[]).await;
}
return self.parse_balance(response);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
let mut balances: Value = self.safe_list_k(response.clone(), "balances", &[response.clone()]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1121: bool = true;
while { if !__for_first_1121 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_1121 = false; i.as_f64().unwrap_or(f64::NAN) < ((balances.len() as i64) as f64) } {
let mut balance: Value = self.safe_dict(balances.clone(), i.clone(), &[]);
let mut code: Value = self.safe_currency_code(self.safe_string_k(balance.clone(), "asset", &[]), &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string2(balance.clone(), Value::Str("free".into()), Value::Str("availableBalance".into()), &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string2(balance.clone(), Value::Str("total".into()), Value::Str("balance".into()), &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(balance, "locked", &[])); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name toobit#createOrder
* @description create a trade order
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#new-order-trade
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#new-order-trade
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market', 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let mut requestparamsRequestVariable = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut request: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsRequest: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_11 = self.extend(request.clone(), &[paramsRequest.clone()]);
response = self.private_post_api_v1_spot_order(&[__ws_arg_11]).await;
} else {
let mut requestparamsRequestVariable = self.create_contract_order_request(symbol, type_var, side, amount, &[price, params]);
let mut request: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsRequest: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_12 = self.extend(request, &[paramsRequest]);
response = self.private_post_api_v1_futures_order(&[__ws_arg_12]).await;
}
return self.parse_order(response, &[market]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
let mut market: Value = self.market(symbol.clone());
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a side argument".into()))));
}
let mut id: Value = market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), id.clone());
m.insert("side".to_string(), side.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null));
m
});
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
}
let mut costparamsCostVariable = self.handle_param_string(params, Value::Str("cost".into()), &[]);
let mut cost: Value = costparamsCostVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsCost: Value = costparamsCostVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (type_var.as_str() == Some("market")) && (side.as_str() == Some("buy")) {
if (cost == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires params[\"cost\"] for market buy order".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.cost_to_precision(symbol.clone(), cost)); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.amount_to_precision(symbol, amount)); }
}
let mut isPostOnlyparamsPostOnlyVariable = self.handle_post_only(Value::Bool(type_var.as_str() == Some("market")), Value::Bool(false), &[paramsCost]);
let mut isPostOnly: Value = isPostOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = isPostOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if isPostOnly.as_bool() == Some(true) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("LIMIT_MAKER".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), type_var.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null)); }
}
return Value::from(vec![request, paramsPostOnly]);
Value::Null
}
pub fn create_contract_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount));
m
});
let mut reduceOnlyparamsReduceOnlyVariable = self.handle_param_bool(params, Value::Str("reduceOnly".into()), &[]);
let mut reduceOnly: Value = reduceOnlyparamsReduceOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsReduceOnly: Value = reduceOnlyparamsReduceOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (side.as_str() == Some("buy")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("side".into(), (if (reduceOnly.as_bool() == Some(true)) { Value::Str("BUY_CLOSE".into()) } else { Value::Str("BUY_OPEN".into()) })); }
} else if (side.as_str() == Some("sell")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("side".into(), (if (reduceOnly.as_bool() == Some(true)) { Value::Str("SELL_CLOSE".into()) } else { Value::Str("SELL_OPEN".into()) })); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("side".into(), side); }
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price.clone())); }
}
if self.in_array(type_var.clone(), Value::from(vec![Value::Str("limit".into()), Value::Str("LIMIT".into())])).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), type_var.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
} else if (type_var.as_str() == Some("market")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("LIMIT".into())); }; // weird, but exchange works this way
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("priceType".into(), Value::Str("MARKET".into())); }
}
let mut isPostOnlyparamsPostOnlyVariable = self.handle_post_only(Value::Bool(type_var.as_str() == Some("market")), Value::Bool(false), &[paramsReduceOnly]);
let mut isPostOnly: Value = isPostOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = isPostOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if isPostOnly.as_bool() == Some(true) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("timeInForce".into(), Value::Str("LIMIT_MAKER".into())); }
}
let mut values: Value = self.handle_trigger_prices_and_params(symbol.clone(), paramsPostOnly, &[]);
let mut triggerPrice: Value = values.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTrigger: Value = values.as_array().and_then(|__arr| __arr.get(3)).cloned().unwrap_or(Value::Null);
if (triggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stopPrice".into(), triggerPrice); }
}
let mut stopLoss: Value = self.safe_dict_k(paramsTrigger.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_dict_k(paramsTrigger.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = stopLoss != Value::Null;
let mut hasTakeProfit: bool = takeProfit != Value::Null;
let mut triggerPriceTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Str("MARK_PRICE".into()));
m.insert("last".to_string(), Value::Str("CONTRACT_PRICE".into()));
m
});
if hasStopLoss {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stopLoss".into(), self.safe_value_k(stopLoss.clone(), "triggerPrice", &[])); }
let mut limitPrice: Value = self.safe_string_k(stopLoss.clone(), "price", &[]);
if (limitPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("slOrderType".into(), Value::Str("LIMIT".into())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("slLimitPrice".into(), self.price_to_precision(symbol.clone(), limitPrice.clone())); }
}
let mut triggerPriceType: Value = self.safe_string_k(stopLoss, "triggerPriceType", &[]);
if (triggerPriceType != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("slTriggerBy".into(), self.safe_string(triggerPriceTypes.clone(), triggerPriceType.clone(), &[triggerPriceType.clone()])); }
}
}
if hasTakeProfit {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("takeProfit".into(), self.safe_value_k(takeProfit.clone(), "triggerPrice", &[])); }
let mut limitPrice: Value = self.safe_string_k(takeProfit.clone(), "price", &[]);
if (limitPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("tpOrderType".into(), Value::Str("LIMIT".into())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("tpLimitPrice".into(), self.price_to_precision(symbol, limitPrice)); }
}
let mut triggerPriceType: Value = self.safe_string_k(takeProfit, "triggerPriceType", &[]);
if (triggerPriceType != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("tpTriggerBy".into(), self.safe_string(triggerPriceTypes, triggerPriceType.clone(), &[triggerPriceType.clone()])); }
}
}
let mut paramsOmitted: Value = self.omit(paramsTrigger, Value::from(vec![Value::Str("stopLoss".into()), Value::Str("takeProfit".into())]), &[]);
if !(in_op(¶msOmitted, &Value::Str("newClientOrderId".into()))) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("newClientOrderId".into(), self.uuid(&[])); }
}
return Value::from(vec![request, paramsOmitted]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder, cancelOrder
//
// {
// "symbol": "ETHUSDT",
// "price": "0",
// "origQty": "0.001",
// "orderId": "2024837825254460160",
// "clientOrderId": "1756115478113679",
// "executedQty": "0",
// "status": "PENDING_NEW",
// "timeInForce": "GTC",
// "type": "MARKET",
// "side": "SELL"
// "accountId": "1783404067076253952", // only in spot
// "symbolName": "ETHUSDT", // only in spot
// "transactTime": "1756115478604", // only in spot
// "time": "1668418485058", // only in contract
// "updateTime": "1668418485058", // only in contract
// "leverage": "2", // only in contract
// "avgPrice": "0", // only in contract
// "marginLocked": "9.5", // only in contract
// "priceType": "INPUT" // only in contract
// }
//
//
// fetchOrder, fetchOrders, fetchOpenOrders
//
// {
// "time": "1756140208069",
// "updateTime": "1756140208078",
// "orderId": "2025045271033977089",
// "clientOrderId": "17561402075722006",
// "symbol": "ETHUSDT",
// "price": "3000",
// "origQty": "0.002",
// "executedQty": "0",
// "avgPrice": "0",
// "type": "LIMIT",
// "side": "BUY",
// "timeInForce": "GTC",
// "status": "NEW",
// "accountId": "1783404067076253952", // only in SPOT
// "exchangeId": "301", // only in SPOT
// "symbolName": "ETHUSDT", // only in SPOT
// "cummulativeQuoteQty": "0", // only in SPOT
// "cumulativeQuoteQty": "0", // only in SPOT
// "stopPrice": "0.0", // only in SPOT
// "icebergQty": "0.0", // only in SPOT
// "isWorking": true // only in SPOT
// "leverage": "2", // only in CONTRACT
// "marginLocked": "9.5", // only in CONTRACT
// "priceType": "INPUT" // only in CONTRACT
// "triggerType": "0", // only in CONTRACT fetchClosedOrders
// "fallType": "0", // only in CONTRACT fetchClosedOrders
// "activeStatus": "0" // only in CONTRACT fetchClosedOrders
// }
//
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("transactTime".into()), Value::Str("time".into()), &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut rawType: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut rawSideLower: Value = self.safe_string_lower_k(order.clone(), "side", &[]);
let mut reduceOnly: Value = Value::Null;
if (rawSideLower != Value::Null) {
// contract orders arrive as BUY_OPEN, SELL_CLOSE and the like -
// the suffix is the only signal that carries reduceOnly, so read
// it before discarding it (spot sides have no suffix: undefined)
let mut sideParts: Value = Value::Array(rawSideLower.as_str().map(|__s| __s.split("_").map(|__p| Value::Str(__p.to_string().into())).collect()).unwrap_or_default());
let mut sideSuffix: Option<String> = self.safe_string(sideParts.clone(), Value::Int(1), &[]).as_str().map(str::to_owned);
if (sideSuffix.is_some()) {
reduceOnly = (Value::Bool(sideSuffix.as_deref() == Some("close")));
}
rawSideLower = self.safe_string(sideParts, Value::Int(0), &[]);
}
// omitZero already maps '0.0' to undefined
let mut triggerPrice: Value = self.omit_zero(self.safe_string_k(order.clone(), "stopPrice", &[]));
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string_k(order.clone(), "orderId", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "clientOrderId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(order.clone(), "updateTime", &[]));
m.insert("status".to_string(), self.parse_order_status(self.safe_string_k(order.clone(), "status", &[])).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), self.parse_order_type(rawType.clone()).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("timeInForce".to_string(), self.safe_string_k(order.clone(), "timeInForce", &[]));
m.insert("postOnly".to_string(), (Value::Bool(rawType.as_str() == Some("LIMIT_MAKER"))));
m.insert("side".to_string(), rawSideLower);
m.insert("price".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "price", &[])));
m.insert("triggerPrice".to_string(), triggerPrice);
m.insert("cost".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "cumulativeQuoteQty", &[])));
m.insert("average".to_string(), self.safe_string_k(order.clone(), "avgPrice", &[]));
m.insert("amount".to_string(), self.safe_string_k(order.clone(), "origQty", &[]));
m.insert("filled".to_string(), self.safe_string_k(order, "executedQty", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), reduceOnly);
m.insert("leverage".to_string(), Value::Null);
m.insert("hedged".to_string(), Value::Null);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("PENDING_NEW".to_string(), Value::Str("open".into()));
m.insert("NEW".to_string(), Value::Str("open".into()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".into()));
m.insert("FILLED".to_string(), Value::Str("closed".into()));
m.insert("PENDING_CANCEL".to_string(), Value::Str("canceled".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("REJECTED".to_string(), Value::Str("canceled".into()));
m
});
if (status == Value::Null) {
return None;
}
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_order_type(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".into()));
m.insert("LIMIT".to_string(), Value::Str("limit".into()));
m.insert("LIMIT_MAKER".to_string(), Value::Str("limit".into()));
m
});
if (status == Value::Null) {
return None;
}
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name toobit#cancelOrder
* @description cancels an open order
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#cancel-order-trade
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#cancel-order-trade
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (self.safe_string_k(params.clone(), "clientOrderId", &[]) == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderId".into(), id.clone()); }
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("cancelOrder".into()), &[market.clone(), params, Value::Str("none".into())]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (marketType.as_str() == Some("none")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() requires a symbol argument or the \"defaultType\" parameter to be set to \"spot\" or \"swap\"".into()))));
}
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (marketType.as_str() == Some("spot")) {
let __ws_arg_13 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_delete_api_v1_spot_order(&[__ws_arg_13]).await;
} else {
let __ws_arg_14 = self.extend(request, &[paramsMarketType]);
response = self.private_delete_api_v1_futures_order(&[__ws_arg_14]).await;
}
// response same as in `createOrder`
let mut status: Option<String> = self.parse_order_status(self.safe_string_k(response.clone(), "status", &[]));
if (status.as_deref() != Some("open")) {
panic!("{}", crate::exchange_errors::order_not_found(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" order ".into())).into()), id).into()), Value::Str(" can not be canceled, ".into())).into()), json_stringify(&response))));
}
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name toobit#cancelAllOrders
* @description cancel all open orders in a market
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#cancel-all-open-orders-trade
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#cancel-orders-trade
* @param {string} symbol unified symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("cancelAllOrders".into()), &[market, params, Value::Str("none".into())]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (marketType.as_str() == Some("none")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() requires a symbol argument or the \"defaultType\" parameter to be set to \"spot\" or \"swap\"".into()))));
}
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
let __ws_arg_15 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_delete_api_v1_spot_open_orders(&[__ws_arg_15]).await;
} else {
let __ws_arg_16 = self.extend(request, &[paramsMarketType]);
response = self.private_delete_api_v1_futures_batch_orders(&[__ws_arg_16]).await;
}
return Value::from(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
}), &[])]);
Value::Null
}
/*
* @method
* @name toobit#cancelOrders
* @description cancel multiple orders
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#cancel-multiple-orders-trade
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#cancel-multiple-orders-trade
* @param {string[]} ids order ids
* @param {string} [symbol] unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut idsString: Value = Value::Str(ids.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",")).unwrap_or_default().into());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ids".to_string(), idsString);
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("cancelOrders".into()), &[market.clone(), params, Value::Str("none".into())]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (marketType.as_str() == Some("none")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrders() requires a symbol argument or the \"defaultType\" parameter to be set to \"spot\" or \"swap\"".into()))));
}
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
let __ws_arg_17 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_delete_api_v1_spot_cancel_order_by_ids(&[__ws_arg_17]).await;
} else {
let __ws_arg_18 = self.extend(request, &[paramsMarketType]);
response = self.private_delete_api_v1_futures_cancel_order_by_ids(&[__ws_arg_18]).await;
}
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_orders(result, &[market]);
Value::Null
}
/*
* @method
* @name toobit#fetchOrder
* @description fetches information on an order made by the user
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#query-order-user-data
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#query-order-user-data
* @param {string} id the order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id);
m
});
let mut market: Value = self.market(symbol);
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_spot_order(&[__ws_arg_19]).await;
} else {
let __ws_arg_20 = self.extend(request, &[params]);
response = self.private_get_api_v1_futures_order(&[__ws_arg_20]).await;
}
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name toobit#fetchOpenOrders
* @description fetches information on multiple orders made by the user
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#current-open-orders-user-data
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#query-current-open-order-user-data
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".into()), &[market.clone(), params]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::from(vec![]);
if (marketType.as_str() == Some("spot")) {
let __ws_arg_21 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_get_api_v1_spot_open_orders(&[__ws_arg_21]).await;
} else {
let __ws_arg_22 = self.extend(request, &[paramsMarketType]);
response = self.private_get_api_v1_futures_open_orders(&[__ws_arg_22]).await;
}
return self.parse_orders(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name toobit#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#all-orders-user-data
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("endTime".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut marketType: Value = self.handle_market_type_and_params(Value::Str("fetchOrders".into()), &[market.clone(), paramsUntil]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::from(vec![]);
if (marketType.as_str() == Some("spot")) {
response = self.private_get_api_v1_spot_trade_orders(&[requestUntil]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() is not supported for ".into())).into()), marketType).into()), Value::Str(" markets".into()))));
}
return self.parse_orders(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name toobit#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#query-history-orders-user-data
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_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
}));
// returns the most recent closed or canceled orders up to circa two weeks ago
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("endTime".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marketType: Value = self.handle_market_type_and_params(Value::Str("fetchClosedOrders".into()), &[market.clone(), paramsUntil]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::from(vec![]);
if (marketType.as_str() == Some("spot")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() is not supported for ".into())).into()), marketType).into()), Value::Str(" markets".into()))));
} else {
response = self.private_get_api_v1_futures_history_orders(&[requestUntil]).await;
}
let mut ordersList: Vec<Value> = Vec::new();
let mut responseList: Value = Value::from(vec![]);
if (matches!(&response, Value::Arr(_))) {
responseList = response.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_1122: bool = true;
while { if !__for_first_1122 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_1122 = false; i.as_f64().unwrap_or(f64::NAN) < ((responseList.len() as i64) as f64) } {
ordersList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), responseList.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
m
}));
}
}
return self.parse_orders(Value::from(ordersList), &[market, since, limit]);
Value::Null
}
/*
* @method
* @name toobit#fetchMyTrades
* @description fetch all trades made by the user
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#account-trade-list-user-data
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#account-trade-list-user-data
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trade structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades for
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut market: Value = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchMyTrades".into()), &[market.clone(), params]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("endTime".into()), request, paramsMarketType, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::from(vec![]);
if (marketType.as_str() == Some("spot")) {
let __ws_arg_23 = self.extend(requestUntil.clone(), &[paramsUntil]);
response = self.private_get_api_v1_account_trades(&[__ws_arg_23]).await;
} else {
response = self.private_get_api_v1_futures_user_trades(&[requestUntil]).await;
}
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name toobit#transfer
* @description transfer currency internally between wallets on the same account
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#account-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount 'spot', 'swap'
* @param {string} toAccount 'spot', 'swap'
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountsByType, toAccount.clone(), &[toAccount.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.currency_to_precision(code, amount, &[]));
m.insert("fromAccountType".to_string(), fromId);
m.insert("toAccountType".to_string(), toId);
m
});
let __ws_arg_24 = self.extend(request, &[params]);
let mut response: Value = self.private_post_api_v1_sub_account_transfer(&[__ws_arg_24]).await;
return self.parse_transfer(response, &[currency]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer);
m.insert("id".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("currency".to_string(), Value::Null);
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://api-docs.toobit.com/api/spot-account-and-trading.html#get-account-transaction-history-list-user-data
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#get-futures-account-transaction-history-list-user-data
* @param {string} [code] unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] end time in ms
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("coin".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("endTime".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchLedger".into()), &[Value::Null, paramsUntil]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
let __ws_arg_25 = self.extend(requestUntil.clone(), &[paramsMarketType.clone()]);
response = self.private_get_api_v1_account_balance_flow(&[__ws_arg_25]).await;
} else {
let __ws_arg_26 = self.extend(requestUntil, &[paramsMarketType]);
response = self.private_get_api_v1_futures_balance_flow(&[__ws_arg_26]).await;
}
return self.parse_ledger(response, &[currency, since, limit]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyId: Value = self.safe_string_k(item.clone(), "coinId", &[]);
let mut currencyResolved: Value = self.safe_currency(currencyId, &[currency]);
let mut timestamp: Value = self.safe_integer_k(item.clone(), "created", &[]);
let mut after: Value = self.safe_number_k(item.clone(), "total", &[]);
let mut amountRaw: Value = self.safe_string_k(item.clone(), "change", &[Value::Str("".into())]);
let mut amount: Value = self.parse_number(crate::precise::Precise::stringAbs(&amountRaw), &[]);
let mut direction: Value = Value::Str("in".into());
if (amountRaw.as_str().is_some_and(|__s| __s.starts_with("-"))) {
direction = Value::Str("out".into());
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string_k(item.clone(), "id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("direction".to_string(), direction);
m.insert("account".to_string(), Value::Null);
m.insert("referenceId".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_ledger_type(self.safe_string_k(item, "flowType", &[])).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("currency".to_string(), currencyResolved.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), amount);
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), after);
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currencyResolved]);
Value::Null
}
pub fn parse_ledger_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USER_ACCOUNT_TRANSFER".to_string(), Value::Str("transfer".into()));
m.insert("AIRDROP".to_string(), Value::Str("rebate".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name toobit#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#user-trade-fee-rate-user-data
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
let mut market: Value = Value::Null;
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchTradingFees".into()), &[Value::Null, params]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (marketType.as_str() == Some("spot")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchTradingFees(): does not support ".into())).into()), marketType).into()), Value::Str(" markets".into()))));
} else if self.in_array(marketType, Value::from(vec![Value::Str("swap".into()), Value::Str("future".into())])).as_bool() == Some(true) {
let mut symbolparamsSymbolVariable = self.handle_param_string(paramsMarketType, Value::Str("symbol".into()), &[]);
let mut symbol: Value = symbolparamsSymbolVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSymbol: Value = symbolparamsSymbolVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchTradingFees requires a params[\"symbol\"]".into()))));
}
market = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_27 = self.extend(request, &[paramsSymbol]);
response = self.private_get_api_v1_futures_commission_rate(&[__ws_arg_27]).await;
}
//
// {
// "openMakerFee": "0.000006", // The trade fee rate for opening pending orders
// "openTakerFee": "0.0001", // The trade fee rate for open position taker
// "closeMakerFee": "0.0002", // The trade fee rate for closing pending orders
// "closeTakerFee": "0.0004" // The trade fee rate for closing a taker order
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut entry: Value = response;
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
market = self.safe_market(&[marketId, market.clone()]);
let mut fee: Value = self.parse_trading_fee(entry, &[market.clone()]);
add_element_to_object(&mut result, &market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), fee);
return result;
Value::Null
}
pub fn parse_trading_fee(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(data.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("maker".to_string(), self.safe_number_k(data.clone(), "closeMakerFee", &[]));
m.insert("taker".to_string(), self.safe_number_k(data, "closeTakerFee", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchDeposits
* @description fetch all deposits made to an account
* @see https://api-docs.toobit.com/api/spot-wallet.html#deposit-history-user-data
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposit structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = 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
}));
return self.fetch_deposits_or_withdrawals_helper(Value::Str("deposits".into()), code, since, limit, &[params]).await;
Value::Null
}
/*
* @method
* @name toobit#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://api-docs.toobit.com/api/spot-wallet.html#withdrawal-records-user-data
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawal structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = 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
}));
return self.fetch_deposits_or_withdrawals_helper(Value::Str("withdrawals".into()), code, since, limit, &[params]).await;
Value::Null
}
pub async fn fetch_deposits_or_withdrawals_helper(&mut self, mut type_var: Value, mut code: Value, mut since: Value, mut limit: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("coin".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("endTime".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut response: Value = Value::from(vec![]);
if (type_var.as_str() == Some("deposits")) {
let __ws_arg_28 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_get_api_v1_account_deposit_orders(&[__ws_arg_28]).await;
} else if (type_var.as_str() == Some("withdrawals")) {
let __ws_arg_29 = self.extend(requestUntil, &[paramsUntil.clone()]);
response = self.private_get_api_v1_account_withdraw_orders(&[__ws_arg_29]).await;
}
let mut transactType: Value = (if (type_var.as_str() == Some("deposits")) { Value::Str("deposit".into()) } else { Value::Str("withdrawal".into()) });
let mut results: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_1123: bool = true;
while { if !__for_first_1123 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_1123 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let __ws_arg_30 = self.parse_transaction_with_type(response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[currency.clone(), transactType.clone()]);
results.push(self.extend(__ws_arg_30, &[paramsUntil.clone()]));
}
}
let mut sorted: Value = self.sort_by(Value::from(results), Value::Str("timestamp".into()), &[]);
let mut currencyCode: Value = (if (currency != Value::Null) { currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null) } else { Value::Null });
return self.filter_by_currency_since_limit(sorted, &[currencyCode, since, limit]);
Value::Null
}
pub fn parse_transaction_with_type(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut transactType = get_arg(optional_args, 1, Value::Null);
let mut result: Value = self.parse_transaction(transaction.clone(), &[currency]);
if (transactType != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("type".into(), transactType.clone()); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("status".into(), self.parse_transaction_status(self.safe_string_k(transaction, "status", &[]), &[transactType]).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null)); }
}
return result;
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchDeposits & fetchWithdrawals
//
// {
// "time": 1499865549590,
// "id": 100234,
// "coinName": "EOS",
// "statusCode": "DEPOSIT_CAN_WITHDRAW",
// "status": "2", // 2=SUCCESS, 11=REJECT, 12=AUDIT
// "address": "deposit2bb",
// "txId": "98A3EA560C6B3336D348B6C83F0F95ECE4F1F5919E94BD006E5BF3BF264FACFC",
// "txIdUrl": "",
// "requiredConfirmTimes": "5",
// "confirmTimes": "5",
// "quantity": "1.01",
// "coin": "EOS", // present in "fetchDeposits"
// "coinId ":"BHC", // present in "fetchWithdrawals"
// "addressTag": "19012584", // present in "fetchDeposits"
// "addressExt":"address tag", // present in "fetchWithdrawals"
// "fromAddress": "clarkkent", // present in "fetchDeposits"
// "fromAddressTag": "19029901" // present in "fetchDeposits"
// "arriveQuantity":"14", // present in "fetchWithdrawals"
// "walletHandleTime":"1536232111669",// present in "fetchWithdrawals"
// "feeCoinId ":"BHC", // present in "fetchWithdrawals"
// "feeCoinName ":"BHC", // present in "fetchWithdrawals"
// "fee":"0.1", // present in "fetchWithdrawals"
// "kernelId":"", // present in "fetchWithdrawals"
// "isInternalTransfer": false // present in "fetchWithdrawals"
// }
//
// withdraw
//
// {
// "status": 0,
// "success": true,
// "needBrokerAudit": false, // Do you need a brokerage review?
// "id": "423885103582776064",
// "refuseReason":"" // failure rejection reason
// }
//
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "time", &[]);
let mut currencyId: Value = self.safe_string2(transaction.clone(), Value::Str("coin".into()), Value::Str("coinId".into()), &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency]);
let mut feeString: Value = self.safe_string_k(transaction.clone(), "fee", &[]);
let mut feeCoin: Value = self.safe_string_k(transaction.clone(), "feeCoinName", &[]);
let mut fee: Value = Value::Null;
if (feeString != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeString, &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCoin, &[]));
m
});
}
let mut tagTo: Value = self.safe_string2(transaction.clone(), Value::Str("addressTag".into()), Value::Str("addressExt".into()), &[]);
let mut tagFrom: Value = self.safe_string_k(transaction.clone(), "fromAddressTag", &[]);
let mut addressTo: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut addressFrom: Value = self.safe_string_k(transaction.clone(), "fromAddress", &[]);
let mut isWithdraw: bool = (matches!(&transaction, Value::Dict(__d) if __d.contains_key("arriveQuantity"))) || (matches!(&transaction, Value::Dict(__d) if __d.contains_key("success")));
let mut type_var: Value = (if isWithdraw { Value::Str("withdrawal".into()) } else { Value::Str("deposit".into()) });
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string_k(transaction.clone(), "id", &[]));
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "txId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), Value::Null);
m.insert("addressTo".to_string(), addressTo);
m.insert("addressFrom".to_string(), addressFrom);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), tagTo);
m.insert("tagFrom".to_string(), tagFrom);
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "quantity", &[]));
m.insert("currency".to_string(), code);
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction, "status", &[]), &[type_var]).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("updated".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value, optional_args: &[Value]) -> Option<String> {
let mut type_var = get_arg(optional_args, 0, Value::Null);
let mut statusesByType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("2".to_string(), Value::Str("ok".into()));
m.insert("11".to_string(), Value::Str("failed".into()));
m.insert("12".to_string(), Value::Str("pending".into()));
m
}));
m.insert("withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("pending".into()));
m.insert("1".to_string(), Value::Str("pending".into()));
m.insert("2".to_string(), Value::Str("failed".into()));
m.insert("3".to_string(), Value::Str("pending".into()));
m.insert("6".to_string(), Value::Str("ok".into()));
m.insert("7".to_string(), Value::Str("failed".into()));
m.insert("9".to_string(), Value::Str("canceled".into()));
m.insert("10".to_string(), Value::Str("pending".into()));
m.insert("11".to_string(), Value::Str("pending".into()));
m
}));
m
});
if (status == Value::Null) {
return None;
}
let mut statuses: Value = self.safe_dict(statusesByType, type_var, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name toobit#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://api-docs.toobit.com/api/spot-wallet.html#deposit-address-user-data
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_31 = self.extend(request.clone(), &[params]);
let mut networkCodeparamsOmittedVariable = self.handle_network_code_and_params(__ws_arg_31);
let mut networkCode: Value = networkCodeparamsOmittedVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsOmitted: Value = networkCodeparamsOmittedVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (networkCode == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddress() : param[\"network\"] is required".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("chainType".into(), self.network_code_to_id(networkCode, &[code])); }
let __ws_arg_32 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_get_api_v1_account_deposit_address(&[__ws_arg_32]).await;
return self.parse_deposit_address(response, &[currency]);
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
let mut address: Value = self.safe_string_k(depositAddress.clone(), "address", &[]);
self.check_address(&[address.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), (match currency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null }));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address);
m.insert("tag".to_string(), self.safe_string_k(depositAddress, "addressExt", &[]));
m
});
Value::Null
}
/*
* @method
* @name toobit#withdraw
* @description make a withdrawal
* @see https://api-docs.toobit.com/api/spot-wallet.html#withdraw-user-data
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tag] memo / destination tag, required for currencies in options['withdrawTagRequiredCurrencies']
* @param {string} [params.addressType] recipient identifier type, one of BLOCK_CHAIN, PHONE_NUMBER, EMAIL, or UID
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut tagparamsWithdrawTagVariable = self.handle_param_string(params, Value::Str("tag".into()), &[]);
let mut tag: Value = tagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone()]);
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(paramsWithdrawTag);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (networkCode == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" withdraw() : param[\"network\"] is required".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("address".to_string(), address);
m.insert("quantity".to_string(), self.currency_to_precision(currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null), amount, &[]));
m.insert("chainType".to_string(), self.network_code_to_id(networkCode, &[code]));
m.insert("clientOrderId".to_string(), self.milliseconds());
m
});
if (tag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("addressExt".into(), tag); }
}
let __ws_arg_33 = self.extend(request, &[paramsNetworkCode]);
let mut response: Value = self.private_post_api_v1_account_withdraw(&[__ws_arg_33]).await;
return self.parse_transaction(response, &[currency]);
Value::Null
}
/*
* @method
* @name toobit#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#change-margin-type-trade
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_margin_mode(&mut self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null).as_str() != Some("swap")) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() supports swap contracts only".into()))));
}
let mut marginModeValue: Value = marginMode.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("marginType".to_string(), marginModeValue);
m
});
let __ws_arg_34 = self.extend(request, &[params]);
let mut response: Value = self.private_post_api_v1_futures_margin_type(&[__ws_arg_34]).await;
return response;
Value::Null
}
/*
* @method
* @name toobit#setLeverage
* @description set the level of leverage for a market
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#change-initial-leverage-trade
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("leverage".to_string(), leverage);
m
});
let __ws_arg_35 = self.extend(request, &[params]);
let mut response: Value = self.private_post_api_v1_futures_leverage(&[__ws_arg_35]).await;
return response;
Value::Null
}
/*
* @method
* @name toobit#fetchLeverage
* @description fetch the set leverage for a market
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#get-the-leverage-multiple-and-position-mode-user-data
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage structure]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverage(&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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_36 = self.extend(request, &[params]);
let mut response: Value = self.private_get_api_v1_futures_account_leverage(&[__ws_arg_36]).await;
//
// [
// {
// "symbolId":"ETH-SWAP-USDT",
// "leverage":"50",
// "marginType":"CROSS" // CROSS;ISOLATED
// }
// ]
//
let mut data: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(data, &[market]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string2(leverage.clone(), Value::Str("symbolId".into()), Value::Str("symbol".into()), &[]);
let mut leverageValue: Value = self.safe_integer_k(leverage.clone(), "leverage", &[]);
let mut marginType: Option<String> = self.safe_string_lower_k(leverage.clone(), "marginType", &[]).as_str().map(str::to_owned);
let mut marginMode: Value = (if (marginType.as_deref() == Some("cross")) { Value::Str("cross".into()) } else { Value::Str("isolated".into()) });
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("marginMode".to_string(), marginMode);
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue);
m
});
Value::Null
}
/*
* @method
* @name toobit#fetchPositions
* @description fetch all open positions
* @see https://api-docs.toobit.com/api/usdt-m-account-and-trading.html#query-position-user-data
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbols != Value::Null) {
let mut length: f64 = ((symbols.len() as i64) as f64);
if length > ((1i64) as f64) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchPositions() only accepts an array with a single symbol or without symbols argument".into()))));
}
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
if (firstSymbol != Value::Null) {
market = self.market(firstSymbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
}
let __ws_arg_37 = self.extend(request, &[params]);
let mut response: Value = self.private_get_api_v1_futures_positions(&[__ws_arg_37]).await;
return self.parse_positions(response, &[symbols]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut side: Value = self.safe_string_lower_k(position.clone(), "side", &[]);
let mut quantity: Value = self.safe_string_k(position.clone(), "position", &[]);
let mut leverage: Value = self.safe_integer_k(position.clone(), "leverage", &[]);
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(), "id", &[]));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "avgPrice", &[]));
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "markPrice", &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "lastPrice", &[]));
m.insert("notional".to_string(), self.safe_number_k(position.clone(), "positionValue", &[]));
m.insert("collateral".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealizedPnL", &[]));
m.insert("side".to_string(), side);
m.insert("contracts".to_string(), self.parse_number(quantity, &[]));
m.insert("contractSize".to_string(), self.safe_number_k(marketResolved, "contractSize", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("hedged".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number_k(position, "margin", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), leverage);
m.insert("liquidationPrice".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __api_empty = Vec::new();
let api = api.as_array().unwrap_or(&__api_empty);
let mut apiName: Value = api.get(0).cloned().unwrap_or(Value::Null);
let mut baseApiUrl: Value = self.safe_string(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), apiName.clone(), &[]);
if (baseApiUrl == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut baseUrl: Value = baseApiUrl;
let mut url: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", baseUrl, Value::Str("/".into())).into()), self.implode_params(path.clone(), params.clone())).into());
let mut isPost: bool = method.as_str() == Some("POST");
let mut isDelete: bool = method.as_str() == Some("DELETE");
let mut extraQuery: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut query: Value = self.omit(params.clone(), self.extract_params(path), &[]);
if (apiName.as_str() != Some("private")) {
// Public endpoints
if !isPost {
if ((Value::Array(query.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).len() as i64) as f64) > ((0i64) as f64) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into())).into());
}
}
} else {
self.check_required_credentials(&[]);
let mut timestamp: Value = self.milliseconds();
// Add timestamp to parameters for signed endpoints
if let Value::Dict(__d) = &mut extraQuery { std::sync::Arc::make_mut(__d).insert("recvWindow".into(), self.safe_string_k(self.options.clone(), "recvWindow", &[Value::Str("5000".into())])); }
if let Value::Dict(__d) = &mut extraQuery { std::sync::Arc::make_mut(__d).insert("timestamp".into(), Value::Str(format!("{}", timestamp).into())); }
let mut queryExtended: Value = self.extend(query.clone(), &[extraQuery.clone()]);
let mut queryString: Value = Value::Str("".into());
let mut privateBody: Value = Value::Null;
if isPost || isDelete {
// everything else except Batch-Orders
if !(matches!(¶ms, Value::Arr(_))) {
privateBody = self.urlencode(queryExtended.clone(), &[]);
} else {
queryString = self.urlencode(extraQuery, &[]);
privateBody = json_stringify(&query);
}
} else {
queryString = self.urlencode(queryExtended, &[]);
}
let mut payloadBody: Value = Value::Null;
if isPost || isDelete {
payloadBody = privateBody.clone();
}
let mut payload: Value = queryString.clone();
if (payloadBody != Value::Null) {
payload = Value::Str(format!("{}{}", payloadBody, payload).into());
}
let mut signature: Value = self.hmac(self.encode(payload), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[Value::Str("hex".into())]);
if (queryString.as_str() != Some("")) {
queryString = Value::Str(format!("{}{}", queryString, Value::Str(format!("{}{}", Value::Str("&signature=".into()), signature).into())).into());
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), queryString).into())).into());
} else {
privateBody = Value::Str(format!("{}{}", privateBody, Value::Str(format!("{}{}", Value::Str("&signature=".into()), signature).into())).into());
}
let mut privateHeaders: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Referrer".to_string(), Value::Str("CCXT".into()));
m.insert("X-BB-APIKEY".to_string(), self.apiKey.clone());
m.insert("X-BB-API-PLATFORM".to_string(), self.safe_string_k(self.options.clone(), "brokerId", &[Value::Str("177321641268789".into())]));
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".into()));
m
});
let mut requestBody: Value = Value::Null;
if isPost || isDelete {
requestBody = privateBody;
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), requestBody);
m.insert("headers".to_string(), privateHeaders);
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), Value::Null);
m.insert("headers".to_string(), Value::Null);
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut message: Value = self.safe_string_k(response, "msg", &[]);
if ((errorCode != Value::Null) && (errorCode.as_str() != Some(""))) && (errorCode.as_str() != Some("200")) && (errorCode.as_str() != Some("0")) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode, feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}