// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct 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);
// compatibility for sandbox/testnet options in userConfig
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for 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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on 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[2.min(args.len())..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_contract_order" => 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[4.min(args.len())..]).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[2.min(args.len())..]).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[4.min(args.len())..]).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[4.min(args.len())..]).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[4.min(args.len())..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&args[..]).await,
"fetch_canceled_orders" => self.fetch_canceled_orders(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args[..]).await,
"fetch_funding_interval" => self.fetch_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args[..]).await,
"fetch_market_leverage_tiers" => self.fetch_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(&args[..]).await,
"fetch_swap_and_future_markets" => self.fetch_swap_and_future_markets(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"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[3.min(args.len())..]).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[1.min(args.len())..]),
"parse_funding_history" => self.parse_funding_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"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[1.min(args.len())..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"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[1.min(args.len())..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_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[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction_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[1.min(args.len())..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for 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".into()));
m.insert("name".to_string(), Value::Str("XT".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("SC".into())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v4".into()));
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".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("https://sapi.xt.com".into()));
m.insert("linear".to_string(), Value::Str("https://fapi.xt.com".into()));
m.insert("inverse".to_string(), Value::Str("https://dapi.xt.com".into()));
m.insert("user".to_string(), Value::Str("https://api.xt.com".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://xt.com".into()));
m.insert("referral".to_string(), Value::Str("https://www.xt.com/en/accounts/register?ref=9PTM9VW".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://doc.xt.com/".into()), Value::Str("https://github.com/xtpub/api-doc".into())]));
m.insert("fees".to_string(), Value::Str("https://www.xt.com/en/rate".into()));
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/copytrade/user/v1/copy-trade/current-following-v2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/copytrade/user/v1/copy-trade/follower-balance-bill".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("future/copytrade/user/v1/copy-trade/follower-position".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-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/profit-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/reverse-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/reverse-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/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-entrust/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/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/order/trade-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/position/cross-margin/{symbol}".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/leverage/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/position/list/active".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/trade/v1/order/trade-list-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/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/auto-deleverage/history".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/compat/balance/{coin}".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/taker-over/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/profit-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/reverse-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/reverse-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/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-entrust/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/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/order/trade-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/position/cross-margin/{symbol}".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/leverage/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/position/list/active".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/trade/v1/order/trade-list-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/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/auto-deleverage/history".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/compat/balance/{coin}".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/taker-over/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".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.002".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000".into()), &[]), self.parse_number(Value::Str("0.0018".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000".into()), &[]), self.parse_number(Value::Str("0.0016".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000".into()), &[]), self.parse_number(Value::Str("0.0014".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000".into()), &[]), self.parse_number(Value::Str("0.0012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("150000".into()), &[]), self.parse_number(Value::Str("0.0010".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("300000".into()), &[]), self.parse_number(Value::Str("0.0008".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("600000".into()), &[]), self.parse_number(Value::Str("0.0007".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1200000".into()), &[]), self.parse_number(Value::Str("0.0006".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500000".into()), &[]), self.parse_number(Value::Str("0.0005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6000000".into()), &[]), self.parse_number(Value::Str("0.0004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0.0003".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("30000000".into()), &[]), self.parse_number(Value::Str("0.0002".into()), &[])])]));
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000".into()), &[]), self.parse_number(Value::Str("0.0018".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000".into()), &[]), self.parse_number(Value::Str("0.0016".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000".into()), &[]), self.parse_number(Value::Str("0.0014".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000".into()), &[]), self.parse_number(Value::Str("0.0012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("150000".into()), &[]), self.parse_number(Value::Str("0.0010".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("300000".into()), &[]), self.parse_number(Value::Str("0.0008".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("600000".into()), &[]), self.parse_number(Value::Str("0.0007".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1200000".into()), &[]), self.parse_number(Value::Str("0.0006".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500000".into()), &[]), self.parse_number(Value::Str("0.0005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6000000".into()), &[]), self.parse_number(Value::Str("0.0004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0.0003".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("30000000".into()), &[]), self.parse_number(Value::Str("0.0002".into()), &[])])]));
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".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0006".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.0004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200000".into()), &[]), self.parse_number(Value::Str("0.00038".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.00036".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.00034".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.00032".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0.00028".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("30000000".into()), &[]), self.parse_number(Value::Str("0.00024".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000000".into()), &[]), self.parse_number(Value::Str("0.0002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("100000000".into()), &[]), self.parse_number(Value::Str("0.00016".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("300000000".into()), &[]), self.parse_number(Value::Str("0.00012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000000".into()), &[]), self.parse_number(Value::Str("0.00008".into()), &[])])]));
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.0006".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200000".into()), &[]), self.parse_number(Value::Str("0.000588".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.00057".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.00054".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.00051".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0.00048".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("30000000".into()), &[]), self.parse_number(Value::Str("0.00045".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000000".into()), &[]), self.parse_number(Value::Str("0.00045".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("100000000".into()), &[]), self.parse_number(Value::Str("0.00036".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("300000000".into()), &[]), self.parse_number(Value::Str("0.00033".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000000".into()), &[]), self.parse_number(Value::Str("0.0003".into()), &[])])]));
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".into()).clone());
m.insert("404".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("429".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("500".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("502".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("503".to_string(), Value::Str("OnMaintenance".into()).clone());
m.insert("AUTH_001".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_002".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_003".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_004".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_005".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_006".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_007".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_101".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_102".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_103".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_104".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_105".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("AUTH_106".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("SYMBOL_001".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("SYMBOL_002".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("SYMBOL_003".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("SYMBOL_004".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("SYMBOL_005".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("ORDER_001".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_002".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("ORDER_003".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_004".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_005".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_006".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_007".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("ORDER_F0101".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0102".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0103".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0201".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0202".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0203".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0301".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0401".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0501".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0502".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_F0601".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("COMMON_001".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("COMMON_002".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("COMMON_003".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("CURRENCY_001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("DEPOSIT_001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("DEPOSIT_002".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("DEPOSIT_003".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("DEPOSIT_004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("DEPOSIT_005".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("DEPOSIT_006".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("DEPOSIT_007".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("DEPOSIT_008".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_002".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_003".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("WITHDRAW_004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_005".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_006".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_008".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("WITHDRAW_009".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("WITHDRAW_010".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_011".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("WITHDRAW_012".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("WITHDRAW_013".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("WITHDRAW_014".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_015".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_016".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_017".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_018".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_019".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_020".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("WITHDRAW_021".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("WITHDRAW_022".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_023".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_024".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("WITHDRAW_025".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_002".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("FUND_003".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_004".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("FUND_005".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("FUND_014".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_015".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_016".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_017".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_018".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_019".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_020".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_021".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_022".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("FUND_044".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("TRANSFER_001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("TRANSFER_002".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("TRANSFER_003".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("TRANSFER_004".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("TRANSFER_005".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("TRANSFER_006".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("TRANSFER_007".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("TRANSFER_008".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("TRANSFER_009".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("TRANSFER_010".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("TRANSFER_011".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("TRANSFER_012".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("symbol_not_support_trading_via_api".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("open_order_min_nominal_value_limit".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("insufficient_balance".to_string(), Value::Str("InsufficientFunds".into()).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".into()).clone());
m.insert("Exceeds the minimum notional value of a single order".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("insufficient balance".to_string(), Value::Str("InsufficientFunds".into()).clone());
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15m".to_string(), Value::Str("15m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("2h".to_string(), Value::Str("2h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("8h".to_string(), Value::Str("8h".into()));
m.insert("1d".to_string(), Value::Str("1d".into()));
m.insert("3d".to_string(), Value::Str("3d".into()));
m.insert("1w".to_string(), Value::Str("1w".into()));
m.insert("1M".to_string(), Value::Str("1M".into()));
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".into()));
m.insert("leverage".to_string(), Value::Str("LEVER".into()));
m.insert("finance".to_string(), Value::Str("FINANCE".into()));
m.insert("swap".to_string(), Value::Str("FUTURES_U".into()));
m.insert("future".to_string(), Value::Str("FUTURES_U".into()));
m.insert("linear".to_string(), Value::Str("FUTURES_U".into()));
m.insert("inverse".to_string(), Value::Str("FUTURES_C".into()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ERC20".to_string(), Value::Str("Ethereum".into()));
m.insert("TRC20".to_string(), Value::Str("Tron".into()));
m.insert("BEP20".to_string(), Value::Str("BNB Smart Chain".into()));
m.insert("BEP2".to_string(), Value::Str("BNB-BEP2".into()));
m.insert("AVAX".to_string(), Value::Str("AVAX C-Chain".into()));
m.insert("GAL".to_string(), Value::Str("GAL(FT)".into()));
m.insert("ALEO".to_string(), Value::Str("ALEO(IOU)".into()));
m.insert("BTC".to_string(), Value::Str("Bitcoin".into()));
m.insert("XT".to_string(), Value::Str("XT Smart Chain".into()));
m.insert("ETC".to_string(), Value::Str("Ethereum Classic".into()));
m.insert("MATIC".to_string(), Value::Str("Polygon".into()));
m.insert("LTC".to_string(), Value::Str("Litecoin".into()));
m.insert("BTS".to_string(), Value::Str("BitShares".into()));
m.insert("XRP".to_string(), Value::Str("Ripple".into()));
m.insert("XLM".to_string(), Value::Str("Stellar Network".into()));
m.insert("ADA".to_string(), Value::Str("Cardano".into()));
m.insert("XWC".to_string(), Value::Str("XWC-XWC".into()));
m.insert("DOGE".to_string(), Value::Str("dogecoin".into()));
m.insert("DCR".to_string(), Value::Str("Decred".into()));
m.insert("SC".to_string(), Value::Str("Siacoin".into()));
m.insert("XTZ".to_string(), Value::Str("Tezos".into()));
m.insert("ZEC".to_string(), Value::Str("Zcash".into()));
m.insert("XMR".to_string(), Value::Str("Monero".into()));
m.insert("LSK".to_string(), Value::Str("Lisk".into()));
m.insert("ATOM".to_string(), Value::Str("Cosmos".into()));
m.insert("ONT".to_string(), Value::Str("Ontology".into()));
m.insert("ALGO".to_string(), Value::Str("Algorand".into()));
m.insert("SOL".to_string(), Value::Str("SOL-SOL".into()));
m.insert("DOT".to_string(), Value::Str("Polkadot".into()));
m.insert("ZEN".to_string(), Value::Str("Horizen".into()));
m.insert("FIL".to_string(), Value::Str("Filecoin".into()));
m.insert("CHZ".to_string(), Value::Str("chz".into()));
m.insert("ICP".to_string(), Value::Str("Internet Computer".into()));
m.insert("KSM".to_string(), Value::Str("Kusama".into()));
m.insert("LUNA".to_string(), Value::Str("Terra".into()));
m.insert("THETA".to_string(), Value::Str("Theta Token".into()));
m.insert("FTM".to_string(), Value::Str("Fantom".into()));
m.insert("VET".to_string(), Value::Str("VeChain".into()));
m.insert("NEAR".to_string(), Value::Str("NEAR Protocol".into()));
m.insert("ONE".to_string(), Value::Str("Harmony".into()));
m.insert("KLAY".to_string(), Value::Str("Klaytn".into()));
m.insert("AR".to_string(), Value::Str("Arweave".into()));
m.insert("CELT".to_string(), Value::Str("OKT".into()));
m.insert("EGLD".to_string(), Value::Str("Elrond eGold".into()));
m.insert("CRO".to_string(), Value::Str("CRO-CRONOS".into()));
m.insert("BCH".to_string(), Value::Str("Bitcoin Cash".into()));
m.insert("GLMR".to_string(), Value::Str("Moonbeam".into()));
m.insert("LOOP".to_string(), Value::Str("LOOP-LRC".into()));
m.insert("REI".to_string(), Value::Str("REI Network".into()));
m.insert("ASTR".to_string(), Value::Str("Astar Network".into()));
m.insert("OP".to_string(), Value::Str("OPT".into()));
m.insert("MMT".to_string(), Value::Str("MMT-MMT".into()));
m.insert("TBC".to_string(), Value::Str("TBC-TBC".into()));
m.insert("OMAX".to_string(), Value::Str("OMAX-OMAX CHAIN".into()));
m.insert("GMMT".to_string(), Value::Str("GMMT chain".into()));
m.insert("ZIL".to_string(), Value::Str("Zilliqa".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Ethereum".to_string(), Value::Str("ERC20".into()));
m.insert("Tron".to_string(), Value::Str("TRC20".into()));
m.insert("BNB Smart Chain".to_string(), Value::Str("BEP20".into()));
m.insert("BNB-BEP2".to_string(), Value::Str("BEP2".into()));
m.insert("Bitcoin".to_string(), Value::Str("BTC".into()));
m.insert("XT Smart Chain".to_string(), Value::Str("XT".into()));
m.insert("Ethereum Classic".to_string(), Value::Str("ETC".into()));
m.insert("Polygon".to_string(), Value::Str("MATIC".into()));
m.insert("Litecoin".to_string(), Value::Str("LTC".into()));
m.insert("BitShares".to_string(), Value::Str("BTS".into()));
m.insert("Ripple".to_string(), Value::Str("XRP".into()));
m.insert("Stellar Network".to_string(), Value::Str("XLM".into()));
m.insert("Cardano".to_string(), Value::Str("ADA".into()));
m.insert("XWC-XWC".to_string(), Value::Str("XWC".into()));
m.insert("dogecoin".to_string(), Value::Str("DOGE".into()));
m.insert("Decred".to_string(), Value::Str("DCR".into()));
m.insert("Siacoin".to_string(), Value::Str("SC".into()));
m.insert("Tezos".to_string(), Value::Str("XTZ".into()));
m.insert("Zcash".to_string(), Value::Str("ZEC".into()));
m.insert("Monero".to_string(), Value::Str("XMR".into()));
m.insert("Lisk".to_string(), Value::Str("LSK".into()));
m.insert("Cosmos".to_string(), Value::Str("ATOM".into()));
m.insert("Ontology".to_string(), Value::Str("ONT".into()));
m.insert("Algorand".to_string(), Value::Str("ALGO".into()));
m.insert("SOL-SOL".to_string(), Value::Str("SOL".into()));
m.insert("Polkadot".to_string(), Value::Str("DOT".into()));
m.insert("Horizen".to_string(), Value::Str("ZEN".into()));
m.insert("Filecoin".to_string(), Value::Str("FIL".into()));
m.insert("chz".to_string(), Value::Str("CHZ".into()));
m.insert("Internet Computer".to_string(), Value::Str("ICP".into()));
m.insert("Kusama".to_string(), Value::Str("KSM".into()));
m.insert("Terra".to_string(), Value::Str("LUNA".into()));
m.insert("Theta Token".to_string(), Value::Str("THETA".into()));
m.insert("Fantom".to_string(), Value::Str("FTM".into()));
m.insert("VeChain".to_string(), Value::Str("VET".into()));
m.insert("AVAX C-Chain".to_string(), Value::Str("AVAX".into()));
m.insert("NEAR Protocol".to_string(), Value::Str("NEAR".into()));
m.insert("Harmony".to_string(), Value::Str("ONE".into()));
m.insert("Klaytn".to_string(), Value::Str("KLAY".into()));
m.insert("Arweave".to_string(), Value::Str("AR".into()));
m.insert("OKT".to_string(), Value::Str("CELT".into()));
m.insert("Elrond eGold".to_string(), Value::Str("EGLD".into()));
m.insert("CRO-CRONOS".to_string(), Value::Str("CRO".into()));
m.insert("Bitcoin Cash".to_string(), Value::Str("BCH".into()));
m.insert("Moonbeam".to_string(), Value::Str("GLMR".into()));
m.insert("LOOP-LRC".to_string(), Value::Str("LOOP".into()));
m.insert("REI Network".to_string(), Value::Str("REI".into()));
m.insert("Astar Network".to_string(), Value::Str("ASTR".into()));
m.insert("GAL(FT)".to_string(), Value::Str("GAL".into()));
m.insert("ALEO(IOU)".to_string(), Value::Str("ALEO".into()));
m.insert("OPT".to_string(), Value::Str("OP".into()));
m.insert("MMT-MMT".to_string(), Value::Str("MMT".into()));
m.insert("TBC-TBC".to_string(), Value::Str("TBC".into()));
m.insert("OMAX-OMAX CHAIN".to_string(), Value::Str("OMAX".into()));
m.insert("GMMT chain".to_string(), Value::Str("GMMT".into()));
m.insert("Zilliqa".to_string(), Value::Str("ZIL".into()));
m
}));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("recvWindow".to_string(), Value::Str("5000".into()));
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".into()));
m
}));
m.insert("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
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".into()));
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".into()));
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".into()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".into()));
m
}));
m
}));
m
}));
m
})]);
Value::Null
}
pub fn nonce(&self) -> Value {
return (match (&(self.milliseconds()), &(self.safe_integer_k(self.options.clone(), "timeDifference", &[Value::Int(0)]))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
Value::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]).await;
//
// {
// "rc": 0,
// "mc": "SUCCESS",
// "ma": [],
// "result": {
// "serverTime": 1677823301643
// }
// }
//
let mut data: Value = self.safe_dict_k(response, "result", &[]);
return self.safe_integer_k(data, "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::from(vec![self.public_spot_get_wallet_support_currency(&[params.clone()]).await, self.public_spot_get_currencies(&[params]).await]);
let mut chainsResponsecurrenciesResponseVariable = promise_all(&promisesRaw).await;
let mut chainsResponse: Value = chainsResponsecurrenciesResponseVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut currenciesResponse: Value = chainsResponsecurrenciesResponseVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
//
// 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, "result", &[Value::from(vec![])]);
let mut currenciesResult: Value = self.safe_dict_k(currenciesResponse, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currenciesData: Value = self.safe_list_k(currenciesResult, "currencies", &[Value::from(vec![])]);
let mut chainsDataIndexed: Value = self.index_by(chainsData, Value::Str("currency".into()));
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1159: bool = true;
while { if !__for_first_1159 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1159 = false; i.as_f64().unwrap_or(f64::NAN) < ((currenciesData.len() as i64) as f64) } {
let mut entry: Value = currenciesData.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut 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, "supportChains", &[Value::from(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_1158: bool = true;
while { if !__for_first_1158 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1158 = false; j.as_f64().unwrap_or(f64::NAN) < ((rawNetworks.len() as i64) as f64) } {
let mut rawNetwork: Value = rawNetworks.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.safe_string_k(rawNetwork.clone(), "chain", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut networks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rawNetwork.clone());
m.insert("id".to_string(), networkId);
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, "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: Option<String> = self.safe_string_k(entry.clone(), "type", &[]).as_str().map(str::to_owned);
let mut type_var: Value = Value::Null;
if (typeRaw.as_deref() == Some("FT")) {
type_var = Value::Str("crypto".into());
} else {
type_var = Value::Str("other".into());
}
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&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);
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(self.safe_string_k(entry.clone(), "depositStatus", &[]).as_str() == Some("1")));
m.insert("withdraw".to_string(), Value::Bool(self.safe_string_k(entry, "withdrawStatus", &[]).as_str() == Some("1")));
m.insert("networks".to_string(), networks);
m.insert("type".to_string(), type_var);
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 matches!(self.safe_bool_k(self.options.clone(), "adjustForTimeDifference", &[Value::Bool(false)]), Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut promisesUnresolved: Value = Value::from(vec![self.fetch_spot_markets(&[params.clone()]).await, self.fetch_swap_and_future_markets(&[params]).await]);
let mut promises: Value = promise_all(&promisesUnresolved).await;
let mut spotMarkets: Value = promises.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut swapAndFutureMarkets: Value = promises.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return self.array_concat(spotMarkets, swapAndFutureMarkets);
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]).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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut symbols: Value = self.safe_list_k(data, "symbols", &[Value::from(vec![])]);
return self.parse_markets(symbols);
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::from(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]).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(markets.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), Value::Str("result".into()), &[Value::from(vec![])]), self.safe_list(markets.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null), Value::Str("result".into()), &[Value::from(vec![])]));
return self.parse_markets(swapAndFutureMarkets);
Value::Null
}
pub fn parse_markets(&self, mut markets: Value) -> Value {
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1160: bool = true;
while { if !__for_first_1160 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1160 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&markets).as_f64().unwrap_or(f64::NAN) } {
let mut parsed: Value = self.parse_market(get_value(&markets, &i));
if (parsed != Value::Null) {
append_to_array(&mut result, parsed);
}
}
}
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".into()), Value::Str("baseCoin".into()), &[]);
let mut quoteId: Value = self.safe_string2(market.clone(), Value::Str("quoteCurrency".into()), Value::Str("quoteCoin".into()), &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut state: Option<String> = self.safe_string_k(market.clone(), "state", &[]).as_str().map(str::to_owned);
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut filters: Value = self.safe_list_k(market.clone(), "filters", &[Value::from(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_1161: bool = true;
while { if !__for_first_1161 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1161 = false; i.as_f64().unwrap_or(f64::NAN) < ((filters.len() as i64) as f64) } {
let mut entry: Value = self.safe_dict(filters.clone(), i.clone(), &[]);
let mut filter: Option<String> = self.safe_string_k(entry.clone(), "filter", &[]).as_str().map(str::to_owned);
if (filter.as_deref() == Some("QUANTITY")) {
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 (filter.as_deref() == Some("QUOTE_QTY")) {
minCost = self.safe_number_k(entry.clone(), "min", &[]);
}
if (filter.as_deref() == Some("PRICE")) {
minPrice = self.safe_number_k(entry.clone(), "min", &[]);
maxPrice = self.safe_number_k(entry, "max", &[]);
}
}
}
if (amountPrecision == Value::Null) {
amountPrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quantityPrecision", &[])]), &[]);
}
let mut underlyingType: Option<String> = self.safe_string_k(market.clone(), "underlyingType", &[]).as_str().map(str::to_owned);
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".into());
if (underlyingType.as_deref() == Some("U_BASED")) {
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), quote).into());
settleId = baseId.clone();
settle = quote.clone();
linear = Value::Bool(true);
inverse = Value::Bool(false);
} else if (underlyingType.as_deref() == Some("COIN_BASED")) {
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), base).into());
settleId = baseId.clone();
settle = base.clone();
linear = Value::Bool(false);
inverse = Value::Bool(true);
}
if (underlyingType.is_some()) {
expiry = self.safe_integer_k(market.clone(), "deliveryDate", &[]);
let mut productType: Option<String> = self.safe_string_k(market.clone(), "productType", &[]).as_str().map(str::to_owned);
if (productType.as_deref() != Some("perpetual")) {
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str("-".into())).into()), self.yymmdd(expiry.clone(), &[])).into());
type_var = Value::Str("future".into());
future = Value::Bool(true);
} else {
type_var = Value::Str("swap".into());
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 contract.as_bool() == Some(true) {
isActive = self.safe_bool_k(market.clone(), "isOpenApi", &[Value::Bool(false)]);
} else {
if (state.as_deref() == Some("ONLINE")) && matches!((self.safe_bool_k(market.clone(), "tradingEnabled", &[Value::Bool(false)])), Value::Bool(true)) && matches!((self.safe_bool_k(market.clone(), "openapiEnabled", &[Value::Bool(false)])), 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);
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), settle);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), type_var);
m.insert("spot".to_string(), spot);
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), swap);
m.insert("future".to_string(), future);
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), isActive);
m.insert("contract".to_string(), contract);
m.insert("linear".to_string(), linear);
m.insert("inverse".to_string(), inverse);
m.insert("taker".to_string(), self.safe_number2(market.clone(), Value::Str("takerFee".into()), Value::Str("takerFeeRate".into()), &[]));
m.insert("maker".to_string(), self.safe_number2(market.clone(), Value::Str("makerFee".into()), Value::Str("makerFeeRate".into()), &[]));
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));
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);
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".into()), &[]));
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);
m.insert("max".to_string(), maxAmount);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minPrice);
m.insert("max".to_string(), maxPrice);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minCost);
m.insert("max".to_string(), maxCost);
m
}));
m
}));
m.insert("info".to_string(), market);
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".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), Value::Int(1000)]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
if (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 = (match (&(self.parse_timeframe(timeframe.clone())), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), (match (&(math_ceil(&(match ((since).as_f64(), (duration).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))), &(duration)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })); }
}
let mut limitResolved: Value = limit.clone();
if (limit != Value::Null) {
let mut maxLimit: Value = (if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { Value::Int(1000) } else { Value::Int(1500) }); // spot : derivatives max limit
limitResolved = crate::runtime::Math::min(&limit, &maxLimit);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limitResolved.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), Value::Int(1000)); }
}
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("endTime".into(), until); }
}
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_0 = self.extend(request.clone(), &[paramsOmitted.clone()]);
response = self.public_linear_get_future_market_v1_public_q_kline(&[__ws_arg_0]).await;
} else if (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_1 = self.extend(request.clone(), &[paramsOmitted.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_kline(&[__ws_arg_1]).await;
} else {
let __ws_arg_2 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::from(vec![])]);
return self.parse_ohlc_vs(ohlcvs, &[market, timeframe, since, limitResolved]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let __market_empty = indexmap::IndexMap::new();
let market = market.as_map().unwrap_or(&__market_empty);
//
// 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 = (match market.get("inverse") { Some(Value::Bool(__b)) => Value::Bool(*__b), _ => Value::Null });
let mut volumeIndex: Value = Value::Str("a".into());
if (isInverse.as_bool() == Some(true)) {
volumeIndex = Value::Str("v".into());
}
return Value::from(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, Value::Str("q".into()), volumeIndex, &[])]);
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 (self.markets.clone() == 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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), 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 (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("level".into(), crate::runtime::Math::min(&limit, &Value::Int(50))); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("level".into(), Value::Int(50)); }
}
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(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 (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_5 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer2(orderBook.clone(), Value::Str("timestamp".into()), Value::Str("t".into()), &[]);
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let mut ob: Value = self.parse_order_book(orderBook.clone(), symbol.clone(), &[timestamp.clone()]);
add_element_to_object(&mut ob, &Value::Str("nonce".into()), self.safe_integer_k(orderBook.clone(), "lastUpdateId", &[]));
return ob;
}
let mut swapOb: Value = self.parse_order_book(orderBook.clone(), symbol, &[timestamp, Value::Str("b".into()), Value::Str("a".into())]);
add_element_to_object(&mut swapOb, &Value::Str("nonce".into()), self.safe_integer2(orderBook, Value::Str("u".into()), Value::Str("lastUpdateId".into()), &[]));
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(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 (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(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, &[params]);
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, "result", &[]);
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
return self.parse_ticker(get_value(&ticker, &Value::Int(0)), &[market.clone()]);
}
return self.parse_ticker(ticker, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
if (symbolsNormalized != Value::Null) {
market = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchTickers".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchTickers".into()), &[market.clone(), paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_9 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_agg_tickers(&[__ws_arg_9]).await;
} else if (subType.as_str() == Some("linear")) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
let __ws_arg_10 = self.extend(request.clone(), &[paramsSubType.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, &[paramsSubType]);
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, "result", &[Value::from(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1162: bool = true;
while { if !__for_first_1162 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1162 = false; i.as_f64().unwrap_or(f64::NAN) < ((tickers.len() as i64) as f64) } {
let mut ticker: Value = self.parse_ticker(tickers.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[market.clone()]);
let mut symbol: Value = ticker.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if (symbol != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), ticker); }
}
}
}
return self.filter_by_array(result, Value::Str("symbol".into()), &[symbolsNormalized]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbolsNormalized != Value::Null) {
market = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
}
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchBidsAsks".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchBidsAsks".into()), &[market.clone(), paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut isInverse: bool = subType.as_str() == Some("inverse");
let mut isLinear: bool = (subType.as_str() == Some("linear")) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
let mut isContract: bool = isInverse || isLinear;
let mut response: Value = Value::Null;
if isInverse {
let __ws_arg_12 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.public_inverse_get_future_market_v1_public_q_ticker_books(&[__ws_arg_12]).await;
} else if isLinear {
let __ws_arg_13 = self.extend(request.clone(), &[paramsSubType.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, &[paramsSubType]);
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, "result", &[Value::from(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1163: bool = true;
while { if !__for_first_1163 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1163 = false; i.as_f64().unwrap_or(f64::NAN) < ((tickers.len() as i64) as f64) } {
let mut rawTicker: Value = tickers.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
// 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 = Value::Str("spot".into());
if isContract {
marketType = Value::Str("contract".into());
}
let mut marketInner: Value = self.safe_market(&[marketId, market.clone(), Value::Str("_".into()), marketType]);
let mut ticker: Value = self.parse_ticker(rawTicker, &[marketInner]);
let mut symbol: Value = ticker.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if (symbol != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), ticker); }
}
}
}
return self.filter_by_array(result, Value::Str("symbol".into()), &[symbolsNormalized]);
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 = (if (market != Value::Null) { self.safe_string_k(market.clone(), "type", &[]) } else { Value::Null });
let mut hasSpotKeys: bool = (matches!(&ticker, Value::Dict(__d) if __d.contains_key("cv"))) || (matches!(&ticker, Value::Dict(__d) if __d.contains_key("aq")));
if (marketType == Value::Null) {
marketType = (if hasSpotKeys { Value::Str("spot".into()) } else { Value::Str("contract".into()) });
}
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Str("_".into()), marketType]);
let mut symbol: Value = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
let mut open: Value = self.safe_string_k(ticker.clone(), "o", &[]);
// spot 'cv' and 'cr' can lag 'o' and 'c', so safeTicker derives both from open and last
let mut percentage: Value = self.safe_string_k(ticker.clone(), "r", &[]);
if (open == Value::Null) {
percentage = self.safe_string2(ticker.clone(), Value::Str("cr".into()), Value::Str("r".into()), &[]);
}
if (percentage != Value::Null) {
percentage = crate::precise::Precise::stringMul(&percentage, &Value::Str("100".into()));
}
let mut baseVolume: Value = self.safe_string2(ticker.clone(), Value::Str("a".into()), Value::Str("q".into()), &[]);
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "v", &[]);
let mut contractSize: Value = self.safe_string_k(marketResolved.clone(), "contractSize", &[]);
if (marketResolved.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) && (contractSize != Value::Null) {
// 'a' counts contracts, 'v' is in the settle currency
let mut contractVolume: Value = crate::precise::Precise::stringMul(&baseVolume, &contractSize);
if (marketResolved.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
baseVolume = quoteVolume.clone();
quoteVolume = contractVolume.clone();
} else {
baseVolume = contractVolume;
}
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
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(), open);
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(), Value::Null);
m.insert("percentage".to_string(), self.parse_number(percentage, &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume);
m.insert("quoteVolume".to_string(), quoteVolume);
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), 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 (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("num".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(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 (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_17 = self.extend(request, &[params]);
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, "result", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchMyTrades".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchMyTrades".into()), &[market.clone(), paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("size".into(), limit.clone()); }
}
if (subType.as_str() == Some("inverse")) {
let __ws_arg_18 = self.extend(request.clone(), &[paramsSubType.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(), &[paramsSubType.clone()]);
response = self.private_linear_get_future_trade_v1_order_trade_list(&[__ws_arg_19]).await;
}
} else {
let mut marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("fetchMyTrades".into()), &[paramsSubType]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginOrSpotRequest: Value = Value::Str("SPOT".into());
if (marginMode != Value::Null) {
marginOrSpotRequest = Value::Str("LEVER".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("bizType".into(), marginOrSpotRequest); }
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_20 = self.extend(request, &[paramsMarginMode]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(data, "items", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market, since, limit]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// 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".into()), Value::Str("symbol".into()), &[]);
let mut marketType: Value = (if (market != Value::Null) { self.safe_string_k(market.clone(), "type", &[]) } else { Value::Null });
let mut hasSpotKeys: bool = (matches!(&trade, Value::Dict(__d) if __d.contains_key("b"))) || (matches!(&trade, Value::Dict(__d) if __d.contains_key("bizType"))) || (matches!(&trade, Value::Dict(__d) if __d.contains_key("oi")));
if (marketType == Value::Null) {
marketType = (if hasSpotKeys { Value::Str("spot".into()) } else { Value::Str("contract".into()) });
}
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Str("_".into()), 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 (isBuyerMaker != Value::Null) {
side = (if isBuyerMaker.as_bool() == Some(true) { Value::Str("sell".into()) } else { Value::Str("buy".into()) });
takerOrMaker = Value::Str("taker".into()); // public trades always taker
} else {
let mut takerMaker: Value = self.safe_string_lower_k(trade.clone(), "takerMaker", &[]);
if (takerMaker != Value::Null) {
takerOrMaker = takerMaker;
} else {
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "isMaker", &[]);
if (isMaker != Value::Null) {
takerOrMaker = (if isMaker.as_bool() == Some(true) { Value::Str("maker".into()) } else { Value::Str("taker".into()) });
}
}
let mut orderSide: Value = self.safe_string_lower_k(trade.clone(), "orderSide", &[]);
if (orderSide != Value::Null) {
side = orderSide;
} else {
let mut bidOrAsk: Option<String> = self.safe_string_k(trade.clone(), "m", &[]).as_str().map(str::to_owned);
if (bidOrAsk.is_some()) {
side = (if (bidOrAsk.as_deref() == Some("BID")) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
}
}
}
let mut timestamp: Value = self.safe_integer_n(trade.clone(), Value::from(vec![Value::Str("t".into()), Value::Str("time".into()), Value::Str("timestamp".into())]), &[]);
let mut quantity: Value = self.safe_string2(trade.clone(), Value::Str("q".into()), Value::Str("quantity".into()), &[]);
let mut amount: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
amount = quantity.clone();
} else {
if (quantity == Value::Null) {
amount = crate::precise::Precise::stringMul(&self.safe_string_k(trade.clone(), "a", &[]), &self.number_to_string(marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null)));
} else {
amount = crate::precise::Precise::stringMul(&quantity, &self.number_to_string(marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null)));
}
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string_n(trade.clone(), Value::from(vec![Value::Str("i".into()), Value::Str("tradeId".into()), Value::Str("execId".into())]), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("order".to_string(), self.safe_string2(trade.clone(), Value::Str("orderId".into()), Value::Str("oi".into()), &[]));
m.insert("type".to_string(), self.safe_string_lower_k(trade.clone(), "orderType", &[]));
m.insert("side".to_string(), side);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("price".to_string(), self.safe_string2(trade.clone(), Value::Str("p".into()), Value::Str("price".into()), &[]));
m.insert("amount".to_string(), amount);
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".into()), Value::Str("feeCoin".into()), &[]), &[]));
m.insert("cost".to_string(), self.safe_string_k(trade, "fee", &[]));
m
}));
m
}), &[marketResolved]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchBalance".into()), &[Value::Null, params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchBalance".into()), &[Value::Null, paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut isContractWallet: bool = (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
if (subType.as_str() == Some("inverse")) {
response = self.private_inverse_get_future_user_v1_balance_list(&[paramsSubType.clone()]).await;
} else if (subType.as_str() == Some("linear")) || isContractWallet {
response = self.private_linear_get_future_user_v1_balance_list(&[paramsSubType.clone()]).await;
} else {
response = self.private_spot_get_balances(&[paramsSubType]).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 (subType != Value::Null) || isContractWallet {
balances = self.safe_list_k(response.clone(), "result", &[Value::from(vec![])]);
} else {
let mut data: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
balances = self.safe_list_k(data, "assets", &[Value::from(vec![])]);
}
return self.parse_balance(balances);
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_1164: bool = true;
while { if !__for_first_1164 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1164 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut balance: Value = self.safe_dict(response.clone(), i.clone(), &[]);
let mut currencyId: Value = self.safe_string2(balance.clone(), Value::Str("currency".into()), Value::Str("coin".into()), &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
let mut free: Value = self.safe_string2(balance.clone(), Value::Str("availableAmount".into()), Value::Str("availableBalance".into()), &[]);
let mut used: Value = self.safe_string_k(balance.clone(), "frozenAmount", &[]);
let mut total: Value = self.safe_string2(balance.clone(), Value::Str("totalAmount".into()), Value::Str("walletBalance".into()), &[]);
if (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, "openOrderMarginFrozen", &[]), &crossedAndIsolatedMargin);
}
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), free); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), used); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), total); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketBuyOrderWithCost() supports spot orders only".into()))));
}
return self.create_order(symbol, Value::Str("market".into()), Value::Str("buy".into()), cost, &[Value::Int(1), params]).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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut symbolValue: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let mut isTrailing: bool = (matches!(¶ms, Value::Dict(__d) if __d.contains_key("trailingPercent"))) || (matches!(¶ms, Value::Dict(__d) if __d.contains_key("trailingAmount"))) || (matches!(¶ms, Value::Dict(__d) if __d.contains_key("trailingTriggerPrice")));
if isTrailing {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() trailing orders are only supported on swap markets".into()))));
}
return self.create_spot_order(symbolValue.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else {
return self.create_contract_order(symbolValue, type_var, side, amount, &[price, params]).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 (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a side argument".into()))));
}
if (self.markets.clone() == 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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
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 marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("createOrder".into()), &[params]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginOrSpotRequest: Value = Value::Str("SPOT".into());
if (marginMode != Value::Null) {
marginOrSpotRequest = Value::Str("LEVER".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("bizType".into(), marginOrSpotRequest); }
if (type_var.as_str() == Some("market")) {
timeInForce = self.safe_string_upper_k(paramsMarginMode.clone(), "timeInForce", &[Value::Str("FOK".into())]);
if (side.as_str() == Some("buy")) {
let mut cost: Value = self.safe_string_k(paramsMarginMode.clone(), "cost", &[]);
let mut createMarketBuyOrderRequiresPrice: Value = self.safe_bool_k(self.options.clone(), "createMarketBuyOrderRequiresPrice", &[Value::Bool(true)]);
if (createMarketBuyOrderRequiresPrice.as_bool() == Some(true)) {
if (price == Value::Null) && (cost == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), 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".into()))));
} 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 (price != Value::Null) {
costCalculated = crate::precise::Precise::stringMul(&amountString, &priceString);
} else {
costCalculated = cost.clone();
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quoteQty".into(), self.cost_to_precision(symbol.clone(), costCalculated)); }
}
} else {
let mut amountCost: Value = (if (cost != Value::Null) { cost } else { amount.clone() });
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quoteQty".into(), self.cost_to_precision(symbol.clone(), amountCost)); }
}
}
} else {
timeInForce = self.safe_string_upper_k(paramsMarginMode.clone(), "timeInForce", &[Value::Str("GTC".into())]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
}
let mut isMarketBuy: bool = (type_var.as_str() == Some("market")) && (side.as_str() == Some("buy"));
let mut paramsWithoutCost: Value = paramsMarginMode.clone();
if isMarketBuy {
paramsWithoutCost = self.omit(paramsMarginMode, Value::Str("cost".into()), &[]);
}
let mut postOnlyparamsPostOnlyVariable = self.handle_post_only(Value::Bool(type_var.as_str() == Some("market")), Value::Bool(timeInForce.as_str() == Some("GTX")), &[paramsWithoutCost]);
let mut postOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (postOnly.as_bool() == Some(true)) {
timeInForce = Value::Str("GTX".into());
}
let mut paramsOmitted: Value = self.omit(paramsPostOnly, Value::from(vec![Value::Str("timeInForce".into()), Value::Str("postOnly".into())]), &[]);
if (side.as_str() == Some("sell")) || (type_var.as_str() == Some("limit")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.amount_to_precision(symbol, amount)); }
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("timeInForce".into(), timeInForce); }
let __ws_arg_21 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[market]);
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 (self.markets.clone() == 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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("origQty".to_string(), self.amount_to_precision(symbol.clone(), amount));
m
});
let mut timeInForce: Value = self.safe_string_upper_k(params.clone(), "timeInForce", &[]);
let mut postOnlyparamsPostOnlyVariable = self.handle_post_only(Value::Bool(type_var.as_str() == Some("market")), Value::Bool(timeInForce.as_str() == Some("GTX")), &[params]);
let mut postOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (postOnly.as_bool() == Some(true)) {
timeInForce = Value::Str("GTX".into());
}
let mut paramsOmitted4: Value = self.omit(paramsPostOnly, Value::from(vec![Value::Str("timeInForce".into()), Value::Str("postOnly".into())]), &[]);
if (timeInForce != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("timeInForce".into(), timeInForce.clone()); }
}
let mut reduceOnly: Value = self.safe_bool_k(paramsOmitted4.clone(), "reduceOnly", &[Value::Bool(false)]);
if (side.as_str() == Some("buy")) {
let mut requestType: Value = Value::Str("LONG".into());
if (reduceOnly.as_bool() == Some(true)) {
requestType = Value::Str("SHORT".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("positionSide".into(), requestType.clone()); }
} else {
let mut requestType: Value = Value::Str("SHORT".into());
if (reduceOnly.as_bool() == Some(true)) {
requestType = Value::Str("LONG".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("positionSide".into(), requestType); }
}
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut triggerPrice: Value = self.safe_number2(paramsOmitted4.clone(), Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), &[]);
let mut stopLoss: Value = self.safe_number2(paramsOmitted4.clone(), Value::Str("stopLoss".into()), Value::Str("triggerStopPrice".into()), &[]);
let mut takeProfit: Value = self.safe_number2(paramsOmitted4.clone(), Value::Str("takeProfit".into()), Value::Str("triggerProfitPrice".into()), &[]);
let mut trailingPercent: Value = self.safe_string_k(paramsOmitted4.clone(), "trailingPercent", &[]);
let mut trailingAmount: Value = self.safe_string_k(paramsOmitted4.clone(), "trailingAmount", &[]);
let mut trailingTriggerPrice: Value = self.safe_number_k(paramsOmitted4.clone(), "trailingTriggerPrice", &[]);
let mut isTrigger: bool = triggerPrice != Value::Null;
let mut isStopLoss: bool = stopLoss != Value::Null;
let mut isTakeProfit: bool = takeProfit != Value::Null;
let mut isTrailing: bool = (trailingPercent != Value::Null) || (trailingAmount != Value::Null);
if isTrailing && (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() trailing orders are only supported on swap markets".into()))));
}
if (trailingTriggerPrice != Value::Null) && !isTrailing {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() trailingTriggerPrice requires trailingPercent or trailingAmount".into()))));
}
if (price != Value::Null) {
if !(isStopLoss) && !(isTakeProfit) && !(isTrailing) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
}
}
if isTrailing {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderSide".into(), to_upper(&side)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("triggerPriceType".into(), self.safe_string_k(paramsOmitted4.clone(), "triggerPriceType", &[Value::Str("LATEST_PRICE".into())])); }
let mut marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("createOrder".into()), &[paramsOmitted4.clone(), Value::Str("cross".into())]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("positionType".into(), (if (marginMode.as_str() == Some("isolated")) { Value::Str("ISOLATED".into()) } else { Value::Str("CROSSED".into()) })); }
if (trailingPercent != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("callback".into(), Value::Str("PROPORTION".into())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("callbackVal".into(), self.parse_to_numeric(crate::precise::Precise::stringDiv(&trailingPercent, &Value::Str("100".into())))); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("callback".into(), Value::Str("FIXED".into())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("callbackVal".into(), self.parse_to_numeric(trailingAmount)); }
}
if (trailingTriggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("activationPrice".into(), self.price_to_precision(symbol.clone(), trailingTriggerPrice)); }
}
let mut paramsOmitted3: Value = self.omit(paramsMarginMode, Value::from(vec![Value::Str("trailingPercent".into()), Value::Str("trailingAmount".into()), Value::Str("trailingTriggerPrice".into())]), &[]);
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_22 = self.extend(request.clone(), &[paramsOmitted3.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_create_track(&[__ws_arg_22]).await;
} else if (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_23 = self.extend(request.clone(), &[paramsOmitted3]);
response = self.private_inverse_post_future_trade_v1_entrust_create_track(&[__ws_arg_23]).await;
}
} else if isTrigger {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("timeInForce".into(), (if (timeInForce == Value::Null) { Value::Str("GTC".into()) } else { timeInForce })); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("triggerPriceType".into(), self.safe_string_k(paramsOmitted4.clone(), "triggerPriceType", &[Value::Str("LATEST_PRICE".into())])); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderSide".into(), to_upper(&side)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stopPrice".into(), self.price_to_precision(symbol.clone(), triggerPrice)); }
let mut entrustType: Value = Value::Str("STOP".into());
if (type_var.as_str() == Some("market")) {
entrustType = Value::Str("STOP_MARKET".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("entrustType".into(), entrustType); }
let mut paramsOmitted2: Value = self.omit(paramsOmitted4.clone(), Value::Str("triggerPrice".into()), &[]);
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_24 = self.extend(request.clone(), &[paramsOmitted2.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_create_plan(&[__ws_arg_24]).await;
} else if (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_25 = self.extend(request.clone(), &[paramsOmitted2]);
response = self.private_inverse_post_future_trade_v1_entrust_create_plan(&[__ws_arg_25]).await;
}
} else if isStopLoss || isTakeProfit {
if isStopLoss {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("triggerStopPrice".into(), self.price_to_precision(symbol.clone(), stopLoss)); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("triggerProfitPrice".into(), self.price_to_precision(symbol, takeProfit)); }
}
let mut paramsOmitted: Value = self.omit(paramsOmitted4.clone(), Value::from(vec![Value::Str("stopLoss".into()), Value::Str("takeProfit".into())]), &[]);
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_26 = self.extend(request.clone(), &[paramsOmitted.clone()]);
response = self.private_linear_post_future_trade_v1_entrust_create_profit(&[__ws_arg_26]).await;
} else if (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_27 = self.extend(request.clone(), &[paramsOmitted]);
response = self.private_inverse_post_future_trade_v1_entrust_create_profit(&[__ws_arg_27]).await;
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderSide".into(), to_upper(&side)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderType".into(), to_upper(&type_var)); }
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_28 = self.extend(request.clone(), &[paramsOmitted4.clone()]);
response = self.private_linear_post_future_trade_v1_order_create(&[__ws_arg_28]).await;
} else if (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_29 = self.extend(request, &[paramsOmitted4]);
response = self.private_inverse_post_future_trade_v1_order_create(&[__ws_arg_29]).await;
}
}
return self.parse_order(response, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchOrder".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchOrder".into()), &[market.clone(), paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut trigger: Value = self.safe_bool2(paramsSubType.clone(), Value::Str("trigger".into()), Value::Str("stop".into()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(paramsSubType.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(paramsSubType.clone(), "trailing", &[]);
if (trailing.as_bool() == Some(true)) {
let mut isContract: bool = (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
if !isContract {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() trailing orders are only supported on swap and future markets".into()))));
}
}
if (trigger.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("entrustId".into(), id.clone()); }
} else if (stopLossTakeProfit.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("profitId".into(), id.clone()); }
} else if (trailing.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("trackId".into(), id.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderId".into(), id); }
}
if (trigger.as_bool() == Some(true)) {
let mut paramsOmitted3: Value = self.omit(paramsSubType.clone(), Value::from(vec![Value::Str("trigger".into()), Value::Str("stop".into())]), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_30 = self.extend(request.clone(), &[paramsOmitted3.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(), &[paramsOmitted3]);
response = self.private_linear_get_future_trade_v1_entrust_plan_detail(&[__ws_arg_31]).await;
}
} else if (stopLossTakeProfit.as_bool() == Some(true)) {
let mut paramsOmitted2: Value = self.omit(paramsSubType.clone(), Value::Str("stopLossTakeProfit".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_32 = self.extend(request.clone(), &[paramsOmitted2.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(), &[paramsOmitted2]);
response = self.private_linear_get_future_trade_v1_entrust_profit_detail(&[__ws_arg_33]).await;
}
} else if (trailing.as_bool() == Some(true)) {
let mut paramsOmitted: Value = self.omit(paramsSubType.clone(), Value::Str("trailing".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_34 = self.extend(request.clone(), &[paramsOmitted.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(), &[paramsOmitted]);
response = self.private_linear_get_future_trade_v1_entrust_track_detail(&[__ws_arg_35]).await;
}
} else if (subType.as_str() == Some("inverse")) {
let __ws_arg_36 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_get_future_trade_v1_order_detail(&[__ws_arg_36]).await;
} else if (subType.as_str() == Some("linear")) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
let __ws_arg_37 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_linear_get_future_trade_v1_order_detail(&[__ws_arg_37]).await;
} else {
let __ws_arg_38 = self.extend(request, &[paramsSubType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchOrders".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchOrders".into()), &[market.clone(), paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut trigger: Value = self.safe_bool2(paramsSubType.clone(), Value::Str("trigger".into()), Value::Str("stop".into()), &[]);
let mut trailing: Value = self.safe_bool_k(paramsSubType.clone(), "trailing", &[]);
if (trailing.as_bool() == Some(true)) {
let mut isContract: bool = (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
if !isContract {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() trailing orders are only supported on swap and future markets".into()))));
}
}
if (trigger.as_bool() == Some(true)) {
let mut paramsOmitted2: Value = self.omit(paramsSubType.clone(), Value::from(vec![Value::Str("trigger".into()), Value::Str("stop".into())]), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_39 = self.extend(request.clone(), &[paramsOmitted2.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(), &[paramsOmitted2]);
response = self.private_linear_get_future_trade_v1_entrust_plan_list_history(&[__ws_arg_40]).await;
}
} else if (trailing.as_bool() == Some(true)) {
let mut paramsOmitted: Value = self.omit(paramsSubType.clone(), Value::Str("trailing".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_41 = self.extend(request.clone(), &[paramsOmitted.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(), &[paramsOmitted]);
response = self.private_linear_get_future_trade_v1_entrust_track_list_history(&[__ws_arg_42]).await;
}
} else if (subType.as_str() == Some("inverse")) {
let __ws_arg_43 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_get_future_trade_v1_order_list_history(&[__ws_arg_43]).await;
} else if (subType.as_str() == Some("linear")) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
let __ws_arg_44 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_linear_get_future_trade_v1_order_list_history(&[__ws_arg_44]).await;
} else {
let mut marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("fetchOrders".into()), &[paramsSubType]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginOrSpotRequest: Value = Value::Str("SPOT".into());
if (marginMode != Value::Null) {
marginOrSpotRequest = Value::Str("LEVER".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("bizType".into(), marginOrSpotRequest); }
let __ws_arg_45 = self.extend(request, &[paramsMarginMode]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data, "items", &[Value::from(vec![])]);
return self.parse_orders(orders, &[market, since, limit]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
add_element_to_object(&mut request, &Value::Str("symbol".into()), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".into()), limit.clone());
}
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".into()), since.clone());
}
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchOrdersByStatus".into()), &[market.clone(), paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut trigger: Value = self.safe_bool2(paramsSubType.clone(), Value::Str("stop".into()), Value::Str("trigger".into()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(paramsSubType.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(paramsSubType.clone(), "trailing", &[]);
if (trailing.as_bool() == Some(true)) {
let mut isContract: bool = (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
if !isContract {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrdersByStatus() trailing orders are only supported on swap and future markets".into()))));
}
// 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::from(vec![Value::Str("state".into()), Value::Str("size".into())]), &[]);
} else if (status.as_str() == Some("open")) {
if (trigger.as_bool() == Some(true)) || (stopLossTakeProfit.as_bool() == Some(true)) {
add_element_to_object(&mut request, &Value::Str("state".into()), Value::Str("NOT_TRIGGERED".into()));
} else if (type_var.as_str() == Some("swap")) {
add_element_to_object(&mut request, &Value::Str("state".into()), Value::Str("UNFINISHED".into())); // NEW & PARTIALLY_FILLED
}
} else if (status.as_str() == Some("closed")) {
if (trigger.as_bool() == Some(true)) || (stopLossTakeProfit.as_bool() == Some(true)) {
add_element_to_object(&mut request, &Value::Str("state".into()), Value::Str("TRIGGERED".into()));
} else {
add_element_to_object(&mut request, &Value::Str("state".into()), Value::Str("FILLED".into()));
}
} else if (status.as_str() == Some("canceled")) {
if (trigger.as_bool() == Some(true)) || (stopLossTakeProfit.as_bool() == Some(true)) {
add_element_to_object(&mut request, &Value::Str("state".into()), Value::Str("USER_REVOCATION".into()));
} else {
add_element_to_object(&mut request, &Value::Str("state".into()), Value::Str("CANCELED".into()));
}
} else {
add_element_to_object(&mut request, &Value::Str("state".into()), status.clone());
}
if (trigger.as_bool() == Some(true)) || (stopLossTakeProfit.as_bool() == Some(true)) || (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".into()), since.clone());
}
if (limit != Value::Null) && (trailing.as_bool() != Some(true)) {
add_element_to_object(&mut request, &Value::Str("size".into()), limit.clone());
}
}
if (trigger.as_bool() == Some(true)) {
let mut paramsOmitted3: Value = self.omit(paramsSubType.clone(), Value::from(vec![Value::Str("stop".into()), Value::Str("trigger".into())]), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_46 = self.extend(request.clone(), &[paramsOmitted3.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(), &[paramsOmitted3]);
response = self.private_linear_get_future_trade_v1_entrust_plan_list(&[__ws_arg_47]).await;
}
} else if (stopLossTakeProfit.as_bool() == Some(true)) {
let mut paramsOmitted2: Value = self.omit(paramsSubType.clone(), Value::Str("stopLossTakeProfit".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_48 = self.extend(request.clone(), &[paramsOmitted2.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(), &[paramsOmitted2]);
response = self.private_linear_get_future_trade_v1_entrust_profit_list(&[__ws_arg_49]).await;
}
} else if (trailing.as_bool() == Some(true)) {
let mut paramsOmitted: Value = self.omit(paramsSubType.clone(), Value::Str("trailing".into()), &[]);
if (status.as_str() == Some("open")) {
if (subType.as_str() == Some("inverse")) {
let __ws_arg_50 = self.extend(request.clone(), &[paramsOmitted.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(), &[paramsOmitted.clone()]);
response = self.private_linear_get_future_trade_v1_entrust_track_list(&[__ws_arg_51]).await;
}
} else {
if (subType.as_str() == Some("inverse")) {
let __ws_arg_52 = self.extend(request.clone(), &[paramsOmitted.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(), &[paramsOmitted]);
response = self.private_linear_get_future_trade_v1_entrust_track_list_history(&[__ws_arg_53]).await;
}
}
} else if (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
if (subType.as_str() == Some("inverse")) {
let __ws_arg_54 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_get_future_trade_v1_order_list(&[__ws_arg_54]).await;
} else {
let __ws_arg_55 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_linear_get_future_trade_v1_order_list(&[__ws_arg_55]).await;
}
} else {
let mut marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("fetchOrdersByStatus".into()), &[paramsSubType]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginOrSpotRequest: Value = Value::Str("SPOT".into());
if (marginMode != Value::Null) {
marginOrSpotRequest = Value::Str("LEVER".into());
}
add_element_to_object(&mut request, &Value::Str("bizType".into()), marginOrSpotRequest);
if (status.as_str() != Some("open")) {
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".into()), since.clone());
}
if (limit != Value::Null) {
request = self.omit(request.clone(), Value::Str("size".into()), &[]);
add_element_to_object(&mut request, &Value::Str("limit".into()), limit.clone());
}
let __ws_arg_56 = self.extend(request.clone(), &[paramsMarginMode.clone()]);
response = self.private_spot_get_history_order(&[__ws_arg_56]).await;
} else {
let __ws_arg_57 = self.extend(request, &[paramsMarginMode]);
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::from(vec![]);
let mut resultDict: Value = self.safe_dict_k(response.clone(), "result", &[]);
if (resultDict != Value::Null) {
orders = self.safe_list_k(resultDict, "items", &[Value::from(vec![])]);
} else {
orders = self.safe_list_k(response, "result", &[Value::from(vec![])]);
}
if (trailing.as_bool() == Some(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, Value::Str("status".into()), status, &[]);
return self.filter_by_since_limit(filteredOrders, &[since.clone(), limit.clone()]);
}
return self.parse_orders(orders, &[market, since, limit]);
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".into()), &[symbol, since, limit, params]).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".into()), &[symbol, since, limit, params]).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".into()), &[symbol, since, limit, params]).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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("cancelOrder".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("cancelOrder".into()), &[market.clone(), paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut trigger: Value = self.safe_bool2(paramsSubType.clone(), Value::Str("trigger".into()), Value::Str("stop".into()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(paramsSubType.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(paramsSubType.clone(), "trailing", &[]);
if (trailing.as_bool() == Some(true)) {
let mut isContract: bool = (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
if !isContract {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() trailing orders are only supported on swap and future markets".into()))));
}
}
if (trigger.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("entrustId".into(), id.clone()); }
} else if (stopLossTakeProfit.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("profitId".into(), id.clone()); }
} else if (trailing.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("trackId".into(), id.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderId".into(), id); }
}
if (trigger.as_bool() == Some(true)) {
let mut paramsOmitted3: Value = self.omit(paramsSubType.clone(), Value::from(vec![Value::Str("trigger".into()), Value::Str("stop".into())]), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_58 = self.extend(request.clone(), &[paramsOmitted3.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(), &[paramsOmitted3]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_plan(&[__ws_arg_59]).await;
}
} else if (stopLossTakeProfit.as_bool() == Some(true)) {
let mut paramsOmitted2: Value = self.omit(paramsSubType.clone(), Value::Str("stopLossTakeProfit".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_60 = self.extend(request.clone(), &[paramsOmitted2.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(), &[paramsOmitted2]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_profit_stop(&[__ws_arg_61]).await;
}
} else if (trailing.as_bool() == Some(true)) {
let mut paramsOmitted: Value = self.omit(paramsSubType.clone(), Value::Str("trailing".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_62 = self.extend(request.clone(), &[paramsOmitted.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(), &[paramsOmitted]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_track(&[__ws_arg_63]).await;
}
} else if (subType.as_str() == Some("inverse")) {
let __ws_arg_64 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_post_future_trade_v1_order_cancel(&[__ws_arg_64]).await;
} else if (subType.as_str() == Some("linear")) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
let __ws_arg_65 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_linear_post_future_trade_v1_order_cancel(&[__ws_arg_65]).await;
} else {
let __ws_arg_66 = self.extend(request, &[paramsSubType]);
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 = (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
let mut order: Value = (if isContractResponse { response.clone() } else { self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]) });
return self.parse_order(order, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("cancelAllOrders".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("cancelAllOrders".into()), &[market, paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut trigger: Value = self.safe_bool2(paramsSubType.clone(), Value::Str("trigger".into()), Value::Str("stop".into()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(paramsSubType.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(paramsSubType.clone(), "trailing", &[]);
if (trailing.as_bool() == Some(true)) {
let mut isContract: bool = (subType != Value::Null) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
if !isContract {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() trailing orders are only supported on swap and future markets".into()))));
}
}
if (trigger.as_bool() == Some(true)) {
let mut paramsOmitted3: Value = self.omit(paramsSubType.clone(), Value::from(vec![Value::Str("trigger".into()), Value::Str("stop".into())]), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_67 = self.extend(request.clone(), &[paramsOmitted3.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(), &[paramsOmitted3]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_all_plan(&[__ws_arg_68]).await;
}
} else if (stopLossTakeProfit.as_bool() == Some(true)) {
let mut paramsOmitted2: Value = self.omit(paramsSubType.clone(), Value::Str("stopLossTakeProfit".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_69 = self.extend(request.clone(), &[paramsOmitted2.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(), &[paramsOmitted2]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_all_profit_stop(&[__ws_arg_70]).await;
}
} else if (trailing.as_bool() == Some(true)) {
let mut paramsOmitted: Value = self.omit(paramsSubType.clone(), Value::Str("trailing".into()), &[]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_71 = self.extend(request.clone(), &[paramsOmitted.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(), &[paramsOmitted]);
response = self.private_linear_post_future_trade_v1_entrust_cancel_all_track(&[__ws_arg_72]).await;
}
} else if (subType.as_str() == Some("inverse")) {
let __ws_arg_73 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_post_future_trade_v1_order_cancel_all(&[__ws_arg_73]).await;
} else if (subType.as_str() == Some("linear")) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
let __ws_arg_74 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_linear_post_future_trade_v1_order_cancel_all(&[__ws_arg_74]).await;
} else {
let mut marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("cancelAllOrders".into()), &[paramsSubType]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginOrSpotRequest: Value = Value::Str("SPOT".into());
if (marginMode != Value::Null) {
marginOrSpotRequest = Value::Str("LEVER".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("bizType".into(), marginOrSpotRequest); }
let __ws_arg_75 = self.extend(request, &[paramsMarginMode]);
response = self.private_spot_delete_open_order(&[__ws_arg_75]).await;
}
return Value::from(vec![self.safe_order(response, &[])]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderIds".to_string(), ids);
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("cancelOrders".into()), &[market, params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (subType != Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrders() does not support swap and future orders, only spot orders are accepted".into()))));
}
let __ws_arg_76 = self.extend(request, &[paramsSubType]);
let mut response: Value = self.private_spot_delete_batch_order(&[__ws_arg_76]).await;
return Value::from(vec![self.safe_order(response, &[])]);
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 = (if (matches!(&order, Value::Dict(__d) if __d.contains_key("result"))) || (matches!(&order, Value::Dict(__d) if __d.contains_key("positionSide"))) { Value::Str("contract".into()) } else { Value::Str("spot".into()) });
let mut marketResolved: Value = self.safe_market(&[marketId.clone(), market, Value::Null, marketType.clone()]);
let mut symbol: Value = self.safe_symbol(marketId, &[marketResolved.clone(), Value::Null, marketType.clone()]);
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("time".into()), Value::Str("createdTime".into()), &[]);
let mut quantity: Value = self.safe_number_k(order.clone(), "origQty", &[]);
let mut amount: Value = (if (marketType.as_str() == Some("spot")) { quantity.clone() } else { crate::precise::Precise::stringMul(&self.number_to_string(quantity), &self.number_to_string(marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null))) });
let mut filledQuantity: Value = self.safe_number_k(order.clone(), "executedQty", &[]);
let mut filled: Value = (if (marketType.as_str() == Some("spot")) { filledQuantity.clone() } else { crate::precise::Precise::stringMul(&self.number_to_string(filledQuantity), &self.number_to_string(marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null))) });
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 (timeInForce != Value::Null) {
if (timeInForce.as_str() == Some("GTX")) {
// GTX means "Good Till Crossing" and is an equivalent way of saying Post Only
timeInForce = Value::Str("PO".into());
}
postOnly = (Value::Bool(timeInForce.as_str() == Some("PO")));
}
let mut side: Value = self.safe_string_lower2(order.clone(), Value::Str("side".into()), Value::Str("orderSide".into()), &[]);
if (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: Option<String> = self.safe_string_k(order.clone(), "positionSide", &[]).as_str().map(str::to_owned);
if (positionSide.is_some()) {
if (positionSide.as_deref() == Some("LONG")) {
side = Value::Str("sell".into());
} else {
side = Value::Str("buy".into());
}
}
}
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::from(vec![Value::Str("orderId".into()), Value::Str("result".into()), Value::Str("cancelId".into()), Value::Str("entrustId".into()), Value::Str("profitId".into()), Value::Str("trackId".into())]), &[]));
m.insert("clientOrderId".to_string(), self.safe_string2(order.clone(), Value::Str("clientOrderId".into()), Value::Str("clientModifyId".into()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), lastUpdatedTimestamp.clone());
m.insert("lastUpdateTimestamp".to_string(), lastUpdatedTimestamp);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), self.safe_string_lower2(order.clone(), Value::Str("type".into()), Value::Str("orderType".into()), &[]));
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), postOnly);
m.insert("side".to_string(), side);
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("stopLossPrice".to_string(), self.safe_number_k(order.clone(), "triggerStopPrice", &[]));
m.insert("takeProfitPrice".to_string(), self.safe_number_k(order.clone(), "triggerProfitPrice", &[]));
m.insert("amount".to_string(), amount);
m.insert("filled".to_string(), filled);
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, "fee", &[]));
m
}));
m.insert("trades".to_string(), Value::Null);
m
}), &[marketResolved]);
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".into()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".into()));
m.insert("FILLED".to_string(), Value::Str("closed".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("REJECTED".to_string(), Value::Str("rejected".into()));
m.insert("EXPIRED".to_string(), Value::Str("expired".into()));
m.insert("UNFINISHED".to_string(), Value::Str("open".into()));
m.insert("NOT_ACTIVATION".to_string(), Value::Str("open".into()));
m.insert("NOT_TRIGGERED".to_string(), Value::Str("open".into()));
m.insert("TRIGGERING".to_string(), Value::Str("open".into()));
m.insert("TRIGGERED".to_string(), Value::Str("closed".into()));
m.insert("USER_REVOCATION".to_string(), Value::Str("canceled".into()));
m.insert("PLATFORM_REVOCATION".to_string(), Value::Str("rejected".into()));
m.insert("DELEGATION_FAILED".to_string(), Value::Str("rejected".into()));
m.insert("HISTORY".to_string(), Value::Str("expired".into()));
m
});
return self.safe_string(statuses, 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 (self.markets.clone() == 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 (code != Value::Null) {
currency = self.currency(code);
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut response: Value = Value::Null;
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchLedger".into()), &[Value::Null, params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchLedger".into()), &[Value::Null, paramsMarketType]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_77 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_get_future_user_v1_balance_bills(&[__ws_arg_77]).await;
} else if (subType.as_str() == Some("linear")) || (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
let __ws_arg_78 = self.extend(request, &[paramsSubType]);
response = self.private_linear_get_future_user_v1_balance_bills(&[__ws_arg_78]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLedger() does not support spot transactions, only swap and future wallet transactions are supported".into()))));
}
//
// {
// "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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ledger: Value = self.safe_list_k(data, "items", &[Value::from(vec![])]);
return self.parse_ledger(ledger, &[currency, since, limit]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": "207260567109387524",
// "coin": "usdt",
// "symbol": "btc_usdt",
// "type": "FEE",
// "amount": "-0.0213",
// "side": "SUB",
// "afterAmount": null,
// "createdTime": 1679116769914
// }
//
let mut side: Option<String> = self.safe_string_k(item.clone(), "side", &[]).as_str().map(str::to_owned);
let mut direction: Value = Value::Str("out".into());
if (side.as_deref() == Some("ADD")) {
direction = Value::Str("in".into());
}
let mut currencyId: Value = self.safe_string_k(item.clone(), "coin", &[]);
let mut currencyResolved: Value = self.safe_currency(currencyId.clone(), &[currency]);
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);
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, &[currencyResolved.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));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), self.safe_number_k(item, "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
}), &[currencyResolved]);
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".into()));
m.insert("CLOSE_POSITION".to_string(), Value::Str("trade".into()));
m.insert("TAKE_OVER".to_string(), Value::Str("trade".into()));
m.insert("MERGE".to_string(), Value::Str("trade".into()));
m.insert("QIANG_PING_MANAGER".to_string(), Value::Str("fee".into()));
m.insert("FUND".to_string(), Value::Str("fee".into()));
m.insert("FEE".to_string(), Value::Str("fee".into()));
m.insert("ADL".to_string(), Value::Str("auto-deleveraging".into()));
m
});
return self.safe_string(ledgerType, 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(params);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut currency: Value = self.currency(code.clone());
let mut networkId: Value = self.network_code_to_id(networkCode, &[code]);
self.check_required_argument(Value::Str("fetchDepositAddress".into()), networkId.clone(), Value::Str("network".into()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("chain".to_string(), networkId);
m
});
let __ws_arg_79 = self.extend(request, &[paramsNetworkCode]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_address(result, &[currency]);
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "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]));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address);
m.insert("tag".to_string(), self.safe_string_k(depositAddress, "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 (self.markets.clone() == 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 (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // default 10, max 200
}
let __ws_arg_80 = self.extend(request, &[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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut deposits: Value = self.safe_list_k(data, "items", &[Value::from(vec![])]);
return self.parse_transactions(deposits, &[currency, since, limit, params]);
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 (self.markets.clone() == 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 (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // default 10, max 200
}
let __ws_arg_81 = self.extend(request, &[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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut withdrawals: Value = self.safe_list_k(data, "items", &[Value::from(vec![])]);
return self.parse_transactions(withdrawals, &[currency, since, limit, params]);
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 {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 params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut tagWithdrawTagparamsWithdrawTagVariable = self.handle_param_string(params, Value::Str("tag".into()), &[]);
let mut tagWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone(), code.clone(), tagWithdrawTag.clone()]);
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(paramsWithdrawTag);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
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, networkCode, code.clone(), &[code.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("chain".to_string(), networkId);
m.insert("amount".to_string(), self.currency_to_precision(code, amount, &[]));
m.insert("address".to_string(), address);
m
});
if (tagWithdrawTag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("memo".into(), tagWithdrawTag); }
}
let __ws_arg_82 = self.extend(request, &[paramsNetworkCode]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(result, &[currency]);
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 = (if (matches!(&transaction, Value::Dict(__d) if __d.contains_key("fromAddr"))) { Value::Str("deposit".into()) } else { Value::Str("withdraw".into()) });
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]);
let mut fee: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
let mut feeCurrency: Value = (if (fee != Value::Null) { currencyCode.clone() } else { 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));
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);
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);
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, currencyCode]));
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction, "status", &[])));
m.insert("comment".to_string(), memo);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), feeCurrency);
m.insert("cost".to_string(), fee);
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".into()));
m.insert("REVIEW".to_string(), Value::Str("pending".into()));
m.insert("AUDITED".to_string(), Value::Str("pending".into()));
m.insert("PENDING".to_string(), Value::Str("pending".into()));
m.insert("CANCEL".to_string(), Value::Str("canceled".into()));
m.insert("FAIL".to_string(), Value::Str("failed".into()));
m.insert("SUCCESS".to_string(), Value::Str("ok".into()));
m
});
return self.safe_string(statuses, 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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
let mut positionSide: Value = self.safe_string_k(params.clone(), "positionSide", &[]);
self.check_required_argument(Value::Str("setLeverage".into()), positionSide.clone(), Value::Str("positionSide".into()), &[Value::from(vec![Value::Str("LONG".into()), Value::Str("SHORT".into())])]);
if (leverage.as_f64().unwrap_or(f64::NAN) < ((1i64) as f64)) || (leverage.as_f64().unwrap_or(f64::NAN) > ((125i64) as f64)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() leverage should be between 1 and 125".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() supports contract markets only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("positionSide".to_string(), positionSide);
m.insert("leverage".to_string(), leverage);
m
});
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("setLeverage".into()), &[market, params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_83 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_post_future_user_v1_position_adjust_leverage(&[__ws_arg_83]).await;
} else {
let __ws_arg_84 = self.extend(request, &[paramsSubType]);
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, amount, Value::Str("ADD".into()), &[params]).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, amount, Value::Str("SUB".into()), &[params]).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 = Value::Str("reduceMargin".into());
if (addOrReduce.as_str() == Some("ADD")) {
methodName = Value::Str("addMargin".into());
}
self.check_required_argument(methodName, positionSide.clone(), Value::Str("positionSide".into()), &[Value::from(vec![Value::Str("LONG".into()), Value::Str("SHORT".into())])]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("margin".to_string(), amount);
m.insert("type".to_string(), addOrReduce);
m.insert("positionSide".to_string(), positionSide);
m
});
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("modifyMarginHelper".into()), &[market.clone(), params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_85 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_post_future_user_v1_position_margin(&[__ws_arg_85]).await;
} else {
let __ws_arg_86 = self.extend(request, &[paramsSubType]);
response = self.private_linear_post_future_user_v1_position_margin(&[__ws_arg_86]).await;
}
return self.parse_margin_modification(response, &[market]);
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);
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]));
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchLeverageTiers".into()), &[Value::Null, params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
response = self.public_inverse_get_future_market_v1_public_leverage_bracket_list(&[paramsSubType.clone()]).await;
} else {
response = self.public_linear_get_future_market_v1_public_leverage_bracket_list(&[paramsSubType]).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, "result", &[Value::from(vec![])]);
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
return self.parse_leverage_tiers(data, &[symbolsNormalized, Value::Str("symbol".into())]);
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_1165: bool = true;
while { if !__for_first_1165 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1165 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = self.safe_dict(response.clone(), i.clone(), &[]);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Str("_".into()), Value::Str("contract".into())]);
let mut symbol: Value = self.safe_symbol(marketId, &[market.clone()]);
if (symbols != Value::Null) {
if self.in_array(symbol.clone(), symbols.clone()).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), self.parse_market_leverage_tiers(entry, &[market.clone()])); }
}
} else {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), self.parse_market_leverage_tiers(get_value(&response, &i), &[market])); }
}
}
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchMarketLeverageTiers".into()), &[market.clone(), params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_87 = self.extend(request.clone(), &[paramsSubType.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, &[paramsSubType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_market_leverage_tiers(data, &[market]);
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::from(vec![]);
let mut brackets: Value = self.safe_list_k(info.clone(), "leverageBrackets", &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1166: bool = true;
while { if !__for_first_1166 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1166 = false; i.as_f64().unwrap_or(f64::NAN) < ((brackets.len() as i64) as f64) } {
let mut tier: Value = self.safe_dict(brackets.clone(), i.clone(), &[]);
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".into()), Value::Str("contract".into())]);
let mut minNotional: Value = self.safe_number(get_value(&brackets, &(match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null })), Value::Str("maxNominalValue".into()), &[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, &[marketResolved.clone(), Value::Str("_".into()), Value::Str("contract".into())]));
m.insert("currency".to_string(), marketResolved.as_map().and_then(|__m| __m.get("settle")).cloned().unwrap_or(Value::Null));
m.insert("minNotional".to_string(), minNotional);
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);
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_cursor(Value::Str("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Str("id".into()), Value::Str("id".into()), Value::Int(1), Value::Int(200)]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() supports swap contracts only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), Value::Int(200)); }; // max
}
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchFundingRateHistory".into()), &[market.clone(), paramsPaginate]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_89 = self.extend(request.clone(), &[paramsSubType.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, &[paramsSubType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(result, "items", &[Value::from(vec![])]);
let mut rates: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1167: bool = true;
while { if !__for_first_1167 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1167 = false; i.as_f64().unwrap_or(f64::NAN) < ((items.len() as i64) as f64) } {
let mut entry: Value = items.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut symbolInner: Value = self.safe_symbol(marketId, &[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);
m.insert("fundingRate".to_string(), self.safe_number_k(entry, "fundingRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates, Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[self.safe_string_k(market, "symbol", &[]), since, limit]);
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
* @param {string} [params.tag] memo / destination tag, required for currencies in options['withdrawTagRequiredCurrencies']
* @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, &[params]).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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate() supports swap contracts only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchFundingRate".into()), &[market.clone(), params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_91 = self.extend(request.clone(), &[paramsSubType.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, &[paramsSubType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(result, &[market]);
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, &[market, Value::Str("_".into()), Value::Str("swap".into())]);
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "nextCollectionTime", &[]);
let mut interval: Value = self.safe_string_k(contract.clone(), "collectionInternal", &[]);
if (interval != Value::Null) {
interval = Value::Str(format!("{}{}", interval, Value::Str("h".into())).into());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol);
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract, "fundingRate", &[]));
m.insert("fundingTimestamp".to_string(), timestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(timestamp));
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);
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);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenInterest() supports swap contracts only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchOpenInterest".into()), &[market.clone(), params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_93 = self.extend(request.clone(), &[paramsSubType.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, &[paramsSubType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_open_interest(result, &[market]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Null, Value::Str("contract".into())]);
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(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
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));
m.insert("info".to_string(), interest);
m
}), &[marketResolved]);
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);
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTradingFee() supports contract markets only".into()))));
}
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchTradingFee".into()), &[market.clone(), params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
response = self.private_inverse_get_future_user_v1_user_step_rate(&[paramsSubType.clone()]).await;
} else {
response = self.private_linear_get_future_user_v1_user_step_rate(&[paramsSubType]).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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(result, &[market]);
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 subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchTradingFees".into()), &[Value::Null, params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut isInverse: bool = subType.as_str() == Some("inverse");
let mut response: Value = Value::Null;
if isInverse {
response = self.private_inverse_get_future_user_v1_user_step_rate(&[paramsSubType.clone()]).await;
} else {
response = self.private_linear_get_future_user_v1_user_step_rate(&[paramsSubType]).await;
}
//
// same response as fetchTradingFee
//
let mut fee: Value = self.safe_dict_k(response, "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_1168: bool = true;
while { if !__for_first_1168 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1168 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbols.len() as i64) as f64) } {
let mut symbol: Value = symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(symbol.clone());
let mut matchesSubType: Value = (if (isInverse) { market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null) } else { market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null) });
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) && (matchesSubType.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), self.parse_trading_fee(fee.clone(), &[market])); }
}
}
}
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 = (if (market != Value::Null) { market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) } else { Value::Null });
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), symbol);
m.insert("maker".to_string(), self.safe_number_k(fee.clone(), "makerFee", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee, "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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingHistory() supports swap contracts only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchFundingHistory".into()), &[market.clone(), params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_95 = self.extend(request.clone(), &[paramsSubType.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, &[paramsSubType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(data, "items", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1169: bool = true;
while { if !__for_first_1169 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1169 = false; i.as_f64().unwrap_or(f64::NAN) < ((items.len() as i64) as f64) } {
let mut entry: Value = self.safe_dict(items.clone(), i.clone(), &[]);
append_to_array(&mut result, self.parse_funding_history(entry, &[market.clone()]));
}
}
let mut sorted: Value = self.sort_by(result, Value::Str("timestamp".into()), &[]);
return self.filter_by_since_limit(sorted, &[since, limit]);
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, &[market, Value::Str("_".into()), Value::Str("swap".into())]);
let mut currencyId: Value = self.safe_string_k(contract.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
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);
m.insert("code".to_string(), code);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("id".to_string(), self.safe_string_k(contract.clone(), "id", &[]));
m.insert("amount".to_string(), self.safe_number_k(contract, "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_1170: bool = true;
while { if !__for_first_1170 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1170 = false; i.as_f64().unwrap_or(f64::NAN) < ((breakList.len() as i64) as f64) } {
let mut breakEntry: Value = breakList.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
// 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 = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.safe_string_k(breakEntry.clone(), "symbol", &[]), Value::Str("_".into())).into()), self.safe_string_k(breakEntry.clone(), "positionSide", &[])).into());
if let Value::Dict(__d) = &mut breakBySymbolSide { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&key), breakEntry); }
}
}
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 = Value::Str(format!("{}{}", Value::Str(format!("{}{}", marketId, Value::Str("_".into())).into()), self.safe_string_k(entry.clone(), "positionSide", &[])).into());
let mut breakEntry: Value = self.safe_dict(breakBySymbolSide, key, &[]);
if (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, "calMarkPrice", &[]);
return self.extend(entry, &[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 (self.markets.clone() == 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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchPosition".into()), &[market, params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut promisesUnresolved: Value = Value::from(vec![]);
if (subType.as_str() == Some("inverse")) {
let __ws_arg_99 = self.extend(request.clone(), &[paramsSubType.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(), &[paramsSubType.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(), &[paramsSubType.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, &[paramsSubType]);
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 = responsebreakResponseVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut breakResponse: Value = responsebreakResponseVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
//
// 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, "result", &[Value::from(vec![])]);
let mut breakBySymbolSide: Value = self.index_position_break_list(self.safe_list_k(breakResponse, "result", &[Value::from(vec![])]));
{
let mut i: Value = Value::Int(0);
let mut __for_first_1171: bool = true;
while { if !__for_first_1171 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1171 = false; i.as_f64().unwrap_or(f64::NAN) < ((positions.len() as i64) as f64) } {
let mut entry: Value = positions.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut marketInner: Value = self.safe_market(&[marketId, Value::Null, Value::Null, Value::Str("contract".into())]);
let mut positionSize: Option<String> = self.safe_string_k(entry.clone(), "positionSize", &[]).as_str().map(str::to_owned);
if (positionSize.as_deref() != Some("0")) {
let mut merged: Value = self.merge_position_break_info(entry, breakBySymbolSide.clone());
return self.parse_position(merged, &[marketInner]);
}
}
}
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchPosition() could not find a position for ".into())).into()), 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchPositions".into()), &[Value::Null, params]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut promisesUnresolved: Value = Value::from(vec![]);
if (subType.as_str() == Some("inverse")) {
append_to_array(&mut promisesUnresolved, self.private_inverse_get_future_user_v1_position_list(&[paramsSubType.clone()]).await);
append_to_array(&mut promisesUnresolved, self.private_inverse_get_future_user_v1_position_break_list(&[paramsSubType.clone()]).await);
} else {
append_to_array(&mut promisesUnresolved, self.private_linear_get_future_user_v1_position_list(&[paramsSubType.clone()]).await);
append_to_array(&mut promisesUnresolved, self.private_linear_get_future_user_v1_position_break_list(&[paramsSubType]).await);
}
let mut responsebreakResponseVariable = promise_all(&promisesUnresolved).await;
let mut response: Value = responsebreakResponseVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut breakResponse: Value = responsebreakResponseVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
//
// 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, "result", &[Value::from(vec![])]);
let mut breakBySymbolSide: Value = self.index_position_break_list(self.safe_list_k(breakResponse, "result", &[Value::from(vec![])]));
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1172: bool = true;
while { if !__for_first_1172 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_1172 = false; i.as_f64().unwrap_or(f64::NAN) < ((positions.len() as i64) as f64) } {
let mut entry: Value = positions.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut marketInner: Value = self.safe_market(&[marketId, Value::Null, Value::Null, Value::Str("contract".into())]);
let mut merged: Value = self.merge_position_break_info(entry, breakBySymbolSide.clone());
append_to_array(&mut result, self.parse_position(merged, &[marketInner]));
}
}
return self.filter_by_array_positions(result, Value::Str("symbol".into()), &[symbols]);
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;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbolsNormalized != Value::Null) {
let mut symbolsLength: f64 = ((symbolsNormalized.len() as i64) as f64);
if (symbolsLength == 1.0) {
market = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("endTime".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("fetchPositionsHistory".into()), &[market, paramsUntil]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_103 = self.extend(requestUntil.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_get_future_trade_v1_position_list_history(&[__ws_arg_103]).await;
} else {
let __ws_arg_104 = self.extend(requestUntil, &[paramsSubType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(result, "items", &[Value::from(vec![])]);
let mut positions: Value = self.parse_positions(items, &[symbolsNormalized]);
return self.filter_by_since_limit(positions, &[since, limit]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone(), market, Value::Null, Value::Str("contract".into())]);
let mut symbol: Value = self.safe_symbol(marketId, &[marketResolved.clone(), Value::Null, Value::Str("contract".into())]);
// "ISOLATED"/"CROSSED" on position/list, 1 = cross / 2 = isolated on position/list-history
let mut positionType: Option<String> = self.safe_string_k(position.clone(), "positionType", &[]).as_str().map(str::to_owned);
let mut isCross: bool = (positionType.as_deref() == Some("CROSSED")) || (positionType.as_deref() == Some("1"));
let mut marginMode: Value = Value::Str("isolated".into());
if isCross {
marginMode = Value::Str("cross".into());
}
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".into()), Value::Str("forceMarkPrice".into()), &[]));
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);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("hedged".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_lower_k(position.clone(), "positionSide", &[]));
m.insert("contracts".to_string(), self.safe_number2(position.clone(), Value::Str("positionSize".into()), Value::Str("closePositionSize".into()), &[]));
m.insert("contractSize".to_string(), marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null));
m.insert("entryPrice".to_string(), self.safe_number2(position.clone(), Value::Str("entryPrice".into()), Value::Str("closeOpenPrice".into()), &[]));
m.insert("markPrice".to_string(), self.safe_number2(position.clone(), Value::Str("markPrice".into()), Value::Str("calMarkPrice".into()), &[]));
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".into()), Value::Str("endLeverage".into()), &[]));
m.insert("collateral".to_string(), collateral.clone());
m.insert("initialMargin".to_string(), collateral);
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, Value::Str("realizedProfit".into()), Value::Str("closeProfit".into()), &[]));
m.insert("liquidationPrice".to_string(), self.parse_number(liquidationPriceString, &[]));
m.insert("marginMode".to_string(), marginMode);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsById", &[]);
let mut fromAccountId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toAccountId: Value = self.safe_string(accountsByType, toAccount.clone(), &[toAccount.clone()]);
let mut amountString: Value = self.currency_to_precision(code, amount, &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bizId".to_string(), self.uuid(&[]));
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), amountString);
m.insert("from".to_string(), fromAccountId);
m.insert("to".to_string(), toAccountId);
m
});
let __ws_arg_105 = self.extend(request, &[params]);
let mut response: Value = self.private_spot_post_balance_transfer(&[__ws_arg_105]).await;
return self.parse_transfer(response, &[currency]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), self.safe_string_k(transfer, "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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() supports contract markets only".into()))));
}
let mut marginModeLower: Value = to_lower(&marginMode);
if (marginModeLower.as_str() != Some("isolated")) && (marginModeLower.as_str() != Some("cross")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() marginMode argument should be isolated or cross".into()))));
}
let mut positionType: Value = (if (marginModeLower.as_str() == Some("cross")) { Value::Str("CROSSED".into()) } else { Value::Str("ISOLATED".into()) });
let mut posSide: Value = self.safe_string_upper_k(params.clone(), "positionSide", &[]);
self.check_required_argument(Value::Str("setMarginMode".into()), posSide.clone(), Value::Str("positionSide".into()), &[Value::from(vec![Value::Str("LONG".into()), Value::Str("SHORT".into())])]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("positionSide".into()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("positionType".to_string(), positionType);
m.insert("positionSide".to_string(), posSide);
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("setMarginMode".into()), &[market, paramsOmitted]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (subType.as_str() == Some("inverse")) {
let __ws_arg_106 = self.extend(request.clone(), &[paramsSubType.clone()]);
response = self.private_inverse_post_future_user_v1_position_change_type(&[__ws_arg_106]).await;
} else {
let __ws_arg_107 = self.extend(request, &[paramsSubType]);
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 (amount == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" editOrder() requires an amount argument".into()))));
}
if (self.markets.clone() == 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".into()), Value::Str("triggerStopPrice".into()), &[]);
let mut takeProfit: Value = self.safe_number2(params.clone(), Value::Str("takeProfit".into()), Value::Str("triggerProfitPrice".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("stopLoss".into()), Value::Str("takeProfit".into())]), &[]);
let mut isStopLoss: bool = stopLoss != Value::Null;
let mut isTakeProfit: bool = takeProfit != Value::Null;
if isStopLoss || isTakeProfit {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("profitId".into(), id.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderId".into(), id); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
}
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if isStopLoss {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("triggerStopPrice".into(), self.price_to_precision(symbol.clone(), stopLoss)); }
} else if (takeProfit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("triggerProfitPrice".into(), self.price_to_precision(symbol.clone(), takeProfit)); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("origQty".into(), self.amount_to_precision(symbol.clone(), amount.clone())); }
}
let mut subTypeparamsSubTypeVariable = self.handle_sub_type_and_params(Value::Str("editOrder".into()), &[market.clone(), paramsOmitted.clone()]);
let mut subType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSubType: Value = subTypeparamsSubTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (subType.as_str() == Some("inverse")) {
if isStopLoss || isTakeProfit {
let __ws_arg_108 = self.extend(request.clone(), &[paramsSubType.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(), &[paramsSubType.clone()]);
response = self.private_inverse_post_future_trade_v1_order_update(&[__ws_arg_109]).await;
}
} else {
if isStopLoss || isTakeProfit {
let __ws_arg_110 = self.extend(request.clone(), &[paramsSubType.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(), &[paramsSubType]);
response = self.private_linear_post_future_trade_v1_order_update(&[__ws_arg_111]).await;
}
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.amount_to_precision(symbol, amount)); }
let __ws_arg_112 = self.extend(request, &[paramsOmitted]);
response = self.private_spot_put_order_order_id(&[__ws_arg_112]).await;
}
let mut result: Value = (if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { response.clone() } else { self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]) });
return self.parse_order(result, &[market]);
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: Option<String> = self.safe_string_upper2(response.clone(), Value::Str("msgInfo".into()), Value::Str("mc".into()), &[]).as_str().map(str::to_owned);
if (status.is_some()) && (status.as_deref() != Some("SUCCESS")) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
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]);
let mut spotMessage: Value = self.safe_string_k(response, "msgInfo", &[]);
let mut message: Value = self.safe_string_k(error, "msg", &[spotMessage]);
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode, feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __api_empty = Vec::new();
let api = api.as_array().unwrap_or(&__api_empty);
let mut signed: bool = api.get(0).cloned().unwrap_or(Value::Null).as_str() == Some("private");
let mut endpoint: Value = api.get(1).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Str(format!("{}{}", Value::Str("/".into()), self.implode_params(path.clone(), params.clone())).into());
let mut payload: Value = Value::Null;
if (endpoint.as_str() == Some("spot")) || (endpoint.as_str() == Some("user")) {
if signed {
payload = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("/".into()), self.version.clone()).into()), request).into());
} else {
payload = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("/".into()), self.version.clone()).into()), Value::Str("/public".into())).into()), request).into());
}
} else {
payload = request;
}
let mut apiUrl: Value = self.safe_string(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), endpoint.clone(), &[]);
if (apiUrl == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", apiUrl, payload).into());
let mut query: Value = self.omit(params, self.extract_params(path.clone()), &[]);
let mut urlencoded: Value = self.urlencode(self.keysort(query.clone(), &[]), &[]);
let mut headersValue: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
let mut signedBody: Value = Value::Null;
if 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]);
let mut timestamp: Value = self.number_to_string(self.nonce());
if (payload.as_str() == Some("/v4/order")) || (payload.as_str() == Some("/future/trade/v1/order/create")) || (payload.as_str() == Some("/future/trade/v1/entrust/create-plan")) || (payload.as_str() == Some("/future/trade/v1/entrust/create-profit")) || (payload.as_str() == Some("/future/trade/v1/order/create-batch")) {
let mut id: Value = Value::Str("CCXT".into());
if (query == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" sign() returned empty body".into()))));
}
if Value::Int(payload.as_str().and_then(|__s| __s.find("future")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) > ((-1i64) as f64) {
add_element_to_object(&mut query, &Value::Str("clientMedia".into()), id.clone());
if (query == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" sign() returned empty body".into()))));
}
} else {
add_element_to_object(&mut query, &Value::Str("media".into()), id);
}
}
let mut isUndefinedBody: bool = (method.as_str() == Some("GET")) || (path.as_str() == Some("order/{orderId}")) || (path.as_str() == Some("ws-token"));
if (method.as_str() == Some("PUT")) && (endpoint.as_str() == Some("spot")) {
isUndefinedBody = false;
}
signedBody = (if isUndefinedBody { Value::Null } else { json_stringify(&query) });
let mut payloadString: Value = Value::Null;
if (endpoint.as_str() == Some("spot")) || (endpoint.as_str() == Some("user")) {
payloadString = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("xt-validate-algorithms=HmacSHA256&xt-validate-appkey=".into()), self.apiKey.clone()).into()), Value::Str("&xt-validate-recvwindow=".into())).into()), recvWindow).into()), Value::Str("&xt-validate-t".into())).into()), Value::Str("imestamp=".into())).into()), timestamp).into());
if isUndefinedBody {
if (urlencoded.as_str() != Some("")) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), urlencoded).into())).into());
payloadString = Value::Str(format!("{}{}", payloadString, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("#".into()), method).into()), Value::Str("#".into())).into()), payload).into()), Value::Str("#".into())).into()), self.rawencode(self.keysort(query, &[]), &[])).into())).into());
} else {
payloadString = Value::Str(format!("{}{}", payloadString, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("#".into()), method).into()), Value::Str("#".into())).into()), payload).into())).into());
}
} else {
payloadString = Value::Str(format!("{}{}", payloadString, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("#".into()), method).into()), Value::Str("#".into())).into()), payload).into()), Value::Str("#".into())).into()), signedBody).into())).into());
}
if let Value::Dict(__d) = &mut headersValue { std::sync::Arc::make_mut(__d).insert("xt-validate-algorithms".into(), Value::Str("HmacSHA256".into())); }
if let Value::Dict(__d) = &mut headersValue { std::sync::Arc::make_mut(__d).insert("xt-validate-recvwindow".into(), recvWindow); }
} else {
payloadString = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("xt-validate-appkey=".into()), self.apiKey.clone()).into()), Value::Str("&xt-validate-t".into())).into()), Value::Str("imestamp=".into())).into()), timestamp).into()); // we can't glue timestamp, breaks in php
if (method.as_str() == Some("GET")) {
if (urlencoded.as_str() != Some("")) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), urlencoded).into())).into());
payloadString = Value::Str(format!("{}{}", payloadString, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("#".into()), payload).into()), Value::Str("#".into())).into()), urlencoded).into())).into());
} else {
payloadString = Value::Str(format!("{}{}", payloadString, Value::Str(format!("{}{}", Value::Str("#".into()), payload).into())).into());
}
} else {
payloadString = Value::Str(format!("{}{}", payloadString, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("#".into()), payload).into()), Value::Str("#".into())).into()), signedBody).into())).into());
}
}
let mut signature: Value = self.hmac(self.encode(payloadString), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[]);
if let Value::Dict(__d) = &mut headersValue { std::sync::Arc::make_mut(__d).insert("xt-validate-appkey".into(), self.apiKey.clone()); }
if let Value::Dict(__d) = &mut headersValue { std::sync::Arc::make_mut(__d).insert("xt-validate-timestamp".into(), timestamp); }
if let Value::Dict(__d) = &mut headersValue { std::sync::Arc::make_mut(__d).insert("xt-validate-signature".into(), signature); }
} else {
if (urlencoded.as_str() != Some("")) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), urlencoded).into())).into());
}
}
let mut bodyValue: Value = Value::Null;
if signed {
bodyValue = signedBody;
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), bodyValue);
m.insert("headers".to_string(), headersValue);
m
});
Value::Null
}
}