// 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 XtCore {
pub exchange: crate::exchange::Exchange,
}
impl XtCore {
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 = XtCore::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 XtCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::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 XtCore.
XtCore::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 XtCore.
XtCore::parse_deposit_address(self, depositAddress, &[currency.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::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 XtCore.
XtCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on XtCore.
XtCore::parse_market_leverage_tiers(self, info, &[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 XtCore.
XtCore::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 XtCore.
XtCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for XtCore {
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 {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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" => self.create_contract_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_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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_spot_order" => self.create_spot_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,
"edit_order" => self.edit_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,
"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_canceled_orders" => self.fetch_canceled_orders(&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_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_interval" => self.fetch_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_market_leverage_tiers" => self.fetch_market_leverage_tiers(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_interest" => self.fetch_open_interest(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_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_swap_and_future_markets" => self.fetch_swap_and_future_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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_fee" => self.fetch_trading_fee(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)),
"index_position_break_list" => self.index_position_break_list(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"merge_position_break_info" => self.merge_position_break_info(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"modify_margin_helper" => self.modify_margin_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..).unwrap_or(&[]).to_vec()[..]).await,
"nonce" => self.nonce(),
"parse_balance" => self.parse_balance(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_history" => self.parse_funding_history(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_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_leverage_tiers" => self.parse_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(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_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_markets" => self.parse_markets(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_open_interest" => self.parse_open_interest(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_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()[..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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 XtCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for XtCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl XtCore {
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("xt".to_string()));
m.insert("name".to_string(), Value::Str("XT".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("SC".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v4".to_string()));
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::Bool(false));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(true));
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("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
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("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposit".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingInterval".to_string(), Value::Bool(true));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchL3OrderBook".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
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("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTicker".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("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTradingLimits".to_string(), Value::Bool(false));
m.insert("fetchTransactionFee".to_string(), Value::Bool(false));
m.insert("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
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/1f916564-6507-4549-af96-22837bb0a0c7".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("https://sapi.xt.com".to_string()));
m.insert("linear".to_string(), Value::Str("https://fapi.xt.com".to_string()));
m.insert("inverse".to_string(), Value::Str("https://dapi.xt.com".to_string()));
m.insert("user".to_string(), Value::Str("https://api.xt.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://xt.com".to_string()));
m.insert("referral".to_string(), Value::Str("https://www.xt.com/en/accounts/register?ref=9PTM9VW".to_string()));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://doc.xt.com/".to_string()), Value::Str("https://github.com/xtpub/api-doc".to_string())]));
m.insert("fees".to_string(), Value::Str("https://www.xt.com/en/rate".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("symbol".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker/book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker/24h".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/recent".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wallet/support/currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("linear".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("future/market/v1/public/contract/risk-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/contract/open-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/leverage/bracket/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/leverage/bracket/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/agg-ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/agg-tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/deal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/funding-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/funding-rate-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/index-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/mark-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/symbol-index-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/symbol-mark-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/ticker/books".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/symbol/coins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(3.33));
m
}));
m.insert("future/market/v1/public/symbol/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(3.33));
m
}));
m.insert("future/market/v1/public/symbol/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("inverse".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("future/market/v1/public/contract/risk-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/contract/open-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/leverage/bracket/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/leverage/bracket/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/agg-ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/agg-tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/deal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/funding-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/funding-rate-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/index-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/mark-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/symbol-index-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/symbol-mark-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/ticker/books".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/q/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/market/v1/public/symbol/coins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(3.33));
m
}));
m.insert("future/market/v1/public/symbol/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(3.33));
m
}));
m.insert("future/market/v1/public/symbol/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("batch-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposit/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("history-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("open-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdraw/history".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("order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("balance/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("balance/account/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ws-token".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("batch-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("open-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/{orderId}".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("order/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("linear".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("future/trade/v1/entrust/plan-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/plan-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/plan-list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/profit-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/profit-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/track-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/track-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/track-list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/position/list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/trade-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/account/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/funding-rate-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/adl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/break-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/step-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/collection/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/listen-key".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("future/trade/v1/entrust/cancel-all-plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-all-profit-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-all-track".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-profit-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/create-plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-track".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/create-profit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/create-track".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/update-profit-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/create-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/account/open".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/adjust-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/auto-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/close-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/collection/add".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/collection/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/change-type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("inverse".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("future/trade/v1/entrust/plan-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/plan-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/plan-list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/profit-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/profit-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/track-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/track-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/track-list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/position/list-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/trade-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/account/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/funding-rate-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/balance/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/adl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/break-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/step-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/collection/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/listen-key".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("future/trade/v1/entrust/cancel-all-plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-all-profit-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-all-track".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-profit-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/create-plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/cancel-track".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/create-profit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/create-track".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/entrust/update-profit-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/create-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/trade/v1/order/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/account/open".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/adjust-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/auto-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/close-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/collection/add".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/user/collection/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/user/v1/position/change-type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("user".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("user/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("user/account/api-key".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("user/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("user/account/api-key".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("user/account/api-key".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("user/account/{apiKeyId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".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("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.002".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.002".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000".to_string()), &[]), self.parse_number(Value::Str("0.0018".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000".to_string()), &[]), self.parse_number(Value::Str("0.0016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000".to_string()), &[]), self.parse_number(Value::Str("0.0014".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000".to_string()), &[]), self.parse_number(Value::Str("0.0012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("150000".to_string()), &[]), self.parse_number(Value::Str("0.0010".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300000".to_string()), &[]), self.parse_number(Value::Str("0.0008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("600000".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1200000".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6000000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0.0002".to_string()), &[])])]));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000".to_string()), &[]), self.parse_number(Value::Str("0.0018".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000".to_string()), &[]), self.parse_number(Value::Str("0.0016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000".to_string()), &[]), self.parse_number(Value::Str("0.0014".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000".to_string()), &[]), self.parse_number(Value::Str("0.0012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("150000".to_string()), &[]), self.parse_number(Value::Str("0.0010".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300000".to_string()), &[]), self.parse_number(Value::Str("0.0008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("600000".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1200000".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6000000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0.0002".to_string()), &[])])]));
m
}));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0004".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0006".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200000".to_string()), &[]), self.parse_number(Value::Str("0.00038".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.00036".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.00034".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.00032".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000000".to_string()), &[]), self.parse_number(Value::Str("0.00028".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0.00024".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.0002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0.00016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300000000".to_string()), &[]), self.parse_number(Value::Str("0.00012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000000".to_string()), &[]), self.parse_number(Value::Str("0.00008".to_string()), &[])])]));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200000".to_string()), &[]), self.parse_number(Value::Str("0.000588".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.00057".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.00054".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.00051".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000000".to_string()), &[]), self.parse_number(Value::Str("0.00048".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0.00045".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.00045".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0.00036".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300000000".to_string()), &[]), self.parse_number(Value::Str("0.00033".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])])]));
m
}));
m
}));
m
}));
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("400".to_string(), Value::Str("NetworkError".to_string()).clone());
m.insert("404".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("429".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("500".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("502".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("503".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("AUTH_001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_003".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_005".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_006".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_007".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_101".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_102".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_103".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_104".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_105".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("AUTH_106".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("SYMBOL_001".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("SYMBOL_002".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("SYMBOL_003".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("SYMBOL_004".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("SYMBOL_005".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("ORDER_001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_002".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("ORDER_003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_007".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("ORDER_F0101".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0102".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0103".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0201".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0202".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0203".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0301".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0401".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0501".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0502".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_F0601".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("COMMON_001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("COMMON_002".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("COMMON_003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("CURRENCY_001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("DEPOSIT_001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("DEPOSIT_002".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("DEPOSIT_003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("DEPOSIT_004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("DEPOSIT_005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("DEPOSIT_006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("DEPOSIT_007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("DEPOSIT_008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_003".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("WITHDRAW_004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_008".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("WITHDRAW_009".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("WITHDRAW_010".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_011".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("WITHDRAW_012".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("WITHDRAW_013".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("WITHDRAW_014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_015".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_016".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_019".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_020".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("WITHDRAW_021".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("WITHDRAW_022".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_023".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_024".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("WITHDRAW_025".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_002".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("FUND_003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_004".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("FUND_005".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("FUND_014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_015".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_016".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_019".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_020".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_021".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_022".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("FUND_044".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("TRANSFER_001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("TRANSFER_002".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("TRANSFER_003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("TRANSFER_004".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("TRANSFER_005".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("TRANSFER_006".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("TRANSFER_007".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("TRANSFER_008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("TRANSFER_009".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("TRANSFER_010".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("TRANSFER_011".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("TRANSFER_012".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("symbol_not_support_trading_via_api".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("open_order_min_nominal_value_limit".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("insufficient_balance".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("The symbol does not support trading via API".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("Exceeds the minimum notional value of a single order".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("insufficient balance".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
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("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("1d".to_string(), Value::Str("1d".to_string()));
m.insert("3d".to_string(), Value::Str("3d".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("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("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("leverage".to_string(), Value::Str("LEVER".to_string()));
m.insert("finance".to_string(), Value::Str("FINANCE".to_string()));
m.insert("swap".to_string(), Value::Str("FUTURES_U".to_string()));
m.insert("future".to_string(), Value::Str("FUTURES_U".to_string()));
m.insert("linear".to_string(), Value::Str("FUTURES_U".to_string()));
m.insert("inverse".to_string(), Value::Str("FUTURES_C".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ERC20".to_string(), Value::Str("Ethereum".to_string()));
m.insert("TRC20".to_string(), Value::Str("Tron".to_string()));
m.insert("TRX".to_string(), Value::Str("Tron".to_string()));
m.insert("BEP20".to_string(), Value::Str("BNB Smart Chain".to_string()));
m.insert("BEP2".to_string(), Value::Str("BNB-BEP2".to_string()));
m.insert("ETH".to_string(), Value::Str("Ethereum".to_string()));
m.insert("AVAX".to_string(), Value::Str("AVAX C-Chain".to_string()));
m.insert("GAL".to_string(), Value::Str("GAL(FT)".to_string()));
m.insert("ALEO".to_string(), Value::Str("ALEO(IOU)".to_string()));
m.insert("BTC".to_string(), Value::Str("Bitcoin".to_string()));
m.insert("XT".to_string(), Value::Str("XT Smart Chain".to_string()));
m.insert("ETC".to_string(), Value::Str("Ethereum Classic".to_string()));
m.insert("MATIC".to_string(), Value::Str("Polygon".to_string()));
m.insert("LTC".to_string(), Value::Str("Litecoin".to_string()));
m.insert("BTS".to_string(), Value::Str("BitShares".to_string()));
m.insert("XRP".to_string(), Value::Str("Ripple".to_string()));
m.insert("XLM".to_string(), Value::Str("Stellar Network".to_string()));
m.insert("ADA".to_string(), Value::Str("Cardano".to_string()));
m.insert("XWC".to_string(), Value::Str("XWC-XWC".to_string()));
m.insert("DOGE".to_string(), Value::Str("dogecoin".to_string()));
m.insert("DCR".to_string(), Value::Str("Decred".to_string()));
m.insert("SC".to_string(), Value::Str("Siacoin".to_string()));
m.insert("XTZ".to_string(), Value::Str("Tezos".to_string()));
m.insert("ZEC".to_string(), Value::Str("Zcash".to_string()));
m.insert("XMR".to_string(), Value::Str("Monero".to_string()));
m.insert("LSK".to_string(), Value::Str("Lisk".to_string()));
m.insert("ATOM".to_string(), Value::Str("Cosmos".to_string()));
m.insert("ONT".to_string(), Value::Str("Ontology".to_string()));
m.insert("ALGO".to_string(), Value::Str("Algorand".to_string()));
m.insert("SOL".to_string(), Value::Str("SOL-SOL".to_string()));
m.insert("DOT".to_string(), Value::Str("Polkadot".to_string()));
m.insert("ZEN".to_string(), Value::Str("Horizen".to_string()));
m.insert("FIL".to_string(), Value::Str("Filecoin".to_string()));
m.insert("CHZ".to_string(), Value::Str("chz".to_string()));
m.insert("ICP".to_string(), Value::Str("Internet Computer".to_string()));
m.insert("KSM".to_string(), Value::Str("Kusama".to_string()));
m.insert("LUNA".to_string(), Value::Str("Terra".to_string()));
m.insert("THETA".to_string(), Value::Str("Theta Token".to_string()));
m.insert("FTM".to_string(), Value::Str("Fantom".to_string()));
m.insert("VET".to_string(), Value::Str("VeChain".to_string()));
m.insert("NEAR".to_string(), Value::Str("NEAR Protocol".to_string()));
m.insert("ONE".to_string(), Value::Str("Harmony".to_string()));
m.insert("KLAY".to_string(), Value::Str("Klaytn".to_string()));
m.insert("AR".to_string(), Value::Str("Arweave".to_string()));
m.insert("CELT".to_string(), Value::Str("OKT".to_string()));
m.insert("EGLD".to_string(), Value::Str("Elrond eGold".to_string()));
m.insert("CRO".to_string(), Value::Str("CRO-CRONOS".to_string()));
m.insert("BCH".to_string(), Value::Str("Bitcoin Cash".to_string()));
m.insert("GLMR".to_string(), Value::Str("Moonbeam".to_string()));
m.insert("LOOP".to_string(), Value::Str("LOOP-LRC".to_string()));
m.insert("REI".to_string(), Value::Str("REI Network".to_string()));
m.insert("ASTR".to_string(), Value::Str("Astar Network".to_string()));
m.insert("OP".to_string(), Value::Str("OPT".to_string()));
m.insert("MMT".to_string(), Value::Str("MMT-MMT".to_string()));
m.insert("TBC".to_string(), Value::Str("TBC-TBC".to_string()));
m.insert("OMAX".to_string(), Value::Str("OMAX-OMAX CHAIN".to_string()));
m.insert("GMMT".to_string(), Value::Str("GMMT chain".to_string()));
m.insert("ZIL".to_string(), Value::Str("Zilliqa".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Ethereum".to_string(), Value::Str("ERC20".to_string()));
m.insert("Tron".to_string(), Value::Str("TRC20".to_string()));
m.insert("BNB Smart Chain".to_string(), Value::Str("BEP20".to_string()));
m.insert("BNB-BEP2".to_string(), Value::Str("BEP2".to_string()));
m.insert("Bitcoin".to_string(), Value::Str("BTC".to_string()));
m.insert("XT Smart Chain".to_string(), Value::Str("XT".to_string()));
m.insert("Ethereum Classic".to_string(), Value::Str("ETC".to_string()));
m.insert("Polygon".to_string(), Value::Str("MATIC".to_string()));
m.insert("Litecoin".to_string(), Value::Str("LTC".to_string()));
m.insert("BitShares".to_string(), Value::Str("BTS".to_string()));
m.insert("Ripple".to_string(), Value::Str("XRP".to_string()));
m.insert("Stellar Network".to_string(), Value::Str("XLM".to_string()));
m.insert("Cardano".to_string(), Value::Str("ADA".to_string()));
m.insert("XWC-XWC".to_string(), Value::Str("XWC".to_string()));
m.insert("dogecoin".to_string(), Value::Str("DOGE".to_string()));
m.insert("Decred".to_string(), Value::Str("DCR".to_string()));
m.insert("Siacoin".to_string(), Value::Str("SC".to_string()));
m.insert("Tezos".to_string(), Value::Str("XTZ".to_string()));
m.insert("Zcash".to_string(), Value::Str("ZEC".to_string()));
m.insert("Monero".to_string(), Value::Str("XMR".to_string()));
m.insert("Lisk".to_string(), Value::Str("LSK".to_string()));
m.insert("Cosmos".to_string(), Value::Str("ATOM".to_string()));
m.insert("Ontology".to_string(), Value::Str("ONT".to_string()));
m.insert("Algorand".to_string(), Value::Str("ALGO".to_string()));
m.insert("SOL-SOL".to_string(), Value::Str("SOL".to_string()));
m.insert("Polkadot".to_string(), Value::Str("DOT".to_string()));
m.insert("Horizen".to_string(), Value::Str("ZEN".to_string()));
m.insert("Filecoin".to_string(), Value::Str("FIL".to_string()));
m.insert("chz".to_string(), Value::Str("CHZ".to_string()));
m.insert("Internet Computer".to_string(), Value::Str("ICP".to_string()));
m.insert("Kusama".to_string(), Value::Str("KSM".to_string()));
m.insert("Terra".to_string(), Value::Str("LUNA".to_string()));
m.insert("Theta Token".to_string(), Value::Str("THETA".to_string()));
m.insert("Fantom".to_string(), Value::Str("FTM".to_string()));
m.insert("VeChain".to_string(), Value::Str("VET".to_string()));
m.insert("AVAX C-Chain".to_string(), Value::Str("AVAX".to_string()));
m.insert("NEAR Protocol".to_string(), Value::Str("NEAR".to_string()));
m.insert("Harmony".to_string(), Value::Str("ONE".to_string()));
m.insert("Klaytn".to_string(), Value::Str("KLAY".to_string()));
m.insert("Arweave".to_string(), Value::Str("AR".to_string()));
m.insert("OKT".to_string(), Value::Str("CELT".to_string()));
m.insert("Elrond eGold".to_string(), Value::Str("EGLD".to_string()));
m.insert("CRO-CRONOS".to_string(), Value::Str("CRO".to_string()));
m.insert("Bitcoin Cash".to_string(), Value::Str("BCH".to_string()));
m.insert("Moonbeam".to_string(), Value::Str("GLMR".to_string()));
m.insert("LOOP-LRC".to_string(), Value::Str("LOOP".to_string()));
m.insert("REI Network".to_string(), Value::Str("REI".to_string()));
m.insert("Astar Network".to_string(), Value::Str("ASTR".to_string()));
m.insert("GAL(FT)".to_string(), Value::Str("GAL".to_string()));
m.insert("ALEO(IOU)".to_string(), Value::Str("ALEO".to_string()));
m.insert("OPT".to_string(), Value::Str("OP".to_string()));
m.insert("MMT-MMT".to_string(), Value::Str("MMT".to_string()));
m.insert("TBC-TBC".to_string(), Value::Str("TBC".to_string()));
m.insert("OMAX-OMAX CHAIN".to_string(), Value::Str("OMAX".to_string()));
m.insert("GMMT chain".to_string(), Value::Str("GMMT".to_string()));
m.insert("Zilliqa".to_string(), Value::Str("ZIL".to_string()));
m
}));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("recvWindow".to_string(), Value::Str("5000".to_string()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".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(true));
m.insert("triggerPrice".to_string(), Value::Bool(false));
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("triggerPriceType".to_string(), Value::Null);
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("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".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("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("marketType".to_string(), Value::Bool(true));
m.insert("subType".to_string(), Value::Bool(true));
m.insert("symbolRequired".to_string(), Value::Bool(false));
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(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("marketType".to_string(), Value::Bool(true));
m.insert("subType".to_string(), Value::Bool(true));
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(true));
m.insert("limit".to_string(), Value::Int(100));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("marketType".to_string(), Value::Bool(true));
m.insert("subType".to_string(), Value::Bool(true));
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(true));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("marketType".to_string(), Value::Bool(true));
m.insert("subType".to_string(), Value::Bool(true));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("daysBackCanceled".to_string(), Value::Int(1));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("marketType".to_string(), Value::Bool(true));
m.insert("subType".to_string(), Value::Bool(true));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m.insert("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
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::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trailing".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trailing".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trailing".to_string(), Value::Bool(true));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trailing".to_string(), Value::Bool(true));
m
}));
m.insert("fetchCanceledOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trailing".to_string(), Value::Bool(true));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".to_string()));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trailing".to_string(), Value::Bool(true));
m
}));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".to_string()));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trailing".to_string(), Value::Bool(true));
m
}));
m
}));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".to_string()));
m
}));
m
}));
m
}));
m
})]);
Value::Null
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
/*
* @method
* @name xt#fetchTime
* @description fetches the current integer timestamp in milliseconds from the xt server
* @see https://doc.xt.com/docs/spot/Market/GetServerTime
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the xt 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.public_spot_get_time(&[params.clone()]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "serverTime": 1677823301643
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[]);
return self.safe_integer_k(data.clone(), "serverTime", &[]);
Value::Null
}
/*
* @method
* @name xt#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://doc.xt.com/docs/spot/Deposit&Withdrawal/GetSupportedCurrencies
* @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 promisesRaw: Value = Value::List(vec![self.public_spot_get_wallet_support_currency(&[params.clone()]).await, self.public_spot_get_currencies(&[params.clone()]).await]);
let mut chainsResponsecurrenciesResponseVariable = promise_all(&promisesRaw).await;
let mut chainsResponse: Value = get_value(&chainsResponsecurrenciesResponseVariable, &Value::Int(0));
let mut currenciesResponse: Value = get_value(&chainsResponsecurrenciesResponseVariable, &Value::Int(1));
//
// currencies
//
// {
// "time": "1686626116145",
// "version": "5dbbb2f2527c22b2b2e3b47187ef13d1",
// "currencies": [
// {
// "id": "2",
// "currency": "btc",
// "fullName": "Bitcoin",
// "logo": "https://a.static-global.com/1/currency/btc.png",
// "cmcLink": "https://coinmarketcap.com/currencies/bitcoin/",
// "weight": "99999",
// "maxPrecision": "10",
// "depositStatus": "1",
// "withdrawStatus": "1",
// "convertEnabled": "1",
// "transferEnabled": "1",
// "isChainExist": "1",
// "plates": [152]
// },
// ],
// }
//
//
// chains
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": [
// {
// "currency": "btc",
// "supportChains": [
// {
// "chain": "Bitcoin",
// "depositEnabled": true,
// "withdrawEnabled": true,
// "withdrawFeeAmount": 0.0009,
// "withdrawMinAmount": 0.0005,
// "depositFeeRate": 0
// },
// ]
// },
// ]
// }
//
// note: individual network's full data is available on per-currency endpoint: https://www.xt.com/sapi/v4/balance/public/currency/11
//
let mut chainsData: Value = self.safe_list_k(chainsResponse.clone(), "result", &[Value::List(vec![])]);
let mut currenciesResult: Value = self.safe_dict_k(currenciesResponse.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currenciesData: Value = self.safe_list_k(currenciesResult.clone(), "currencies", &[Value::List(vec![])]);
let mut chainsDataIndexed: Value = self.index_by(chainsData.clone(), Value::Str("currency".to_string()));
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1135: bool = true;
while { if !__for_first_1135 { i = add(&i, &Value::Int(1)); } __for_first_1135 = false; is_less_than(&i, &get_array_length(¤ciesData)) } {
let mut entry: Value = get_value(¤ciesData, &i);
let mut entry: Value = get_value(¤ciesData, &i);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut networkEntry: Value = self.safe_dict(chainsDataIndexed.clone(), currencyId.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rawNetworks: Value = self.safe_list_k(networkEntry.clone(), "supportChains", &[Value::List(vec![])]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_1134: bool = true;
while { if !__for_first_1134 { j = add(&j, &Value::Int(1)); } __for_first_1134 = 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(), "chain", &[]);
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("info".to_string(), rawNetwork.clone());
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("name".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), self.safe_number_k(rawNetwork.clone(), "withdrawFeeAmount", &[]));
m.insert("precision".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(rawNetwork.clone(), "depositEnabled", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(rawNetwork.clone(), "withdrawEnabled", &[]));
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(), self.safe_number_k(rawNetwork.clone(), "withdrawMinAmount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".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
}));
}
}
}
let mut typeRaw: Value = self.safe_string_k(entry.clone(), "type", &[]);
let mut type_var: Value = Value::Null;
if is_equal(&typeRaw, &Value::Str("FT".to_string())) {
type_var = Value::Str("crypto".to_string());
} else {
type_var = Value::Str("other".to_string());
}
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("id".to_string(), currencyId.clone());
m.insert("code".to_string(), code.clone());
m.insert("name".to_string(), self.safe_string_k(entry.clone(), "fullName", &[]));
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(entry.clone(), "maxPrecision", &[])]), &[]));
m.insert("deposit".to_string(), Value::Bool(is_equal(&self.safe_string_k(entry.clone(), "depositStatus", &[]), &Value::Str("1".to_string()))));
m.insert("withdraw".to_string(), Value::Bool(is_equal(&self.safe_string_k(entry.clone(), "withdrawStatus", &[]), &Value::Str("1".to_string()))));
m.insert("networks".to_string(), networks.clone());
m.insert("type".to_string(), type_var.clone());
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.insert("deposit".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
})));
}
}
}
return result;
Value::Null
}
/*
* @method
* @name xt#fetchMarkets
* @description retrieves data on all markets for xt
* @see https://doc.xt.com/docs/spot/Market/GetSymbolInformation
* @see https://doc.xt.com/docs/futures/MarketData/get-configuration-information-for-listed-and-tradeable-symbols
* @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
}));
if is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut promisesUnresolved: Value = Value::List(vec![self.fetch_spot_markets(&[params.clone()]).await, self.fetch_swap_and_future_markets(&[params.clone()]).await]);
let mut promises: Value = promise_all(&promisesUnresolved).await;
let mut spotMarkets: Value = get_value(&promises, &Value::Int(0));
let mut swapAndFutureMarkets: Value = get_value(&promises, &Value::Int(1));
return self.array_concat(spotMarkets.clone(), swapAndFutureMarkets.clone());
Value::Null
}
pub async fn fetch_spot_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.public_spot_get_symbol(&[params.clone()]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "time": 1677881368812,
// "version": "abb101d1543e54bee40687b135411ba0",
// "symbols": [
// {
// "id": 640,
// "symbol": "xt_usdt",
// "state": "ONLINE",
// "stateTime": 1554048000000,
// "tradingEnabled": true,
// "openapiEnabled": true,
// "nextStateTime": null,
// "nextState": null,
// "depthMergePrecision": 5,
// "baseCurrency": "xt",
// "baseCurrencyPrecision": 8,
// "baseCurrencyId": 128,
// "quoteCurrency": "usdt",
// "quoteCurrencyPrecision": 8,
// "quoteCurrencyId": 11,
// "pricePrecision": 4,
// "quantityPrecision": 2,
// "orderTypes": ["LIMIT","MARKET"],
// "timeInForces": ["GTC","IOC"],
// "displayWeight": 10002,
// "displayLevel": "FULL",
// "plates": [],
// "filters":[
// {
// "filter": "QUOTE_QTY",
// "min": "1"
// },
// {
// "filter": "PROTECTION_LIMIT",
// "buyMaxDeviation": "0.8",
// "sellMaxDeviation": "4"
// },
// {
// "filter": "PROTECTION_MARKET",
// "maxDeviation": "0.02"
// }
// ]
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut symbols: Value = self.safe_list_k(data.clone(), "symbols", &[Value::List(vec![])]);
return self.parse_markets(symbols.clone());
Value::Null
}
pub async fn fetch_swap_and_future_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 markets: Value = promise_all(&Value::List(vec![self.public_linear_get_future_market_v1_public_symbol_list(&[params.clone()]).await, self.public_inverse_get_future_market_v1_public_symbol_list(&[params.clone()]).await])).await;
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "id": 52,
// "symbolGroupId": 71,
// "symbol": "xt_usdt",
// "pair": "xt_usdt",
// "contractType": "PERPETUAL",
// "productType": "perpetual",
// "predictEventType": null,
// "underlyingType": "U_BASED",
// "contractSize": "1",
// "tradeSwitch": true,
// "isDisplay": true,
// "isOpenApi": false,
// "state": 0,
// "initLeverage": 20,
// "initPositionType": "CROSSED",
// "baseCoin": "xt",
// "quoteCoin": "usdt",
// "baseCoinPrecision": 8,
// "baseCoinDisplayPrecision": 4,
// "quoteCoinPrecision": 8,
// "quoteCoinDisplayPrecision": 4,
// "quantityPrecision": 0,
// "pricePrecision": 4,
// "supportOrderType": "LIMIT,MARKET",
// "supportTimeInForce": "GTC,FOK,IOC,GTX",
// "supportEntrustType": "TAKE_PROFIT,STOP,TAKE_PROFIT_MARKET,STOP_MARKET,TRAILING_STOP_MARKET",
// "supportPositionType": "CROSSED,ISOLATED",
// "minQty": "1",
// "minNotional": "5",
// "maxNotional": "20000000",
// "multiplierDown": "0.1",
// "multiplierUp": "0.1",
// "maxOpenOrders": 200,
// "maxEntrusts": 200,
// "makerFee": "0.0004",
// "takerFee": "0.0006",
// "liquidationFee": "0.01",
// "marketTakeBound": "0.1",
// "depthPrecisionMerge": 5,
// "labels": ["HOT"],
// "onboardDate": 1657101601000,
// "enName": "XTUSDT ",
// "cnName": "XTUSDT",
// "minStepPrice": "0.0001",
// "minPrice": null,
// "maxPrice": null,
// "deliveryDate": 1669879634000,
// "deliveryPrice": null,
// "deliveryCompletion": false,
// "cnDesc": null,
// "enDesc": null
// },
// ]
// }
//
let mut swapAndFutureMarkets: Value = self.array_concat(self.safe_list(get_value(&markets, &Value::Int(0)), Value::Str("result".to_string()), &[Value::List(vec![])]), self.safe_list(get_value(&markets, &Value::Int(1)), Value::Str("result".to_string()), &[Value::List(vec![])]));
return self.parse_markets(swapAndFutureMarkets.clone());
Value::Null
}
pub fn parse_markets(&self, mut markets: Value) -> Value {
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1136: bool = true;
while { if !__for_first_1136 { i = add(&i, &Value::Int(1)); } __for_first_1136 = false; is_less_than(&i, &get_array_length(&markets)) } {
append_to_array(&mut result, self.parse_market(get_value(&markets, &i)));
}
}
return result;
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
//
// spot
//
// {
// "id": 640,
// "symbol": "xt_usdt",
// "state": "ONLINE",
// "stateTime": 1554048000000,
// "tradingEnabled": true,
// "openapiEnabled": true,
// "nextStateTime": null,
// "nextState": null,
// "depthMergePrecision": 5,
// "baseCurrency": "xt",
// "baseCurrencyPrecision": 8,
// "baseCurrencyId": 128,
// "quoteCurrency": "usdt",
// "quoteCurrencyPrecision": 8,
// "quoteCurrencyId": 11,
// "pricePrecision": 4,
// "quantityPrecision": 2,
// "orderTypes": ["LIMIT","MARKET"],
// "timeInForces": ["GTC","IOC"],
// "displayWeight": 10002,
// "displayLevel": "FULL",
// "plates": [],
// "filters":[
// {
// "filter": "QUOTE_QTY",
// "min": "1"
// },
// {
// "filter": "PRICE",
// "min": null,
// "max": null,
// "tickSize": null
// },
// {
// "filter": "QUANTITY",
// "min": null,
// "max": null,
// "tickSize": null
// },
// {
// "filter": "PROTECTION_LIMIT",
// "buyMaxDeviation": "0.8",
// "sellMaxDeviation": "4"
// },
// {
// "filter": "PROTECTION_MARKET",
// "maxDeviation": "0.02"
// },
// {
// "filter": "PROTECTION_ONLINE",
// "durationSeconds": "300",
// "maxPriceMultiple": "5"
// },
// ]
// }
//
// swap and future
//
// {
// "id": 52,
// "symbolGroupId": 71,
// "symbol": "xt_usdt",
// "pair": "xt_usdt",
// "contractType": "PERPETUAL",
// "productType": "perpetual",
// "predictEventType": null,
// "underlyingType": "U_BASED",
// "contractSize": "1",
// "tradeSwitch": true,
// "isDisplay": true,
// "isOpenApi": false,
// "state": 0,
// "initLeverage": 20,
// "initPositionType": "CROSSED",
// "baseCoin": "xt",
// "quoteCoin": "usdt",
// "baseCoinPrecision": 8,
// "baseCoinDisplayPrecision": 4,
// "quoteCoinPrecision": 8,
// "quoteCoinDisplayPrecision": 4,
// "quantityPrecision": 0,
// "pricePrecision": 4,
// "supportOrderType": "LIMIT,MARKET",
// "supportTimeInForce": "GTC,FOK,IOC,GTX",
// "supportEntrustType": "TAKE_PROFIT,STOP,TAKE_PROFIT_MARKET,STOP_MARKET,TRAILING_STOP_MARKET",
// "supportPositionType": "CROSSED,ISOLATED",
// "minQty": "1",
// "minNotional": "5",
// "maxNotional": "20000000",
// "multiplierDown": "0.1",
// "multiplierUp": "0.1",
// "maxOpenOrders": 200,
// "maxEntrusts": 200,
// "makerFee": "0.0004",
// "takerFee": "0.0006",
// "liquidationFee": "0.01",
// "marketTakeBound": "0.1",
// "depthPrecisionMerge": 5,
// "labels": ["HOT"],
// "onboardDate": 1657101601000,
// "enName": "XTUSDT ",
// "cnName": "XTUSDT",
// "minStepPrice": "0.0001",
// "minPrice": null,
// "maxPrice": null,
// "deliveryDate": 1669879634000,
// "deliveryPrice": null,
// "deliveryCompletion": false,
// "cnDesc": null,
// "enDesc": null
// }
//
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string2(market.clone(), Value::Str("baseCurrency".to_string()), Value::Str("baseCoin".to_string()), &[]);
let mut quoteId: Value = self.safe_string2(market.clone(), Value::Str("quoteCurrency".to_string()), Value::Str("quoteCoin".to_string()), &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut state: Value = self.safe_string_k(market.clone(), "state", &[]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut filters: Value = self.safe_list_k(market.clone(), "filters", &[Value::List(vec![])]);
let mut minAmount: Value = Value::Null;
let mut maxAmount: Value = Value::Null;
let mut minCost: Value = Value::Null;
let mut maxCost: Value = Value::Null;
let mut minPrice: Value = Value::Null;
let mut maxPrice: Value = Value::Null;
let mut amountPrecision: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_1137: bool = true;
while { if !__for_first_1137 { i = add(&i, &Value::Int(1)); } __for_first_1137 = false; is_less_than(&i, &get_array_length(&filters)) } {
let mut entry: Value = get_value(&filters, &i);
let mut entry: Value = get_value(&filters, &i);
let mut filter: Value = self.safe_string_k(entry.clone(), "filter", &[]);
if is_equal(&filter, &Value::Str("QUANTITY".to_string())) {
minAmount = self.safe_number_k(entry.clone(), "min", &[]);
maxAmount = self.safe_number_k(entry.clone(), "max", &[]);
amountPrecision = self.safe_number_k(entry.clone(), "tickSize", &[]);
}
if is_equal(&filter, &Value::Str("QUOTE_QTY".to_string())) {
minCost = self.safe_number_k(entry.clone(), "min", &[]);
}
if is_equal(&filter, &Value::Str("PRICE".to_string())) {
minPrice = self.safe_number_k(entry.clone(), "min", &[]);
maxPrice = self.safe_number_k(entry.clone(), "max", &[]);
}
}
}
if is_equal(&amountPrecision, &Value::Null) {
amountPrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quantityPrecision", &[])]), &[]);
}
let mut underlyingType: Value = self.safe_string_k(market.clone(), "underlyingType", &[]);
let mut linear: Value = Value::Null;
let mut inverse: Value = Value::Null;
let mut settleId: Value = Value::Null;
let mut settle: Value = Value::Null;
let mut expiry: Value = Value::Null;
let mut future: Value = Value::Bool(false);
let mut swap: Value = Value::Bool(false);
let mut contract: Value = Value::Bool(false);
let mut spot: Value = Value::Bool(true);
let mut type_var: Value = Value::Str("spot".to_string());
if is_equal(&underlyingType, &Value::Str("U_BASED".to_string())) {
symbol = add(&add(&symbol, &Value::Str(":".to_string())), "e);
settleId = baseId.clone();
settle = quote.clone();
linear = Value::Bool(true);
inverse = Value::Bool(false);
} else if is_equal(&underlyingType, &Value::Str("COIN_BASED".to_string())) {
symbol = add(&add(&symbol, &Value::Str(":".to_string())), &base);
settleId = baseId.clone();
settle = base.clone();
linear = Value::Bool(false);
inverse = Value::Bool(true);
}
if !is_equal(&underlyingType, &Value::Null) {
expiry = self.safe_integer_k(market.clone(), "deliveryDate", &[]);
let mut productType: Value = self.safe_string_k(market.clone(), "productType", &[]);
if !is_equal(&productType, &Value::Str("perpetual".to_string())) {
symbol = add(&add(&symbol, &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[]));
type_var = Value::Str("future".to_string());
future = Value::Bool(true);
} else {
type_var = Value::Str("swap".to_string());
swap = Value::Bool(true);
}
minAmount = self.safe_number_k(market.clone(), "minQty", &[]);
minCost = self.safe_number_k(market.clone(), "minNotional", &[]);
maxCost = self.safe_number_k(market.clone(), "maxNotional", &[]);
minPrice = self.safe_number_k(market.clone(), "minPrice", &[]);
maxPrice = self.safe_number_k(market.clone(), "maxPrice", &[]);
contract = Value::Bool(true);
spot = Value::Bool(false);
}
let mut isActive: Value = Value::Bool(false);
if is_true(&contract) {
isActive = self.safe_bool_k(market.clone(), "isOpenApi", &[Value::Bool(false)]);
} else {
if is_true(&(is_equal(&state, &Value::Str("ONLINE".to_string())))) && is_true(&(is_equal(&self.safe_bool_k(market.clone(), "tradingEnabled", &[]), &Value::Bool(true)))) && is_true(&(is_equal(&self.safe_bool_k(market.clone(), "openapiEnabled", &[]), &Value::Bool(true)))) {
isActive = Value::Bool(true);
}
}
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(), type_var.clone());
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), future.clone());
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), isActive.clone());
m.insert("contract".to_string(), contract.clone());
m.insert("linear".to_string(), linear.clone());
m.insert("inverse".to_string(), inverse.clone());
m.insert("taker".to_string(), self.safe_number2(market.clone(), Value::Str("takerFee".to_string()), Value::Str("takerFeeRate".to_string()), &[]));
m.insert("maker".to_string(), self.safe_number2(market.clone(), Value::Str("makerFee".to_string()), Value::Str("makerFeeRate".to_string()), &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
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("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "pricePrecision", &[])]), &[]));
m.insert("amount".to_string(), amountPrecision.clone());
m.insert("base".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "baseCoinPrecision", &[])]), &[]));
m.insert("quote".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quoteCoinPrecision", &[])]), &[]));
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(), self.parse_number(Value::Str("1".to_string()), &[]));
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(), minAmount.clone());
m.insert("max".to_string(), maxAmount.clone());
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minPrice.clone());
m.insert("max".to_string(), maxPrice.clone());
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minCost.clone());
m.insert("max".to_string(), maxCost.clone());
m
}));
m
}));
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name xt#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://doc.xt.com/docs/spot/Market/GetKlineData
* @see https://doc.xt.com/docs/futures/MarketData/get-trading-pair-information-of-kline
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle 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 [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); 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("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(1000)]).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) {
// xt rounds startTime down to the candle boundary, which makes a mid-candle
// window start return one pre-since candle, shifting paginated windows and
// dropping one candle per page - align up so the rounding is a no-op, see https://github.com/ccxt/ccxt/issues/25285
let mut duration: Value = multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000));
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), multiply(&math_ceil(÷(&since, &duration)), &duration));
}
if !is_equal(&limit, &Value::Null) {
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
limit = crate::runtime::Math::min(&limit, &Value::Int(1000)); // spot max limit
} else {
limit = crate::runtime::Math::min(&limit, &Value::Int(1500)); // derivatives max limit
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), Value::Int(1000));
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_kline(&[__ws_arg_0]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_kline(&[__ws_arg_1]).await;
} else {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.public_spot_get_kline(&[__ws_arg_2]).await;
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": [
// {
// "t": 1678167720000,
// "o": "22467.85",
// "c": "22465.87",
// "h": "22468.86",
// "l": "22465.21",
// "q": "1.316656",
// "v": "29582.73018498"
// },
// ]
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "s": "btc_usdt",
// "p": "btc_usdt",
// "t": 1678168020000,
// "o": "22450.0",
// "c": "22441.5",
// "h": "22450.0",
// "l": "22441.5",
// "a": "312931",
// "v": "702461.58895"
// },
// ]
// }
//
let mut ohlcvs: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_ohlc_vs(ohlcvs.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);
//
// spot
//
// {
// "t": 1678167720000,
// "o": "22467.85",
// "c": "22465.87",
// "h": "22468.86",
// "l": "22465.21",
// "q": "1.316656",
// "v": "29582.73018498"
// }
//
// swap and future
//
// {
// "s": "btc_usdt",
// "p": "btc_usdt",
// "t": 1678168020000,
// "o": "22450.0",
// "c": "22441.5",
// "h": "22450.0",
// "l": "22441.5",
// "a": "312931",
// "v": "702461.58895"
// }
//
let mut isInverse: Value = self.safe_bool_k(market.clone(), "inverse", &[]);
let mut volumeIndex: Value = ternary(is_true(&(is_equal(&isInverse, &Value::Bool(true)))), Value::Str("v".to_string()), Value::Str("a".to_string()));
return Value::List(vec![self.safe_integer_k(ohlcv.clone(), "t", &[]), self.safe_number_k(ohlcv.clone(), "o", &[]), self.safe_number_k(ohlcv.clone(), "h", &[]), self.safe_number_k(ohlcv.clone(), "l", &[]), self.safe_number_k(ohlcv.clone(), "c", &[]), self.safe_number2(ohlcv.clone(), Value::Str("q".to_string()), volumeIndex.clone(), &[])]);
Value::Null
}
/*
* @method
* @name xt#fetchOrderBook
* @see https://doc.xt.com/docs/spot/Market/GetDepthData
* @see https://doc.xt.com/docs/futures/MarketData/get-depth-data-of-trading-pairs
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @param {string} symbol unified market symbol 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/en/latest/manual.html#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
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(500)));
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.public_spot_get_depth(&[__ws_arg_3]).await;
} else {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("level".to_string()), crate::runtime::Math::min(&limit, &Value::Int(50)));
} else {
add_element_to_object(&mut request, &Value::Str("level".to_string()), Value::Int(50));
}
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_depth(&[__ws_arg_4]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_depth(&[__ws_arg_5]).await;
}
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "timestamp": 1678169975184,
// "lastUpdateId": 1675333221812,
// "bids": [
// ["22444.51", "0.129887"],
// ["22444.49", "0.114245"],
// ["22444.30", "0.225956"]
// ],
// "asks": [
// ["22446.19", "0.095330"],
// ["22446.24", "0.224413"],
// ["22446.28", "0.329095"]
// ]
// }
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "t": 1678170311005,
// "s": "btc_usdt",
// "u": 471694545627,
// "b": [
// ["22426", "198623"],
// ["22423.5", "80295"],
// ["22423", "163580"]
// ],
// "a": [
// ["22427", "3417"],
// ["22428.5", "43532"],
// ["22429", "119"]
// ]
// }
// }
//
let mut orderBook: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer2(orderBook.clone(), Value::Str("timestamp".to_string()), Value::Str("t".to_string()), &[]);
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let mut ob: Value = self.parse_order_book(orderBook.clone(), symbol.clone(), &[timestamp.clone()]);
add_element_to_object(&mut ob, &Value::Str("nonce".to_string()), self.safe_integer_k(orderBook.clone(), "lastUpdateId", &[]));
return ob;
}
let mut swapOb: Value = self.parse_order_book(orderBook.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("b".to_string()), Value::Str("a".to_string())]);
add_element_to_object(&mut swapOb, &Value::Str("nonce".to_string()), self.safe_integer2(orderBook.clone(), Value::Str("u".to_string()), Value::Str("lastUpdateId".to_string()), &[]));
return swapOb;
Value::Null
}
/*
* @method
* @name xt#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://doc.xt.com/docs/spot/Market/Get24hStatisticsTicker
* @see https://doc.xt.com/docs/futures/MarketData/get-aggregated-market-information-for-specific-trading-pair
* @param {string} symbol unified market symbol to fetch the ticker for
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/en/latest/manual.html#ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
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 mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_agg_ticker(&[__ws_arg_6]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_agg_ticker(&[__ws_arg_7]).await;
} else {
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.public_spot_get_ticker24h(&[__ws_arg_8]).await;
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": [
// {
// "s": "btc_usdt",
// "t": 1678172693931,
// "cv": "34.00",
// "cr": "0.0015",
// "o": "22398.05",
// "l": "22323.72",
// "h": "22600.50",
// "c": "22432.05",
// "q": "7962.256931",
// "v": "178675209.47416856"
// }
// ]
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "t": 1678172848572,
// "s": "btc_usdt",
// "c": "22415.5",
// "h": "22590.0",
// "l": "22310.0",
// "a": "623654031",
// "v": "1399166074.31675",
// "o": "22381.5",
// "r": "0.0015",
// "i": "22424.5",
// "m": "22416.5",
// "bp": "22415",
// "ap": "22415.5"
// }
// }
//
let mut ticker: Value = self.safe_value_k(response.clone(), "result", &[]);
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
return self.parse_ticker(get_value(&ticker, &Value::Int(0)), &[market.clone()]);
}
return self.parse_ticker(ticker.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchTickers
* @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market
* @see https://doc.xt.com/docs/spot/Market/Get24hStatisticsTicker
* @see https://doc.xt.com/docs/futures/MarketData/get_aggregated_market_information_for_all_trading_pairs
* @param {string} [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} an array of [ticker structures]{@link https://docs.ccxt.com/en/latest/manual.html#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;
}
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
market = self.market(get_value(&symbols, &Value::Int(0)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ 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 __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_agg_tickers(&[__ws_arg_9]).await;
} else if is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_agg_tickers(&[__ws_arg_10]).await;
} else {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.public_spot_get_ticker24h(&[__ws_arg_11]).await;
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": [
// {
// "s": "btc_usdt",
// "t": 1678172693931,
// "cv": "34.00",
// "cr": "0.0015",
// "o": "22398.05",
// "l": "22323.72",
// "h": "22600.50",
// "c": "22432.05",
// "q": "7962.256931",
// "v": "178675209.47416856"
// }
// ]
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "t": 1680738775108,
// "s": "badger_usdt",
// "c": "2.7176",
// "h": "2.7917",
// "l": "2.6818",
// "a": "88332",
// "v": "242286.3520",
// "o": "2.7422",
// "r": "-0.0089",
// "i": "2.7155",
// "m": "2.7161",
// "bp": "2.7152",
// "ap": "2.7176"
// },
// ]
// }
//
let mut tickers: Value = self.safe_list_k(response.clone(), "result", &[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_1138: bool = true;
while { if !__for_first_1138 { i = add(&i, &Value::Int(1)); } __for_first_1138 = false; is_less_than(&i, &get_array_length(&tickers)) } {
let mut ticker: Value = self.parse_ticker(get_value(&tickers, &i), &[market.clone()]);
let mut symbol: Value = get_value(&ticker, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut result, &symbol, ticker.clone());
}
}
}
return self.filter_by_array(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchBidsAsks
* @description fetches the bid and ask price and volume for multiple markets
* @see https://doc.xt.com/docs/spot/Market/GetBestPendingOrderTicker
* @see https://doc.xt.com/docs/futures/MarketData/get-ask-bid-market-information-for-all-trading-pairs
* @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/en/latest/manual.html#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
});
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
market = self.market(get_value(&symbols, &Value::Int(0)));
}
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBidsAsks".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchBidsAsks".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isInverse: bool = is_equal(&subType, &Value::Str("inverse".to_string()));
let mut isLinear: bool = is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
let mut isContract: bool = is_true(&isInverse) || is_true(&isLinear);
let mut response: Value = Value::Null;
if is_true(&isInverse) {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_ticker_books(&[__ws_arg_12]).await;
} else if is_true(&isLinear) {
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_ticker_books(&[__ws_arg_13]).await;
} else {
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.public_spot_get_ticker_book(&[__ws_arg_14]).await;
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": [
// {
// "s": "kas_usdt",
// "t": 1679539891853,
// "ap": "0.016298",
// "aq": "5119.09",
// "bp": "0.016290",
// "bq": "135.37"
// },
// ]
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "s": "btc_usdt",
// "t": 1785928174370,
// "ap": "64085.5",
// "aq": "101843",
// "bp": "64085.3",
// "bq": "121042"
// },
// ]
// }
//
let mut tickers: Value = self.safe_list_k(response.clone(), "result", &[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_1139: bool = true;
while { if !__for_first_1139 { i = add(&i, &Value::Int(1)); } __for_first_1139 = false; is_less_than(&i, &get_array_length(&tickers)) } {
let mut rawTicker: Value = get_value(&tickers, &i);
let mut rawTicker: Value = get_value(&tickers, &i);
// the spot and contract payloads share the same field names, so
// the market type cannot be inferred from the entry itself
let mut marketId: Value = self.safe_string_k(rawTicker.clone(), "s", &[]);
let mut marketType: Value = ternary(is_true(&isContract), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
let mut marketInner: Value = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string()), marketType.clone()]);
let mut ticker: Value = self.parse_ticker(rawTicker.clone(), &[marketInner.clone()]);
let mut symbol: Value = get_value(&ticker, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut result, &symbol, ticker.clone());
}
}
}
return self.filter_by_array(result.clone(), Value::Str("symbol".to_string()), &[symbols.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);
//
// spot: fetchTicker, fetchTickers
//
// {
// "s": "btc_usdt",
// "t": 1678172693931,
// "cv": "34.00",
// "cr": "0.0015",
// "o": "22398.05",
// "l": "22323.72",
// "h": "22600.50",
// "c": "22432.05",
// "q": "7962.256931",
// "v": "178675209.47416856"
// }
//
// swap and future: fetchTicker, fetchTickers
//
// {
// "t": 1678172848572,
// "s": "btc_usdt",
// "c": "22415.5",
// "h": "22590.0",
// "l": "22310.0",
// "a": "623654031",
// "v": "1399166074.31675",
// "o": "22381.5",
// "r": "0.0015",
// "i": "22424.5",
// "m": "22416.5",
// "bp": "22415",
// "ap": "22415.5"
// }
//
// fetchBidsAsks
//
// {
// "s": "kas_usdt",
// "t": 1679539891853,
// "ap": "0.016298",
// "aq": "5119.09",
// "bp": "0.016290",
// "bq": "135.37"
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "s", &[]);
let mut marketType: Value = ternary(is_true(&(!is_equal(&market, &Value::Null))), get_value(&market, &Value::Str("type".to_string())), Value::Null);
let mut hasSpotKeys: bool = is_true(&(Value::Bool(in_op(&ticker, &Value::Str("cv".to_string()))))) || is_true(&(Value::Bool(in_op(&ticker, &Value::Str("aq".to_string())))));
if is_equal(&marketType, &Value::Null) {
marketType = ternary(is_true(&hasSpotKeys), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
}
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string()), marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
let mut percentage: Value = self.safe_string2(ticker.clone(), Value::Str("cr".to_string()), Value::Str("r".to_string()), &[]);
if !is_equal(&percentage, &Value::Null) {
percentage = crate::precise::Precise::stringMul(&percentage, &Value::Str("100".to_string()));
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_number_k(ticker.clone(), "h", &[]));
m.insert("low".to_string(), self.safe_number_k(ticker.clone(), "l", &[]));
m.insert("bid".to_string(), self.safe_number_k(ticker.clone(), "bp", &[]));
m.insert("bidVolume".to_string(), self.safe_number_k(ticker.clone(), "bq", &[]));
m.insert("ask".to_string(), self.safe_number_k(ticker.clone(), "ap", &[]));
m.insert("askVolume".to_string(), self.safe_number_k(ticker.clone(), "aq", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "o", &[]));
m.insert("close".to_string(), self.safe_string_k(ticker.clone(), "c", &[]));
m.insert("last".to_string(), self.safe_string_k(ticker.clone(), "c", &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_number_k(ticker.clone(), "cv", &[]));
m.insert("percentage".to_string(), self.parse_number(percentage.clone(), &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_number2(ticker.clone(), Value::Str("a".to_string()), Value::Str("q".to_string()), &[]));
m.insert("quoteVolume".to_string(), self.safe_number_k(ticker.clone(), "v", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://doc.xt.com/docs/spot/Market/QueryRecentTransactions
* @see https://doc.xt.com/docs/futures/MarketData/get-latest-transaction-information-of-trading-pairs
* @param {string} symbol unified market symbol to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#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
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.public_spot_get_trade_recent(&[__ws_arg_15]).await;
} else {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("num".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_deal(&[__ws_arg_16]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_deal(&[__ws_arg_17]).await;
}
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": [
// {
// "i": 203530723141917063,
// "t": 1678227505815,
// "p": "22038.81",
// "q": "0.000978",
// "v": "21.55395618",
// "b": true
// },
// ]
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "t": 1678227683897,
// "s": "btc_usdt",
// "p": "22031",
// "a": "1067",
// "m": "BID"
// },
// ]
// }
//
let mut trades: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_trades(trades.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchMyTrades
* @description fetch all trades made by the user
* @see https://doc.xt.com/docs/spot/Trade/QueryTrade
* @see https://doc.xt.com/docs/futures/Order/see-transaction-details
* @param {string} [symbol] unified market symbol to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
*/
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(&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 mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone());
}
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_order_trade_list(&[__ws_arg_18]).await;
} else {
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_order_trade_list(&[__ws_arg_19]).await;
}
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchMyTrades".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginOrSpotRequest: Value = ternary(is_true(&(!is_equal(&marginMode, &Value::Null))), Value::Str("LEVER".to_string()), Value::Str("SPOT".to_string()));
add_element_to_object(&mut request, &Value::Str("bizType".to_string()), marginOrSpotRequest.clone());
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_get_trade(&[__ws_arg_20]).await;
}
//
// spot and margin
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "hasPrev": false,
// "hasNext": false,
// "items": [
// {
// "symbol": "btc_usdt",
// "tradeId": "206906233569974658",
// "orderId": "206906233178463488",
// "orderSide": "SELL",
// "orderType": "MARKET",
// "bizType": "SPOT",
// "time": 1679032290215,
// "price": "25703.46",
// "quantity": "0.000099",
// "quoteQty": "2.54464254",
// "baseCurrency": "btc",
// "quoteCurrency": "usdt",
// "fee": "0.00508929",
// "feeCurrency": "usdt",
// "takerMaker": "TAKER"
// },
// ]
// }
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "page": 1,
// "ps": 10,
// "total": 2,
// "items": [
// {
// "orderId": "207260566170987200",
// "execId": "207260566790603265",
// "symbol": "btc_usdt",
// "quantity": "13",
// "price": "27368",
// "fee": "0.02134704",
// "feeCoin": "usdt",
// "timestamp": 1679116769838,
// "takerMaker": "TAKER"
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_trades(trades.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);
//
// spot: fetchTrades
//
// {
// "i": 203530723141917063,
// "t": 1678227505815,
// "p": "22038.81",
// "q": "0.000978",
// "v": "21.55395618",
// "b": true
// }
//
// spot: watchTrades
//
// {
// s: 'btc_usdt',
// i: '228825383103928709',
// t: 1684258222702,
// p: '27003.65',
// q: '0.000796',
// b: true
// }
//
// spot: watchMyTrades
//
// {
// "s": "btc_usdt", // symbol
// "t": 1656043204763, // time
// "i": "6316559590087251233", // tradeId
// "oi": "6216559590087220004", // orderId
// "p": "30000", // trade price
// "q": "3", // qty quantity
// "v": "90000" // volume trade amount
// }
//
// swap and future: fetchTrades
//
// {
// "t": 1678227683897,
// "s": "btc_usdt",
// "p": "22031",
// "a": "1067",
// "m": "BID"
// }
//
// spot: fetchMyTrades
//
// {
// "symbol": "btc_usdt",
// "tradeId": "206906233569974658",
// "orderId": "206906233178463488",
// "orderSide": "SELL",
// "orderType": "MARKET",
// "bizType": "SPOT",
// "time": 1679032290215,
// "price": "25703.46",
// "quantity": "0.000099",
// "quoteQty": "2.54464254",
// "baseCurrency": "btc",
// "quoteCurrency": "usdt",
// "fee": "0.00508929",
// "feeCurrency": "usdt",
// "takerMaker": "TAKER"
// }
//
// swap and future: fetchMyTrades
//
// {
// "orderId": "207260566170987200",
// "execId": "207260566790603265",
// "symbol": "btc_usdt",
// "quantity": "13",
// "price": "27368",
// "fee": "0.02134704",
// "feeCoin": "usdt",
// "timestamp": 1679116769838,
// "takerMaker": "TAKER"
// }
//
// contract watchMyTrades
//
// {
// "symbol": 'btc_usdt',
// "orderSide": 'SELL',
// "positionSide": 'LONG',
// "orderId": '231485367663419328',
// "price": '27152.7',
// "quantity": '33',
// "marginUnfrozen": '2.85318000',
// "timestamp": 1684892412565
// }
//
// watchMyTrades (ws, swap)
//
// {
// 'fee': '0.04080840',
// 'isMaker': False,
// 'marginUnfrozen': '0.75711984',
// 'orderId': '376172779053188416',
// 'orderSide': 'BUY',
// 'positionSide': 'LONG',
// 'price': '3400.70',
// 'quantity': '2',
// 'symbol': 'eth_usdt',
// 'timestamp': 1719388579622
// }
//
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("s".to_string()), Value::Str("symbol".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(!is_equal(&market, &Value::Null))), get_value(&market, &Value::Str("type".to_string())), Value::Null);
let mut hasSpotKeys: bool = is_true(&(Value::Bool(in_op(&trade, &Value::Str("b".to_string()))))) || is_true(&(Value::Bool(in_op(&trade, &Value::Str("bizType".to_string()))))) || is_true(&(Value::Bool(in_op(&trade, &Value::Str("oi".to_string())))));
if is_equal(&marketType, &Value::Null) {
marketType = ternary(is_true(&hasSpotKeys), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
}
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string()), marketType.clone()]);
let mut side: Value = Value::Null;
let mut takerOrMaker: Value = Value::Null;
let mut isBuyerMaker: Value = self.safe_bool_k(trade.clone(), "b", &[]);
if !is_equal(&isBuyerMaker, &Value::Null) {
side = ternary(is_true(&isBuyerMaker), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
takerOrMaker = Value::Str("taker".to_string()); // public trades always taker
} else {
let mut takerMaker: Value = self.safe_string_lower(trade.clone(), Value::Str("takerMaker".to_string()), &[]);
if !is_equal(&takerMaker, &Value::Null) {
takerOrMaker = takerMaker.clone();
} else {
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "isMaker", &[]);
if !is_equal(&isMaker, &Value::Null) {
takerOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
}
let mut orderSide: Value = self.safe_string_lower(trade.clone(), Value::Str("orderSide".to_string()), &[]);
if !is_equal(&orderSide, &Value::Null) {
side = orderSide.clone();
} else {
let mut bidOrAsk: Value = self.safe_string_k(trade.clone(), "m", &[]);
if !is_equal(&bidOrAsk, &Value::Null) {
side = ternary(is_true(&(is_equal(&bidOrAsk, &Value::Str("BID".to_string())))), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
}
}
}
let mut timestamp: Value = self.safe_integer_n(trade.clone(), Value::List(vec![Value::Str("t".to_string()), Value::Str("time".to_string()), Value::Str("timestamp".to_string())]), &[]);
let mut quantity: Value = self.safe_string2(trade.clone(), Value::Str("q".to_string()), Value::Str("quantity".to_string()), &[]);
let mut amount: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
amount = quantity.clone();
} else {
if is_equal(&quantity, &Value::Null) {
amount = crate::precise::Precise::stringMul(&self.safe_string_k(trade.clone(), "a", &[]), &self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string()))));
} else {
amount = crate::precise::Precise::stringMul(&quantity, &self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string()))));
}
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("i".to_string()), Value::Str("tradeId".to_string()), Value::Str("execId".to_string())]), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("order".to_string(), self.safe_string2(trade.clone(), Value::Str("orderId".to_string()), Value::Str("oi".to_string()), &[]));
m.insert("type".to_string(), self.safe_string_lower(trade.clone(), Value::Str("orderType".to_string()), &[]));
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), self.safe_string2(trade.clone(), Value::Str("p".to_string()), Value::Str("price".to_string()), &[]));
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string2(trade.clone(), Value::Str("feeCurrency".to_string()), Value::Str("feeCoin".to_string()), &[]), &[]));
m.insert("cost".to_string(), self.safe_string_k(trade.clone(), "fee", &[]));
m
}));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://doc.xt.com/docs/spot/Balance/GetBalances
* @see https://doc.xt.com/docs/futures/User/GetUserFunds
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/en/latest/manual.html?#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 type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isContractWallet: bool = is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.private_inverse_get_future_user_v1_balance_list(&[params.clone()]).await;
} else if is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&isContractWallet) {
response = self.private_linear_get_future_user_v1_balance_list(&[params.clone()]).await;
} else {
response = self.private_spot_get_balances(&[params.clone()]).await;
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "totalUsdtAmount": "31.75931133",
// "totalBtcAmount": "0.00115951",
// "assets": [
// {
// "currency": "usdt",
// "currencyId": 11,
// "frozenAmount": "0.03834082",
// "availableAmount": "31.70995965",
// "totalAmount": "31.74830047",
// "convertBtcAmount": "0.00115911",
// "convertUsdtAmount": "31.74830047"
// },
// ]
// }
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "coin": "usdt",
// "walletBalance": "19.29849875",
// "openOrderMarginFrozen": "0",
// "isolatedMargin": "0.709475",
// "crossedMargin": "0",
// "availableBalance": "18.58902375",
// "bonus": "0",
// "coupon":"0"
// }
// ]
// }
//
let mut balances: Value = Value::Null;
if is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&isContractWallet) {
balances = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
} else {
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
balances = self.safe_list_k(data.clone(), "assets", &[Value::List(vec![])]);
}
return self.parse_balance(balances.clone());
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
//
// spot
//
// {
// "currency": "usdt",
// "currencyId": 11,
// "frozenAmount": "0.03834082",
// "availableAmount": "31.70995965",
// "totalAmount": "31.74830047",
// "convertBtcAmount": "0.00115911",
// "convertUsdtAmount": "31.74830047"
// }
//
// swap and future
//
// {
// "coin": "usdt",
// "walletBalance": "19.29849875",
// "openOrderMarginFrozen": "0",
// "isolatedMargin": "0.709475",
// "crossedMargin": "0",
// "availableBalance": "18.58902375",
// "bonus": "0",
// "coupon":"0"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1140: bool = true;
while { if !__for_first_1140 { i = add(&i, &Value::Int(1)); } __for_first_1140 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut balance: Value = get_value(&response, &i);
let mut balance: Value = get_value(&response, &i);
let mut currencyId: Value = self.safe_string2(balance.clone(), Value::Str("currency".to_string()), Value::Str("coin".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
let mut free: Value = self.safe_string2(balance.clone(), Value::Str("availableAmount".to_string()), Value::Str("availableBalance".to_string()), &[]);
let mut used: Value = self.safe_string_k(balance.clone(), "frozenAmount", &[]);
let mut total: Value = self.safe_string2(balance.clone(), Value::Str("totalAmount".to_string()), Value::Str("walletBalance".to_string()), &[]);
if is_equal(&used, &Value::Null) {
let mut crossedAndIsolatedMargin: Value = crate::precise::Precise::stringAdd(&self.safe_string_k(balance.clone(), "crossedMargin", &[]), &self.safe_string_k(balance.clone(), "isolatedMargin", &[]));
used = crate::precise::Precise::stringAdd(&self.safe_string_k(balance.clone(), "openOrderMarginFrozen", &[]), &crossedAndIsolatedMargin);
}
add_element_to_object(&mut account, &Value::Str("free".to_string()), free.clone());
add_element_to_object(&mut account, &Value::Str("used".to_string()), used.clone());
add_element_to_object(&mut account, &Value::Str("total".to_string()), total.clone());
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 xt#createMarketBuyOrderWithCost
* @see https://doc.xt.com/docs/spot/Order/SubmitOrder
* @description create a market buy order by providing the symbol and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @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 create_market_buy_order_with_cost(&mut self, mut symbol: Value, mut cost: 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());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketBuyOrderWithCost() supports spot orders only".to_string()))));
}
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), cost.clone(), &[Value::Int(1), params.clone()]).await;
Value::Null
}
/*
* @method
* @name xt#createOrder
* @description create a trade order
* @see https://doc.xt.com/docs/spot/Order/SubmitOrder
* @see https://doc.xt.com/docs/futures/Order/Create%20Orders
* @see https://doc.xt.com/docs/futures/Entrust/CreateTriggerOrders
* @see https://doc.xt.com/docs/futures/Entrust/CreateStopLimit
* @see https://doc.xt.com/docs/futures/Entrust/CreateTrack
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price to fulfill the order, in units of the quote currency, can be ignored in market orders
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', 'PO' or 'GTX'
* @param {bool} [params.postOnly] true or false whether the order is post-only, mapped to timeInForce GTX
* @param {string} [params.entrustType] 'TAKE_PROFIT', 'STOP', 'TAKE_PROFIT_MARKET', 'STOP_MARKET', 'TRAILING_STOP_MARKET', required if stopPrice is defined, currently isn't functioning on xt's side
* @param {string} [params.triggerPriceType] 'INDEX_PRICE', 'MARK_PRICE', 'LATEST_PRICE', required if stopPrice is defined
* @param {float} [params.triggerPrice] price to trigger a stop order
* @param {float} [params.stopPrice] alias for triggerPrice
* @param {float} [params.stopLoss] price to set a stop-loss on an open position
* @param {float} [params.takeProfit] price to set a take-profit on an open position
* @param {float} [params.trailingPercent] the percent to trail away from the current market price, swap markets only
* @param {float} [params.trailingAmount] the quote amount to trail away from the current market price, swap markets only
* @param {float} [params.trailingTriggerPrice] the price to activate a trailing order, swap markets only
* @param {string} [params.marginMode] 'cross' or 'isolated', for trailing orders only, default is 'cross'
* @returns {object} an [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#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());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let mut isTrailing: bool = is_true(&(Value::Bool(in_op(¶ms, &Value::Str("trailingPercent".to_string()))))) || is_true(&(Value::Bool(in_op(¶ms, &Value::Str("trailingAmount".to_string()))))) || is_true(&(Value::Bool(in_op(¶ms, &Value::Str("trailingTriggerPrice".to_string())))));
if is_true(&isTrailing) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() trailing orders are only supported on swap markets".to_string()))));
}
return self.create_spot_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else {
return self.create_contract_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
}
Value::Null
}
pub async fn create_spot_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.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), to_upper(&side));
m.insert("type".to_string(), to_upper(&type_var));
m
});
let mut timeInForce: Value = Value::Null;
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginOrSpotRequest: Value = ternary(is_true(&(!is_equal(&marginMode, &Value::Null))), Value::Str("LEVER".to_string()), Value::Str("SPOT".to_string()));
add_element_to_object(&mut request, &Value::Str("bizType".to_string()), marginOrSpotRequest.clone());
if is_equal(&type_var, &Value::Str("market".to_string())) {
timeInForce = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[Value::Str("FOK".to_string())]);
if is_equal(&side, &Value::Str("buy".to_string())) {
let mut cost: Value = self.safe_string_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
let mut createMarketBuyOrderRequiresPrice: Value = self.safe_bool_k(self.options.clone(), "createMarketBuyOrderRequiresPrice", &[Value::Bool(true)]);
if is_equal(&createMarketBuyOrderRequiresPrice, &Value::Bool(true)) {
if is_equal(&price, &Value::Null) && is_true(&(is_equal(&cost, &Value::Null))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires a price argument or cost in params for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter".to_string()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
let mut costCalculated: Value = Value::Null;
if !is_equal(&price, &Value::Null) {
costCalculated = crate::precise::Precise::stringMul(&amountString, &priceString);
} else {
costCalculated = cost.clone();
}
add_element_to_object(&mut request, &Value::Str("quoteQty".to_string()), self.cost_to_precision(symbol.clone(), costCalculated.clone()));
}
} else {
let mut amountCost: Value = ternary(is_true(&(!is_equal(&cost, &Value::Null))), cost.clone(), amount.clone());
add_element_to_object(&mut request, &Value::Str("quoteQty".to_string()), self.cost_to_precision(symbol.clone(), amountCost.clone()));
}
}
} else {
timeInForce = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[Value::Str("GTC".to_string())]);
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(is_equal(&timeInForce, &Value::Str("GTX".to_string()))), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&postOnly, &Value::Bool(true)) {
timeInForce = Value::Str("GTX".to_string());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("timeInForce".to_string()), Value::Str("postOnly".to_string())]), &[]);
if is_true(&(is_equal(&side, &Value::Str("sell".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("limit".to_string())))) {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), timeInForce.clone());
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_spot_post_order(&[__ws_arg_21]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "orderId": "204371980095156544"
// }
// }
//
let mut order: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
pub async fn create_contract_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.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("origQty".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
let mut timeInForce: Value = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[]);
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(is_equal(&timeInForce, &Value::Str("GTX".to_string()))), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&postOnly, &Value::Bool(true)) {
timeInForce = Value::Str("GTX".to_string());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("timeInForce".to_string()), Value::Str("postOnly".to_string())]), &[]);
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), timeInForce.clone());
}
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
if is_equal(&side, &Value::Str("buy".to_string())) {
let mut requestType: Value = ternary(is_true(&(is_equal(&reduceOnly, &Value::Bool(true)))), Value::Str("SHORT".to_string()), Value::Str("LONG".to_string()));
add_element_to_object(&mut request, &Value::Str("positionSide".to_string()), requestType.clone());
} else {
let mut requestType: Value = ternary(is_true(&(is_equal(&reduceOnly, &Value::Bool(true)))), Value::Str("LONG".to_string()), Value::Str("SHORT".to_string()));
add_element_to_object(&mut request, &Value::Str("positionSide".to_string()), requestType.clone());
}
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut triggerPrice: Value = self.safe_number2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLoss: Value = self.safe_number2(params.clone(), Value::Str("stopLoss".to_string()), Value::Str("triggerStopPrice".to_string()), &[]);
let mut takeProfit: Value = self.safe_number2(params.clone(), Value::Str("takeProfit".to_string()), Value::Str("triggerProfitPrice".to_string()), &[]);
let mut trailingPercent: Value = self.safe_string_k(params.clone(), "trailingPercent", &[]);
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut trailingTriggerPrice: Value = self.safe_number_k(params.clone(), "trailingTriggerPrice", &[]);
let mut isTrigger: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLoss: Value = Value::Bool(!is_equal(&stopLoss, &Value::Null));
let mut isTakeProfit: Value = Value::Bool(!is_equal(&takeProfit, &Value::Null));
let mut isTrailing: Value = Value::Bool(is_true(&(!is_equal(&trailingPercent, &Value::Null))) || is_true(&(!is_equal(&trailingAmount, &Value::Null))));
if is_true(&isTrailing) && is_true(&(!is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() trailing orders are only supported on swap markets".to_string()))));
}
if is_true(&(!is_equal(&trailingTriggerPrice, &Value::Null))) && !is_true(&isTrailing) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() trailingTriggerPrice requires trailingPercent or trailingAmount".to_string()))));
}
if !is_equal(&price, &Value::Null) {
if !is_true(&(isStopLoss)) && !is_true(&(isTakeProfit)) && !is_true(&(isTrailing)) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
}
if is_true(&isTrailing) {
add_element_to_object(&mut request, &Value::Str("orderSide".to_string()), to_upper(&side));
add_element_to_object(&mut request, &Value::Str("triggerPriceType".to_string()), self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("LATEST_PRICE".to_string())]));
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone(), Value::Str("cross".to_string())]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("positionType".to_string()), ternary(is_true(&(is_equal(&marginMode, &Value::Str("isolated".to_string())))), Value::Str("ISOLATED".to_string()), Value::Str("CROSSED".to_string())));
if !is_equal(&trailingPercent, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("callback".to_string()), Value::Str("PROPORTION".to_string()));
add_element_to_object(&mut request, &Value::Str("callbackVal".to_string()), self.parse_to_numeric(crate::precise::Precise::stringDiv(&trailingPercent, &Value::Str("100".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("callback".to_string()), Value::Str("FIXED".to_string()));
add_element_to_object(&mut request, &Value::Str("callbackVal".to_string()), self.parse_to_numeric(trailingAmount.clone()));
}
if !is_equal(&trailingTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("activationPrice".to_string()), self.price_to_precision(symbol.clone(), trailingTriggerPrice.clone()));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("trailingPercent".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("trailingTriggerPrice".to_string())]), &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_create_track(&[__ws_arg_22]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_create_track(&[__ws_arg_23]).await;
}
} else if is_true(&isTrigger) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), ternary(is_true(&(is_equal(&timeInForce, &Value::Null))), Value::Str("GTC".to_string()), timeInForce.clone()));
add_element_to_object(&mut request, &Value::Str("triggerPriceType".to_string()), self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("LATEST_PRICE".to_string())]));
add_element_to_object(&mut request, &Value::Str("orderSide".to_string()), to_upper(&side));
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
let mut entrustType: Value = ternary(is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))), Value::Str("STOP_MARKET".to_string()), Value::Str("STOP".to_string()));
add_element_to_object(&mut request, &Value::Str("entrustType".to_string()), entrustType.clone());
params = self.omit(params.clone(), Value::Str("triggerPrice".to_string()), &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_create_plan(&[__ws_arg_24]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_create_plan(&[__ws_arg_25]).await;
}
} else if is_true(&isStopLoss) || is_true(&isTakeProfit) {
if is_true(&isStopLoss) {
add_element_to_object(&mut request, &Value::Str("triggerStopPrice".to_string()), self.price_to_precision(symbol.clone(), stopLoss.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("triggerProfitPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfit.clone()));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_create_profit(&[__ws_arg_26]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_create_profit(&[__ws_arg_27]).await;
}
} else {
add_element_to_object(&mut request, &Value::Str("orderSide".to_string()), to_upper(&side));
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), to_upper(&type_var));
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_order_create(&[__ws_arg_28]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_order_create(&[__ws_arg_29]).await;
}
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchOrder
* @description fetches information on an order made by the user
* @see https://doc.xt.com/docs/spot/Order/GetSingleOrder
* @see https://doc.xt.com/docs/futures/Order/see-orders-by-id
* @see https://doc.xt.com/docs/futures/Entrust/SeeTriggerOrdersByEntrustId
* @see https://doc.xt.com/docs/futures/Entrust/SeeStopLimitByProfitId
* @see https://doc.xt.com/docs/futures/Entrust/GetSingleTrackDetail
* @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
* @param {bool} [params.trigger] if the order is a trigger order or not
* @param {bool} [params.stopLossTakeProfit] if the order is a stop-loss or take-profit order
* @param {bool} [params.trailing] if the order is a trailing order or not
* @returns {object} An [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#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(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(params.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[]);
if is_equal(&trailing, &Value::Bool(true)) {
let mut isContract: bool = is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
if !is_true(&isContract) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrder() trailing orders are only supported on swap and future markets".to_string()))));
}
}
if is_equal(&trigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("entrustId".to_string()), id.clone());
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("profitId".to_string()), id.clone());
} else if is_equal(&trailing, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("trackId".to_string()), id.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
if is_equal(&trigger, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_plan_detail(&[__ws_arg_30]).await;
} else {
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_plan_detail(&[__ws_arg_31]).await;
}
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("stopLossTakeProfit".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_profit_detail(&[__ws_arg_32]).await;
} else {
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_profit_detail(&[__ws_arg_33]).await;
}
} else if is_equal(&trailing, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("trailing".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_track_detail(&[__ws_arg_34]).await;
} else {
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_track_detail(&[__ws_arg_35]).await;
}
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_order_detail(&[__ws_arg_36]).await;
} else if is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_order_detail(&[__ws_arg_37]).await;
} else {
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_get_order_order_id(&[__ws_arg_38]).await;
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "symbol": "btc_usdt",
// "orderId": "207505997850909952",
// "clientOrderId": null,
// "baseCurrency": "btc",
// "quoteCurrency": "usdt",
// "side": "BUY",
// "type": "LIMIT",
// "timeInForce": "GTC",
// "price": "20000.00",
// "origQty": "0.001000",
// "origQuoteQty": "20.00",
// "executedQty": "0.000000",
// "leavingQty": "0.001000",
// "tradeBase": "0.000000",
// "tradeQuote": "0.00",
// "avgPrice": null,
// "fee": null,
// "feeCurrency": null,
// "closed": false,
// "state": "NEW",
// "time": 1679175285162,
// "updatedTime": 1679175285255
// }
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "orderId": "211451874783183936",
// "clientOrderId": null,
// "symbol": "btc_usdt",
// "orderType": "LIMIT",
// "orderSide": "BUY",
// "positionSide": "LONG",
// "timeInForce": "GTC",
// "closePosition": false,
// "price": "20000",
// "origQty": "10",
// "avgPrice": "0",
// "executedQty": "0",
// "marginFrozen": "1.34533334",
// "remark": null,
// "triggerProfitPrice": null,
// "triggerStopPrice": null,
// "sourceId": null,
// "sourceType": "DEFAULT",
// "forceClose": false,
// "closeProfit": null,
// "state": "NEW",
// "createdTime": 1680116055693,
// "updatedTime": 1680116055693
// }
// }
//
// trigger
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "entrustId": "216300248132756992",
// "symbol": "btc_usdt",
// "entrustType": "STOP",
// "orderSide": "SELL",
// "positionSide": "SHORT",
// "timeInForce": "GTC",
// "closePosition": null,
// "price": "20000",
// "origQty": "1",
// "stopPrice": "19000",
// "triggerPriceType": "LATEST_PRICE",
// "state": "NOT_TRIGGERED",
// "marketOrderLevel": null,
// "createdTime": 1681271998064,
// "updatedTime": 1681271998064,
// "ordinary": false
// }
// }
//
// stop-loss and take-profit
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "profitId": "216306213226230400",
// "symbol": "btc_usdt",
// "positionSide": "LONG",
// "origQty": "1",
// "triggerPriceType": "LATEST_PRICE",
// "triggerProfitPrice": null,
// "triggerStopPrice": "20000",
// "entryPrice": null,
// "positionSize": null,
// "isolatedMargin": null,
// "executedQty": null,
// "avgPrice": null,
// "positionType": "ISOLATED",
// "state": "NOT_TRIGGERED",
// "createdTime": 1681273420039
// }
// }
//
let mut order: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://doc.xt.com/docs/spot/Order/QueryHistoricalOrders
* @see https://doc.xt.com/docs/futures/Order/see-order-history
* @see https://doc.xt.com/docs/futures/Entrust/SeeTriggerOrdersHistory
* @see https://doc.xt.com/docs/futures/Entrust/GetHistoryTrackListInactive
* @param {string} [symbol] unified market symbol of the market the orders were made in
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] if the order is a trigger order or not
* @param {bool} [params.trailing] if the orders are trailing orders or not
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#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
});
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());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrders".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOrders".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[]);
if is_equal(&trailing, &Value::Bool(true)) {
let mut isContract: bool = is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
if !is_true(&isContract) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrders() trailing orders are only supported on swap and future markets".to_string()))));
}
}
if is_equal(&trigger, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_39 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_plan_list_history(&[__ws_arg_39]).await;
} else {
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_plan_list_history(&[__ws_arg_40]).await;
}
} else if is_equal(&trailing, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("trailing".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_track_list_history(&[__ws_arg_41]).await;
} else {
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_track_list_history(&[__ws_arg_42]).await;
}
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_order_list_history(&[__ws_arg_43]).await;
} else if is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_order_list_history(&[__ws_arg_44]).await;
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchOrders".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginOrSpotRequest: Value = ternary(is_true(&(!is_equal(&marginMode, &Value::Null))), Value::Str("LEVER".to_string()), Value::Str("SPOT".to_string()));
add_element_to_object(&mut request, &Value::Str("bizType".to_string()), marginOrSpotRequest.clone());
let __ws_arg_45 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_get_history_order(&[__ws_arg_45]).await;
}
//
// spot and margin
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "hasPrev": false,
// "hasNext": true,
// "items": [
// {
// "symbol": "btc_usdt",
// "orderId": "207505997850909952",
// "clientOrderId": null,
// "baseCurrency": "btc",
// "quoteCurrency": "usdt",
// "side": "BUY",
// "type": "LIMIT",
// "timeInForce": "GTC",
// "price": "20000.00",
// "origQty": "0.001000",
// "origQuoteQty": "20.00",
// "executedQty": "0.000000",
// "leavingQty": "0.000000",
// "tradeBase": "0.000000",
// "tradeQuote": "0.00",
// "avgPrice": null,
// "fee": null,
// "feeCurrency": null,
// "closed": true,
// "state": "CANCELED",
// "time": 1679175285162,
// "updatedTime": 1679175488492
// },
// ]
// }
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "hasPrev": false,
// "hasNext": true,
// "items": [
// {
// "orderId": "207519546930995456",
// "clientOrderId": null,
// "symbol": "btc_usdt",
// "orderType": "LIMIT",
// "orderSide": "BUY",
// "positionSide": "LONG",
// "timeInForce": "GTC",
// "closePosition": false,
// "price": "20000",
// "origQty": "100",
// "avgPrice": "0",
// "executedQty": "0",
// "marginFrozen": "4.12",
// "remark": null,
// "triggerProfitPrice": null,
// "triggerStopPrice": null,
// "sourceId": null,
// "sourceType": "DEFAULT",
// "forceClose": false,
// "closeProfit": null,
// "state": "CANCELED",
// "createdTime": 1679178515689,
// "updatedTime": 1679180096172
// },
// ]
// }
// }
//
// stop
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "hasPrev": false,
// "hasNext": false,
// "items": [
// {
// "entrustId": "216300248132756992",
// "symbol": "btc_usdt",
// "entrustType": "STOP",
// "orderSide": "SELL",
// "positionSide": "SHORT",
// "timeInForce": "GTC",
// "closePosition": null,
// "price": "20000",
// "origQty": "1",
// "stopPrice": "19000",
// "triggerPriceType": "LATEST_PRICE",
// "state": "USER_REVOCATION",
// "marketOrderLevel": null,
// "createdTime": 1681271998064,
// "updatedTime": 1681273188674,
// "ordinary": false
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub async fn fetch_orders_by_status(&mut self, mut status: Value, 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("size".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(params.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[]);
if is_equal(&trailing, &Value::Bool(true)) {
let mut isContract: bool = is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
if !is_true(&isContract) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrdersByStatus() trailing orders are only supported on swap and future markets".to_string()))));
}
// the track endpoints do not accept a state filter, and a server-side
// size would truncate the mixed-state page before the local status
// filter runs, so the limit is only applied locally after filtering
request = self.omit(request.clone(), Value::List(vec![Value::Str("state".to_string()), Value::Str("size".to_string())]), &[]);
} else if is_equal(&status, &Value::Str("open".to_string())) {
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("NOT_TRIGGERED".to_string()));
} else if is_equal(&type_var, &Value::Str("swap".to_string())) {
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("UNFINISHED".to_string())); // NEW & PARTIALLY_FILLED
}
} else if is_equal(&status, &Value::Str("closed".to_string())) {
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("TRIGGERED".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("FILLED".to_string()));
}
} else if is_equal(&status, &Value::Str("canceled".to_string())) {
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("USER_REVOCATION".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("CANCELED".to_string()));
}
} else {
add_element_to_object(&mut request, &Value::Str("state".to_string()), status.clone());
}
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if is_true(&(!is_equal(&limit, &Value::Null))) && is_true(&(!is_equal(&trailing, &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone());
}
}
if is_equal(&trigger, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_46 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_plan_list(&[__ws_arg_46]).await;
} else {
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_plan_list(&[__ws_arg_47]).await;
}
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("stopLossTakeProfit".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_48 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_profit_list(&[__ws_arg_48]).await;
} else {
let __ws_arg_49 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_profit_list(&[__ws_arg_49]).await;
}
} else if is_equal(&trailing, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("trailing".to_string()), &[]);
if is_equal(&status, &Value::Str("open".to_string())) {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_50 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_track_list(&[__ws_arg_50]).await;
} else {
let __ws_arg_51 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_track_list(&[__ws_arg_51]).await;
}
} else {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_52 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_entrust_track_list_history(&[__ws_arg_52]).await;
} else {
let __ws_arg_53 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_track_list_history(&[__ws_arg_53]).await;
}
}
} else if is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_54 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_order_list(&[__ws_arg_54]).await;
} else {
let __ws_arg_55 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_order_list(&[__ws_arg_55]).await;
}
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginOrSpotRequest: Value = ternary(is_true(&(!is_equal(&marginMode, &Value::Null))), Value::Str("LEVER".to_string()), Value::Str("SPOT".to_string()));
add_element_to_object(&mut request, &Value::Str("bizType".to_string()), marginOrSpotRequest.clone());
if !is_equal(&status, &Value::Str("open".to_string())) {
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) {
request = self.omit(request.clone(), Value::Str("size".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_56 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_get_history_order(&[__ws_arg_56]).await;
} else {
let __ws_arg_57 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_get_open_order(&[__ws_arg_57]).await;
}
}
//
// spot and margin
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "hasPrev": false,
// "hasNext": true,
// "items": [
// {
// "symbol": "btc_usdt",
// "orderId": "207505997850909952",
// "clientOrderId": null,
// "baseCurrency": "btc",
// "quoteCurrency": "usdt",
// "side": "BUY",
// "type": "LIMIT",
// "timeInForce": "GTC",
// "price": "20000.00",
// "origQty": "0.001000",
// "origQuoteQty": "20.00",
// "executedQty": "0.000000",
// "leavingQty": "0.000000",
// "tradeBase": "0.000000",
// "tradeQuote": "0.00",
// "avgPrice": null,
// "fee": null,
// "feeCurrency": null,
// "closed": true,
// "state": "CANCELED",
// "time": 1679175285162,
// "updatedTime": 1679175488492
// },
// ]
// }
// }
//
// spot and margin: fetchOpenOrders
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": [
// {
// "symbol": "eth_usdt",
// "orderId": "208249323222264320",
// "clientOrderId": null,
// "baseCurrency": "eth",
// "quoteCurrency": "usdt",
// "side": "BUY",
// "type": "LIMIT",
// "timeInForce": "GTC",
// "price": "1300.00",
// "origQty": "0.0032",
// "origQuoteQty": "4.16",
// "executedQty": "0.0000",
// "leavingQty": "0.0032",
// "tradeBase": "0.0000",
// "tradeQuote": "0.00",
// "avgPrice": null,
// "fee": null,
// "feeCurrency": null,
// "closed": false,
// "state": "NEW",
// "time": 1679352507741,
// "updatedTime": 1679352507869
// },
// ]
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "page": 1,
// "ps": 10,
// "total": 25,
// "items": [
// {
// "orderId": "207519546930995456",
// "clientOrderId": null,
// "symbol": "btc_usdt",
// "orderType": "LIMIT",
// "orderSide": "BUY",
// "positionSide": "LONG",
// "timeInForce": "GTC",
// "closePosition": false,
// "price": "20000",
// "origQty": "100",
// "avgPrice": "0",
// "executedQty": "0",
// "marginFrozen": "4.12",
// "remark": null,
// "triggerProfitPrice": null,
// "triggerStopPrice": null,
// "sourceId": null,
// "sourceType": "DEFAULT",
// "forceClose": false,
// "closeProfit": null,
// "state": "CANCELED",
// "createdTime": 1679178515689,
// "updatedTime": 1679180096172
// },
// ]
// }
// }
//
// stop
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "page": 1,
// "ps": 3,
// "total": 8,
// "items": [
// {
// "entrustId": "216300248132756992",
// "symbol": "btc_usdt",
// "entrustType": "STOP",
// "orderSide": "SELL",
// "positionSide": "SHORT",
// "timeInForce": "GTC",
// "closePosition": null,
// "price": "20000",
// "origQty": "1",
// "stopPrice": "19000",
// "triggerPriceType": "LATEST_PRICE",
// "state": "USER_REVOCATION",
// "marketOrderLevel": null,
// "createdTime": 1681271998064,
// "updatedTime": 1681273188674,
// "ordinary": false
// },
// ]
// }
// }
//
// stop-loss and take-profit
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "page": 1,
// "ps": 3,
// "total": 2,
// "items": [
// {
// "profitId": "216306213226230400",
// "symbol": "btc_usdt",
// "positionSide": "LONG",
// "origQty": "1",
// "triggerPriceType": "LATEST_PRICE",
// "triggerProfitPrice": null,
// "triggerStopPrice": "20000",
// "entryPrice": "0",
// "positionSize": "0",
// "isolatedMargin": "0",
// "executedQty": "0",
// "avgPrice": null,
// "positionType": "ISOLATED",
// "state": "USER_REVOCATION",
// "createdTime": 1681273420039
// },
// ]
// }
// }
//
let mut orders: Value = Value::List(vec![]);
let mut resultDict: Value = self.safe_dict_k(response.clone(), "result", &[]);
if !is_equal(&resultDict, &Value::Null) {
orders = self.safe_list_k(resultDict.clone(), "items", &[Value::List(vec![])]);
} else {
orders = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
}
if is_equal(&trailing, &Value::Bool(true)) {
// the track endpoints do not support a server-side state filter
// and return entries in every state, so filter by status first,
// otherwise since/limit could cut off matching rows
let mut parsedOrders: Value = self.parse_orders(orders.clone(), &[market.clone()]);
let mut filteredOrders: Value = self.filter_by(parsedOrders.clone(), Value::Str("status".to_string()), status.clone(), &[]);
return self.filter_by_since_limit(filteredOrders.clone(), &[since.clone(), limit.clone()]);
}
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://doc.xt.com/docs/spot/Order/QueryOpenOrders
* @see https://doc.xt.com/docs/futures/Order/see-orders
* @see https://doc.xt.com/docs/futures/Entrust/SeeTriggerOrders
* @see https://doc.xt.com/docs/futures/Entrust/SeeStopLimit
* @see https://doc.xt.com/docs/futures/Entrust/getTrackList
* @param {string} [symbol] unified market symbol of the market the orders were made in
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the maximum number of open order structures to retrieve
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] if the order is a trigger order or not
* @param {bool} [params.stopLossTakeProfit] if the order is a stop-loss or take-profit order
* @param {bool} [params.trailing] if the orders are trailing orders or not
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#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
}));
return self.fetch_orders_by_status(Value::Str("open".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name xt#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://doc.xt.com/docs/spot/Order/QueryHistoricalOrders
* @see https://doc.xt.com/docs/futures/Order/see-orders
* @see https://doc.xt.com/docs/futures/Entrust/SeeTriggerOrders
* @see https://doc.xt.com/docs/futures/Entrust/SeeStopLimit
* @see https://doc.xt.com/docs/futures/Entrust/GetHistoryTrackListInactive
* @param {string} [symbol] unified market symbol of the market the orders were made in
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] if the order is a trigger order or not
* @param {bool} [params.stopLossTakeProfit] if the order is a stop-loss or take-profit order
* @param {bool} [params.trailing] if the orders are trailing orders or not
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#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
}));
return self.fetch_orders_by_status(Value::Str("closed".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name xt#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://doc.xt.com/docs/spot/Order/QueryHistoricalOrders
* @see https://doc.xt.com/docs/futures/Order/see-orders
* @see https://doc.xt.com/docs/futures/Entrust/SeeTriggerOrders
* @see https://doc.xt.com/docs/futures/Entrust/SeeStopLimit
* @see https://doc.xt.com/docs/futures/Entrust/GetHistoryTrackListInactive
* @param {string} [symbol] unified market symbol of the market the orders were made in
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] if the order is a trigger order or not
* @param {bool} [params.stopLossTakeProfit] if the order is a stop-loss or take-profit order
* @param {bool} [params.trailing] if the orders are trailing orders or not
* @returns {object} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
pub async fn fetch_canceled_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
}));
return self.fetch_orders_by_status(Value::Str("canceled".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name xt#cancelOrder
* @description cancels an open order
* @see https://doc.xt.com/docs/spot/Order/CancelOrder
* @see https://doc.xt.com/docs/futures/Order/cancel-orders
* @see https://doc.xt.com/docs/futures/Entrust/CancelTriggerOrders
* @see https://doc.xt.com/docs/futures/Entrust/CancelStopLimit
* @see https://doc.xt.com/docs/futures/Entrust/CancelSingleTrack
* @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
* @param {bool} [params.trigger] if the order is a trigger order or not
* @param {bool} [params.stopLossTakeProfit] if the order is a stop-loss or take-profit order
* @param {bool} [params.trailing] if the order is a trailing order or not
* @returns {object} An [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(params.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[]);
if is_equal(&trailing, &Value::Bool(true)) {
let mut isContract: bool = is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
if !is_true(&isContract) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrder() trailing orders are only supported on swap and future markets".to_string()))));
}
}
if is_equal(&trigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("entrustId".to_string()), id.clone());
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("profitId".to_string()), id.clone());
} else if is_equal(&trailing, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("trackId".to_string()), id.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
if is_equal(&trigger, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_58 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_cancel_plan(&[__ws_arg_58]).await;
} else {
let __ws_arg_59 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_plan(&[__ws_arg_59]).await;
}
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("stopLossTakeProfit".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_60 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_cancel_profit_stop(&[__ws_arg_60]).await;
} else {
let __ws_arg_61 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_profit_stop(&[__ws_arg_61]).await;
}
} else if is_equal(&trailing, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("trailing".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_62 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_cancel_track(&[__ws_arg_62]).await;
} else {
let __ws_arg_63 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_track(&[__ws_arg_63]).await;
}
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_64 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_order_cancel(&[__ws_arg_64]).await;
} else if is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let __ws_arg_65 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_order_cancel(&[__ws_arg_65]).await;
} else {
let __ws_arg_66 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_delete_order_order_id(&[__ws_arg_66]).await;
}
//
// spot
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "cancelId": "208322474307982720"
// }
// }
//
// swap and future
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": "208319789679471616"
// }
//
let mut isContractResponse: bool = is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
let mut order: Value = ternary(is_true(&isContractResponse), response.clone(), self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]));
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#cancelAllOrders
* @description cancel all open orders in a market
* @see https://doc.xt.com/docs/spot/Order/CancelCurrentPendingOrder
* @see https://doc.xt.com/docs/futures/Order/cancel-all-orders
* @see https://doc.xt.com/docs/futures/Entrust/CancelAllTriggerOrders
* @see https://doc.xt.com/docs/futures/Entrust/CancelAllStopLimit
* @see https://doc.xt.com/docs/futures/Entrust/CancelAllTrack
* @param {string} [symbol] unified market symbol of the market to cancel orders in
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] if the order is a trigger order or not
* @param {bool} [params.stopLossTakeProfit] if the order is a stop-loss or take-profit order
* @param {bool} [params.trailing] if the orders are trailing orders or not
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#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 type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(params.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[]);
if is_equal(&trailing, &Value::Bool(true)) {
let mut isContract: bool = is_true(&(!is_equal(&subType, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string()))));
if !is_true(&isContract) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelAllOrders() trailing orders are only supported on swap and future markets".to_string()))));
}
}
if is_equal(&trigger, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_67 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_cancel_all_plan(&[__ws_arg_67]).await;
} else {
let __ws_arg_68 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_all_plan(&[__ws_arg_68]).await;
}
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("stopLossTakeProfit".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_69 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_cancel_all_profit_stop(&[__ws_arg_69]).await;
} else {
let __ws_arg_70 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_all_profit_stop(&[__ws_arg_70]).await;
}
} else if is_equal(&trailing, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("trailing".to_string()), &[]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_71 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_cancel_all_track(&[__ws_arg_71]).await;
} else {
let __ws_arg_72 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_all_track(&[__ws_arg_72]).await;
}
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_73 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_order_cancel_all(&[__ws_arg_73]).await;
} else if is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let __ws_arg_74 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_order_cancel_all(&[__ws_arg_74]).await;
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("cancelAllOrders".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginOrSpotRequest: Value = ternary(is_true(&(!is_equal(&marginMode, &Value::Null))), Value::Str("LEVER".to_string()), Value::Str("SPOT".to_string()));
add_element_to_object(&mut request, &Value::Str("bizType".to_string()), marginOrSpotRequest.clone());
let __ws_arg_75 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_delete_open_order(&[__ws_arg_75]).await;
}
return Value::List(vec![self.safe_order(response.clone(), &[])]);
Value::Null
}
/*
* @method
* @name xt#cancelOrders
* @description cancel multiple orders
* @see https://doc.xt.com/docs/spot/Order/CancelBatchOrder
* @param {string[]} ids order ids
* @param {string} [symbol] unified market symbol of the market to cancel orders in
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderIds".to_string(), ids.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("cancelOrders".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&subType, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrders() does not support swap and future orders, only spot orders are accepted".to_string()))));
}
let __ws_arg_76 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_spot_delete_batch_order(&[__ws_arg_76]).await;
return Value::List(vec![self.safe_order(response.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);
//
// spot: createOrder
//
// {
// "orderId": "204371980095156544"
// }
//
// spot: cancelOrder
//
// {
// "cancelId": "208322474307982720"
// }
//
// swap and future: createOrder, cancelOrder, editOrder
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": "206410760006650176"
// }
//
// spot: fetchOrder, fetchOrders, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders, fetchOrdersByStatus
//
// {
// "symbol": "btc_usdt",
// "orderId": "207505997850909952",
// "clientOrderId": null,
// "baseCurrency": "btc",
// "quoteCurrency": "usdt",
// "side": "BUY",
// "type": "LIMIT",
// "timeInForce": "GTC",
// "price": "20000.00",
// "origQty": "0.001000",
// "origQuoteQty": "20.00",
// "executedQty": "0.000000",
// "leavingQty": "0.001000",
// "tradeBase": "0.000000",
// "tradeQuote": "0.00",
// "avgPrice": null,
// "fee": null,
// "feeCurrency": null,
// "closed": false,
// "state": "NEW",
// "time": 1679175285162,
// "updatedTime": 1679175285255
// }
//
// swap and future: fetchOrder, fetchOrders, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders, fetchOrdersByStatus
//
// {
// "orderId": "207519546930995456",
// "clientOrderId": null,
// "symbol": "btc_usdt",
// "orderType": "LIMIT",
// "orderSide": "BUY",
// "positionSide": "LONG",
// "timeInForce": "GTC",
// "closePosition": false,
// "price": "20000",
// "origQty": "100",
// "avgPrice": "0",
// "executedQty": "0",
// "marginFrozen": "4.12",
// "remark": null,
// "triggerProfitPrice": null,
// "triggerStopPrice": null,
// "sourceId": null,
// "sourceType": "DEFAULT",
// "forceClose": false,
// "closeProfit": null,
// "state": "CANCELED",
// "createdTime": 1679178515689,
// "updatedTime": 1679180096172
// }
//
// trigger: fetchOrder, fetchOrders, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders, fetchOrdersByStatus
//
// {
// "entrustId": "216300248132756992",
// "symbol": "btc_usdt",
// "entrustType": "STOP",
// "orderSide": "SELL",
// "positionSide": "SHORT",
// "timeInForce": "GTC",
// "closePosition": null,
// "price": "20000",
// "origQty": "1",
// "stopPrice": "19000",
// "triggerPriceType": "LATEST_PRICE",
// "state": "NOT_TRIGGERED",
// "marketOrderLevel": null,
// "createdTime": 1681271998064,
// "updatedTime": 1681271998064,
// "ordinary": false
// }
//
// stop-loss and take-profit: fetchOrder, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders, fetchOrdersByStatus
//
// {
// "profitId": "216306213226230400",
// "symbol": "btc_usdt",
// "positionSide": "LONG",
// "origQty": "1",
// "triggerPriceType": "LATEST_PRICE",
// "triggerProfitPrice": null,
// "triggerStopPrice": "20000",
// "entryPrice": null,
// "positionSize": null,
// "isolatedMargin": null,
// "executedQty": null,
// "avgPrice": null,
// "positionType": "ISOLATED",
// "state": "NOT_TRIGGERED",
// "createdTime": 1681273420039
// }
//
// spot editOrder
//
// {
// "orderId": "484203027161892224",
// "modifyId": "484203544105344000",
// "clientModifyId": null
// }
//
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut marketType: Value = ternary(is_true(&(Value::Bool(in_op(&order, &Value::Str("result".to_string()))))) || is_true(&(Value::Bool(in_op(&order, &Value::Str("positionSide".to_string()))))), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, marketType.clone()]);
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("time".to_string()), Value::Str("createdTime".to_string()), &[]);
let mut quantity: Value = self.safe_number_k(order.clone(), "origQty", &[]);
let mut amount: Value = ternary(is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))), quantity.clone(), crate::precise::Precise::stringMul(&self.number_to_string(quantity.clone()), &self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string())))));
let mut filledQuantity: Value = self.safe_number_k(order.clone(), "executedQty", &[]);
let mut filled: Value = ternary(is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))), filledQuantity.clone(), crate::precise::Precise::stringMul(&self.number_to_string(filledQuantity.clone()), &self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string())))));
let mut lastUpdatedTimestamp: Value = self.safe_integer_k(order.clone(), "updatedTime", &[]);
let mut timeInForce: Value = self.safe_string_k(order.clone(), "timeInForce", &[]);
let mut postOnly: Value = Value::Null;
if !is_equal(&timeInForce, &Value::Null) {
if is_equal(&timeInForce, &Value::Str("GTX".to_string())) {
// GTX means "Good Till Crossing" and is an equivalent way of saying Post Only
timeInForce = Value::Str("PO".to_string());
}
postOnly = Value::Bool(is_equal(&timeInForce, &Value::Str("PO".to_string())));
}
let mut side: Value = self.safe_string_lower2(order.clone(), Value::Str("side".to_string()), Value::Str("orderSide".to_string()), &[]);
if is_equal(&side, &Value::Null) {
// the stop loss and take profit entries carry only the position
// side, they close the position, so a long position closes with a
// sell and a short position closes with a buy
// see https://github.com/ccxt/ccxt/issues/25288
let mut positionSide: Value = self.safe_string_k(order.clone(), "positionSide", &[]);
if !is_equal(&positionSide, &Value::Null) {
if is_equal(&positionSide, &Value::Str("LONG".to_string())) {
side = Value::Str("sell".to_string());
} else {
side = Value::Str("buy".to_string());
}
}
}
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_n(order.clone(), Value::List(vec![Value::Str("orderId".to_string()), Value::Str("result".to_string()), Value::Str("cancelId".to_string()), Value::Str("entrustId".to_string()), Value::Str("profitId".to_string()), Value::Str("trackId".to_string())]), &[]));
m.insert("clientOrderId".to_string(), self.safe_string2(order.clone(), Value::Str("clientOrderId".to_string()), Value::Str("clientModifyId".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), lastUpdatedTimestamp.clone());
m.insert("lastUpdateTimestamp".to_string(), lastUpdatedTimestamp.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), self.safe_string_lower2(order.clone(), Value::Str("type".to_string()), Value::Str("orderType".to_string()), &[]));
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.safe_number_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), self.safe_number_k(order.clone(), "stopPrice", &[]));
m.insert("stopLoss".to_string(), self.safe_number_k(order.clone(), "triggerStopPrice", &[]));
m.insert("takeProfit".to_string(), self.safe_number_k(order.clone(), "triggerProfitPrice", &[]));
m.insert("amount".to_string(), amount.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), self.safe_number_k(order.clone(), "leavingQty", &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), self.safe_number_k(order.clone(), "avgPrice", &[]));
m.insert("status".to_string(), self.parse_order_status(self.safe_string_k(order.clone(), "state", &[])));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(order.clone(), "feeCurrency", &[]), &[]));
m.insert("cost".to_string(), self.safe_number_k(order.clone(), "fee", &[]));
m
}));
m.insert("trades".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("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("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("REJECTED".to_string(), Value::Str("rejected".to_string()));
m.insert("EXPIRED".to_string(), Value::Str("expired".to_string()));
m.insert("UNFINISHED".to_string(), Value::Str("open".to_string()));
m.insert("NOT_ACTIVATION".to_string(), Value::Str("open".to_string()));
m.insert("NOT_TRIGGERED".to_string(), Value::Str("open".to_string()));
m.insert("TRIGGERING".to_string(), Value::Str("open".to_string()));
m.insert("TRIGGERED".to_string(), Value::Str("closed".to_string()));
m.insert("USER_REVOCATION".to_string(), Value::Str("canceled".to_string()));
m.insert("PLATFORM_REVOCATION".to_string(), Value::Str("rejected".to_string()));
m.insert("DELEGATION_FAILED".to_string(), Value::Str("rejected".to_string()));
m.insert("HISTORY".to_string(), Value::Str("expired".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://doc.xt.com/docs/futures/User/Get%20User's%20Account%20Flow%20Information
* @param {string} [code] unified currency code
* @param {int} [since] timestamp in ms of the earliest ledger entry
* @param {int} [limit] max number of ledger entries to return
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/en/latest/manual.html#ledger-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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
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 type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_77 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_user_v1_balance_bills(&[__ws_arg_77]).await;
} else if is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let __ws_arg_78 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_user_v1_balance_bills(&[__ws_arg_78]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLedger() does not support spot transactions, only swap and future wallet transactions are supported".to_string()))));
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "hasPrev": false,
// "hasNext": false,
// "items": [
// {
// "id": "207260567109387525",
// "coin": "usdt",
// "symbol": "btc_usdt",
// "type": "FEE",
// "amount": "-0.0213",
// "side": "SUB",
// "afterAmount": null,
// "createdTime": 1679116769914
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ledger: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_ledger(ledger.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);
//
// {
// "id": "207260567109387524",
// "coin": "usdt",
// "symbol": "btc_usdt",
// "type": "FEE",
// "amount": "-0.0213",
// "side": "SUB",
// "afterAmount": null,
// "createdTime": 1679116769914
// }
//
let mut side: Value = self.safe_string_k(item.clone(), "side", &[]);
let mut direction: Value = ternary(is_true(&(is_equal(&side, &Value::Str("ADD".to_string())))), Value::Str("in".to_string()), Value::Str("out".to_string()));
let mut currencyId: Value = self.safe_string_k(item.clone(), "coin", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_k(item.clone(), "createdTime", &[]);
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("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_entry_type(self.safe_string_k(item.clone(), "type", &[])));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("amount".to_string(), self.safe_number_k(item.clone(), "amount", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), self.safe_number_k(item.clone(), "afterAmount", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m
}));
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut ledgerType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("EXCHANGE".to_string(), Value::Str("transfer".to_string()));
m.insert("CLOSE_POSITION".to_string(), Value::Str("trade".to_string()));
m.insert("TAKE_OVER".to_string(), Value::Str("trade".to_string()));
m.insert("MERGE".to_string(), Value::Str("trade".to_string()));
m.insert("QIANG_PING_MANAGER".to_string(), Value::Str("fee".to_string()));
m.insert("FUND".to_string(), Value::Str("fee".to_string()));
m.insert("FEE".to_string(), Value::Str("fee".to_string()));
m.insert("ADL".to_string(), Value::Str("auto-deleveraging".to_string()));
m
});
return self.safe_string(ledgerType.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://doc.xt.com/docs/spot/Deposit&Withdrawal/GetDepositAddress
* @param {string} code unified currency code
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} params.network required network id
* @returns {object} an [address structure]{@link https://docs.ccxt.com/en/latest/manual.html#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 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)); }
let mut currency: Value = self.currency(code.clone());
let mut networkId: Value = self.network_code_to_id(networkCode.clone(), &[code.clone()]);
self.check_required_argument(Value::Str("fetchDepositAddress".to_string()), networkId.clone(), Value::Str("network".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("chain".to_string(), networkId.clone());
m
});
let __ws_arg_79 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_spot_get_deposit_address(&[__ws_arg_79]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "address": "0x7f7173cf29d3846d20ca5a3aec1120b93dbd157a",
// "memo": ""
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_address(result.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);
//
// {
// "address": "0x7f7173cf29d3846d20ca5a3aec1120b93dbd157a",
// "memo": ""
// }
//
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_currency_code(Value::Null, &[currency.clone()]));
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(), "memo", &[]));
m
});
Value::Null
}
/*
* @method
* @name xt#fetchDeposits
* @description fetch all deposits made to an account
* @see https://doc.xt.com/docs/spot/Deposit&Withdrawal/GetDepositHistory
* @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 transaction 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/en/latest/manual.html#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
}));
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 currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".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());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 10, max 200
}
let __ws_arg_80 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_spot_get_deposit_history(&[__ws_arg_80]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "hasPrev": false,
// "hasNext": false,
// "items": [
// {
// "id": 170368702,
// "currency": "usdt",
// "chain": "Ethereum",
// "memo": "",
// "status": "SUCCESS",
// "amount": "31.792528",
// "confirmations": 12,
// "transactionId": "0x90b8487c258b81b85e15e461b1839c49d4d8e6e9de4c1adb658cd47d4f5c5321",
// "address": "0x7f7172cf29d3846d30ca5a3aec1120b92dbd150b",
// "fromAddr": "0x7830c87c02e56aff27fa9ab1241711331fa86f58",
// "createdTime": 1678491442000
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut deposits: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_transactions(deposits.clone(), &[currency.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://doc.xt.com/docs/spot/Deposit&Withdrawal/WithdrawHistory
* @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 transaction 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/en/latest/manual.html#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
}));
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 currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".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());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 10, max 200
}
let __ws_arg_81 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_spot_get_withdraw_history(&[__ws_arg_81]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "hasPrev": false,
// "hasNext": false,
// "items": [
// {
// "id": 950898,
// "currency": "usdt",
// "chain": "Tron",
// "address": "TGB2vxTjiqraVZBy7YHXF8V3CSMVhQKcaf",
// "memo": "",
// "status": "SUCCESS",
// "amount": "5",
// "fee": "2",
// "confirmations": 6,
// "transactionId": "c36e230b879842b1d7afd19d15ee1a866e26eaa0626e367d6f545d2932a15156",
// "createdTime": 1680049062000
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut withdrawals: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_transactions(withdrawals.clone(), &[currency.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name xt#withdraw
* @description make a withdrawal
* @see https://doc.xt.com/docs/spot/Deposit&Withdrawal/Withdraw
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} [tag]
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/en/latest/manual.html#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()]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
{ let __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
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)); }
let mut networkIdsByCodes: Value = self.safe_dict_k(self.options.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networkId: Value = self.safe_string2(networkIdsByCodes.clone(), networkCode.clone(), code.clone(), &[code.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("chain".to_string(), networkId.clone());
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("address".to_string(), address.clone());
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("memo".to_string()), tag.clone());
}
let __ws_arg_82 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_spot_post_withdraw(&[__ws_arg_82]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "id": 950898
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(result.clone(), &[currency.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
//
// {
// "id": 170368702,
// "currency": "usdt",
// "chain": "Ethereum",
// "memo": "",
// "status": "SUCCESS",
// "amount": "31.792528",
// "confirmations": 12,
// "transactionId": "0x90b8487c258b81b85e15e461b1839c49d4d8e6e9de4c1adb658cd47d4f5c5321",
// "address": "0x7f7172cf29d3846d30ca5a3aec1120b92dbd150b",
// "fromAddr": "0x7830c87c02e56aff27fa9ab1241711331fa86f58",
// "createdTime": 1678491442000
// }
//
// fetchWithdrawals
//
// {
// "id": 950898,
// "currency": "usdt",
// "chain": "Tron",
// "address": "TGB2vxTjiqraVZBy7YHXF8V3CSMVhQKcaf",
// "memo": "",
// "status": "SUCCESS",
// "amount": "5",
// "fee": "2",
// "confirmations": 6,
// "transactionId": "c36e230b879842b1d7afd19d15ee1a866e26eaa0626e367d6f545d2932a15156",
// "createdTime": 1680049062000
// }
//
// withdraw
//
// {
// "id": 950898
// }
//
let mut type_var: Value = ternary(is_true(&(Value::Bool(in_op(&transaction, &Value::Str("fromAddr".to_string()))))), Value::Str("deposit".to_string()), Value::Str("withdraw".to_string()));
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "createdTime", &[]);
let mut address: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut memo: Value = self.safe_string_k(transaction.clone(), "memo", &[]);
let mut currencyCode: Value = self.safe_currency_code(self.safe_string_k(transaction.clone(), "currency", &[]), &[currency.clone()]);
let mut fee: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
let mut feeCurrency: Value = ternary(is_true(&(!is_equal(&fee, &Value::Null))), currencyCode.clone(), Value::Null);
let mut networkId: Value = self.safe_string_k(transaction.clone(), "chain", &[]);
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(), "transactionId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("updated".to_string(), Value::Null);
m.insert("addressFrom".to_string(), self.safe_string_k(transaction.clone(), "fromAddr", &[]));
m.insert("addressTo".to_string(), address.clone());
m.insert("address".to_string(), address.clone());
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tag".to_string(), memo.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), currencyCode.clone());
m.insert("network".to_string(), self.network_id_to_code(&[networkId.clone(), currencyCode.clone()]));
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])));
m.insert("comment".to_string(), memo.clone());
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), feeCurrency.clone());
m.insert("cost".to_string(), fee.clone());
m.insert("rate".to_string(), Value::Null);
m
}));
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("SUBMIT".to_string(), Value::Str("pending".to_string()));
m.insert("REVIEW".to_string(), Value::Str("pending".to_string()));
m.insert("AUDITED".to_string(), Value::Str("pending".to_string()));
m.insert("PENDING".to_string(), Value::Str("pending".to_string()));
m.insert("CANCEL".to_string(), Value::Str("canceled".to_string()));
m.insert("FAIL".to_string(), Value::Str("failed".to_string()));
m.insert("SUCCESS".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name xt#setLeverage
* @description set the level of leverage for a market
* @see https://doc.xt.com/docs/futures/User/Adjust%20Leverage
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} params.positionSide 'LONG' or 'SHORT'
* @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()))));
}
let mut positionSide: Value = self.safe_string_k(params.clone(), "positionSide", &[]);
self.check_required_argument(Value::Str("setLeverage".to_string()), positionSide.clone(), Value::Str("positionSide".to_string()), &[Value::List(vec![Value::Str("LONG".to_string()), Value::Str("SHORT".to_string())])]);
if is_true(&(is_less_than(&leverage, &Value::Int(1)))) || is_true(&(is_greater_than(&leverage, &Value::Int(125)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setLeverage() leverage should be between 1 and 125".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("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setLeverage() supports contract markets only".to_string()))));
}
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("positionSide".to_string(), positionSide.clone());
m.insert("leverage".to_string(), leverage.clone());
m
});
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("setLeverage".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_83 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_user_v1_position_adjust_leverage(&[__ws_arg_83]).await;
} else {
let __ws_arg_84 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_user_v1_position_adjust_leverage(&[__ws_arg_84]).await;
}
return response;
Value::Null
}
/*
* @method
* @name xt#addMargin
* @description add margin to a position
* @see https://doc.xt.com/docs/futures/User/Alter%20Margin
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} params.positionSide 'LONG' or 'SHORT'
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Str("ADD".to_string()), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name xt#reduceMargin
* @description remove margin from a position
* @see https://doc.xt.com/docs/futures/User/Alter%20Margin
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} params.positionSide 'LONG' or 'SHORT'
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Str("SUB".to_string()), &[params.clone()]).await;
Value::Null
}
pub async fn modify_margin_helper(&mut self, mut symbol: Value, mut amount: Value, mut addOrReduce: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut positionSide: Value = self.safe_string_k(params.clone(), "positionSide", &[]);
let mut methodName: Value = ternary(is_true(&(is_equal(&addOrReduce, &Value::Str("ADD".to_string())))), Value::Str("addMargin".to_string()), Value::Str("reduceMargin".to_string()));
self.check_required_argument(methodName.clone(), positionSide.clone(), Value::Str("positionSide".to_string()), &[Value::List(vec![Value::Str("LONG".to_string()), Value::Str("SHORT".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("margin".to_string(), amount.clone());
m.insert("type".to_string(), addOrReduce.clone());
m.insert("positionSide".to_string(), positionSide.clone());
m
});
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("modifyMarginHelper".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_85 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_user_v1_position_margin(&[__ws_arg_85]).await;
} else {
let __ws_arg_86 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_user_v1_position_margin(&[__ws_arg_86]).await;
}
return self.parse_margin_modification(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("type".to_string(), Value::Null);
m.insert("amount".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("symbol".to_string(), self.safe_symbol(Value::Null, &[market.clone()]));
m.insert("status".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("total".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name xt#fetchLeverageTiers
* @description retrieve information on the maximum leverage for different trade sizes
* @see https://doc.xt.com/docs/futures/MarketData/see-leverage-stratification-of-single-trading-pair
* @param {string} [symbols] a list of unified market symbols
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
*/
pub async fn fetch_leverage_tiers(&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 subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchLeverageTiers".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.public_inverse_get_future_market_v1_public_leverage_bracket_list(&[params.clone()]).await;
} else {
response = self.public_linear_get_future_market_v1_public_leverage_bracket_list(&[params.clone()]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "symbol": "rad_usdt",
// "leverageBrackets": [
// {
// "symbol": "rad_usdt",
// "bracket": 1,
// "maxNominalValue": "5000",
// "maintMarginRate": "0.025",
// "startMarginRate": "0.05",
// "maxStartMarginRate": null,
// "maxLeverage": "20",
// "minLeverage": "1"
// },
// ]
// },
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
symbols = self.market_symbols(&[symbols.clone()]);
return self.parse_leverage_tiers(data.clone(), &[symbols.clone(), Value::Str("symbol".to_string())]);
Value::Null
}
pub fn parse_leverage_tiers(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut marketIdKey = get_arg(optional_args, 1, Value::Null);
//
// {
// "symbol": "rad_usdt",
// "leverageBrackets": [
// {
// "symbol": "rad_usdt",
// "bracket": 1,
// "maxNominalValue": "5000",
// "maintMarginRate": "0.025",
// "startMarginRate": "0.05",
// "maxStartMarginRate": null,
// "maxLeverage": "20",
// "minLeverage": "1"
// },
// ]
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1141: bool = true;
while { if !__for_first_1141 { i = add(&i, &Value::Int(1)); } __for_first_1141 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("_".to_string()), Value::Str("contract".to_string())]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
if !is_equal(&symbols, &Value::Null) {
if is_true(&self.in_array(symbol.clone(), symbols.clone())) {
add_element_to_object(&mut result, &symbol, self.parse_market_leverage_tiers(entry.clone(), &[market.clone()]));
}
} else {
add_element_to_object(&mut result, &symbol, self.parse_market_leverage_tiers(get_value(&response, &i), &[market.clone()]));
}
}
}
return result;
Value::Null
}
/*
* @method
* @name xt#fetchMarketLeverageTiers
* @description retrieve information on the maximum leverage for different trade sizes of a single market
* @see https://doc.xt.com/docs/futures/MarketData/see-leverage-stratification-of-single-trading-pair
* @param {string} symbol unified market symbol
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
*/
pub async fn fetch_market_leverage_tiers(&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 mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchMarketLeverageTiers".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_87 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_leverage_bracket_detail(&[__ws_arg_87]).await;
} else {
let __ws_arg_88 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_leverage_bracket_detail(&[__ws_arg_88]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "symbol": "btc_usdt",
// "leverageBrackets": [
// {
// "symbol": "btc_usdt",
// "bracket": 1,
// "maxNominalValue": "500000",
// "maintMarginRate": "0.004",
// "startMarginRate": "0.008",
// "maxStartMarginRate": null,
// "maxLeverage": "125",
// "minLeverage": "1"
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_market_leverage_tiers(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_market_leverage_tiers(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "rad_usdt",
// "leverageBrackets": [
// {
// "symbol": "rad_usdt",
// "bracket": 1,
// "maxNominalValue": "5000",
// "maintMarginRate": "0.025",
// "startMarginRate": "0.05",
// "maxStartMarginRate": null,
// "maxLeverage": "20",
// "minLeverage": "1"
// },
// ]
// }
//
let mut tiers: Value = Value::List(vec![]);
let mut brackets: Value = self.safe_list_k(info.clone(), "leverageBrackets", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1142: bool = true;
while { if !__for_first_1142 { i = add(&i, &Value::Int(1)); } __for_first_1142 = false; is_less_than(&i, &get_array_length(&brackets)) } {
let mut tier: Value = get_value(&brackets, &i);
let mut tier: Value = get_value(&brackets, &i);
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string()), Value::Str("contract".to_string())]);
let mut minNotional: Value = self.safe_number(get_value(&brackets, &subtract(&i, &Value::Int(1))), Value::Str("maxNominalValue".to_string()), &[Value::Int(0)]);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_integer_k(tier.clone(), "bracket", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("_".to_string()), Value::Str("contract".to_string())]));
m.insert("currency".to_string(), get_value(&market, &Value::Str("settle".to_string())));
m.insert("minNotional".to_string(), minNotional.clone());
m.insert("maxNotional".to_string(), self.safe_number_k(tier.clone(), "maxNominalValue", &[]));
m.insert("maintenanceMarginRate".to_string(), self.safe_number_k(tier.clone(), "maintMarginRate", &[]));
m.insert("maxLeverage".to_string(), self.safe_number_k(tier.clone(), "maxLeverage", &[]));
m.insert("info".to_string(), tier.clone());
m
}));
}
}
return tiers;
Value::Null
}
/*
* @method
* @name xt#fetchFundingRateHistory
* @description fetches historical funding rates
* @see https://doc.xt.com/docs/futures/MarketData/get-funding-rate-records
* @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] to fetch
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {bool} params.paginate true/false whether to use the pagination helper to aumatically paginate through the results
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/en/latest/manual.html?#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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
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_cursor(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("id".to_string()), Value::Str("id".to_string()), Value::Int(1), Value::Int(200)]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRateHistory() supports swap contracts only".to_string()))));
}
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());
} else {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), Value::Int(200)); // max
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchFundingRateHistory".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_89 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_funding_rate_record(&[__ws_arg_89]).await;
} else {
let __ws_arg_90 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_funding_rate_record(&[__ws_arg_90]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "hasPrev": false,
// "hasNext": true,
// "items": [
// {
// "id": "210441653482221888",
// "symbol": "btc_usdt",
// "fundingRate": "0.000057",
// "createdTime": 1679875200000,
// "collectionInternal": 28800
// },
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(result.clone(), "items", &[Value::List(vec![])]);
let mut rates: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1143: bool = true;
while { if !__for_first_1143 { i = add(&i, &Value::Int(1)); } __for_first_1143 = false; is_less_than(&i, &get_array_length(&items)) } {
let mut entry: Value = get_value(&items, &i);
let mut entry: Value = get_value(&items, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut symbolInner: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "createdTime", &[]);
append_to_array(&mut rates, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), symbolInner.clone());
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "fundingRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchFundingInterval
* @description fetch the current funding rate interval
* @see https://doc.xt.com/docs/futures/MarketData/get-funding-rate-information
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_interval(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_funding_rate(symbol.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name xt#fetchFundingRate
* @description fetch the current funding rate
* @see https://doc.xt.com/docs/futures/MarketData/get-funding-rate-information
* @param {string} symbol unified market symbol
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRate() supports swap contracts only".to_string()))));
}
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 mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchFundingRate".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_91 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_funding_rate(&[__ws_arg_91]).await;
} else {
let __ws_arg_92 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_q_funding_rate(&[__ws_arg_92]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "symbol": "btc_usdt",
// "fundingRate": "0.000086",
// "nextCollectionTime": 1680307200000,
// "collectionInternal": 8
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(result.clone(), &[market.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);
//
// {
// "symbol": "btc_usdt",
// "fundingRate": "0.000086",
// "nextCollectionTime": 1680307200000,
// "collectionInternal": 8
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("_".to_string()), Value::Str("swap".to_string())]);
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "nextCollectionTime", &[]);
let mut interval: Value = self.safe_string_k(contract.clone(), "collectionInternal", &[]);
if !is_equal(&interval, &Value::Null) {
interval = add(&interval, &Value::Str("h".to_string()));
}
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("fundingRate".to_string(), self.safe_number_k(contract.clone(), "fundingRate", &[]));
m.insert("fundingTimestamp".to_string(), timestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), Value::Null);
m.insert("nextFundingDatetime".to_string(), Value::Null);
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), interval.clone());
m
});
Value::Null
}
/*
* @method
* @name xt#fetchOpenInterest
* @description retrieves the open interest of a contract trading pair
* @see https://doc.xt.com/docs/futures/MarketData/get-the-open-position-of-a-trading-pair
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [open interest structure]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest(&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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOpenInterest() supports swap contracts only".to_string()))));
}
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 mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOpenInterest".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_93 = self.extend(request.clone(), &[params.clone()]);
response = self.public_inverse_get_future_market_v1_public_contract_open_interest(&[__ws_arg_93]).await;
} else {
let __ws_arg_94 = self.extend(request.clone(), &[params.clone()]);
response = self.public_linear_get_future_market_v1_public_contract_open_interest(&[__ws_arg_94]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "symbol": "btc_usdt",
// "openInterest": "21005.8646",
// "openInterestUsd": "1120726916.46709",
// "time": 1785925443734
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_open_interest(result.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "btc_usdt",
// "openInterest": "21005.8646",
// "openInterestUsd": "1120726916.46709",
// "time": 1785925443734
// }
//
let mut marketId: Value = self.safe_string_k(interest.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut timestamp: Value = self.safe_integer_k(interest.clone(), "time", &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("openInterestAmount".to_string(), self.safe_number_k(interest.clone(), "openInterest", &[]));
m.insert("openInterestValue".to_string(), self.safe_number_k(interest.clone(), "openInterestUsd", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchTradingFee
* @description fetch the trading fees for a contract market, the same account-level rate applies to all contract markets of the same subtype
* @see https://doc.xt.com/docs/futures/User/Get%20User's%20Step%20Rate
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_trading_fee(&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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTradingFee() supports contract markets only".to_string()))));
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchTradingFee".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.private_inverse_get_future_user_v1_user_step_rate(&[params.clone()]).await;
} else {
response = self.private_linear_get_future_user_v1_user_step_rate(&[params.clone()]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "specialType": false,
// "vipProType": false,
// "stepRateProName": null,
// "discountLevel": 0,
// "makerFee": "0.0002",
// "takerFee": "0.0006",
// "levelReturnDay": 90,
// "totalTradeVolume": "78.708",
// "walletBalance": "21.95",
// "nextLvTradeVolume": "200000",
// "nextLvMakerFee": "0.00018",
// "nextLvTakerFee": "0.00054",
// "feeSource": "step_rate"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name xt#fetchTradingFees
* @description fetch the trading fees for multiple markets, the same account-level rate applies to all contract markets of the requested subtype
* @see https://doc.xt.com/docs/futures/User/Get%20User's%20Step%20Rate
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] 'linear' (default) or 'inverse'
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbol
*/
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
}));
self.load_markets(&[]).await;
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchTradingFees".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isInverse: Value = Value::Bool(is_equal(&subType, &Value::Str("inverse".to_string())));
let mut response: Value = Value::Null;
if is_true(&isInverse) {
response = self.private_inverse_get_future_user_v1_user_step_rate(&[params.clone()]).await;
} else {
response = self.private_linear_get_future_user_v1_user_step_rate(&[params.clone()]).await;
}
//
// same response as fetchTradingFee
//
let mut fee: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut symbols: Value = self.symbols.clone();
{
let mut i: Value = Value::Int(0);
let mut __for_first_1144: bool = true;
while { if !__for_first_1144 { i = add(&i, &Value::Int(1)); } __for_first_1144 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut market: Value = self.market(symbol.clone());
let mut matchesSubType: Value = ternary(is_true(&(isInverse)), get_value(&market, &Value::Str("inverse".to_string())), get_value(&market, &Value::Str("linear".to_string())));
if is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))) && is_true(&(is_equal(&matchesSubType, &Value::Bool(true)))) {
add_element_to_object(&mut result, &symbol, self.parse_trading_fee(fee.clone(), &[market.clone()]));
}
}
}
return result;
Value::Null
}
pub fn parse_trading_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut symbol: Value = ternary(is_true(&(!is_equal(&market, &Value::Null))), get_value(&market, &Value::Str("symbol".to_string())), Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), self.safe_number_k(fee.clone(), "makerFee", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee.clone(), "takerFee", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
/*
* @method
* @name xt#fetchFundingHistory
* @description fetch the funding history
* @see https://doc.xt.com/docs/futures/User/Get%20Fund%20Fee%20Information
* @param {string} symbol unified market symbol
* @param {int} [since] the starting timestamp in milliseconds
* @param {int} [limit] the number of entries to return
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding history structures]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
pub async fn fetch_funding_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 market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingHistory() supports swap contracts only".to_string()))));
}
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(&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 subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchFundingHistory".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_95 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_user_v1_balance_funding_rate_list(&[__ws_arg_95]).await;
} else {
let __ws_arg_96 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_user_v1_balance_funding_rate_list(&[__ws_arg_96]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "hasPrev": false,
// "hasNext": false,
// "items": [
// {
// "id": "210804044057280512",
// "symbol": "btc_usdt",
// "cast": "-0.0013",
// "coin": "usdt",
// "positionSide": "SHORT",
// "createdTime": 1679961600653
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1145: bool = true;
while { if !__for_first_1145 { i = add(&i, &Value::Int(1)); } __for_first_1145 = false; is_less_than(&i, &get_array_length(&items)) } {
let mut entry: Value = get_value(&items, &i);
let mut entry: Value = get_value(&items, &i);
append_to_array(&mut result, self.parse_funding_history(entry.clone(), &[market.clone()]));
}
}
let mut sorted: Value = self.sort_by(result.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_since_limit(sorted.clone(), &[since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_funding_history(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": "210804044057280512",
// "symbol": "btc_usdt",
// "cast": "-0.0013",
// "coin": "usdt",
// "positionSide": "SHORT",
// "createdTime": 1679961600653
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("_".to_string()), Value::Str("swap".to_string())]);
let mut currencyId: Value = self.safe_string_k(contract.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "createdTime", &[]);
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("code".to_string(), code.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), self.safe_string_k(contract.clone(), "id", &[]));
m.insert("amount".to_string(), self.safe_number_k(contract.clone(), "cast", &[]));
m
});
Value::Null
}
/*
* @ignore
* @method
* @param {object[]} breakList the "result" array of a position/break-list response
*/
pub fn index_position_break_list(&self, mut breakList: Value) -> Value {
let mut breakBySymbolSide: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1146: bool = true;
while { if !__for_first_1146 { i = add(&i, &Value::Int(1)); } __for_first_1146 = false; is_less_than(&i, &get_array_length(&breakList)) } {
let mut breakEntry: Value = get_value(&breakList, &i);
let mut breakEntry: Value = get_value(&breakList, &i);
// xt is hedge-mode only (positionSide is always 'LONG'/'SHORT' on every
// endpoint, including here and on position/list; there is no one-way/net
// mode that would report 'BOTH', see setLeverage()/setMarginMode() which
// both validate positionSide against exactly ['LONG', 'SHORT'])
let mut key: Value = add(&add(&self.safe_string_k(breakEntry.clone(), "symbol", &[]), &Value::Str("_".to_string())), &self.safe_string_k(breakEntry.clone(), "positionSide", &[]));
add_element_to_object(&mut breakBySymbolSide, &key, breakEntry.clone());
}
}
return breakBySymbolSide;
Value::Null
}
/*
* @ignore
* @method
* @param {object} entry a single entry from a position/list response
* @param {object} breakBySymbolSide the result of indexPositionBreakList()
*/
pub fn merge_position_break_info(&self, mut entry: Value, mut breakBySymbolSide: Value) -> Value {
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut key: Value = add(&add(&marketId, &Value::Str("_".to_string())), &self.safe_string_k(entry.clone(), "positionSide", &[]));
let mut breakEntry: Value = self.safe_dict(breakBySymbolSide.clone(), key.clone(), &[]);
if is_equal(&breakEntry, &Value::Null) {
return entry;
}
let __ws_arg_97 = self.safe_string_k(breakEntry.clone(), "breakPrice", &[]);
let __ws_arg_98 = self.safe_string_k(breakEntry.clone(), "calMarkPrice", &[]);
return self.extend(entry.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("breakPrice".to_string(), __ws_arg_97);
m.insert("calMarkPrice".to_string(), __ws_arg_98);
m
})]);
Value::Null
}
/*
* @method
* @name xt#fetchPosition
* @description fetch data on a single open contract trade position
* @see https://doc.xt.com/docs/futures/User/Get%20Position%20Information
* @see https://doc.xt.com/docs/futures/User/Get%20Margin%20Call%20Information
* @param {string} symbol unified market symbol of the market the position is held in
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position(&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 mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPosition".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut promisesUnresolved: Value = Value::List(vec![]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_99 = self.extend(request.clone(), &[params.clone()]);
append_to_array(&mut promisesUnresolved, self.private_inverse_get_future_user_v1_position_list(&[__ws_arg_99]).await);
let __ws_arg_100 = self.extend(request.clone(), &[params.clone()]);
append_to_array(&mut promisesUnresolved, self.private_inverse_get_future_user_v1_position_break_list(&[__ws_arg_100]).await);
} else {
let __ws_arg_101 = self.extend(request.clone(), &[params.clone()]);
append_to_array(&mut promisesUnresolved, self.private_linear_get_future_user_v1_position_list(&[__ws_arg_101]).await);
let __ws_arg_102 = self.extend(request.clone(), &[params.clone()]);
append_to_array(&mut promisesUnresolved, self.private_linear_get_future_user_v1_position_break_list(&[__ws_arg_102]).await);
}
let mut responsebreakResponseVariable = promise_all(&promisesUnresolved).await;
let mut response: Value = get_value(&responsebreakResponseVariable, &Value::Int(0));
let mut breakResponse: Value = get_value(&responsebreakResponseVariable, &Value::Int(1));
//
// position/list
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "symbol": "btc_usdt",
// "positionType": "ISOLATED",
// "positionSide": "SHORT",
// "contractType": "PERPETUAL",
// "positionSize": "10",
// "closeOrderSize": "0",
// "availableCloseSize": "10",
// "entryPrice": "27060",
// "openOrderSize": "0",
// "isolatedMargin": "1.0824",
// "openOrderMarginFrozen": "0",
// "realizedProfit": "-0.00130138",
// "autoMargin": false,
// "leverage": 25,
// "markPrice": "27050"
// },
// ]
// }
//
// position/break-list
//
// {
// "returnCode": 0,
// "result": [
// {
// "symbol": "btc_usdt",
// "positionSide": "SHORT",
// "breakPrice": "0",
// "calMarkPrice": "27050"
// },
// ]
// }
//
let mut positions: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
let mut breakBySymbolSide: Value = self.index_position_break_list(self.safe_list_k(breakResponse.clone(), "result", &[Value::List(vec![])]));
{
let mut i: Value = Value::Int(0);
let mut __for_first_1147: bool = true;
while { if !__for_first_1147 { i = add(&i, &Value::Int(1)); } __for_first_1147 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut entry: Value = get_value(&positions, &i);
let mut entry: Value = get_value(&positions, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut marketInner: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, Value::Str("contract".to_string())]);
let mut positionSize: Value = self.safe_string_k(entry.clone(), "positionSize", &[]);
if !is_equal(&positionSize, &Value::Str("0".to_string())) {
let mut merged: Value = self.merge_position_break_info(entry.clone(), breakBySymbolSide.clone());
return self.parse_position(merged.clone(), &[marketInner.clone()]);
}
}
}
panic!("{}", crate::exchange_errors::null_response(add(&add(&self.id, &Value::Str(" fetchPosition() could not find a position for ".to_string())), &symbol)));
Value::Null
}
/*
* @method
* @name xt#fetchPositions
* @description fetch all open positions
* @see https://doc.xt.com/docs/futures/User/Get%20Position%20Information
* @see https://doc.xt.com/docs/futures/User/Get%20Margin%20Call%20Information
* @param {string} [symbols] list of unified market symbols, not supported with xt
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structure]{@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 subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPositions".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut promisesUnresolved: Value = Value::List(vec![]);
if is_equal(&subType, &Value::Str("inverse".to_string())) {
append_to_array(&mut promisesUnresolved, self.private_inverse_get_future_user_v1_position_list(&[params.clone()]).await);
append_to_array(&mut promisesUnresolved, self.private_inverse_get_future_user_v1_position_break_list(&[params.clone()]).await);
} else {
append_to_array(&mut promisesUnresolved, self.private_linear_get_future_user_v1_position_list(&[params.clone()]).await);
append_to_array(&mut promisesUnresolved, self.private_linear_get_future_user_v1_position_break_list(&[params.clone()]).await);
}
let mut responsebreakResponseVariable = promise_all(&promisesUnresolved).await;
let mut response: Value = get_value(&responsebreakResponseVariable, &Value::Int(0));
let mut breakResponse: Value = get_value(&responsebreakResponseVariable, &Value::Int(1));
//
// position/list
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": [
// {
// "symbol": "btc_usdt",
// "positionType": "ISOLATED",
// "positionSide": "SHORT",
// "contractType": "PERPETUAL",
// "positionSize": "10",
// "closeOrderSize": "0",
// "availableCloseSize": "10",
// "entryPrice": "27060",
// "openOrderSize": "0",
// "isolatedMargin": "1.0824",
// "openOrderMarginFrozen": "0",
// "realizedProfit": "-0.00130138",
// "autoMargin": false,
// "leverage": 25,
// "markPrice": "27050"
// },
// ]
// }
//
// position/break-list
//
// {
// "returnCode": 0,
// "result": [
// {
// "symbol": "btc_usdt",
// "positionSide": "SHORT",
// "breakPrice": "0",
// "calMarkPrice": "27050"
// },
// ]
// }
//
let mut positions: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
let mut breakBySymbolSide: Value = self.index_position_break_list(self.safe_list_k(breakResponse.clone(), "result", &[Value::List(vec![])]));
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1148: bool = true;
while { if !__for_first_1148 { i = add(&i, &Value::Int(1)); } __for_first_1148 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut entry: Value = get_value(&positions, &i);
let mut entry: Value = get_value(&positions, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut marketInner: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, Value::Str("contract".to_string())]);
let mut merged: Value = self.merge_position_break_info(entry.clone(), breakBySymbolSide.clone());
append_to_array(&mut result, self.parse_position(merged.clone(), &[marketInner.clone()]));
}
}
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
/*
* @method
* @name xt#fetchPositionsHistory
* @description fetches historical closed positions
* @see https://doc.xt.com/docs/futures/Entrust/GetPositionHistory
* @param {string[]} [symbols] unified market symbols, all closed positions are returned if not assigned
* @param {int} [since] timestamp in ms of the earliest position to fetch
* @param {int} [limit] the maximum amount of records to fetch, default=10
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest position to fetch
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
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 symbolsLength: Value = get_array_length(&symbols);
if is_equal(&symbolsLength, &Value::Int(1)) {
market = 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())));
}
}
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 __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 subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPositionsHistory".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_103 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_get_future_trade_v1_position_list_history(&[__ws_arg_103]).await;
} else {
let __ws_arg_104 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_get_future_trade_v1_position_list_history(&[__ws_arg_104]).await;
}
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": {
// "hasPrev": false,
// "hasNext": false,
// "items": [
// {
// "id": "654559911738263296",
// "positionSide": "LONG",
// "contractType": "PERPETUAL",
// "symbol": "xrp_usdt",
// "positionType": 2,
// "closeProfit": "0.001",
// "closePositionSize": "1",
// "closeOpenPrice": "1.0651",
// "closePrice": "1.0652",
// "maxPositionSize": "1",
// "openTime": 1785761266645,
// "closeTime": 1785761266645,
// "startLeverage": 10,
// "endLeverage": 10,
// "working": false,
// "force": false,
// "forceMarkPrice": null,
// "totalFee": "0.0063",
// "totalFundFee": "0"
// }
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(result.clone(), "items", &[Value::List(vec![])]);
let mut positions: Value = self.parse_positions(items.clone(), &[symbols.clone()]);
return self.filter_by_since_limit(positions.clone(), &[since.clone(), limit.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);
//
// position/list
//
// {
// "symbol": "btc_usdt",
// "positionType": "ISOLATED",
// "positionSide": "SHORT",
// "contractType": "PERPETUAL",
// "positionSize": "10",
// "closeOrderSize": "0",
// "availableCloseSize": "10",
// "entryPrice": "27060",
// "openOrderSize": "0",
// "isolatedMargin": "1.0824",
// "openOrderMarginFrozen": "0",
// "realizedProfit": "-0.00130138",
// "autoMargin": false,
// "leverage": 25,
// "markPrice": "27050"
// }
//
// position/break-list
//
// {
// "symbol": "btc_usdt",
// "positionSide": "SHORT",
// "breakPrice": "0",
// "calMarkPrice": "27050"
// }
//
// position/list-history
//
// {
// "id": "654559911738263296",
// "positionSide": "LONG",
// "contractType": "PERPETUAL",
// "symbol": "xrp_usdt",
// "positionType": 2,
// "closeProfit": "0.001",
// "closePositionSize": "1",
// "closeOpenPrice": "1.0651",
// "closePrice": "1.0652",
// "maxPositionSize": "1",
// "openTime": 1785761266645,
// "closeTime": 1785761266645,
// "startLeverage": 10,
// "endLeverage": 10,
// "working": false,
// "force": false,
// "forceMarkPrice": null,
// "totalFee": "0.0063",
// "totalFundFee": "0"
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]);
// "ISOLATED"/"CROSSED" on position/list, 1 = cross / 2 = isolated on position/list-history
let mut positionType: Value = self.safe_string_k(position.clone(), "positionType", &[]);
let mut isCross: Value = Value::Bool(is_true(&(is_equal(&positionType, &Value::Str("CROSSED".to_string())))) || is_true(&(is_equal(&positionType, &Value::Str("1".to_string())))));
let mut marginMode: Value = ternary(is_true(&(isCross)), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
let mut collateral: Value = self.safe_number_k(position.clone(), "isolatedMargin", &[]);
// history entries carry the liquidation price in forceMarkPrice when force is true
let mut liquidationPriceString: Value = self.omit_zero(self.safe_string2(position.clone(), Value::Str("breakPrice".to_string()), Value::Str("forceMarkPrice".to_string()), &[]));
let mut timestamp: Value = self.safe_integer_k(position.clone(), "closeTime", &[]);
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(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("hedged".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_lower(position.clone(), Value::Str("positionSide".to_string()), &[]));
m.insert("contracts".to_string(), self.safe_number2(position.clone(), Value::Str("positionSize".to_string()), Value::Str("closePositionSize".to_string()), &[]));
m.insert("contractSize".to_string(), get_value(&market, &Value::Str("contractSize".to_string())));
m.insert("entryPrice".to_string(), self.safe_number2(position.clone(), Value::Str("entryPrice".to_string()), Value::Str("closeOpenPrice".to_string()), &[]));
m.insert("markPrice".to_string(), self.safe_number2(position.clone(), Value::Str("markPrice".to_string()), Value::Str("calMarkPrice".to_string()), &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "closePrice", &[]));
m.insert("notional".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_integer2(position.clone(), Value::Str("leverage".to_string()), Value::Str("endLeverage".to_string()), &[]));
m.insert("collateral".to_string(), collateral.clone());
m.insert("initialMargin".to_string(), collateral.clone());
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), Value::Null);
m.insert("realizedPnl".to_string(), self.safe_number2(position.clone(), Value::Str("realizedProfit".to_string()), Value::Str("closeProfit".to_string()), &[]));
m.insert("liquidationPrice".to_string(), self.parse_number(liquidationPriceString.clone(), &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("percentage".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name xt#transfer
* @description transfer currency internally between wallets on the same account
* @see https://doc.xt.com/docs/spot/Transfer/TransferBetweenUserSystems
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from - spot, swap, leverage, finance
* @param {string} toAccount account to transfer to - spot, swap, leverage, finance
* @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(), "accountsById", &[]);
let mut fromAccountId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toAccountId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[toAccount.clone()]);
let mut amountString: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bizId".to_string(), self.uuid(&[]));
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), amountString.clone());
m.insert("from".to_string(), fromAccountId.clone());
m.insert("to".to_string(), toAccountId.clone());
m
});
let __ws_arg_105 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_spot_post_balance_transfer(&[__ws_arg_105]).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(), self.safe_string_k(transfer.clone(), "result", &[]));
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 xt#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://doc.xt.com/docs/futures/User/Change%20Position%20Type
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} [symbol] required
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.positionSide] *required* "long" or "short"
* @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("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setMarginMode() supports contract markets only".to_string()))));
}
marginMode = to_lower(&marginMode);
if !is_equal(&marginMode, &Value::Str("isolated".to_string())) && !is_equal(&marginMode, &Value::Str("cross".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setMarginMode() marginMode argument should be isolated or cross".to_string()))));
}
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
marginMode = Value::Str("CROSSED".to_string());
} else {
marginMode = Value::Str("ISOLATED".to_string());
}
let mut posSide: Value = self.safe_string_upper(params.clone(), Value::Str("positionSide".to_string()), &[]);
self.check_required_argument(Value::Str("setMarginMode".to_string()), posSide.clone(), Value::Str("positionSide".to_string()), &[Value::List(vec![Value::Str("LONG".to_string()), Value::Str("SHORT".to_string())])]);
params = self.omit(params.clone(), Value::Str("positionSide".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("positionType".to_string(), marginMode.clone());
m.insert("positionSide".to_string(), posSide.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("setMarginMode".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_106 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_user_v1_position_change_type(&[__ws_arg_106]).await;
} else {
let __ws_arg_107 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_user_v1_position_change_type(&[__ws_arg_107]).await;
}
return response;
Value::Null
}
/*
* @method
* @name xt#editOrder
* @description cancels an order and places a new order
* @see https://doc.xt.com/docs/spot/Order/UpdateOrderLimit
* @see https://doc.xt.com/docs/futures/Order/update-orders
* @see https://doc.xt.com/docs/futures/Entrust/AlterStopLimit
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of the currency you want to trade in units of the 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.stopLoss] price to set a stop-loss on an open position
* @param {float} [params.takeProfit] price to set a take-profit on an open position
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&amount, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires an amount 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
});
let mut stopLoss: Value = self.safe_number2(params.clone(), Value::Str("stopLoss".to_string()), Value::Str("triggerStopPrice".to_string()), &[]);
let mut takeProfit: Value = self.safe_number2(params.clone(), Value::Str("takeProfit".to_string()), Value::Str("triggerProfitPrice".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
let mut isStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut isTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
if is_true(&isStopLoss) || is_true(&isTakeProfit) {
add_element_to_object(&mut request, &Value::Str("profitId".to_string()), id.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_true(&isStopLoss) {
add_element_to_object(&mut request, &Value::Str("triggerStopPrice".to_string()), self.price_to_precision(symbol.clone(), stopLoss.clone()));
} else if !is_equal(&takeProfit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("triggerProfitPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfit.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("origQty".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("editOrder".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Str("inverse".to_string())) {
if is_true(&isStopLoss) || is_true(&isTakeProfit) {
let __ws_arg_108 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_entrust_update_profit_stop(&[__ws_arg_108]).await;
} else {
let __ws_arg_109 = self.extend(request.clone(), &[params.clone()]);
response = self.private_inverse_post_future_trade_v1_order_update(&[__ws_arg_109]).await;
}
} else {
if is_true(&isStopLoss) || is_true(&isTakeProfit) {
let __ws_arg_110 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_update_profit_stop(&[__ws_arg_110]).await;
} else {
let __ws_arg_111 = self.extend(request.clone(), &[params.clone()]);
response = self.private_linear_post_future_trade_v1_order_update(&[__ws_arg_111]).await;
}
}
} else {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
let __ws_arg_112 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_put_order_order_id(&[__ws_arg_112]).await;
}
let mut result: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))), response.clone(), self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]));
return self.parse_order(result.clone(), &[market.clone()]);
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 {
//
// spot: error
//
// {
// "rc": 1,
// "mc": "AUTH_103",
// "ma": [],
// "result": null
// }
//
// spot: success
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": []
// }
//
// swap and future: error
//
// {
// "returnCode": 1,
// "msgInfo": "failure",
// "error": {
// "code": "403",
// "msg": "invalid signature"
// },
// "result": null
// }
//
// swap and future: success
//
// {
// "returnCode": 0,
// "msgInfo": "success",
// "error": null,
// "result": null
// }
//
// other:
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {}
// }
//
// {"returnCode":1,"msgInfo":"failure","error":{"code":"insufficient_balance","msg":"insufficient balance","args":[]},"result":null}
//
//
let mut status: Value = self.safe_string_upper2(response.clone(), Value::Str("msgInfo".to_string()), Value::Str("mc".to_string()), &[]);
if !is_equal(&status, &Value::Null) && !is_equal(&status, &Value::Str("SUCCESS".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
let mut error: Value = self.safe_dict_k(response.clone(), "error", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotErrorCode: Value = self.safe_string_k(response.clone(), "mc", &[]);
let mut errorCode: Value = self.safe_string_k(error.clone(), "code", &[spotErrorCode.clone()]);
let mut spotMessage: Value = self.safe_string_k(response.clone(), "msgInfo", &[]);
let mut message: Value = self.safe_string_k(error.clone(), "msg", &[spotMessage.clone()]);
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
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::List(vec![]));
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 signed: bool = is_equal(&get_value(&api, &Value::Int(0)), &Value::Str("private".to_string()));
let mut endpoint: Value = get_value(&api, &Value::Int(1));
let mut request: Value = add(&Value::Str("/".to_string()), &self.implode_params(path.clone(), params.clone()));
let mut payload: Value = Value::Null;
if is_true(&(is_equal(&endpoint, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&endpoint, &Value::Str("user".to_string())))) {
if is_true(&signed) {
payload = add(&add(&Value::Str("/".to_string()), &self.version), &request);
} else {
payload = add(&add(&add(&Value::Str("/".to_string()), &self.version), &Value::Str("/public".to_string())), &request);
}
} else {
payload = request.clone();
}
let mut url: Value = add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &endpoint), &payload);
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut urlencoded: Value = self.urlencode(self.keysort(query.clone(), &[]), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
if is_true(&signed) {
self.check_required_credentials(&[]);
let mut defaultRecvWindow: Value = self.safe_string_k(self.options.clone(), "recvWindow", &[]);
let mut recvWindow: Value = self.safe_string_k(query.clone(), "recvWindow", &[defaultRecvWindow.clone()]);
let mut timestamp: Value = self.number_to_string(self.nonce());
body = query.clone();
if is_true(&(is_equal(&payload, &Value::Str("/v4/order".to_string())))) || is_true(&(is_equal(&payload, &Value::Str("/future/trade/v1/order/create".to_string())))) || is_true(&(is_equal(&payload, &Value::Str("/future/trade/v1/entrust/create-plan".to_string())))) || is_true(&(is_equal(&payload, &Value::Str("/future/trade/v1/entrust/create-profit".to_string())))) || is_true(&(is_equal(&payload, &Value::Str("/future/trade/v1/order/create-batch".to_string())))) {
let mut id: Value = Value::Str("CCXT".to_string());
if is_equal(&body, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" sign() returned empty body".to_string()))));
}
if is_greater_than(&get_index_of(&payload, &Value::Str("future".to_string())), &negate(&Value::Int(1))) {
add_element_to_object(&mut body, &Value::Str("clientMedia".to_string()), id.clone());
if is_equal(&body, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" sign() returned empty body".to_string()))));
}
} else {
add_element_to_object(&mut body, &Value::Str("media".to_string()), id.clone());
}
}
let mut isUndefinedBody: bool = is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&path, &Value::Str("order/{orderId}".to_string())))) || is_true(&(is_equal(&path, &Value::Str("ws-token".to_string()))));
if is_true(&(is_equal(&method, &Value::Str("PUT".to_string())))) && is_true(&(is_equal(&endpoint, &Value::Str("spot".to_string())))) {
isUndefinedBody = false;
}
body = ternary(is_true(&isUndefinedBody), Value::Null, self.json(body.clone()));
let mut payloadString: Value = Value::Null;
if is_true(&(is_equal(&endpoint, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&endpoint, &Value::Str("user".to_string())))) {
payloadString = add(&add(&add(&add(&add(&add(&Value::Str("xt-validate-algorithms=HmacSHA256&xt-validate-appkey=".to_string()), &self.apiKey), &Value::Str("&xt-validate-recvwindow=".to_string())), &recvWindow), &Value::Str("&xt-validate-t".to_string())), &Value::Str("imestamp=".to_string())), ×tamp);
if is_true(&isUndefinedBody) {
if !is_equal(&urlencoded, &Value::Str("".to_string())) {
url = add(&url, &add(&Value::Str("?".to_string()), &urlencoded));
payloadString = add(&payloadString, &add(&add(&add(&add(&add(&Value::Str("#".to_string()), &method), &Value::Str("#".to_string())), &payload), &Value::Str("#".to_string())), &self.rawencode(self.keysort(query.clone(), &[]), &[])));
} else {
payloadString = add(&payloadString, &add(&add(&add(&Value::Str("#".to_string()), &method), &Value::Str("#".to_string())), &payload));
}
} else {
payloadString = add(&payloadString, &add(&add(&add(&add(&add(&Value::Str("#".to_string()), &method), &Value::Str("#".to_string())), &payload), &Value::Str("#".to_string())), &body));
}
add_element_to_object(&mut headers, &Value::Str("xt-validate-algorithms".to_string()), Value::Str("HmacSHA256".to_string()));
add_element_to_object(&mut headers, &Value::Str("xt-validate-recvwindow".to_string()), recvWindow.clone());
} else {
payloadString = add(&add(&add(&add(&Value::Str("xt-validate-appkey=".to_string()), &self.apiKey), &Value::Str("&xt-validate-t".to_string())), &Value::Str("imestamp=".to_string())), ×tamp); // we can't glue timestamp, breaks in php
if is_equal(&method, &Value::Str("GET".to_string())) {
if !is_equal(&urlencoded, &Value::Str("".to_string())) {
url = add(&url, &add(&Value::Str("?".to_string()), &urlencoded));
payloadString = add(&payloadString, &add(&add(&add(&Value::Str("#".to_string()), &payload), &Value::Str("#".to_string())), &urlencoded));
} else {
payloadString = add(&payloadString, &add(&Value::Str("#".to_string()), &payload));
}
} else {
payloadString = add(&payloadString, &add(&add(&add(&Value::Str("#".to_string()), &payload), &Value::Str("#".to_string())), &body));
}
}
let mut signature: Value = self.hmac(self.encode(payloadString.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[]);
add_element_to_object(&mut headers, &Value::Str("xt-validate-appkey".to_string()), self.apiKey.clone());
add_element_to_object(&mut headers, &Value::Str("xt-validate-timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut headers, &Value::Str("xt-validate-signature".to_string()), signature.clone());
} else {
if !is_equal(&urlencoded, &Value::Str("".to_string())) {
url = add(&url, &add(&Value::Str("?".to_string()), &urlencoded));
}
}
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
}
}