// 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;
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);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for 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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
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.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).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.get(4..).unwrap_or(&[]).to_vec()[..]),
"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.get(4..).unwrap_or(&[]).to_vec()[..]).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.get(4..).unwrap_or(&[]).to_vec()[..]),
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_last_prices" => self.fetch_last_prices(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_status" => self.fetch_status(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_last_price" => self.parse_last_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_type" => self.parse_ledger_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type" => self.parse_order_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(4..).unwrap_or(&[]).to_vec()[..]).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.get(3..).unwrap_or(&[]).to_vec()[..]).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".to_string()));
m.insert("name".to_string(), Value::Str("Toobit".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("KY".to_string())]));
m.insert("version".to_string(), Value::Str("v1".to_string()));
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".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("common".to_string(), Value::Str("https://api.toobit.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api.toobit.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.toobit.com/".to_string()));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://api-docs.toobit.com/".to_string())]));
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".to_string()));
m
}));
m.insert("fees".to_string(), Value::Str("https://www.toobit.com/fee".to_string()));
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(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/spot/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/spot/tradeOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(5), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/historyOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(5), &Value::Float(1.67)));
m
}));
m.insert("api/v1/account/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(5), &Value::Float(1.67)));
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(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(5), &Value::Float(1.67)));
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(), multiply(&Value::Int(5), &Value::Float(1.67)));
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
}));
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(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/spot/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(2), &Value::Float(1.67)));
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(), multiply(&Value::Int(2), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/position/trading-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(3), &Value::Float(1.67)));
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(), multiply(&Value::Int(2), &Value::Float(1.67)));
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(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(1), &Value::Float(1.67)));
m
}));
m.insert("api/v1/spot/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(5), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(3), &Value::Float(1.67)));
m
}));
m.insert("api/v1/spot/cancelOrderByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(5), &Value::Float(1.67)));
m
}));
m.insert("api/v1/futures/cancelOrderByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), multiply(&Value::Int(3), &Value::Float(1.67)));
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".to_string()));
m.insert("3m".to_string(), Value::Str("3m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("8h".to_string(), Value::Str("8h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
m
}));
m.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".to_string()).clone());
m.insert("-1001".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1002".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1003".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-1004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1005".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1006".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1007".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1014".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1015".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-1016".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1020".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1021".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1022".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1023".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1031".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1100".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1101".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1102".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1103".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1104".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1105".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1106".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1107".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1111".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1112".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1114".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1115".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1116".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1117".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1118".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1119".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1120".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1121".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-1125".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1127".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1128".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1129".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1130".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1131".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-1132".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1133".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1134".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1135".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1136".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1137".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1138".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1139".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1140".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1141".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1142".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1143".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("-1144".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1145".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1146".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1147".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1148".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1149".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1150".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1151".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1153".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1156".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1157".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1158".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1161".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1164".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1165".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1166".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1170".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1171".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1172".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1181".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1182".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1193".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1194".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1195".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1196".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1197".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1198".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1199".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1200".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1201".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1202".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1203".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1204".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1205".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1206".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1207".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1208".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1209".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1210".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1211".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1212".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1213".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-1214".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1215".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1216".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1217".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1300".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1400".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1401".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1402".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1403".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1404".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1405".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1406".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1407".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1408".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-1409".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1410".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-1411".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1412".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1413".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1414".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1415".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1416".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-1417".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2010".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-2011".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-2013".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("-2014".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-2015".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-2016".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2017".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-2018".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-3000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-3001".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3050".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-3051".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3052".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-3101".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3102".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3103".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-3105".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3107".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3108".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3109".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3110".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-3116".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3117".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3120".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3124".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3125".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3126".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3127".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-3128".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3129".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-3130".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3131".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-3132".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3133".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3136".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3137".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3138".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3139".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3140".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3141".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3142".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3143".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3144".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3145".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3147".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-3148".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3149".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3150".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-3151".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-3152".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-3153".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-32045".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-32090".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-32093".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-120041".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-120047".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-120055".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-120067".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-120072".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-120073".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-120078".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-120510".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-120511".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-120512".to_string(), Value::Str("BadRequest".to_string()).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".to_string()).clone());
m.insert("Duplicate order sent".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("Market is closed".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Account has insufficient balance for requested action".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("Market orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Iceberg orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Stop loss orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Stop loss limit orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Take profit orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Take profit limit orders are not supported for this symbol".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("QTY is zero or less".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("IcebergQty exceeds QTY".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("This action disabled is on this account".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("Unsupported order combination".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("Order would trigger immediately".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Cancel order is invalid. Check origClOrdId and orderId".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("Order would immediately match and take".to_string(), Value::Str("OperationRejected".to_string()).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".to_string()));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("MAIN".to_string()));
m.insert("swap".to_string(), Value::Str("FUTURES".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("ETH".to_string(), Value::Str("ETH".to_string()));
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRX".to_string()));
m.insert("SOL".to_string(), Value::Str("SOL".to_string()));
m.insert("MATIC".to_string(), Value::Str("MATIC".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBITRUM".to_string()));
m.insert("BASE".to_string(), Value::Str("BASE".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("AVAXC".to_string(), Value::Str("AVAXC".to_string()));
m.insert("DOGE".to_string(), Value::Str("DOGE".to_string()));
m.insert("XRP".to_string(), Value::Str("XRP".to_string()));
m.insert("DOT".to_string(), Value::Str("DOT".to_string()));
m.insert("ADA".to_string(), Value::Str("ADA".to_string()));
m.insert("LTC".to_string(), Value::Str("LTC".to_string()));
m.insert("APT".to_string(), Value::Str("APT".to_string()));
m.insert("ATOM".to_string(), Value::Str("ATOM".to_string()));
m.insert("ALGO".to_string(), Value::Str("ALGO".to_string()));
m.insert("NEAR".to_string(), Value::Str("NEAR".to_string()));
m.insert("XLM".to_string(), Value::Str("XLM".to_string()));
m.insert("SUI".to_string(), Value::Str("SUI".to_string()));
m.insert("ETC".to_string(), Value::Str("ETC".to_string()));
m.insert("EOS".to_string(), Value::Str("EOS".to_string()));
m.insert("WAVES".to_string(), Value::Str("WAVES".to_string()));
m.insert("ICP".to_string(), Value::Str("ICP".to_string()));
m.insert("ONE".to_string(), Value::Str("ONE".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
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.clone()]).await;
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("ok".to_string()));
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.clone());
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.clone()]).await;
return self.safe_integer_k(response.clone(), "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.clone()]).await;
add_element_to_object(&mut self.options, &Value::Str("exchangeInfo".to_string()), 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.clone(), "coins", &[Value::List(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_1080: bool = true;
while { if !__for_first_1080 { i = add(&i, &Value::Int(1)); } __for_first_1080 = false; is_less_than(&i, &get_array_length(&coins)) } {
let mut coin: Value = get_value(&coins, &i);
let mut coin: Value = get_value(&coins, &i);
let mut parsed: Value = self.parse_currency(coin.clone());
if !is_equal(&parsed, &Value::Null) {
let mut code: Value = get_value(&parsed, &Value::Str("code".to_string()));
add_element_to_object(&mut result, &code, parsed.clone());
}
}
}
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::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_1081: bool = true;
while { if !__for_first_1081 { j = add(&j, &Value::Int(1)); } __for_first_1081 = false; is_less_than(&j, &get_array_length(&rawNetworks)) } {
let mut rawNetwork: Value = get_value(&rawNetworks, &j);
let mut rawNetwork: Value = get_value(&rawNetworks, &j);
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 !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId.clone());
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.clone());
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("code".to_string(), code.clone());
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.clone());
m.insert("info".to_string(), rawCurrency.clone());
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 response: Value = self.safe_dict_k(self.options.clone(), "exchangeInfo", &[]);
if !is_equal(&response, &Value::Null) {
add_element_to_object(&mut self.options, &Value::Str("exchangeInfo".to_string()), Value::Null); // reset it to avoid using old cached data
} else {
response = self.common_get_api_v1_exchange_info(&[params.clone()]).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::List(vec![])]);
let mut contracts: Value = self.safe_list_k(response.clone(), "contracts", &[Value::List(vec![])]);
let mut all: Value = self.array_concat(symbols.clone(), contracts.clone());
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1082: bool = true;
while { if !__for_first_1082 { i = add(&i, &Value::Int(1)); } __for_first_1082 = false; is_less_than(&i, &get_array_length(&all)) } {
let mut market: Value = get_value(&all, &i);
let mut market: Value = get_value(&all, &i);
let mut parsed: Value = self.parse_market(market.clone());
if !is_equal(&parsed, &Value::Null) {
append_to_array(&mut result, parsed.clone());
}
}
}
return 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("".to_string())]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteAsset", &[]);
let mut baseParts: Value = split(&baseId, &Value::Str("-".to_string()));
let mut baseIdClean: Value = get_value(&baseParts, &Value::Int(0));
let mut base: Value = self.safe_currency_code(baseIdClean.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "marginToken", &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut active: Value = Value::Bool(is_equal(&status, &Value::Str("TRADING".to_string())));
let mut filters: Value = self.safe_list_k(market.clone(), "filters", &[Value::List(vec![])]);
let mut filtersByType: Value = self.index_by(filters.clone(), Value::Str("filterType".to_string()));
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.clone(), "MIN_NOTIONAL", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut isContract: Value = (Value::Bool(in_op(&market, &Value::Str("contractMultiplier".to_string()))));
let mut inverse: Value = self.safe_bool2(market.clone(), Value::Str("isInverse".to_string()), Value::Str("inverse".to_string()), &[]);
if is_true(&isContract) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &settle));
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), ternary(is_true(&isContract), Value::Str("swap".to_string()), Value::Str("spot".to_string())));
m.insert("spot".to_string(), Value::Bool(!is_true(&isContract)));
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.clone());
m.insert("contract".to_string(), isContract.clone());
m.insert("linear".to_string(), ternary(is_true(&isContract), Value::Bool((!is_equal(&inverse, &Value::Bool(true)))), Value::Null));
m.insert("inverse".to_string(), ternary(is_true(&isContract), inverse.clone(), 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.clone(), "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.clone(), "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.clone(), "minNotional", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
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.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone(), Value::Str("b".to_string()), Value::Str("a".to_string())]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.common_get_quote_v1_trades(&[__ws_arg_1]).await;
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
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".to_string()), Value::Str("time".to_string()), &[]);
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("p".to_string()), Value::Str("price".to_string()), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("q".to_string()), Value::Str("qty".to_string()), &[]);
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", &[]);
if is_equal(&isBuyerMaker, &Value::Null) {
let mut isBuyerTaker: Value = self.safe_bool_k(trade.clone(), "m", &[]);
if !is_equal(&isBuyerTaker, &Value::Null) {
isBuyerMaker = Value::Bool(!is_true(&isBuyerTaker));
}
}
if !is_equal(&isBuyerMaker, &Value::Null) {
if is_true(&isBuyerMaker) {
side = Value::Str("sell".to_string());
} else {
side = Value::Str("buy".to_string());
}
} else {
if is_equal(&isBuyer, &Value::Bool(true)) {
side = Value::Str("buy".to_string());
} else {
side = Value::Str("sell".to_string());
}
}
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 !is_equal(&feeAmount, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(feeCurrencyId.clone(), &[]));
m.insert("cost".to_string(), feeAmount.clone());
m
});
}
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "isMaker", &[]);
let mut takerOrMaker: Value = Value::Null;
if !is_equal(&isMaker, &Value::Null) {
takerOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
market = self.safe_market(&[Value::Null, market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
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.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("id".to_string()), Value::Str("v".to_string()), &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
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
* @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".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::List(vec![]);
let mut endpoint: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("price".to_string()), &[]); endpoint = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&endpoint, &Value::Str("index".to_string())) {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.common_get_quote_v1_index_klines(&[__ws_arg_2]).await;
} else if is_equal(&endpoint, &Value::Str("mark".to_string())) {
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.common_get_quote_v1_mark_price_klines(&[__ws_arg_3]).await;
} else {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.common_get_quote_v1_klines(&[__ws_arg_4]).await;
}
let mut candles: Value = Value::List(vec![]);
if is_true(&Value::Bool(is_array(&response))) {
candles = response.clone();
}
return self.parse_ohlc_vs(candles.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
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::List(vec![self.safe_integer_n(ohlcv.clone(), Value::List(vec![Value::Int(0), Value::Str("time".to_string()), Value::Str("t".to_string())]), &[]), self.safe_number_n(ohlcv.clone(), Value::List(vec![Value::Int(1), Value::Str("open".to_string()), Value::Str("o".to_string())]), &[]), self.safe_number_n(ohlcv.clone(), Value::List(vec![Value::Int(2), Value::Str("high".to_string()), Value::Str("h".to_string())]), &[]), self.safe_number_n(ohlcv.clone(), Value::List(vec![Value::Int(3), Value::Str("low".to_string()), Value::Str("l".to_string())]), &[]), self.safe_number_n(ohlcv.clone(), Value::List(vec![Value::Int(4), Value::Str("close".to_string()), Value::Str("c".to_string())]), &[]), self.safe_number_n(ohlcv.clone(), Value::List(vec![Value::Int(5), Value::Str("volume".to_string()), Value::Str("v".to_string())]), &[])]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut type_var: Value = Value::Null;
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut symbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut length: Value = get_array_length(&symbols);
if is_true(&(is_equal(&length, &Value::Int(1)))) && is_true(&(!is_equal(&market, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) {
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
response = self.common_get_quote_v1_ticker24hr(&[__ws_arg_5]).await;
} else {
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.common_get_quote_v1_contract_ticker24hr(&[__ws_arg_6]).await;
}
return self.parse_tickers(response.clone(), &[symbols.clone(), params.clone()]);
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", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
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", &[]);
if is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))) && is_true(&(!is_equal(&get_value(&market, &Value::Str("contractSize".to_string())), &Value::Null))) {
// 'v' counts contracts, and a ticker reports base volume
baseVolume = crate::precise::Precise::stringMul(&baseVolume, &self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string()))));
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "h", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "l", &[]));
m.insert("bid".to_string(), Value::Null);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), Value::Null);
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.clone());
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".to_string())));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "qv", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut length: Value = get_array_length(&symbols);
if is_equal(&length, &Value::Int(1)) {
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.common_get_quote_v1_ticker_price(&[__ws_arg_7]).await;
return self.parse_last_prices(response.clone(), &[symbols.clone()]);
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", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("price".to_string(), self.safe_number_omit_zero(entry.clone(), Value::Str("price".to_string()), &[]));
m.insert("side".to_string(), Value::Null);
m.insert("info".to_string(), entry.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut length: Value = get_array_length(&symbols);
if is_equal(&length, &Value::Int(1)) {
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.common_get_quote_v1_ticker_book_ticker(&[__ws_arg_8]).await;
return self.parse_bids_asks_custom(response.clone(), &[symbols.clone()]);
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: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1083: bool = true;
while { if !__for_first_1083 { i = add(&i, &Value::Int(1)); } __for_first_1083 = false; is_less_than(&i, &get_array_length(&tickers)) } {
let mut parsedTicker: Value = self.parse_bid_ask_custom(get_value(&tickers, &i));
let mut ticker: Value = self.extend(parsedTicker.clone(), &[params.clone()]);
append_to_array(&mut results, ticker.clone());
}
}
symbols = self.market_symbols(&[symbols.clone()]);
return self.filter_by_array(results.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
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.clone()]);
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.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
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.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut length: Value = get_array_length(&symbols);
if is_equal(&length, &Value::Int(1)) {
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.common_get_api_v1_futures_funding_rate(&[__ws_arg_9]).await;
return self.parse_funding_rates(response.clone(), &[symbols.clone()]);
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.clone(), &[market.clone()]);
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.clone());
m.insert("symbol".to_string(), symbol.clone());
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.clone());
m.insert("fundingTimestamp".to_string(), nextFundingRateTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(nextFundingRateTimestamp.clone()));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.clone()]).await;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.common_get_api_v1_futures_history_funding_rate(&[__ws_arg_10]).await;
return self.parse_funding_rate_histories(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
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.clone(), &[market.clone()]));
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "settleRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&self.in_array(marketType.clone(), Value::List(vec![Value::Str("swap".to_string()), Value::Str("future".to_string())]))) {
response = self.private_get_api_v1_futures_balance(&[]).await;
} else {
response = self.private_get_api_v1_account(&[]).await;
}
return self.parse_balance(response.clone());
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_1084: bool = true;
while { if !__for_first_1084 { i = add(&i, &Value::Int(1)); } __for_first_1084 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut balance: Value = get_value(&balances, &i);
let mut balance: Value = get_value(&balances, &i);
let mut code: Value = self.safe_currency_code(self.safe_string_k(balance.clone(), "asset", &[]), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string2(balance.clone(), Value::Str("free".to_string()), Value::Str("availableBalance".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string2(balance.clone(), Value::Str("total".to_string()), Value::Str("balance".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "locked", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
{ let __destr_tmp = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_api_v1_spot_order(&[__ws_arg_11]).await;
} else {
{ let __destr_tmp = self.create_contract_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_api_v1_futures_order(&[__ws_arg_12]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
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 is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a side argument".to_string()))));
}
let mut id: Value = get_value(&market, &Value::Str("id".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), id.clone());
m.insert("side".to_string(), to_upper(&side));
m
});
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut cost: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("cost".to_string()), &[]); cost = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("market".to_string())) && is_equal(&side, &Value::Str("buy".to_string())) {
if is_equal(&cost, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires params[\"cost\"] for market buy order".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.cost_to_precision(symbol.clone(), cost.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
let mut isPostOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(false), &[params.clone()]); isPostOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&isPostOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("LIMIT_MAKER".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), to_upper(&type_var));
}
return Value::List(vec![request.clone(), params.clone()]);
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 is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
let mut reduceOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_param_bool(params.clone(), Value::Str("reduceOnly".to_string()), &[]); reduceOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&side, &Value::Str("buy".to_string())) {
side = ternary(is_true(&(is_equal(&reduceOnly, &Value::Bool(true)))), Value::Str("BUY_CLOSE".to_string()), Value::Str("BUY_OPEN".to_string()));
} else if is_equal(&side, &Value::Str("sell".to_string())) {
side = ternary(is_true(&(is_equal(&reduceOnly, &Value::Bool(true)))), Value::Str("SELL_CLOSE".to_string()), Value::Str("SELL_OPEN".to_string()));
}
add_element_to_object(&mut request, &Value::Str("side".to_string()), side.clone());
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
if is_true(&self.in_array(type_var.clone(), Value::List(vec![Value::Str("limit".to_string()), Value::Str("LIMIT".to_string())]))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), to_upper(&type_var));
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
} else if is_equal(&type_var, &Value::Str("market".to_string())) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("LIMIT".to_string())); // weird, but exchange works this way
add_element_to_object(&mut request, &Value::Str("priceType".to_string()), Value::Str("MARKET".to_string()));
}
let mut isPostOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(false), &[params.clone()]); isPostOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&isPostOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("LIMIT_MAKER".to_string()));
}
let mut values: Value = self.handle_trigger_prices_and_params(symbol.clone(), params.clone(), &[]);
let mut triggerPrice: Value = get_value(&values, &Value::Int(0));
params = get_value(&values, &Value::Int(3));
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), triggerPrice.clone());
}
let mut stopLoss: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
let mut triggerPriceTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Str("MARK_PRICE".to_string()));
m.insert("last".to_string(), Value::Str("CONTRACT_PRICE".to_string()));
m
});
if is_true(&hasStopLoss) {
add_element_to_object(&mut request, &Value::Str("stopLoss".to_string()), self.safe_value_k(stopLoss.clone(), "triggerPrice", &[]));
let mut limitPrice: Value = self.safe_value_k(stopLoss.clone(), "price", &[]);
if !is_equal(&limitPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("slOrderType".to_string()), Value::Str("LIMIT".to_string()));
add_element_to_object(&mut request, &Value::Str("slLimitPrice".to_string()), self.price_to_precision(symbol.clone(), limitPrice.clone()));
}
let mut triggerPriceType: Value = self.safe_string_k(stopLoss.clone(), "triggerPriceType", &[]);
if !is_equal(&triggerPriceType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("slTriggerBy".to_string()), self.safe_string(triggerPriceTypes.clone(), triggerPriceType.clone(), &[triggerPriceType.clone()]));
}
params = self.omit(params.clone(), Value::Str("stopLoss".to_string()), &[]);
}
if is_true(&hasTakeProfit) {
add_element_to_object(&mut request, &Value::Str("takeProfit".to_string()), self.safe_value_k(takeProfit.clone(), "triggerPrice", &[]));
let mut limitPrice: Value = self.safe_value_k(takeProfit.clone(), "price", &[]);
if !is_equal(&limitPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tpOrderType".to_string()), Value::Str("LIMIT".to_string()));
add_element_to_object(&mut request, &Value::Str("tpLimitPrice".to_string()), self.price_to_precision(symbol.clone(), limitPrice.clone()));
}
let mut triggerPriceType: Value = self.safe_string_k(takeProfit.clone(), "triggerPriceType", &[]);
if !is_equal(&triggerPriceType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tpTriggerBy".to_string()), self.safe_string(triggerPriceTypes.clone(), triggerPriceType.clone(), &[triggerPriceType.clone()]));
}
params = self.omit(params.clone(), Value::Str("takeProfit".to_string()), &[]);
}
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("newClientOrderId".to_string()))))) {
add_element_to_object(&mut request, &Value::Str("newClientOrderId".to_string()), self.uuid(&[]));
}
return Value::List(vec![request.clone(), params.clone()]);
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".to_string()), Value::Str("time".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut rawType: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut rawSideLower: Value = self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]);
let mut reduceOnly: Value = Value::Null;
if !is_equal(&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 = split(&rawSideLower, &Value::Str("_".to_string()));
let mut sideSuffix: Value = self.safe_string(sideParts.clone(), Value::Int(1), &[]);
if !is_equal(&sideSuffix, &Value::Null) {
reduceOnly = Value::Bool(is_equal(&sideSuffix, &Value::Str("close".to_string())));
}
rawSideLower = self.safe_string(sideParts.clone(), Value::Int(0), &[]);
}
let mut triggerPrice: Value = self.omit_zero(self.safe_string_k(order.clone(), "stopPrice", &[]));
if is_equal(&triggerPrice, &Value::Str("0.0".to_string())) {
triggerPrice = Value::Null;
}
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.clone()));
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", &[])));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), self.parse_order_type(rawType.clone()));
m.insert("timeInForce".to_string(), self.safe_string_k(order.clone(), "timeInForce", &[]));
m.insert("postOnly".to_string(), Value::Bool((is_equal(&rawType, &Value::Str("LIMIT_MAKER".to_string())))));
m.insert("side".to_string(), rawSideLower.clone());
m.insert("price".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "price", &[])));
m.insert("triggerPrice".to_string(), triggerPrice.clone());
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.clone(), "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.clone());
m.insert("leverage".to_string(), Value::Null);
m.insert("hedged".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("PENDING_NEW".to_string(), Value::Str("open".to_string()));
m.insert("NEW".to_string(), Value::Str("open".to_string()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".to_string()));
m.insert("FILLED".to_string(), Value::Str("closed".to_string()));
m.insert("PENDING_CANCEL".to_string(), Value::Str("canceled".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("REJECTED".to_string(), Value::Str("canceled".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order_type(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".to_string()));
m.insert("LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("LIMIT_MAKER".to_string(), Value::Str("limit".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @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 is_equal(&self.safe_string_k(params.clone(), "clientOrderId", &[]), &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone(), Value::Str("none".to_string())]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("none".to_string())) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument or the \"defaultType\" parameter to be set to \"spot\" or \"swap\"".to_string()))));
}
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_spot_order(&[__ws_arg_13]).await;
} else {
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_futures_order(&[__ws_arg_14]).await;
}
// response same as in `createOrder`
let mut status: Value = self.parse_order_status(self.safe_string_k(response.clone(), "status", &[]));
if !is_equal(&status, &Value::Str("open".to_string())) {
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&add(&add(&self.id, &Value::Str(" order ".to_string())), &id), &Value::Str(" can not be canceled, ".to_string())), &self.json(response.clone()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
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 is_equal(&self.markets, &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 !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone(), Value::Str("none".to_string())]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("none".to_string())) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument or the \"defaultType\" parameter to be set to \"spot\" or \"swap\"".to_string()))));
}
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_spot_open_orders(&[__ws_arg_15]).await;
} else {
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_futures_batch_orders(&[__ws_arg_16]).await;
}
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut idsString: Value = join(&ids, &Value::Str(",".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ids".to_string(), idsString.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrders".to_string()), &[market.clone(), params.clone(), Value::Str("none".to_string())]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("none".to_string())) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol argument or the \"defaultType\" parameter to be set to \"spot\" or \"swap\"".to_string()))));
}
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_spot_cancel_order_by_ids(&[__ws_arg_17]).await;
} else {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_futures_cancel_order_by_ids(&[__ws_arg_18]).await;
}
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[market.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id.clone());
m
});
let mut market: Value = self.market(symbol.clone());
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(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.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_order(&[__ws_arg_20]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
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 is_equal(&self.markets, &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 !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::List(vec![]);
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_spot_open_orders(&[__ws_arg_21]).await;
} else {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_open_orders(&[__ws_arg_22]).await;
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::List(vec![]);
if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.private_get_api_v1_spot_trade_orders(&[request.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchOrders() is not supported for ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &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 !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchClosedOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::List(vec![]);
if is_equal(&marketType, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchOrders() is not supported for ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
} else {
response = self.private_get_api_v1_futures_history_orders(&[request.clone()]).await;
}
let mut ordersList: Value = Value::List(vec![]);
let mut responseList: Value = Value::List(vec![]);
if is_true(&Value::Bool(is_array(&response))) {
responseList = response.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_1085: bool = true;
while { if !__for_first_1085 { i = add(&i, &Value::Int(1)); } __for_first_1085 = false; is_less_than(&i, &get_array_length(&responseList)) } {
append_to_array(&mut ordersList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&responseList, &i));
m
}));
}
}
return self.parse_orders(ordersList.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::List(vec![]);
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_account_trades(&[__ws_arg_23]).await;
} else {
response = self.private_get_api_v1_futures_user_trades(&[request.clone()]).await;
}
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &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.clone(), toAccount.clone(), &[toAccount.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("quantity".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("fromAccountType".to_string(), fromId.clone());
m.insert("toAccountType".to_string(), toId.clone());
m
});
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_sub_account_transfer(&[__ws_arg_24]).await;
return self.parse_transfer(response.clone(), &[currency.clone()]);
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.clone());
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 is_equal(&self.markets, &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 !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("coin".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_account_balance_flow(&[__ws_arg_25]).await;
} else {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_balance_flow(&[__ws_arg_26]).await;
}
return self.parse_ledger(response.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
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("".to_string())]);
let mut amount: Value = self.parse_number(crate::precise::Precise::stringAbs(&amountRaw), &[]);
let mut direction: Value = Value::Str("in".to_string());
if is_true(&Value::Bool(starts_with(&amountRaw, &Value::Str("-".to_string())))) {
direction = Value::Str("out".to_string());
}
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.clone()));
m.insert("direction".to_string(), direction.clone());
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.clone(), "flowType", &[])));
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("code".to_string())));
m.insert("amount".to_string(), amount.clone());
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), after.clone());
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_ledger_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USER_ACCOUNT_TRANSFER".to_string(), Value::Str("transfer".to_string()));
m.insert("AIRDROP".to_string(), Value::Str("rebate".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
let mut marketType: Value = Value::Null;
let mut market: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTradingFees".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchTradingFees(): does not support ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
} else if is_true(&self.in_array(marketType.clone(), Value::List(vec![Value::Str("swap".to_string()), Value::Str("future".to_string())]))) {
let mut symbol: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("symbol".to_string()), &[]); symbol = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchTradingFees requires a params[\"symbol\"]".to_string()))));
}
market = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
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.clone();
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut fee: Value = self.parse_trading_fee(entry.clone(), &[market.clone()]);
add_element_to_object(&mut result, &get_value(&market, &Value::Str("symbol".to_string())), fee.clone());
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.clone(), &[market.clone()]));
m.insert("maker".to_string(), self.safe_number_k(data.clone(), "closeMakerFee", &[]));
m.insert("taker".to_string(), self.safe_number_k(data.clone(), "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".to_string()), code.clone(), since.clone(), limit.clone(), &[params.clone()]).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".to_string()), code.clone(), since.clone(), limit.clone(), &[params.clone()]).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 is_equal(&self.markets, &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 !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("coin".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::List(vec![]);
if is_equal(&type_var, &Value::Str("deposits".to_string())) {
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_account_deposit_orders(&[__ws_arg_28]).await;
} else if is_equal(&type_var, &Value::Str("withdrawals".to_string())) {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_account_withdraw_orders(&[__ws_arg_29]).await;
}
return self.parse_transactions(response.clone(), &[currency.clone(), since.clone(), limit.clone(), params.clone()]);
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".to_string()), Value::Str("coinId".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
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 !is_equal(&feeString, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeString.clone(), &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCoin.clone(), &[]));
m
});
}
let mut tagTo: Value = self.safe_string2(transaction.clone(), Value::Str("addressTag".to_string()), Value::Str("addressExt".to_string()), &[]);
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: Value = (Value::Bool(in_op(&transaction, &Value::Str("arriveQuantity".to_string()))));
let mut type_var: Value = ternary(is_true(&isWithdraw), Value::Str("withdrawal".to_string()), Value::Str("deposit".to_string()));
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.clone()));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), Value::Null);
m.insert("addressTo".to_string(), addressTo.clone());
m.insert("addressFrom".to_string(), addressFrom.clone());
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), tagTo.clone());
m.insert("tagFrom".to_string(), tagFrom.clone());
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.clone());
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])));
m.insert("updated".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
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) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("2".to_string(), Value::Str("pending".to_string()));
m.insert("12".to_string(), Value::Str("pending".to_string()));
m.insert("11".to_string(), Value::Str("failed".to_string()));
m.insert("3".to_string(), Value::Str("ok".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @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 is_equal(&self.markets, &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(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
let mut networkCodeparamsOmittedVariable = self.handle_network_code_and_params(__ws_arg_30);
let mut networkCode: Value = get_value(&networkCodeparamsOmittedVariable, &Value::Int(0));
let mut paramsOmitted: Value = get_value(&networkCodeparamsOmittedVariable, &Value::Int(1));
if is_equal(&networkCode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchDepositAddress() : param[\"network\"] is required".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("chainType".to_string()), self.network_code_to_id(networkCode.clone(), &[code.clone()]));
let __ws_arg_31 = self.extend(request.clone(), &[paramsOmitted.clone()]);
let mut response: Value = self.private_get_api_v1_account_deposit_address(&[__ws_arg_31]).await;
return self.parse_deposit_address(response.clone(), &[currency.clone()]);
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 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(), self.safe_string_k(currency.clone(), "code", &[]));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), self.safe_string_k(depositAddress.clone(), "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 {string} tag a memo for the transaction
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_address(&[address.clone()]);
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&networkCode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" withdraw() : param[\"network\"] is required".to_string()))));
}
if is_equal(&self.markets, &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(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("address".to_string(), address.clone());
m.insert("quantity".to_string(), self.currency_to_precision(get_value(¤cy, &Value::Str("code".to_string())), amount.clone(), &[]));
m.insert("chainType".to_string(), self.network_code_to_id(networkCode.clone(), &[code.clone()]));
m.insert("clientOrderId".to_string(), self.milliseconds());
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("addressExt".to_string()), tag.clone());
}
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_account_withdraw(&[__ws_arg_32]).await;
return self.parse_transaction(response.clone(), &[currency.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("swap".to_string())) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" setMarginMode() supports swap contracts only".to_string()))));
}
marginMode = to_upper(&marginMode);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("marginType".to_string(), marginMode.clone());
m
});
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_futures_margin_type(&[__ws_arg_33]).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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("leverage".to_string(), leverage.clone());
m
});
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_futures_leverage(&[__ws_arg_34]).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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_futures_account_leverage(&[__ws_arg_35]).await;
//
// [
// {
// "symbolId":"ETH-SWAP-USDT",
// "leverage":"50",
// "marginType":"CROSS" // CROSS;ISOLATED
// }
// ]
//
let mut data: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(data.clone(), &[market.clone()]);
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".to_string()), Value::Str("symbol".to_string()), &[]);
let mut leverageValue: Value = self.safe_integer_k(leverage.clone(), "leverage", &[]);
let mut marginType: Value = self.safe_string_lower(leverage.clone(), Value::Str("marginType".to_string()), &[]);
let mut marginMode: Value = ternary(is_true(&(is_equal(&marginType, &Value::Str("cross".to_string())))), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue.clone());
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 is_equal(&self.markets, &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 !is_equal(&symbols, &Value::Null) {
let mut length: Value = get_array_length(&symbols);
if is_greater_than(&length, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchPositions() only accepts an array with a single symbol or without symbols argument".to_string()))));
}
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
if !is_equal(&firstSymbol, &Value::Null) {
market = self.market(firstSymbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_futures_positions(&[__ws_arg_36]).await;
return self.parse_positions(response.clone(), &[symbols.clone()]);
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", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut side: Value = self.safe_string_lower(position.clone(), Value::Str("side".to_string()), &[]);
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(), get_value(&market, &Value::Str("symbol".to_string())));
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.clone());
m.insert("contracts".to_string(), self.parse_number(quantity.clone(), &[]));
m.insert("contractSize".to_string(), Value::Null);
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.clone(), "margin", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), leverage.clone());
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::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &self.implode_params(path.clone(), params.clone()));
let mut isPost: bool = is_equal(&method, &Value::Str("POST".to_string()));
let mut isDelete: bool = is_equal(&method, &Value::Str("DELETE".to_string()));
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.clone()), &[]);
if !is_equal(&api, &Value::Str("private".to_string())) {
// Public endpoints
if !is_true(&isPost) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
}
} else {
self.check_required_credentials(&[]);
let mut timestamp: Value = self.milliseconds();
// Add timestamp to parameters for signed endpoints
add_element_to_object(&mut extraQuery, &Value::Str("recvWindow".to_string()), self.safe_string_k(self.options.clone(), "recvWindow", &[Value::Str("5000".to_string())]));
add_element_to_object(&mut extraQuery, &Value::Str("timestamp".to_string()), to_string_val(×tamp));
let mut queryExtended: Value = self.extend(query.clone(), &[extraQuery.clone()]);
let mut queryString: Value = Value::Str("".to_string());
if is_true(&isPost) || is_true(&isDelete) {
// everything else except Batch-Orders
if !is_true(&Value::Bool(is_array(¶ms))) {
body = self.urlencode(queryExtended.clone(), &[]);
} else {
queryString = self.urlencode(extraQuery.clone(), &[]);
body = self.json(query.clone());
}
} else {
queryString = self.urlencode(queryExtended.clone(), &[]);
}
let mut payload: Value = queryString.clone();
if !is_equal(&body, &Value::Null) {
payload = add(&body, &payload);
}
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("hex".to_string())]);
if !is_equal(&queryString, &Value::Str("".to_string())) {
queryString = add(&queryString, &add(&Value::Str("&signature=".to_string()), &signature));
url = add(&url, &add(&Value::Str("?".to_string()), &queryString));
} else {
body = add(&body, &add(&Value::Str("&signature=".to_string()), &signature));
}
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Referrer".to_string(), Value::Str("CCXT".to_string()));
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".to_string())]));
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".to_string()));
m
});
}
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(), body.clone());
m.insert("headers".to_string(), headers.clone());
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 is_equal(&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.clone(), "msg", &[]);
if is_true(&(!is_equal(&errorCode, &Value::Null) && !is_equal(&errorCode, &Value::Str("".to_string())))) && !is_equal(&errorCode, &Value::Str("200".to_string())) && !is_equal(&errorCode, &Value::Str("0".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}