// 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 CoinexCore {
pub exchange: crate::exchange::Exchange,
}
impl CoinexCore {
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 = CoinexCore::describe(self);
self.initialize_properties(described);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for CoinexCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_order(self, order, &[market])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_position(self, position, &[market])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::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 CoinexCore.
CoinexCore::parse_deposit_address(self, depositAddress, &[currency])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_transfer(self, transfer, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_currency(self, currency)
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_margin_modification(self, data, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_transaction(self, transaction, &[currency])
}
fn parse_borrow_interest(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_borrow_interest(self, info, &[market])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_leverage(self, leverage, &[market])
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_market_leverage_tiers(self, info, &[market])
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::parse_deposit_withdraw_fee(self, fee, &[currency])
}
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 CoinexCore.
CoinexCore::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 CoinexCore.
CoinexCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for CoinexCore {
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,
"borrow_isolated_margin" => self.borrow_isolated_margin(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,
"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,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_deposit_address" => self.create_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.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_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.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,
"edit_orders" => self.edit_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_borrow_interest" => self.fetch_borrow_interest(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_contract_markets" => self.fetch_contract_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)).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_deposit_withdraw_fee" => self.fetch_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_financial_balance" => self.fetch_financial_balance(&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_funding_rates" => self.fetch_funding_rates(&args[..]).await,
"fetch_isolated_borrow_rate" => self.fetch_isolated_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args[..]).await,
"fetch_margin_adjustment_history" => self.fetch_margin_adjustment_history(&args[..]).await,
"fetch_margin_balance" => self.fetch_margin_balance(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders_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_position_history" => self.fetch_position_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_spot_balance" => self.fetch_spot_balance(&args[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_swap_balance" => self.fetch_swap_balance(&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_transfers" => self.fetch_transfers(&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)),
"handle_margin_mode_and_params" => self.handle_margin_mode_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"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_borrow_interest" => self.parse_borrow_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(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_isolated_borrow_rate" => self.parse_isolated_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_loan" => self.parse_margin_loan(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_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_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())..]),
"parse_transfer_status" => self.parse_transfer_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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,
"repay_isolated_margin" => self.repay_isolated_margin(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,
"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 CoinexCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for CoinexCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl CoinexCore {
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("coinex".into()));
m.insert("name".to_string(), Value::Str("CoinEx".into()));
m.insert("version".to_string(), Value::Str("v2".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("CN".into())]));
m.insert("rateLimit".to_string(), Value::Float(2.5));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("certified".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(true));
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("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("editOrders".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(true));
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(true));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(true));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(true));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Str("emulated".into()));
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("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".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("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1min".into()));
m.insert("3m".to_string(), Value::Str("3min".into()));
m.insert("5m".to_string(), Value::Str("5min".into()));
m.insert("15m".to_string(), Value::Str("15min".into()));
m.insert("30m".to_string(), Value::Str("30min".into()));
m.insert("1h".to_string(), Value::Str("1hour".into()));
m.insert("2h".to_string(), Value::Str("2hour".into()));
m.insert("4h".to_string(), Value::Str("4hour".into()));
m.insert("6h".to_string(), Value::Str("6hour".into()));
m.insert("12h".to_string(), Value::Str("12hour".into()));
m.insert("1d".to_string(), Value::Str("1day".into()));
m.insert("3d".to_string(), Value::Str("3day".into()));
m.insert("1w".to_string(), Value::Str("1week".into()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/51840849/87182089-1e05fa00-c2ec-11ea-8da9-cc73b45abbbc.jpg".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.coinex.com".into()));
m.insert("private".to_string(), Value::Str("https://api.coinex.com".into()));
m.insert("perpetualPublic".to_string(), Value::Str("https://api.coinex.com/perpetual".into()));
m.insert("perpetualPrivate".to_string(), Value::Str("https://api.coinex.com/perpetual".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.coinex.com".into()));
m.insert("doc".to_string(), Value::Str("https://docs.coinex.com/api/v2".into()));
m.insert("fees".to_string(), Value::Str("https://www.coinex.com/fees".into()));
m.insert("referral".to_string(), Value::Str("https://www.coinex.com/register?refer_code=yw5fz".into()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".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("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amm/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/currency/rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/asset/config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/maintain/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/temp-maintain/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/ticker/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account/amm/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/investment/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/balance/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/market/fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("balance/coin/deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("balance/coin/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("balance/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("balance/deposit/address/{coin_type}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("contract/transfer/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("credit/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("credit/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("investment/transfer/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("margin/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/loan/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("margin/transfer/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/finished".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("order/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("order/status/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("order/user/deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/stop/finished".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/stop/pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("order/user/trade/fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/market/trade/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub_account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub_account/transfer/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/auth/api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/auth/api/{user_auth_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("balance/coin/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("contract/balance/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("margin/flat".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("margin/loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("margin/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/limit/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/ioc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/modify".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/stop/limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/stop/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/stop/modify".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("sub_account/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/register".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub_account/unfrozen".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/frozen".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/auth/api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("balance/deposit/address/{coin_type}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/unfrozen".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/frozen".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/auth/api/{user_auth_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("v1/account/settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("balance/coin/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/pending/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/stop/pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/stop/pending/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("order/pending/by_client_id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/stop/pending/by_client_id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/auth/api/{user_auth_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub_account/authorize/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m
}));
m
}));
m.insert("perpetualPublic".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("ping".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("market/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/limit_config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/ticker/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/funding_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("perpetualPrivate".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("market/user_deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("order/finished".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/stop_finished".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/stop_pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("order/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("order/stop_status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("position/finished".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("position/pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("position/funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("position/adl_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("market/preference".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("position/margin_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("position/settle_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market/adjust_leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/position_expect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/put_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/put_market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/put_stop_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/put_stop_market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/modify".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/modify_stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/cancel_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/cancel_batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/cancel_stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/cancel_stop_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("order/close_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/close_market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("position/adjust_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("position/stop_loss".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("position/take_profit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("position/market_close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/cancel/by_client_id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("order/cancel_stop/by_client_id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("market/preference".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m
}));
m
}));
m.insert("v2".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("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maintain/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ping".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("spot/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/funding-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/funding-rate-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/premium-index-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/position-level".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/liquidation-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/basis-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/deposit-withdraw-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/all-deposit-withdraw-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account/subs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/subs/api-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/subs/api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/transfer-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/subs/spot-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/trade-fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/futures-market-settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/spot/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/futures/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/margin/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/financial/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/amm/liquidity".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/credit/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/spot/transcation-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/margin/borrow-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/margin/interest-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/transfer-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/amm/liquidity-pool".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/amm/income-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("spot/order-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("spot/batch-order-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("spot/pending-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("spot/finished-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("spot/pending-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("spot/finished-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("spot/user-deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("spot/order-deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("futures/order-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("futures/batch-order-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/pending-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("futures/finished-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("futures/pending-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("futures/finished-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("futures/user-deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/order-deals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/pending-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("futures/finished-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/position-margin-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/position-funding-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("futures/position-adl-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/position-settle-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("refer/referee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("refer/referee-rebate/record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("refer/referee-rebate/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("refer/agent-referee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("refer/agent-rebate/record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("refer/agent-rebate/detail".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("account/subs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/frozen".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/unfrozen".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/edit-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/delete-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/subs/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/futures-market-settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/margin/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/margin/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/renewal-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/cancel-withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("assets/amm/add-liquidity".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assets/amm/remove-liquidity".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("spot/stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("spot/batch-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("spot/batch-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/modify-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("spot/modify-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("spot/batch-modify-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(13.334));
m
}));
m.insert("spot/cancel-all-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(6.667));
m
}));
m.insert("spot/cancel-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(6.667));
m
}));
m.insert("spot/cancel-batch-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/cancel-batch-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/cancel-order-by-client-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/cancel-stop-order-by-client-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/batch-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/batch-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/cancel-position-stop-loss".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/cancel-position-take-profit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/modify-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/modify-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/batch-modify-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/cancel-all-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("futures/cancel-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("futures/cancel-batch-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/cancel-batch-stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/cancel-order-by-client-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/cancel-stop-order-by-client-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/adjust-position-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/adjust-position-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/set-position-stop-loss".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/set-position-take-profit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/modify-position-stop-loss".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("futures/modify-position-take-profit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::Float(0.001));
m.insert("taker".to_string(), Value::Float(0.001));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BCH".to_string(), Value::Int(0));
m.insert("BTC".to_string(), Value::Float(0.001));
m.insert("LTC".to_string(), Value::Float(0.001));
m.insert("ETH".to_string(), Value::Float(0.001));
m.insert("ZEC".to_string(), Value::Float(0.0001));
m.insert("DASH".to_string(), Value::Float(0.0001));
m
}));
m
}));
m
}));
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::Float(0.001));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("brokerId".to_string(), Value::Str("x-167673045".into()));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("defaultType".to_string(), Value::Str("spot".into()));
m.insert("defaultSubType".to_string(), Value::Str("linear".into()));
m.insert("fetchDepositAddress".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fillResponseFromRequest".to_string(), Value::Bool(true));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".into()));
m.insert("margin".to_string(), Value::Str("MARGIN".into()));
m.insert("swap".to_string(), Value::Str("FUTURES".into()));
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SPOT".to_string(), Value::Str("spot".into()));
m.insert("MARGIN".to_string(), Value::Str("margin".into()));
m.insert("FUTURES".to_string(), Value::Str("swap".into()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".into()));
m.insert("BEP20".to_string(), Value::Str("BSC".into()));
m.insert("TRC20".to_string(), Value::Str("TRC20".into()));
m.insert("ERC20".to_string(), Value::Str("ERC20".into()));
m.insert("BRC20".to_string(), Value::Str("BRC20".into()));
m.insert("SOL".to_string(), Value::Str("SOL".into()));
m.insert("TON".to_string(), Value::Str("TON".into()));
m.insert("BSV".to_string(), Value::Str("BSV".into()));
m.insert("AVAXC".to_string(), Value::Str("AVA_C".into()));
m.insert("AVAXX".to_string(), Value::Str("AVA".into()));
m.insert("SUI".to_string(), Value::Str("SUI".into()));
m.insert("ACA".to_string(), Value::Str("ACA".into()));
m.insert("CHZ".to_string(), Value::Str("CHILIZ".into()));
m.insert("ADA".to_string(), Value::Str("ADA".into()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBITRUM".into()));
m.insert("ARBITRUM_NOVA".to_string(), Value::Str("ARBITRUM_NOVA".into()));
m.insert("OP".to_string(), Value::Str("OPTIMISM".into()));
m.insert("APT".to_string(), Value::Str("APTOS".into()));
m.insert("ATOM".to_string(), Value::Str("ATOM".into()));
m.insert("FTM".to_string(), Value::Str("FTM".into()));
m.insert("BCH".to_string(), Value::Str("BCH".into()));
m.insert("ASTR".to_string(), Value::Str("ASTR".into()));
m.insert("LTC".to_string(), Value::Str("LTC".into()));
m.insert("MATIC".to_string(), Value::Str("MATIC".into()));
m.insert("CRONOS".to_string(), Value::Str("CRONOS".into()));
m.insert("DASH".to_string(), Value::Str("DASH".into()));
m.insert("DOT".to_string(), Value::Str("DOT".into()));
m.insert("ETC".to_string(), Value::Str("ETC".into()));
m.insert("ETHW".to_string(), Value::Str("ETHPOW".into()));
m.insert("FIL".to_string(), Value::Str("FIL".into()));
m.insert("ZIL".to_string(), Value::Str("ZIL".into()));
m.insert("DOGE".to_string(), Value::Str("DOGE".into()));
m.insert("TIA".to_string(), Value::Str("CELESTIA".into()));
m.insert("SEI".to_string(), Value::Str("SEI".into()));
m.insert("XRP".to_string(), Value::Str("XRP".into()));
m.insert("XMR".to_string(), Value::Str("XMR".into()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(true));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(5));
m
}));
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(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
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(1000));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
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(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
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("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("spot".into()));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".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(false));
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
}));
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.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ACM".to_string(), Value::Str("Actinium".into()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("23".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("24".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("25".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("34".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("35".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("36".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("213".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("107".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("158".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("600".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("601".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("602".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("606".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3008".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("3109".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("3127".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3157".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("3600".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("3606".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3610".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("3612".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3613".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3614".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3615".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3616".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3617".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3618".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3619".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3620".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3621".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3622".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3627".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3628".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3629".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3632".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3633".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3634".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("3635".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("4001".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("4002".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("4003".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("4004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("4005".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("4006".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("4007".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("4008".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("4009".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("4010".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("4011".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("4017".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("4115".to_string(), Value::Str("AccountSuspended".into()).clone());
m.insert("4117".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("4123".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("4130".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("4158".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("4213".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("4512".to_string(), Value::Str("PermissionDenied".into()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ip not allow visit".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("service too busy".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("Service is not available during funding fee settlement".to_string(), Value::Str("OperationFailed".into()).clone());
m
}));
m
}));
m.insert("rollingWindowSize".to_string(), Value::Int(1000));
m
})]);
Value::Null
}
/*
* @method
* @name coinex#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-all-deposit-withdrawal-config
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.v2_public_get_assets_all_deposit_withdraw_config(&[params]).await;
//
// {
// "code": 0,
// "data": [
// {
// "asset": {
// "ccy": "CET",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "inter_transfer_enabled": true,
// "is_st": false
// },
// "chains": [
// {
// "chain": "CSC",
// "min_deposit_amount": "0.8",
// "min_withdraw_amount": "8",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "deposit_delay_minutes": 0,
// "safe_confirmations": 10,
// "irreversible_confirmations": 20,
// "deflation_rate": "0",
// "withdrawal_fee": "0.026",
// "withdrawal_precision": 8,
// "memo": "",
// "is_memo_required_for_deposit": false,
// "explorer_asset_url": ""
// },
// ]
// }
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_currencies(data);
Value::Null
}
pub fn parse_currency(&self, mut coin: Value) -> Value {
let mut asset: Value = self.safe_dict_k(coin.clone(), "asset", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyId: Value = self.safe_string_k(asset.clone(), "ccy", &[]);
let mut chains: Value = self.safe_list_k(coin.clone(), "chains", &[Value::from(vec![])]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_544: bool = true;
while { if !__for_first_544 { 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_544 = false; j.as_f64().unwrap_or(f64::NAN) < ((chains.len() as i64) as f64) } {
let mut chain: Value = chains.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(chain.clone(), "chain", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if (networkId == Value::Null) {
continue;
}
let mut network: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
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("deposit".to_string(), self.safe_bool_k(chain.clone(), "deposit_enabled", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(chain.clone(), "withdraw_enabled", &[]));
m.insert("fee".to_string(), self.safe_number_k(chain.clone(), "withdrawal_fee", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(chain.clone(), "withdrawal_precision", &[])]), &[]));
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("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(chain.clone(), "min_deposit_amount", &[]));
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(chain.clone(), "min_withdraw_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("info".to_string(), chain);
m
});
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut networks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&networkCode), network); }
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId);
m.insert("code".to_string(), code);
m.insert("name".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(asset.clone(), "deposit_enabled", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(asset, "withdraw_enabled", &[]));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("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.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), networks);
m.insert("type".to_string(), Value::Str("crypto".into()));
m.insert("info".to_string(), coin);
m
}));
Value::Null
}
/*
* @method
* @name coinex#fetchMarkets
* @description retrieves data on all markets for coinex
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut promisesUnresolved: Value = Value::from(vec![self.fetch_spot_markets(params.clone()).await, self.fetch_contract_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 swapMarkets: Value = promises.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return self.array_concat(spotMarkets, swapMarkets);
Value::Null
}
pub async fn fetch_spot_markets(&mut self, mut params: Value) -> Value {
let mut response: Value = self.v2_public_get_spot_market(&[params]).await;
//
// {
// "code": 0,
// "data": [
// {
// "market": "BTCUSDT",
// "taker_fee_rate": "0.002",
// "maker_fee_rate": "0.002",
// "min_amount": "0.0005",
// "base_ccy": "BTC",
// "quote_ccy": "USDT",
// "base_ccy_precision": 8,
// "quote_ccy_precision": 2,
// "is_amm_available": true,
// "is_margin_available": true,
// "is_pre_trading_available": true,
// "is_api_trading_available": true
// }
// ],
// "message": "OK"
// }
//
let mut markets: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_545: bool = true;
while { if !__for_first_545 { 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_545 = false; i.as_f64().unwrap_or(f64::NAN) < ((markets.len() as i64) as f64) } {
let mut market: Value = markets.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 id: Value = self.safe_string_k(market.clone(), "market", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "base_ccy", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quote_ccy", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
append_to_array(&mut result, 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(), Value::Null);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".into()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), self.safe_bool_k(market.clone(), "is_margin_available", &[]));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), self.safe_bool_k(market.clone(), "is_api_trading_available", &[]));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "taker_fee_rate", &[]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "maker_fee_rate", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "base_ccy_precision", &[])]), &[]));
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quote_ccy_precision", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "min_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".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("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
}));
}
}
return result;
Value::Null
}
pub async fn fetch_contract_markets(&mut self, mut params: Value) -> Value {
let mut response: Value = self.v2_public_get_futures_market(&[params]).await;
//
// {
// "code": 0,
// "data": [
// {
// "base_ccy": "BTC",
// "base_ccy_precision": 8,
// "contract_type": "inverse",
// "leverage": ["1","2","3","5","8","10","15","20","30","50","100"],
// "maker_fee_rate": "0",
// "market": "BTCUSD",
// "min_amount": "10",
// "open_interest_volume": "2566879",
// "quote_ccy": "USD",
// "quote_ccy_precision": 2,
// "taker_fee_rate": "0"
// },
// ],
// "message": "OK"
// }
//
let mut markets: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_546: bool = true;
while { if !__for_first_546 { 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_546 = false; i.as_f64().unwrap_or(f64::NAN) < ((markets.len() as i64) as f64) } {
let mut entry: Value = markets.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 fees: Value = self.fees.clone();
let mut leverages: Value = self.safe_list_k(entry.clone(), "leverage", &[Value::from(vec![])]);
let mut subType: Option<String> = self.safe_string_k(entry.clone(), "contract_type", &[]).as_str().map(str::to_owned);
let mut linear: Value = (Value::Bool(subType.as_deref() == Some("linear")));
let mut inverse: Value = (Value::Bool(subType.as_deref() == Some("inverse")));
let mut id: Value = self.safe_string_k(entry.clone(), "market", &[]);
let mut baseId: Value = self.safe_string_k(entry.clone(), "base_ccy", &[]);
let mut quoteId: Value = self.safe_string_k(entry.clone(), "quote_ccy", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settleId: Value = (if (subType.as_deref() == Some("linear")) { Value::Str("USDT".into()) } else { baseId.clone() });
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), settle).into());
let mut leveragesLength: Value = Value::Int(leverages.len() as i64);
append_to_array(&mut result, 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(), Value::Str("swap".into()));
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Null);
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), linear);
m.insert("inverse".to_string(), inverse);
m.insert("taker".to_string(), fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("taker")).cloned().unwrap_or(Value::Null));
m.insert("maker".to_string(), fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("maker")).cloned().unwrap_or(Value::Null));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(entry.clone(), "base_ccy_precision", &[])]), &[]));
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(entry.clone(), "quote_ccy_precision", &[])]), &[]));
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.safe_number(leverages.clone(), Value::Int(0), &[]));
m.insert("max".to_string(), self.safe_number(leverages, (match (&(leveragesLength), &(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 }), &[]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(entry.clone(), "min_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".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("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), entry);
m
}));
}
}
return result;
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
//
// {
// "close": "62393.47",
// "high": "64106.41",
// "last": "62393.47",
// "low": "59650.01",
// "market": "BTCUSDT",
// "open": "61616.15",
// "period": 86400,
// "value": "28711273.4065667262",
// "volume": "461.76557205",
// "volume_buy": "11.41506354",
// "volume_sell": "7.3240169"
// }
//
// Swap fetchTicker, fetchTickers
//
// {
// "close": "62480.08",
// "high": "64100",
// "index_price": "62443.05",
// "last": "62480.08",
// "low": "59600",
// "mark_price": "62443.05",
// "market": "BTCUSDT",
// "open": "61679.98",
// "period": 86400,
// "value": "180226025.69791713065326633165",
// "volume": "2900.2218",
// "volume_buy": "7.3847",
// "volume_sell": "6.1249"
// }
//
let mut marketType: Value = (if (matches!(&ticker, Value::Dict(__d) if __d.contains_key("mark_price"))) { Value::Str("swap".into()) } else { Value::Str("spot".into()) });
let mut marketId: Value = self.safe_string_k(ticker.clone(), "market", &[]);
market = self.safe_market(&[marketId, market.clone(), Value::Null, marketType]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
// on inverse contracts 'value' is denominated in the settle currency, not
// the quote, so it is the quote volume only for spot and linear markets
let mut quoteVolume: Value = (if (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { Value::Null } else { self.safe_string_k(ticker.clone(), "value", &[]) });
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "low", &[]));
m.insert("bid".to_string(), Value::Null);
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "volume_buy", &[]));
m.insert("ask".to_string(), Value::Null);
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "volume_sell", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "open", &[]));
m.insert("close".to_string(), self.safe_string_k(ticker.clone(), "close", &[]));
m.insert("last".to_string(), self.safe_string_k(ticker.clone(), "last", &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "volume", &[]));
m.insert("quoteVolume".to_string(), quoteVolume);
m.insert("markPrice".to_string(), self.safe_string_k(ticker.clone(), "mark_price", &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "index_price", &[]));
m.insert("info".to_string(), ticker);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name coinex#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market-ticker
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-ticker
* @param {string} symbol unified symbol of the market 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/?id=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("market".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("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_public_get_futures_ticker(&[__ws_arg_0]).await;
} else {
let __ws_arg_1 = self.extend(request, &[params]);
response = self.v2_public_get_spot_ticker(&[__ws_arg_1]).await;
}
//
// Spot
//
// {
// "code": 0,
// "data": [
// {
// "close": "62393.47",
// "high": "64106.41",
// "last": "62393.47",
// "low": "59650.01",
// "market": "BTCUSDT",
// "open": "61616.15",
// "period": 86400,
// "value": "28711273.4065667262",
// "volume": "461.76557205",
// "volume_buy": "11.41506354",
// "volume_sell": "7.3240169"
// }
// ],
// "message": "OK"
// }
//
// Swap
//
// {
// "code": 0,
// "data": [
// {
// "close": "62480.08",
// "high": "64100",
// "index_price": "62443.05",
// "last": "62480.08",
// "low": "59600",
// "mark_price": "62443.05",
// "market": "BTCUSDT",
// "open": "61679.98",
// "period": 86400,
// "value": "180226025.69791713065326633165",
// "volume": "2900.2218",
// "volume_buy": "7.3847",
// "volume_sell": "6.1249"
// }
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(result, &[market]);
Value::Null
}
/*
* @method
* @name coinex#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market-ticker
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-ticker
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut market: Value = Value::Null;
if (symbols != Value::Null) {
let mut symbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
market = self.market(symbol);
}
let mut marketTypequeryVariable = self.handle_market_type_and_params(Value::Str("fetchTickers".into()), &[market, params]);
let mut marketType: Value = marketTypequeryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = marketTypequeryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("swap")) {
response = self.v2_public_get_futures_ticker(&[query.clone()]).await;
} else {
response = self.v2_public_get_spot_ticker(&[query]).await;
}
//
// Spot
//
// {
// "code": 0,
// "data": [
// {
// "close": "62393.47",
// "high": "64106.41",
// "last": "62393.47",
// "low": "59650.01",
// "market": "BTCUSDT",
// "open": "61616.15",
// "period": 86400,
// "value": "28711273.4065667262",
// "volume": "461.76557205",
// "volume_buy": "11.41506354",
// "volume_sell": "7.3240169"
// }
// ],
// "message": "OK"
// }
//
// Swap
//
// {
// "code": 0,
// "data": [
// {
// "close": "62480.08",
// "high": "64100",
// "index_price": "62443.05",
// "last": "62480.08",
// "low": "59600",
// "mark_price": "62443.05",
// "market": "BTCUSDT",
// "open": "61679.98",
// "period": 86400,
// "value": "180226025.69791713065326633165",
// "volume": "2900.2218",
// "volume_buy": "7.3847",
// "volume_sell": "6.1249"
// }
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_tickers(data, &[symbols]);
Value::Null
}
/*
* @method
* @name coinex#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://docs.coinex.com/api/v2/common/http/time
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.v2_public_get_time(&[params]).await;
//
// {
// "code": 0,
// "data": {
// "timestamp": 1711699867777
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_integer_k(data, "timestamp", &[]);
Value::Null
}
/*
* @method
* @name coinex#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market-depth
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-depth
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Int(20));
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());
if (limit == Value::Null) {
limit = Value::Int(20); // default
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("limit".to_string(), limit);
m.insert("interval".to_string(), Value::Str("0".into()));
m
});
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)) {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_public_get_futures_depth(&[__ws_arg_2]).await;
} else {
let __ws_arg_3 = self.extend(request, &[params]);
response = self.v2_public_get_spot_depth(&[__ws_arg_3]).await;
}
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut depth: Value = self.safe_dict_k(data, "depth", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(depth.clone(), "updated_at", &[]);
return self.parse_order_book(depth, symbol, &[timestamp]);
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 and Swap fetchTrades (public)
//
// {
// "amount": "0.00049432",
// "created_at": 1713849825667,
// "deal_id": 4137517302,
// "price": "66251",
// "side": "buy"
// }
//
// Spot and Margin fetchMyTrades (private)
//
// {
// "amount": "0.00010087",
// "created_at": 1714618087585,
// "deal_id": 4161200602,
// "margin_market": "",
// "market": "BTCUSDT",
// "order_id": 117654919342,
// "price": "57464.04",
// "side": "sell"
// }
//
// Swap fetchMyTrades (private)
//
// {
// "deal_id": 1180222387,
// "created_at": 1714119054558,
// "market": "BTCUSDT",
// "side": "buy",
// "order_id": 136915589622,
// "price": "64376",
// "amount": "0.0001",
// "role": "taker",
// "fee": "0.0299",
// "fee_ccy": "USDT"
// }
//
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "created_at", &[]);
let mut defaultType: Value = self.safe_string_k(self.options.clone(), "defaultType", &[]);
if (market != Value::Null) {
defaultType = market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null);
}
let mut marketId: Value = self.safe_string_k(trade.clone(), "market", &[]);
market = self.safe_market(&[marketId, market.clone(), Value::Null, defaultType]);
let mut feeCostString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
let mut fee: Value = Value::Null;
if (feeCostString != Value::Null) {
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "fee_ccy", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId, &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString);
m.insert("currency".to_string(), feeCurrencyCode);
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("id".to_string(), self.safe_string_k(trade.clone(), "deal_id", &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "order_id", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_k(trade.clone(), "side", &[]));
m.insert("takerOrMaker".to_string(), self.safe_string_k(trade.clone(), "role", &[]));
m.insert("price".to_string(), self.safe_string_k(trade.clone(), "price", &[]));
m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "amount", &[]));
m.insert("cost".to_string(), self.safe_string_k(trade, "deal_money", &[]));
m.insert("fee".to_string(), fee);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name coinex#fetchTrades
* @description get the list of the most recent trades for a particular symbol
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market-deals
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-deals
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".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(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
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)) {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_public_get_futures_deals(&[__ws_arg_4]).await;
} else {
let __ws_arg_5 = self.extend(request, &[params]);
response = self.v2_public_get_spot_deals(&[__ws_arg_5]).await;
}
return self.parse_trades(response.as_map().and_then(|__m| __m.get("data")).cloned().unwrap_or(Value::Null), &[market, since, limit]);
Value::Null
}
/*
* @method
* @name coinex#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market
* @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
}));
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("market".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)) {
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_public_get_spot_market(&[__ws_arg_6]).await;
} else {
let __ws_arg_7 = self.extend(request, &[params]);
response = self.v2_public_get_futures_market(&[__ws_arg_7]).await;
}
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(result, &[market]);
Value::Null
}
/*
* @method
* @name coinex#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTradingFees".into()), &[Value::Null, params.clone()]); type_var = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
response = self.v2_public_get_futures_market(&[params.clone()]).await;
} else {
response = self.v2_public_get_spot_market(&[params]).await;
}
let mut data: Value = self.safe_list_k(response, "data", &[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_547: bool = true;
while { if !__for_first_547 { 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_547 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.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(), "market", &[]);
let mut market: Value = self.safe_market(&[marketId, Value::Null, Value::Null, type_var.clone()]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), self.parse_trading_fee(entry, &[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 marketId: Value = self.safe_string_k(fee.clone(), "market", &[]);
let mut symbol: Value = self.safe_symbol(marketId, &[market]);
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(), "maker_fee_rate", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee, "taker_fee_rate", &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_integer_k(ohlcv.clone(), "created_at", &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv, "value", &[])]);
Value::Null
}
/*
* @method
* @name coinex#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market-kline
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-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
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("period".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
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;
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_public_get_futures_kline(&[__ws_arg_8]).await;
} else {
let __ws_arg_9 = self.extend(request, &[params]);
response = self.v2_public_get_spot_kline(&[__ws_arg_9]).await;
}
//
// Spot and Swap
//
// {
// "code": 0,
// "data": [
// {
// "close": "66999.95",
// "created_at": 1713934620000,
// "high": "66999.95",
// "low": "66988.53",
// "market": "BTCUSDT",
// "open": "66988.53",
// "value": "0.1572393",
// "volume": "10533.2501364336"
// },
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_ohlc_vs(data, &[market, timeframe, since, limit]);
Value::Null
}
pub async fn fetch_margin_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 = self.v2_private_get_assets_margin_balance(&[params]).await;
//
// {
// "data": [
// {
// "margin_account": "BTCUSDT",
// "base_ccy": "BTC",
// "quote_ccy": "USDT",
// "available": {
// "base_ccy": "0.00000026",
// "quote_ccy": "0"
// },
// "frozen": {
// "base_ccy": "0",
// "quote_ccy": "0"
// },
// "repaid": {
// "base_ccy": "0",
// "quote_ccy": "0"
// },
// "interest": {
// "base_ccy": "0",
// "quote_ccy": "0"
// },
// "rik_rate": "",
// "liq_price": ""
// },
// ],
// "code": 0,
// "message": "OK"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut balances: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_548: bool = true;
while { if !__for_first_548 { 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_548 = false; i.as_f64().unwrap_or(f64::NAN) < ((balances.len() as i64) as f64) } {
let mut entry: Value = balances.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 free: Value = self.safe_dict_k(entry.clone(), "available", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut used: Value = self.safe_dict_k(entry.clone(), "frozen", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut loan: Value = self.safe_dict_k(entry.clone(), "repaid", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut interest: Value = self.safe_dict_k(entry.clone(), "interest", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut baseAccount: Value = self.account();
let mut baseCurrencyId: Value = self.safe_string_k(entry, "base_ccy", &[]);
let mut baseCurrencyCode: Value = self.safe_currency_code(baseCurrencyId, &[]);
add_element_to_object(&mut baseAccount, &Value::Str("free".into()), self.safe_string_k(free, "base_ccy", &[]));
add_element_to_object(&mut baseAccount, &Value::Str("used".into()), self.safe_string_k(used, "base_ccy", &[]));
let mut baseDebt: Value = self.safe_string_k(loan, "base_ccy", &[]);
let mut baseInterest: Value = self.safe_string_k(interest, "base_ccy", &[]);
add_element_to_object(&mut baseAccount, &Value::Str("debt".into()), crate::precise::Precise::stringAdd(&baseDebt, &baseInterest));
if (baseCurrencyCode != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&baseCurrencyCode), baseAccount); }
}
}
}
return self.safe_balance(result);
Value::Null
}
pub async fn fetch_spot_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 = self.v2_private_get_assets_spot_balance(&[params]).await;
//
// {
// "code": 0,
// "data": [
// {
// "available": "0.00000046",
// "ccy": "USDT",
// "frozen": "0"
// }
// ],
// "message": "OK"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut balances: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_549: bool = true;
while { if !__for_first_549 { 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_549 = false; i.as_f64().unwrap_or(f64::NAN) < ((balances.len() as i64) as f64) } {
let mut entry: Value = balances.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(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(entry.clone(), "available", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(entry, "frozen", &[])); }
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
}
pub async fn fetch_swap_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 = self.v2_private_get_assets_futures_balance(&[params]).await;
//
// {
// "code": 0,
// "data": [
// {
// "available": "0.00000046",
// "ccy": "USDT",
// "frozen": "0",
// "margin": "0",
// "transferrable": "0.00000046",
// "unrealized_pnl": "0"
// }
// ],
// "message": "OK"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut balances: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_550: bool = true;
while { if !__for_first_550 { 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_550 = false; i.as_f64().unwrap_or(f64::NAN) < ((balances.len() as i64) as f64) } {
let mut entry: Value = balances.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(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(entry.clone(), "available", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(entry, "frozen", &[])); }
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
}
pub async fn fetch_financial_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 = self.v2_private_get_assets_financial_balance(&[params]).await;
//
// {
// "code": 0,
// "data": [
// {
// "available": "0.00000046",
// "ccy": "USDT",
// "frozen": "0"
// }
// ],
// "message": "OK"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut balances: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_551: bool = true;
while { if !__for_first_551 { 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_551 = false; i.as_f64().unwrap_or(f64::NAN) < ((balances.len() as i64) as f64) } {
let mut entry: Value = balances.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(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(entry.clone(), "available", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(entry, "frozen", &[])); }
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 coinex#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.coinex.com/api/v2/assets/balance/http/get-spot-balance // spot
* @see https://docs.coinex.com/api/v2/assets/balance/http/get-futures-balance // swap
* @see https://docs.coinex.com/api/v2/assets/balance/http/get-marigin-balance // margin
* @see https://docs.coinex.com/api/v2/assets/balance/http/get-financial-balance // financial
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'margin', 'swap', 'financial', or 'spot'
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".into()), &[Value::Null, params.clone()]); marketType = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBalance".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut isMargin: bool = (marginMode != Value::Null) || (marketType.as_str() == Some("margin"));
if (marketType.as_str() == Some("swap")) {
return self.fetch_swap_balance(&[params.clone()]).await;
} else if (marketType.as_str() == Some("financial")) {
return self.fetch_financial_balance(&[params.clone()]).await;
} else if isMargin {
return self.fetch_margin_balance(&[params.clone()]).await;
} else {
return self.fetch_spot_balance(&[params]).await;
}
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("rejected".to_string(), Value::Str("rejected".into()));
m.insert("open".to_string(), Value::Str("open".into()));
m.insert("not_deal".to_string(), Value::Str("open".into()));
m.insert("part_deal".to_string(), Value::Str("open".into()));
m.insert("done".to_string(), Value::Str("closed".into()));
m.insert("cancel".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// Spot and Margin createOrder, createOrders, editOrder, cancelOrders, cancelOrder, fetchOpenOrders
//
// {
// "amount": "0.0001",
// "base_fee": "0",
// "ccy": "BTC",
// "client_id": "x-167673045-a0a3c6461459a801",
// "created_at": 1714114386250,
// "discount_fee": "0",
// "filled_amount": "0",
// "filled_value": "0",
// "last_fill_amount": "0",
// "last_fill_price": "0",
// "maker_fee_rate": "0.002",
// "market": "BTCUSDT",
// "market_type": "SPOT",
// "order_id": 117178743547,
// "price": "61000",
// "quote_fee": "0",
// "side": "buy",
// "taker_fee_rate": "0.002",
// "type": "limit",
// "unfilled_amount": "0.0001",
// "updated_at": 1714114386250
// }
//
// Spot and Margin fetchClosedOrders
//
// {
// "order_id": 117180532345,
// "market": "BTCUSDT",
// "market_type": "SPOT",
// "side": "sell",
// "type": "market",
// "ccy": "BTC",
// "amount": "0.00015484",
// "price": "0",
// "client_id": "",
// "created_at": 1714116494219,
// "updated_at": 0,
// "base_fee": "0",
// "quote_fee": "0.0199931699632",
// "discount_fee": "0",
// "maker_fee_rate": "0",
// "taker_fee_rate": "0.002",
// "unfilled_amount": "0",
// "filled_amount": "0.00015484",
// "filled_value": "9.9965849816"
// }
//
// Spot, Margin and Swap trigger createOrder, createOrders, editOrder
//
// {
// "stop_id": 117180138153
// }
//
// Swap createOrder, createOrders, editOrder, cancelOrders, cancelOrder, fetchOpenOrders, fetchClosedOrders, closePosition
//
// {
// "amount": "0.0001",
// "client_id": "x-167673045-1471b81d747080a0",
// "created_at": 1714116769986,
// "fee": "0",
// "fee_ccy": "USDT",
// "filled_amount": "0",
// "filled_value": "0",
// "last_filled_amount": "0",
// "last_filled_price": "0",
// "maker_fee_rate": "0.0003",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "order_id": 136913377780,
// "price": "61000.42",
// "realized_pnl": "0",
// "side": "buy",
// "taker_fee_rate": "0.0005",
// "type": "limit",
// "unfilled_amount": "0.0001",
// "updated_at": 1714116769986
// }
//
// Swap stopLossPrice and takeProfitPrice createOrder
//
// {
// "adl_level": 1,
// "ath_margin_size": "2.14586666",
// "ath_position_amount": "0.0001",
// "avg_entry_price": "64376",
// "bkr_price": "0",
// "close_avbl": "0.0001",
// "cml_position_value": "6.4376",
// "created_at": 1714119054558,
// "leverage": "3",
// "liq_price": "0",
// "maintenance_margin_rate": "0.005",
// "maintenance_margin_value": "0.03218632",
// "margin_avbl": "2.14586666",
// "margin_mode": "cross",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "max_position_value": "6.4376",
// "open_interest": "0.0001",
// "position_id": 303884204,
// "position_margin_rate": "3.10624785634397912265",
// "realized_pnl": "-0.0032188",
// "settle_price": "64376",
// "settle_value": "6.4376",
// "side": "long",
// "stop_loss_price": "62000",
// "stop_loss_type": "latest_price",
// "take_profit_price": "0",
// "take_profit_type": "",
// "unrealized_pnl": "0",
// "updated_at": 1714119054559
// }
//
// Swap fetchOrder
//
// {
// "amount": "0.0001",
// "client_id": "x-167673045-da5f31dcd478a829",
// "created_at": 1714460987164,
// "fee": "0",
// "fee_ccy": "USDT",
// "filled_amount": "0",
// "filled_value": "0",
// "last_filled_amount": "0",
// "last_filled_price": "0",
// "maker_fee_rate": "0.0003",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "order_id": 137319868771,
// "price": "61000",
// "realized_pnl": "0",
// "side": "buy",
// "status": "open",
// "taker_fee_rate": "0.0005",
// "type": "limit",
// "unfilled_amount": "0.0001",
// "updated_at": 1714460987164
// }
//
// Spot and Margin fetchOrder
//
// {
// "amount": "0.0001",
// "base_fee": "0",
// "ccy": "BTC",
// "client_id": "x-167673045-da918d6724e3af81",
// "created_at": 1714461638958,
// "discount_fee": "0",
// "filled_amount": "0",
// "filled_value": "0",
// "last_fill_amount": "0",
// "last_fill_price": "0",
// "maker_fee_rate": "0.002",
// "market": "BTCUSDT",
// "market_type": "SPOT",
// "order_id": 117492012985,
// "price": "61000",
// "quote_fee": "0",
// "side": "buy",
// "status": "open",
// "taker_fee_rate": "0.002",
// "type": "limit",
// "unfilled_amount": "0.0001",
// "updated_at": 1714461638958
// }
//
// Swap trigger fetchOpenOrders, fetchClosedOrders - Spot and Swap trigger cancelOrders, cancelOrder
//
// {
// "amount": "0.0001",
// "client_id": "x-167673045-a7d7714c6478acf6",
// "created_at": 1714187923820,
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "price": "61000",
// "side": "buy",
// "stop_id": 136984426097,
// "trigger_direction": "higher",
// "trigger_price": "62000",
// "trigger_price_type": "latest_price",
// "type": "limit",
// "updated_at": 1714187974363
// }
//
// Spot and Margin trigger fetchOpenOrders, fetchClosedOrders
//
// {
// "stop_id": 117586439530,
// "market": "BTCUSDT",
// "market_type": "SPOT",
// "ccy": "BTC",
// "side": "buy",
// "type": "limit",
// "amount": "0.0001",
// "price": "51000",
// "trigger_price": "52000",
// "trigger_direction": "higher",
// "trigger_price_type": "mark_price",
// "client_id": "x-167673045-df61777094c69312",
// "created_at": 1714551237335,
// "updated_at": 1714551237335
// }
//
let mut rawStatus: Value = self.safe_string_k(order.clone(), "status", &[]);
let mut timestamp: Value = self.safe_integer_k(order.clone(), "created_at", &[]);
let mut updatedTimestamp: Value = self.safe_integer_k(order.clone(), "updated_at", &[]);
if (updatedTimestamp.as_f64() == Some(0.0)) {
updatedTimestamp = timestamp.clone();
}
let mut marketId: Value = self.safe_string_k(order.clone(), "market", &[]);
let mut defaultType: Value = self.safe_string_k(self.options.clone(), "defaultType", &[]);
let mut orderType: Value = self.safe_string_lower_k(order.clone(), "market_type", &[defaultType]);
if (orderType.as_str() == Some("futures")) {
orderType = Value::Str("swap".into());
}
let mut marketType: Value = (if (orderType.as_str() == Some("swap")) { Value::Str("swap".into()) } else { Value::Str("spot".into()) });
market = self.safe_market(&[marketId, market.clone(), Value::Null, marketType]);
let mut feeCurrencyId: Value = self.safe_string_k(order.clone(), "fee_ccy", &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId, &[]);
if (feeCurrency == Value::Null) {
feeCurrency = market.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null);
}
let mut side: Value = self.safe_string_k(order.clone(), "side", &[]);
if (side.as_str() == Some("long")) {
side = Value::Str("buy".into());
} else if (side.as_str() == Some("short")) {
side = Value::Str("sell".into());
}
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "client_id", &[]);
if (clientOrderId.as_str() == Some("")) {
clientOrderId = Value::Null;
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_n(order.clone(), Value::from(vec![Value::Str("position_id".into()), Value::Str("order_id".into()), Value::Str("stop_id".into())]), &[]));
m.insert("clientOrderId".to_string(), clientOrderId);
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("timestamp".to_string(), timestamp);
m.insert("lastTradeTimestamp".to_string(), updatedTimestamp);
m.insert("status".to_string(), self.parse_order_status(rawStatus));
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), self.safe_string_k(order.clone(), "type", &[]));
m.insert("timeInForce".to_string(), Value::Null);
m.insert("postOnly".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("price".to_string(), self.safe_string_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), self.safe_string_k(order.clone(), "trigger_price", &[]));
m.insert("takeProfitPrice".to_string(), self.safe_number_k(order.clone(), "take_profit_price", &[]));
m.insert("stopLossPrice".to_string(), self.safe_number_k(order.clone(), "stop_loss_price", &[]));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "filled_value", &[]));
m.insert("average".to_string(), self.safe_string_k(order.clone(), "avg_entry_price", &[]));
m.insert("amount".to_string(), self.safe_string_k(order.clone(), "amount", &[]));
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "filled_amount", &[]));
m.insert("remaining".to_string(), self.safe_string_k(order.clone(), "unfilled_amount", &[]));
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), feeCurrency);
m.insert("cost".to_string(), self.safe_string2(order.clone(), Value::Str("quote_fee".into()), Value::Str("fee".into()), &[]));
m
}));
m.insert("info".to_string(), order);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name coinex#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_order
* @see https://docs.coinex.com/api/v2/spot/order/http/put-order
* @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()))));
}
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("createMarketBuyOrderRequiresPrice".into(), Value::Bool(false)); }
return self.create_order(symbol, Value::Str("market".into()), Value::Str("buy".into()), cost, &[Value::Null, params]).await;
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
let mut market: Value = self.market(symbol.clone());
let mut swap: Value = market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null);
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client_id".into()), Value::Str("clientOrderId".into()), &[]);
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]);
let mut stopLossPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut option: Option<String> = self.safe_string_k(params.clone(), "option", &[]).as_str().map(str::to_owned);
let mut isMarketOrder: Value = Value::Bool(type_var.as_str() == Some("market"));
let mut postOnly: Value = self.is_post_only(isMarketOrder.clone(), Value::Bool(option.as_deref() == Some("maker_only")), &[params.clone()]);
let mut timeInForceRaw: Option<String> = self.safe_string_upper_k(params.clone(), "timeInForce", &[]).as_str().map(str::to_owned);
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[]);
if (reduceOnly.as_bool() == Some(true)) {
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrder() does not support reduceOnly for ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" orders, reduceOnly orders are supported for swap markets only".into()))));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (clientOrderId == Value::Null) {
let mut defaultId: Value = Value::Str("x-167673045".into());
let mut brokerId: Value = self.safe_string_k(self.options.clone(), "brokerId", &[defaultId]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_id".into(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", brokerId, Value::Str("-".into())).into()), self.uuid16(&[])).into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_id".into(), clientOrderId); }
}
if (stopLossPrice == Value::Null) && (takeProfitPrice == Value::Null) {
if (reduceOnly.as_bool() != Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("side".into(), side.clone()); }
}
let mut requestType: Value = type_var.clone();
if is_true(&postOnly) {
requestType = Value::Str("maker_only".into());
} else if (timeInForceRaw.is_some()) {
if (timeInForceRaw.as_deref() == Some("IOC")) {
requestType = Value::Str("ioc".into());
} else if (timeInForceRaw.as_deref() == Some("FOK")) {
requestType = Value::Str("fok".into());
}
}
if !(matches!(&isMarketOrder, Value::Bool(true))) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price.clone())); }
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), requestType); }
}
if (swap.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("FUTURES".into())); }
if ((stopLossPrice != Value::Null) && (stopLossPrice.as_str() != Some(""))) || ((takeProfitPrice != Value::Null) && (takeProfitPrice.as_str() != Some(""))) {
if (stopLossPrice != Value::Null) && (stopLossPrice.as_str() != Some("")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stop_loss_price".into(), self.price_to_precision(symbol.clone(), stopLossPrice)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stop_loss_type".into(), self.safe_string_k(params.clone(), "stop_type", &[Value::Str("latest_price".into())])); }
} else if (takeProfitPrice != Value::Null) && (takeProfitPrice.as_str() != Some("")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("take_profit_price".into(), self.price_to_precision(symbol.clone(), takeProfitPrice)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("take_profit_type".into(), self.safe_string_k(params.clone(), "stop_type", &[Value::Str("latest_price".into())])); }
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("amount".into(), self.amount_to_precision(symbol.clone(), amount.clone())); }
if (triggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("trigger_price".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("trigger_price_type".into(), self.safe_string_k(params.clone(), "stop_type", &[Value::Str("latest_price".into())])); }
}
}
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("MARGIN".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("SPOT".into())); }
}
if (type_var.as_str() == Some("market")) && (side.as_str() == Some("buy")) {
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".into()), Value::Str("createMarketBuyOrderRequiresPrice".into()), &[Value::Bool(true)]); createMarketBuyOrderRequiresPrice = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut cost: Value = self.safe_number_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".into()), &[]);
if is_true(&createMarketBuyOrderRequiresPrice) {
if (price == Value::Null) && (cost == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument".into()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price);
let mut quoteAmount: Value = self.parse_to_numeric(crate::precise::Precise::stringMul(&amountString, &priceString));
let mut costRequest: Value = (if (cost != Value::Null) { cost } else { quoteAmount });
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("amount".into(), self.cost_to_precision(symbol.clone(), costRequest)); }
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("amount".into(), self.cost_to_precision(symbol.clone(), amount.clone())); }
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("amount".into(), self.amount_to_precision(symbol.clone(), amount)); }
}
if (triggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("trigger_price".into(), self.price_to_precision(symbol, triggerPrice)); }
}
}
params = self.omit(params.clone(), Value::from(vec![Value::Str("reduceOnly".into()), Value::Str("timeInForce".into()), Value::Str("postOnly".into()), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("takeProfitPrice".into())]), &[]);
return self.extend(request, &[params]);
Value::Null
}
/*
* @method
* @name coinex#createOrder
* @description create a trade order
* @see https://docs.coinex.com/api/v2/spot/order/http/put-order
* @see https://docs.coinex.com/api/v2/spot/order/http/put-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/put-order
* @see https://docs.coinex.com/api/v2/futures/order/http/put-stop-order
* @see https://docs.coinex.com/api/v2/futures/position/http/close-position
* @see https://docs.coinex.com/api/v2/futures/position/http/set-position-stop-loss
* @see https://docs.coinex.com/api/v2/futures/position/http/set-position-take-profit
* @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 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.triggerPrice] price to trigger stop orders
* @param {float} [params.stopLossPrice] price to trigger stop loss orders
* @param {float} [params.takeProfitPrice] price to trigger take profit orders
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', 'PO'
* @param {boolean} [params.postOnly] set to true if you wish to make a post only order
* @param {boolean} [params.reduceOnly] *contract only* indicates if this order is to reduce the size of a position
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[]);
let mut triggerPrice: Option<String> = self.safe_string2(params.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]).as_str().map(str::to_owned);
let mut stopLossTriggerPrice: Option<String> = self.safe_string_k(params.clone(), "stopLossPrice", &[]).as_str().map(str::to_owned);
let mut takeProfitTriggerPrice: Option<String> = self.safe_string_k(params.clone(), "takeProfitPrice", &[]).as_str().map(str::to_owned);
let mut isTriggerOrder: bool = triggerPrice.is_some();
let mut isStopLossTriggerOrder: bool = stopLossTriggerPrice.is_some();
let mut isTakeProfitTriggerOrder: bool = takeProfitTriggerPrice.is_some();
let mut isStopLossOrTakeProfitTrigger: bool = isStopLossTriggerOrder || isTakeProfitTriggerOrder;
let mut request: Value = self.create_order_request(symbol, type_var, side, amount, &[price, params]);
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 isTriggerOrder {
response = self.v2_private_post_spot_stop_order(&[request.clone()]).await;
} else {
response = self.v2_private_post_spot_order(&[request.clone()]).await;
}
} else {
if isTriggerOrder {
response = self.v2_private_post_futures_stop_order(&[request.clone()]).await;
} else if isStopLossOrTakeProfitTrigger {
if isStopLossTriggerOrder {
response = self.v2_private_post_futures_set_position_stop_loss(&[request.clone()]).await;
} else if isTakeProfitTriggerOrder {
response = self.v2_private_post_futures_set_position_take_profit(&[request.clone()]).await;
}
} else {
if (reduceOnly.as_bool() == Some(true)) {
response = self.v2_private_post_futures_close_position(&[request.clone()]).await;
} else {
response = self.v2_private_post_futures_order(&[request]).await;
}
}
}
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[market]);
Value::Null
}
/*
* @method
* @name coinex#createOrders
* @description create a list of trade orders (all orders should be of the same symbol)
* @see https://docs.coinex.com/api/v2/spot/order/http/put-multi-order
* @see https://docs.coinex.com/api/v2/spot/order/http/put-multi-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/put-multi-order
* @see https://docs.coinex.com/api/v2/futures/order/http/put-multi-stop-order
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @param {object} [params] extra parameters specific to the api endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_orders(&mut self, mut orders: 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 ordersRequests: Value = Value::from(vec![]);
let mut symbol: Value = Value::Null;
let mut reduceOnly: Value = Value::Bool(false);
let mut isTriggerOrder: bool = false;
let mut isStopLossOrTakeProfitTrigger: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_552: bool = true;
while { if !__for_first_552 { 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_552 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut rawOrder: Value = orders.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(rawOrder.clone(), "symbol", &[]);
if (symbol == Value::Null) {
symbol = marketId.clone();
} else {
if (symbol.as_str() != marketId.as_str()) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" createOrders() requires all orders to have the same symbol".into()))));
}
}
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_number_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_number_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder, "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (type_var.as_str() != Some("limit")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrders() does not support ".into())).into()), type_var).into()), Value::Str(" orders, only limit orders are accepted".into()))));
}
reduceOnly = self.safe_value_k(orderParams.clone(), "reduceOnly", &[]);
let mut triggerPrice: Value = self.safe_number2(orderParams.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]);
let mut stopLossTriggerPrice: Option<f64> = self.safe_number_k(orderParams.clone(), "stopLossPrice", &[]).as_f64();
let mut takeProfitTriggerPrice: Option<f64> = self.safe_number_k(orderParams.clone(), "takeProfitPrice", &[]).as_f64();
isTriggerOrder = triggerPrice != Value::Null;
let mut isStopLossTriggerOrder: bool = stopLossTriggerPrice.is_some();
let mut isTakeProfitTriggerOrder: bool = takeProfitTriggerPrice.is_some();
isStopLossOrTakeProfitTrigger = isStopLossTriggerOrder || isTakeProfitTriggerOrder;
let mut orderRequest: Value = self.create_order_request(marketId, type_var, side, amount, &[price, orderParams]);
append_to_array(&mut ordersRequests, orderRequest);
}
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("orders".to_string(), ordersRequests);
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 isTriggerOrder {
response = self.v2_private_post_spot_batch_stop_order(&[request.clone()]).await;
} else {
response = self.v2_private_post_spot_batch_order(&[request.clone()]).await;
}
} else {
if isTriggerOrder {
response = self.v2_private_post_futures_batch_stop_order(&[request.clone()]).await;
} else if isStopLossOrTakeProfitTrigger {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrders() does not support stopLossPrice or takeProfitPrice orders".into()))));
} else {
if is_true(&reduceOnly) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrders() does not support reduceOnly orders".into()))));
} else {
response = self.v2_private_post_futures_batch_order(&[request]).await;
}
}
}
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut results: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_553: bool = true;
while { if !__for_first_553 { 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_553 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.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 status: Value = Value::Null;
let mut code: Option<i64> = self.safe_integer_k(entry.clone(), "code", &[]).as_i64();
if (code.is_some()) {
if (code != Some(0)) {
status = Value::Str("rejected".into());
} else {
status = Value::Str("open".into());
}
}
let mut innerData: Value = self.safe_dict_k(entry.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) && !isTriggerOrder {
add_element_to_object(&mut entry, &Value::Str("status".into()), status.clone());
order = self.parse_order(entry, &[market.clone()]);
} else {
if let Value::Dict(__d) = &mut innerData { std::sync::Arc::make_mut(__d).insert("status".into(), status); }
order = self.parse_order(innerData, &[market.clone()]);
}
append_to_array(&mut results, order);
}
}
return results;
Value::Null
}
/*
* @method
* @name coinex#cancelOrders
* @description cancel multiple orders
* @see https://docs.coinex.com/api/v2/spot/order/http/cancel-batch-order
* @see https://docs.coinex.com/api/v2/spot/order/http/cancel-batch-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-order
* @see https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-stop-order
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true for canceling stop orders
* @returns {object} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrders() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".into()), Value::Str("trigger".into()), &[]);
params = self.omit(params.clone(), Value::from(vec![Value::Str("stop".into()), Value::Str("trigger".into())]), &[]);
let mut response: Value = Value::Null;
let mut requestIds: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_554: bool = true;
while { if !__for_first_554 { 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_554 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
append_to_array(&mut requestIds, (match &ids.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) { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null }));
}
}
if (trigger.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stop_ids".into(), requestIds.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("order_ids".into(), requestIds); }
}
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_cancel_batch_stop_order(&[__ws_arg_10]).await;
} else {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_cancel_batch_order(&[__ws_arg_11]).await;
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("FUTURES".into())); }
if (trigger.as_bool() == Some(true)) {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_futures_cancel_batch_stop_order(&[__ws_arg_12]).await;
} else {
let __ws_arg_13 = self.extend(request, &[params]);
response = self.v2_private_post_futures_cancel_batch_order(&[__ws_arg_13]).await;
}
}
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut results: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_555: bool = true;
while { if !__for_first_555 { 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_555 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.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 item: Value = self.safe_dict_k(entry, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(item, &[market.clone()]);
append_to_array(&mut results, order);
}
}
return results;
Value::Null
}
/*
* @method
* @name coinex#editOrder
* @description edit a trade order
* @see https://docs.coinex.com/api/v2/spot/order/http/edit-order
* @see https://docs.coinex.com/api/v2/spot/order/http/edit-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/edit-order
* @see https://docs.coinex.com/api/v2/futures/order/http/edit-stop-order
* @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.triggerPrice] the price to trigger stop orders
* @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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" editOrder() requires a symbol 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("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (amount != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("amount".into(), self.amount_to_precision(symbol.clone(), amount)); }
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
}
let mut response: Value = Value::Null;
let mut triggerPrice: Value = self.safe_string_n(params.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("trigger_price".into())]), &[]);
params = self.omit(params.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("triggerPrice".into())]), &[]);
let mut isTriggerOrder: bool = triggerPrice != Value::Null;
if isTriggerOrder {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("trigger_price".into(), self.price_to_precision(symbol, triggerPrice)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stop_id".into(), self.parse_to_numeric(id.clone())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("order_id".into(), self.parse_to_numeric(id)); }
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("editOrder".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("MARGIN".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("SPOT".into())); }
}
if isTriggerOrder {
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_modify_stop_order(&[__ws_arg_14]).await;
} else {
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_modify_order(&[__ws_arg_15]).await;
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("FUTURES".into())); }
if isTriggerOrder {
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_futures_modify_stop_order(&[__ws_arg_16]).await;
} else {
let __ws_arg_17 = self.extend(request, &[params]);
response = self.v2_private_post_futures_modify_order(&[__ws_arg_17]).await;
}
}
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[market]);
Value::Null
}
/*
* @method
* @name coinex#editOrders
* @description edit a list of trade orders
* @see https://docs.coinex.com/api/v2/spot/order/http/edit-multi-order
* @see https://docs.coinex.com/api/v2/futures/order/http/edit-multi-order
* @param {Array} orders list of orders to edit, each object should contain the parameters required by editOrder, namely id, symbol, amount, price and params
* @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 edit_orders(&mut self, mut orders: 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 ordersRequests: Value = Value::from(vec![]);
let mut orderSymbols: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_556: bool = true;
while { if !__for_first_556 { 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_556 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut rawOrder: Value = orders.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(rawOrder.clone(), "symbol", &[]);
let mut market: Value = self.market(marketId.clone());
if (marketId != Value::Null) {
append_to_array(&mut orderSymbols, marketId.clone());
}
let mut id: Value = self.safe_string_k(rawOrder.clone(), "id", &[]);
let mut amount: Value = self.safe_number_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_number_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder, "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("editOrders".into()), &[orderParams.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); orderParams = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut market_type: Value = Value::Str("SPOT".into());
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
market_type = Value::Str("FUTURES".into());
} else if (marginMode != Value::Null) {
market_type = Value::Str("MARGIN".into());
}
let mut orderRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), self.parse_to_numeric(id.clone()));
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("market_type".to_string(), market_type);
m
});
if (amount != Value::Null) {
if let Value::Dict(__d) = &mut orderRequest { std::sync::Arc::make_mut(__d).insert("amount".into(), self.amount_to_precision(marketId.clone(), amount)); }
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut orderRequest { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(marketId, price)); }
}
append_to_array(&mut ordersRequests, self.extend(orderRequest, &[orderParams]));
}
}
orderSymbols = self.market_symbols(&[orderSymbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut firstSymbol: Value = self.safe_string(orderSymbols, Value::Int(0), &[]);
let mut firstMarket: Value = self.market(firstSymbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), ordersRequests);
m
});
let mut response: Value = Value::Null;
if (firstMarket.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_batch_modify_order(&[__ws_arg_18]).await;
} else {
let __ws_arg_19 = self.extend(request, &[params]);
response = self.v2_private_post_futures_batch_modify_order(&[__ws_arg_19]).await;
}
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_557: bool = true;
while { if !__for_first_557 { 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_557 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.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 code: Value = self.safe_string_k(entry.clone(), "code", &[]);
let mut message: Value = self.safe_string_k(entry.clone(), "message", &[Value::Str("".into())]);
if (code.as_str() != Some("0")) || ((message.as_str() != Some("Success")) && (message.as_str() != Some("Succeeded")) && (to_lower(&message).as_str() != Some("ok")) && (data == Value::Null)) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message).into());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), code, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut item: Value = self.safe_dict_k(entry, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(item, &[]);
append_to_array(&mut result, order);
}
}
return result;
Value::Null
}
/*
* @method
* @name coinex#cancelOrder
* @description cancels an open order
* @see https://docs.coinex.com/api/v2/spot/order/http/cancel-order
* @see https://docs.coinex.com/api/v2/spot/order/http/cancel-stop-order
* @see https://docs.coinex.com/api/v2/spot/order/http/cancel-order-by-client-id
* @see https://docs.coinex.com/api/v2/spot/order/http/cancel-stop-order-by-client-id
* @see https://docs.coinex.com/api/v2/futures/order/http/cancel-order
* @see https://docs.coinex.com/api/v2/futures/order/http/cancel-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/cancel-order-by-client-id
* @see https://docs.coinex.com/api/v2/futures/order/http/cancel-stop-order-by-client-id
* @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 {string} [params.clientOrderId] client order id, defaults to id if not passed
* @param {boolean} [params.trigger] set to true for canceling a trigger order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut isTriggerOrder: Value = self.safe_bool2(params.clone(), Value::Str("stop".into()), Value::Str("trigger".into()), &[]);
let mut swap: Value = market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("cancelOrder".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (swap.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("FUTURES".into())); }
} else {
if (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("MARGIN".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("SPOT".into())); }
}
}
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client_id".into()), Value::Str("clientOrderId".into()), &[]);
params = self.omit(params.clone(), Value::from(vec![Value::Str("stop".into()), Value::Str("trigger".into()), Value::Str("clientOrderId".into())]), &[]);
let mut response: Value = Value::Null;
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_id".into(), clientOrderId.clone()); }
if (isTriggerOrder.as_bool() == Some(true)) {
if (swap.as_bool() == Some(true)) {
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_futures_cancel_stop_order_by_client_id(&[__ws_arg_20]).await;
} else {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_cancel_stop_order_by_client_id(&[__ws_arg_21]).await;
}
} else {
if (swap.as_bool() == Some(true)) {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_futures_cancel_order_by_client_id(&[__ws_arg_22]).await;
} else {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_cancel_order_by_client_id(&[__ws_arg_23]).await;
}
}
} else {
if (isTriggerOrder.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stop_id".into(), self.parse_to_numeric(id.clone())); }
if (swap.as_bool() == Some(true)) {
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_futures_cancel_stop_order(&[__ws_arg_24]).await;
} else {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_cancel_stop_order(&[__ws_arg_25]).await;
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("order_id".into(), self.parse_to_numeric(id)); }
if (swap.as_bool() == Some(true)) {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_futures_cancel_order(&[__ws_arg_26]).await;
} else {
let __ws_arg_27 = self.extend(request, &[params]);
response = self.v2_private_post_spot_cancel_order(&[__ws_arg_27]).await;
}
}
}
let mut data: Value = Value::Null;
if (clientOrderId != Value::Null) {
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
data = self.safe_dict(rows.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), Value::Str("data".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
data = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_order(data, &[market]);
Value::Null
}
/*
* @method
* @name coinex#cancelAllOrders
* @description cancel all open orders in a market
* @see https://docs.coinex.com/api/v2/spot/order/http/cancel-all-order
* @see https://docs.coinex.com/api/v2/futures/order/http/cancel-all-order
* @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 {string} [params.marginMode] 'cross' or 'isolated' for canceling spot margin orders
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".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("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("FUTURES".into())); }
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_futures_cancel_all_order(&[__ws_arg_28]).await;
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("cancelAllOrders".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("MARGIN".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("SPOT".into())); }
}
let __ws_arg_29 = self.extend(request, &[params]);
response = self.v2_private_post_spot_cancel_all_order(&[__ws_arg_29]).await;
}
return Value::from(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
}), &[])]);
Value::Null
}
/*
* @method
* @name coinex#fetchOrder
* @description fetches information on an order made by the user
* @see https://docs.coinex.com/api/v2/spot/order/http/get-order-status
* @see https://docs.coinex.com/api/v2/futures/order/http/get-order-status
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("order_id".to_string(), self.parse_to_numeric(id));
m
});
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)) {
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_futures_order_status(&[__ws_arg_30]).await;
} else {
let __ws_arg_31 = self.extend(request, &[params]);
response = self.v2_private_get_spot_order_status(&[__ws_arg_31]).await;
}
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[market]);
Value::Null
}
/*
* @method
* @name coinex#fetchOrdersByStatus
* @description fetch a list of orders
* @see https://docs.coinex.com/api/v2/spot/order/http/list-finished-order
* @see https://docs.coinex.com/api/v2/spot/order/http/list-finished-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/list-finished-order
* @see https://docs.coinex.com/api/v2/futures/order/http/list-finished-stop-order
* @param {string} status order status to fetch for
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true for fetching trigger orders
* @param {string} [params.marginMode] 'cross' or 'isolated' for fetching spot margin orders
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
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);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".into()), Value::Str("trigger".into()), &[]);
params = self.omit(params.clone(), Value::from(vec![Value::Str("stop".into()), Value::Str("trigger".into())]), &[]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".into()), &[market.clone(), params.clone()]); marketType = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut response: Value = Value::Null;
let mut isClosed: bool = (status.as_str() == Some("finished")) || (status.as_str() == Some("closed"));
let mut isOpen: bool = (status.as_str() == Some("pending")) || (status.as_str() == Some("open"));
if (marketType.as_str() == Some("swap")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("FUTURES".into())); }
if isClosed {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_futures_finished_stop_order(&[__ws_arg_32]).await;
} else {
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_futures_finished_order(&[__ws_arg_33]).await;
}
} else if isOpen {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_futures_pending_stop_order(&[__ws_arg_34]).await;
} else {
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_futures_pending_order(&[__ws_arg_35]).await;
}
}
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchOrdersByStatus".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("MARGIN".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("SPOT".into())); }
}
if isClosed {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_spot_finished_stop_order(&[__ws_arg_36]).await;
} else {
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_spot_finished_order(&[__ws_arg_37]).await;
}
} else if (status.as_str() == Some("pending")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_spot_pending_stop_order(&[__ws_arg_38]).await;
} else {
let __ws_arg_39 = self.extend(request, &[params]);
response = self.v2_private_get_spot_pending_order(&[__ws_arg_39]).await;
}
}
}
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_orders(data, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name coinex#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://docs.coinex.com/api/v2/spot/order/http/list-pending-order
* @see https://docs.coinex.com/api/v2/spot/order/http/list-pending-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/list-pending-order
* @see https://docs.coinex.com/api/v2/futures/order/http/list-pending-stop-order
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true for fetching trigger orders
* @param {string} [params.marginMode] 'cross' or 'isolated' for fetching spot margin orders
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut openOrders: Value = self.fetch_orders_by_status(Value::Str("pending".into()), &[symbol, since, limit, params]).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_558: bool = true;
while { if !__for_first_558 { 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_558 = false; i.as_f64().unwrap_or(f64::NAN) < ((openOrders.len() as i64) as f64) } {
add_element_to_object(get_value_mut(&mut openOrders, &i), &Value::Str("status".into()), Value::Str("open".into()));
}
}
return openOrders;
Value::Null
}
/*
* @method
* @name coinex#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://docs.coinex.com/api/v2/spot/order/http/list-finished-order
* @see https://docs.coinex.com/api/v2/spot/order/http/list-finished-stop-order
* @see https://docs.coinex.com/api/v2/futures/order/http/list-finished-order
* @see https://docs.coinex.com/api/v2/futures/order/http/list-finished-stop-order
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true for fetching trigger orders
* @param {string} [params.marginMode] 'cross' or 'isolated' for fetching spot margin orders
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_orders_by_status(Value::Str("finished".into()), &[symbol, since, limit, params]).await;
Value::Null
}
/*
* @method
* @name coinex#createDepositAddress
* @description create a currency deposit address
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/update-deposit-address
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] the blockchain network to create a deposit address on
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut network: Value = self.safe_string2(params.clone(), Value::Str("chain".into()), Value::Str("network".into()), &[]);
if (network == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createDepositAddress() requires a network parameter".into()))));
}
params = self.omit(params.clone(), Value::Str("network".into()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("chain".to_string(), self.network_code_to_id(network, &[currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null)]));
m
});
let __ws_arg_40 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_post_assets_renewal_deposit_address(&[__ws_arg_40]).await;
//
// {
// "code": 0,
// "data": {
// "address": "0x321bd6479355142334f45653ad5d8b76105a1234",
// "memo": ""
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_address(data, &[currency]);
Value::Null
}
/*
* @method
* @name coinex#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/get-deposit-address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] the blockchain network to create a deposit address on
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (networkCode == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddress() requires a \"network\" parameter".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("chain".into(), self.network_code_to_id(networkCode, &[currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null)])); }; // required for on-chain, not required for inter-user transfer
let __ws_arg_41 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_assets_deposit_address(&[__ws_arg_41]).await;
//
// {
// "code": 0,
// "data": {
// "address": "0x321bd6479355142334f45653ad5d8b76105a1234",
// "memo": ""
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_address(data, &[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": "1P1JqozxioQwaqPwgMAQdNDYNyaVSqgARq",
// "memo": ""
// }
//
let mut coinAddress: Value = self.safe_string_k(depositAddress.clone(), "address", &[Value::Str("".into())]);
let mut parts: Value = split(&coinAddress, &Value::Str(":".into()));
let mut address: Value = Value::Null;
let mut tag: Value = Value::Null;
let mut partsLength: f64 = ((parts.len() as i64) as f64);
if partsLength > ((1i64) as f64) && (parts.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null).as_str() != Some("cfx")) {
address = parts.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
tag = parts.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
} else {
address = coinAddress;
}
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", &[tag]));
m
});
Value::Null
}
/*
* @method
* @name coinex#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.coinex.com/api/v2/spot/deal/http/list-user-deals
* @see https://docs.coinex.com/api/v2/futures/deal/http/list-user-deals
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trade structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest trades
* @param {string} [params.side] the side of the trades, either 'buy' or 'sell', required for swap
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".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()); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".into(), since.clone()); }
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".into()), request.clone(), params.clone(), &[]); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
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 let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("FUTURES".into())); }
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_futures_user_deals(&[__ws_arg_42]).await;
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchMyTrades".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("MARGIN".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market_type".into(), Value::Str("SPOT".into())); }
}
let __ws_arg_43 = self.extend(request, &[params]);
response = self.v2_private_get_spot_user_deals(&[__ws_arg_43]).await;
}
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_trades(data, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name coinex#fetchPositions
* @description fetch all open positions
* @see https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
* @see https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.method] the method to use 'v2PrivateGetFuturesPendingPosition' or 'v2PrivateGetFuturesFinishedPosition' default is 'v2PrivateGetFuturesPendingPosition'
* @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 defaultMethod: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPositions".into()), Value::Str("method".into()), &[Value::Str("v2PrivateGetFuturesPendingPosition".into())]); defaultMethod = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m
});
let mut market: Value = Value::Null;
if (symbols != Value::Null) {
let mut symbol: Value = Value::Null;
if (matches!(&symbols, Value::Arr(_))) {
let mut symbolsLength: f64 = ((symbols.len() as i64) as f64);
if symbolsLength > ((1i64) as f64) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchPositions() symbols argument cannot contain more than 1 symbol".into()))));
}
symbol = symbols.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
} else {
symbol = symbols.clone();
}
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut response: Value = Value::Null;
if (defaultMethod.as_str() == Some("v2PrivateGetFuturesPendingPosition")) {
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_futures_pending_position(&[__ws_arg_44]).await;
} else {
let __ws_arg_45 = self.extend(request, &[params]);
response = self.v2_private_get_futures_finished_position(&[__ws_arg_45]).await;
}
//
// {
// "code": 0,
// "data": [
// {
// "position_id": 305891033,
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "side": "long",
// "margin_mode": "cross",
// "open_interest": "0.0001",
// "close_avbl": "0.0001",
// "ath_position_amount": "0.0001",
// "unrealized_pnl": "0",
// "realized_pnl": "-0.00311684",
// "avg_entry_price": "62336.8",
// "cml_position_value": "6.23368",
// "max_position_value": "6.23368",
// "created_at": 1715152208041,
// "updated_at": 1715152208041,
// "take_profit_price": "0",
// "stop_loss_price": "0",
// "take_profit_type": "",
// "stop_loss_type": "",
// "settle_price": "62336.8",
// "settle_value": "6.23368",
// "leverage": "3",
// "margin_avbl": "2.07789333",
// "ath_margin_size": "2.07789333",
// "position_margin_rate": "2.40545879023305655728",
// "maintenance_margin_rate": "0.005",
// "maintenance_margin_value": "0.03118094",
// "liq_price": "0",
// "bkr_price": "0",
// "adl_level": 1
// }
// ],
// "message": "OK",
// "pagination": {
// "has_next": false
// }
// }
//
let mut position: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_559: bool = true;
while { if !__for_first_559 { 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_559 = false; i.as_f64().unwrap_or(f64::NAN) < ((position.len() as i64) as f64) } {
append_to_array(&mut result, self.parse_position(position.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()]));
}
}
return self.filter_by_array_positions(result, Value::Str("symbol".into()), &[symbols, Value::Bool(false)]);
Value::Null
}
/*
* @method
* @name coinex#fetchPosition
* @description fetch data on a single open contract trade position
* @see https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
* @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);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_46 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_futures_pending_position(&[__ws_arg_46]).await;
//
// {
// "code": 0,
// "data": [
// {
// "position_id": 305891033,
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "side": "long",
// "margin_mode": "cross",
// "open_interest": "0.0001",
// "close_avbl": "0.0001",
// "ath_position_amount": "0.0001",
// "unrealized_pnl": "0",
// "realized_pnl": "-0.00311684",
// "avg_entry_price": "62336.8",
// "cml_position_value": "6.23368",
// "max_position_value": "6.23368",
// "created_at": 1715152208041,
// "updated_at": 1715152208041,
// "take_profit_price": "0",
// "stop_loss_price": "0",
// "take_profit_type": "",
// "stop_loss_type": "",
// "settle_price": "62336.8",
// "settle_value": "6.23368",
// "leverage": "3",
// "margin_avbl": "2.07789333",
// "ath_margin_size": "2.07789333",
// "position_margin_rate": "2.40545879023305655728",
// "maintenance_margin_rate": "0.005",
// "maintenance_margin_value": "0.03118094",
// "liq_price": "0",
// "bkr_price": "0",
// "adl_level": 1
// }
// ],
// "message": "OK",
// "pagination": {
// "has_next": false
// }
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_position(data.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), &[market]);
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_id": 305891033,
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "side": "long",
// "margin_mode": "cross",
// "open_interest": "0.0001",
// "close_avbl": "0.0001",
// "ath_position_amount": "0.0001",
// "unrealized_pnl": "0",
// "realized_pnl": "-0.00311684",
// "avg_entry_price": "62336.8",
// "cml_position_value": "6.23368",
// "max_position_value": "6.23368",
// "created_at": 1715152208041,
// "updated_at": 1715152208041,
// "take_profit_price": "0",
// "stop_loss_price": "0",
// "take_profit_type": "",
// "stop_loss_type": "",
// "settle_price": "62336.8",
// "settle_value": "6.23368",
// "leverage": "3",
// "margin_avbl": "2.07789333",
// "ath_margin_size": "2.07789333",
// "position_margin_rate": "2.40545879023305655728",
// "maintenance_margin_rate": "0.005",
// "maintenance_margin_value": "0.03118094",
// "liq_price": "0",
// "bkr_price": "0",
// "adl_level": 1
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "market", &[]);
market = self.safe_market(&[marketId, market.clone(), Value::Null, Value::Str("swap".into())]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "created_at", &[]);
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_integer_k(position.clone(), "position_id", &[]));
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("notional".to_string(), self.safe_number_k(position.clone(), "settle_value", &[]));
m.insert("marginMode".to_string(), self.safe_string_k(position.clone(), "margin_mode", &[]));
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liq_price", &[]));
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "avg_entry_price", &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealized_pnl", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "realized_pnl", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "close_avbl", &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market, "contractSize", &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_k(position.clone(), "side", &[]));
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "updated_at", &[]));
m.insert("maintenanceMargin".to_string(), self.safe_number_k(position.clone(), "maintenance_margin_value", &[]));
m.insert("maintenanceMarginPercentage".to_string(), self.safe_number_k(position.clone(), "maintenance_margin_rate", &[]));
m.insert("collateral".to_string(), self.safe_number_k(position.clone(), "margin_avbl", &[]));
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("marginRatio".to_string(), self.safe_number_k(position.clone(), "position_margin_rate", &[]));
m.insert("stopLossPrice".to_string(), self.omit_zero(self.safe_string_k(position.clone(), "stop_loss_price", &[])));
m.insert("takeProfitPrice".to_string(), self.omit_zero(self.safe_string_k(position, "take_profit_price", &[])));
m
}));
Value::Null
}
/*
* @method
* @name coinex#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} params.leverage the rate of leverage
* @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()))));
}
marginMode = to_lower(&marginMode);
if (marginMode.as_str() != Some("isolated")) && (marginMode.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()))));
}
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("type")).cloned().unwrap_or(Value::Null).as_str() != Some("swap")) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() supports swap contracts only".into()))));
}
let mut leverage: Value = self.safe_integer_k(params.clone(), "leverage", &[]);
let mut maxLeverage: Value = self.safe_integer(market.as_map().and_then(|__m| __m.get("limits")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("leverage")).cloned().unwrap_or(Value::Null), Value::Str("max".into()), &[Value::Int(100)]);
if (leverage == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() requires a leverage parameter".into()))));
}
if (leverage.as_f64().unwrap_or(f64::NAN) < ((1i64) as f64)) || (leverage.as_f64().unwrap_or(f64::NAN) > maxLeverage.as_f64().unwrap_or(f64::NAN)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() leverage should be between 1 and ".into())).into()), to_string_val(&maxLeverage)).into()), Value::Str(" for ".into())).into()), symbol)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m.insert("margin_mode".to_string(), marginMode);
m.insert("leverage".to_string(), leverage);
m
});
let __ws_arg_47 = self.extend(request, &[params]);
return self.v2_private_post_futures_adjust_position_leverage(&[__ws_arg_47]).await;
Value::Null
}
/*
* @method
* @name coinex#setLeverage
* @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
* @description set the level of leverage for a market
* @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.marginMode] 'cross' or 'isolated' (default is 'cross')
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() supports swap contracts only".into()))));
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setLeverage".into()), &[params.clone(), Value::Str("cross".into())]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut minLeverage: Value = self.safe_integer(market.as_map().and_then(|__m| __m.get("limits")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("leverage")).cloned().unwrap_or(Value::Null), Value::Str("min".into()), &[Value::Int(1)]);
let mut maxLeverage: Value = self.safe_integer(market.as_map().and_then(|__m| __m.get("limits")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("leverage")).cloned().unwrap_or(Value::Null), Value::Str("max".into()), &[Value::Int(100)]);
if (leverage.as_f64().unwrap_or(f64::NAN) < minLeverage.as_f64().unwrap_or(f64::NAN)) || (leverage.as_f64().unwrap_or(f64::NAN) > maxLeverage.as_f64().unwrap_or(f64::NAN)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() leverage should be between ".into())).into()), to_string_val(&minLeverage)).into()), Value::Str(" and ".into())).into()), to_string_val(&maxLeverage)).into()), Value::Str(" for ".into())).into()), symbol)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m.insert("margin_mode".to_string(), marginMode);
m.insert("leverage".to_string(), leverage);
m
});
let __ws_arg_48 = self.extend(request, &[params]);
return self.v2_private_post_futures_adjust_position_leverage(&[__ws_arg_48]).await;
Value::Null
}
/*
* @method
* @name coinex#fetchLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-position-level
* @param {string[]|undefined} symbols 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}, indexed by market symbols
*/
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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbols != Value::Null) {
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market".into(), join(&marketIds, &Value::Str(",".into()))); }
}
let __ws_arg_49 = self.extend(request, &[params]);
let mut response: Value = self.v2_public_get_futures_position_level(&[__ws_arg_49]).await;
//
// {
// "code": 0,
// "data": [
// {
// "level": [
// {
// "amount": "20001",
// "leverage": "20",
// "maintenance_margin_rate": "0.02",
// "min_initial_margin_rate": "0.05"
// },
// {
// "amount": "50001",
// "leverage": "10",
// "maintenance_margin_rate": "0.04",
// "min_initial_margin_rate": "0.1"
// },
// ],
// "market": "MINAUSDT"
// },
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_leverage_tiers(data, &[symbols, Value::Str("market".into())]);
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);
let mut tiers: Value = Value::from(vec![]);
let mut brackets: Value = self.safe_list_k(info.clone(), "level", &[Value::from(vec![])]);
let mut minNotional: Value = Value::Int(0);
{
let mut i: Value = Value::Int(0);
let mut __for_first_560: bool = true;
while { if !__for_first_560 { 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_560 = false; i.as_f64().unwrap_or(f64::NAN) < ((brackets.len() as i64) as f64) } {
let mut tier: Value = brackets.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(info.clone(), "market", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".into())]);
let mut maxNotional: Value = self.safe_number_k(tier.clone(), "amount", &[]);
let mut curr: Value = (if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { market.as_map().and_then(|__m| __m.get("base")).cloned().unwrap_or(Value::Null) } else { market.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null) });
let mut notional: Value = minNotional.clone();
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.sum(&[i.clone(), Value::Int(1)]));
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market.clone(), Value::Null, Value::Str("swap".into())]));
m.insert("currency".to_string(), curr);
m.insert("minNotional".to_string(), notional);
m.insert("maxNotional".to_string(), maxNotional.clone());
m.insert("maintenanceMarginRate".to_string(), self.safe_number_k(tier.clone(), "maintenance_margin_rate", &[]));
m.insert("maxLeverage".to_string(), self.safe_integer_k(tier.clone(), "leverage", &[]));
m.insert("info".to_string(), tier);
m
}));
minNotional = maxNotional;
}
}
return tiers;
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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut rawAmount: Value = self.amount_to_precision(symbol, amount.clone());
let mut requestAmount: Value = rawAmount.clone();
if (addOrReduce.as_str() == Some("reduce")) {
requestAmount = crate::precise::Precise::stringNeg(&rawAmount);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m.insert("amount".to_string(), requestAmount);
m
});
let __ws_arg_50 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_post_futures_adjust_position_margin(&[__ws_arg_50]).await;
//
// {
// "code": 0,
// "data": {
// "adl_level": 1,
// "ath_margin_size": "2.034928",
// "ath_position_amount": "0.0001",
// "avg_entry_price": "61047.84",
// "bkr_price": "30698.5600000000000004142",
// "close_avbl": "0.0001",
// "cml_position_value": "6.104784",
// "created_at": 1715488472908,
// "leverage": "3",
// "liq_price": "30852.82412060301507579316",
// "maintenance_margin_rate": "0.005",
// "maintenance_margin_value": "0.03051465",
// "margin_avbl": "3.034928",
// "margin_mode": "isolated",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "max_position_value": "6.104784",
// "open_interest": "0.0001",
// "position_id": 306458800,
// "position_margin_rate": "0.49713929272518077625",
// "realized_pnl": "-0.003052392",
// "settle_price": "61047.84",
// "settle_value": "6.104784",
// "side": "long",
// "stop_loss_price": "0",
// "stop_loss_type": "",
// "take_profit_price": "0",
// "take_profit_type": "",
// "unrealized_pnl": "0",
// "updated_at": 1715488805563
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut status: Value = self.safe_string_lower_k(response, "message", &[]);
let mut type_var: Value = (if (addOrReduce.as_str() == Some("reduce")) { Value::Str("reduce".into()) } else { Value::Str("add".into()) });
let __ws_arg_51 = self.parse_margin_modification(data, &[market]);
let __ws_arg_52 = self.parse_number(amount, &[]);
return self.extend(__ws_arg_51, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var);
m.insert("amount".to_string(), __ws_arg_52);
m.insert("status".to_string(), status);
m
})]);
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);
//
// addMargin/reduceMargin
//
// {
// "adl_level": 1,
// "ath_margin_size": "2.034928",
// "ath_position_amount": "0.0001",
// "avg_entry_price": "61047.84",
// "bkr_price": "30698.5600000000000004142",
// "close_avbl": "0.0001",
// "cml_position_value": "6.104784",
// "created_at": 1715488472908,
// "leverage": "3",
// "liq_price": "30852.82412060301507579316",
// "maintenance_margin_rate": "0.005",
// "maintenance_margin_value": "0.03051465",
// "margin_avbl": "3.034928",
// "margin_mode": "isolated",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "max_position_value": "6.104784",
// "open_interest": "0.0001",
// "position_id": 306458800,
// "position_margin_rate": "0.49713929272518077625",
// "realized_pnl": "-0.003052392",
// "settle_price": "61047.84",
// "settle_value": "6.104784",
// "side": "long",
// "stop_loss_price": "0",
// "stop_loss_type": "",
// "take_profit_price": "0",
// "take_profit_type": "",
// "unrealized_pnl": "0",
// "updated_at": 1715488805563
// }
//
// fetchMarginAdjustmentHistory
//
// {
// "bkr_pirce": "24698.56000000000000005224",
// "created_at": 1715489978697,
// "leverage": "3",
// "liq_price": "24822.67336683417085432386",
// "margin_avbl": "3.634928",
// "margin_change": "-1.5",
// "margin_mode": "isolated",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "open_interest": "0.0001",
// "position_id": 306458800,
// "settle_price": "61047.84"
// }
//
let mut marketId: Value = self.safe_string_k(data.clone(), "market", &[]);
let mut timestamp: Value = self.safe_integer2(data.clone(), Value::Str("updated_at".into()), Value::Str("created_at".into()), &[]);
let mut change: Value = self.safe_string_k(data.clone(), "margin_change", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market.clone(), Value::Null, Value::Str("swap".into())]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("amount".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&change), &[]));
m.insert("total".to_string(), self.safe_number_k(data, "margin_avbl", &[]));
m.insert("code".to_string(), self.safe_string_k(market, "quote", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
Value::Null
}
/*
* @method
* @name coinex#addMargin
* @description add margin
* @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin
* @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
* @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 coinex#reduceMargin
* @description remove margin from a position
* @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin
* @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
* @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("reduce".into()), &[params]).await;
Value::Null
}
/*
* @method
* @name coinex#fetchFundingHistory
* @description fetch the history of funding fee payments paid and received on this account
* @see https://docs.coinex.com/api/v2/futures/position/http/list-position-funding-history
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch funding history for
* @param {int} [limit] the maximum number of funding history structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding history structure]{@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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingHistory() requires a symbol 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("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m
});
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".into()), request.clone(), params.clone(), &[]); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".into(), since); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit); }
}
let __ws_arg_53 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_futures_position_funding_history(&[__ws_arg_53]).await;
//
// {
// "code": 0,
// "data": [
// {
// "ccy": "USDT",
// "created_at": 1715673620183,
// "funding_rate": "0",
// "funding_value": "0",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "position_id": 306458800,
// "side": "long"
// },
// ],
// "message": "OK",
// "pagination": {
// "has_next": true
// }
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_561: bool = true;
while { if !__for_first_561 { 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_561 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.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 timestamp: Value = self.safe_integer_k(entry.clone(), "created_at", &[]);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), symbol.clone());
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_number_k(entry.clone(), "position_id", &[]));
m.insert("amount".to_string(), self.safe_number_k(entry, "funding_value", &[]));
m
}));
}
}
return result;
Value::Null
}
/*
* @method
* @name coinex#fetchFundingRate
* @description fetch the current funding rate
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate
* @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::bad_symbol(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("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_54 = self.extend(request, &[params]);
let mut response: Value = self.v2_public_get_futures_funding_rate(&[__ws_arg_54]).await;
//
// {
// "code": 0,
// "data": [
// {
// "latest_funding_rate": "0",
// "latest_funding_time": 1715731200000,
// "mark_price": "61602.22",
// "market": "BTCUSDT",
// "max_funding_rate": "0.00375",
// "min_funding_rate": "-0.00375",
// "next_funding_rate": "0.00021074",
// "next_funding_time": 1715760000000
// }
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut first: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(first, &[market]);
Value::Null
}
/*
* @method
* @name coinex#fetchFundingInterval
* @description fetch the current funding rate interval
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_interval(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_funding_rate(symbol, &[params]).await;
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);
//
// fetchFundingRate, fetchFundingRates, fetchFundingInterval
//
// {
// "latest_funding_rate": "0",
// "latest_funding_time": 1715731200000,
// "mark_price": "61602.22",
// "market": "BTCUSDT",
// "max_funding_rate": "0.00375",
// "min_funding_rate": "-0.00375",
// "next_funding_rate": "0.00021074",
// "next_funding_time": 1715760000000
// }
//
let mut currentFundingTimestamp: Value = self.safe_integer_k(contract.clone(), "latest_funding_time", &[]);
let mut futureFundingTimestamp: Value = self.safe_integer_k(contract.clone(), "next_funding_time", &[]);
let mut fundingTimeString: Value = self.safe_string_k(contract.clone(), "latest_funding_time", &[]);
let mut nextFundingTimeString: Value = self.safe_string_k(contract.clone(), "next_funding_time", &[]);
let mut millisecondsInterval: Value = crate::precise::Precise::stringSub(&nextFundingTimeString, &fundingTimeString);
let mut marketId: Value = self.safe_string_k(contract.clone(), "market", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market, Value::Null, Value::Str("swap".into())]));
m.insert("markPrice".to_string(), self.safe_number_k(contract.clone(), "mark_price", &[]));
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "latest_funding_rate", &[]));
m.insert("fundingTimestamp".to_string(), currentFundingTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(currentFundingTimestamp));
m.insert("nextFundingRate".to_string(), self.safe_number_k(contract, "next_funding_rate", &[]));
m.insert("nextFundingTimestamp".to_string(), futureFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(futureFundingTimestamp));
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(), self.parse_funding_interval(millisecondsInterval).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m
});
Value::Null
}
pub fn parse_funding_interval(&self, mut interval: Value) -> Option<String> {
let mut intervals: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("3600000".to_string(), Value::Str("1h".into()));
m.insert("14400000".to_string(), Value::Str("4h".into()));
m.insert("28800000".to_string(), Value::Str("8h".into()));
m.insert("57600000".to_string(), Value::Str("16h".into()));
m.insert("86400000".to_string(), Value::Str("24h".into()));
m
});
return self.safe_string(intervals, interval.clone(), &[interval.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name coinex#fetchFundingRates
* @description fetch the current funding rates for multiple markets
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate
* @param {string[]} symbols unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbols != Value::Null) {
let mut symbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
market = 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::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRates() supports swap contracts only".into()))));
}
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market".into(), join(&marketIds, &Value::Str(",".into()))); }
}
let __ws_arg_55 = self.extend(request, &[params]);
let mut response: Value = self.v2_public_get_futures_funding_rate(&[__ws_arg_55]).await;
//
// {
// "code": 0,
// "data": [
// {
// "latest_funding_rate": "0",
// "latest_funding_time": 1715731200000,
// "mark_price": "61602.22",
// "market": "BTCUSDT",
// "max_funding_rate": "0.00375",
// "min_funding_rate": "-0.00375",
// "next_funding_rate": "0.00021074",
// "next_funding_time": 1715760000000
// }
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_funding_rates(data, &[symbols]);
Value::Null
}
/*
* @method
* @name coinex#withdraw
* @description make a withdrawal
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/withdrawal
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} [tag] memo
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] unified network code
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
{ let __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
self.check_address(&[address.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("to_address".to_string(), address);
m.insert("amount".to_string(), self.currency_to_precision(code, amount, &[]));
m
});
if (tag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("memo".into(), tag); }
}
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("chain".into(), self.network_code_to_id(networkCode, &[currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null)])); }; // required for on-chain, not required for inter-user transfer
}
let __ws_arg_56 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_post_assets_withdraw(&[__ws_arg_56]).await;
//
// {
// "code": 0,
// "data": {
// "withdraw_id": 31193755,
// "created_at": 1716874165038,
// "withdraw_method": "ON_CHAIN",
// "ccy": "USDT",
// "amount": "17.3",
// "actual_amount": "15",
// "chain": "TRC20",
// "tx_fee": "2.3",
// "fee_asset": "USDT",
// "fee_amount": "2.3",
// "to_address": "TY5vq3MT6b5cQVAHWHtpGyPg1ERcQgi3UN",
// "memo": "",
// "tx_id": "",
// "confirmations": 0,
// "explorer_address_url": "https://tronscan.org/#/address/TY5vq3MT6b5cQVAHWHtpGyPg1ERcQgi3UN",
// "explorer_tx_url": "https://tronscan.org/#/transaction/",
// "remark": "",
// "status": "audit_required"
// },
// "message": "OK"
// }
//
let mut transaction: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(transaction, &[currency]);
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("audit".to_string(), Value::Str("pending".into()));
m.insert("pass".to_string(), Value::Str("pending".into()));
m.insert("audit_required".to_string(), Value::Str("pending".into()));
m.insert("processing".to_string(), Value::Str("pending".into()));
m.insert("confirming".to_string(), Value::Str("pending".into()));
m.insert("not_pass".to_string(), Value::Str("failed".into()));
m.insert("cancel".to_string(), Value::Str("canceled".into()));
m.insert("finish".to_string(), Value::Str("ok".into()));
m.insert("finished".to_string(), Value::Str("ok".into()));
m.insert("fail".to_string(), Value::Str("failed".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name coinex#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate-history
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {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)
* @param {int} [params.until] timestamp in ms of the latest funding rate
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[]); paginate = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.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("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), params.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("market".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("start_time".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 __destr_tmp = self.handle_until_option(Value::Str("end_time".into()), request.clone(), params.clone(), &[]); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let __ws_arg_57 = self.extend(request, &[params]);
let mut response: Value = self.v2_public_get_futures_funding_rate_history(&[__ws_arg_57]).await;
//
// {
// "code": 0,
// "data": [
// {
// "actual_funding_rate": "0",
// "funding_time": 1715731221761,
// "market": "BTCUSDT",
// "theoretical_funding_rate": "0"
// },
// ],
// "message": "OK",
// "pagination": {
// "has_next": true
// }
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut rates: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_562: bool = true;
while { if !__for_first_562 { 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_562 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.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(), "market", &[]);
let mut symbolInner: Value = self.safe_symbol(marketId, &[market.clone(), Value::Null, Value::Str("swap".into())]);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "funding_time", &[]);
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, "actual_funding_rate", &[]));
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, &[market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), since, limit]);
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
//
// {
// "deposit_id": 5173806,
// "created_at": 1714021652557,
// "tx_id": "d9f47d2550397c635cb89a8963118f8fe78ef048bc8b6f0caaeaa7dc6",
// "tx_id_display": "",
// "ccy": "USDT",
// "chain": "TRC20",
// "deposit_method": "ON_CHAIN",
// "amount": "30",
// "actual_amount": "",
// "to_address": "TYewD2pVWDUwfNr9A",
// "confirmations": 20,
// "status": "FINISHED",
// "tx_explorer_url": "https://tronscan.org/#/transaction",
// "to_addr_explorer_url": "https://tronscan.org/#/address",
// "remark": ""
// }
//
// fetchWithdrawals and withdraw
//
// {
// "withdraw_id": 259364,
// "created_at": 1701323541548,
// "withdraw_method": "ON_CHAIN",
// "ccy": "USDT",
// "amount": "23.845744",
// "actual_amount": "22.445744",
// "chain": "TRC20",
// "tx_fee": "1.4",
// "fee_asset": "USDT",
// "fee_amount": "1.4",
// "to_address": "T8t5i2454dhdhnnnGdi49vMbihvY",
// "memo": "",
// "tx_id": "1237623941964de9954ed2e36640228d78765c1026",
// "confirmations": 18,
// "explorer_address_url": "https://tronscan.org/#/address",
// "explorer_tx_url": "https://tronscan.org/#/transaction",
// "remark": "",
// "status": "finished"
// }
//
let mut address: Value = self.safe_string_k(transaction.clone(), "to_address", &[]);
let mut tag: Value = self.safe_string_k(transaction.clone(), "memo", &[]);
if (tag != Value::Null) {
if ((tag.len() as i64) as f64) < ((1i64) as f64) {
tag = Value::Null;
}
}
let mut remark: Value = self.safe_string_k(transaction.clone(), "remark", &[]);
if (remark != Value::Null) {
if ((remark.len() as i64) as f64) < ((1i64) as f64) {
remark = Value::Null;
}
}
let mut txid: Value = self.safe_string_k(transaction.clone(), "tx_id", &[]);
if (txid != Value::Null) {
if ((txid.len() as i64) as f64) < ((1i64) as f64) {
txid = Value::Null;
}
}
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency]);
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "created_at", &[]);
let mut type_var: Value = (if (matches!(&transaction, Value::Dict(__d) if __d.contains_key("withdraw_id"))) { Value::Str("withdrawal".into()) } else { Value::Str("deposit".into()) });
let mut networkId: Value = self.safe_string_k(transaction.clone(), "chain", &[]);
let mut feeCost: Value = self.safe_string_k(transaction.clone(), "tx_fee", &[]);
let mut transferMethod: Option<String> = self.safe_string_lower2(transaction.clone(), Value::Str("withdraw_method".into()), Value::Str("deposit_method".into()), &[]).as_str().map(str::to_owned);
let mut internal: Value = Value::Bool(transferMethod.as_deref() == Some("local"));
let mut amount: Value = self.safe_number_k(transaction.clone(), "actual_amount", &[]);
if (amount == Value::Null) {
amount = self.safe_number_k(transaction.clone(), "amount", &[]);
}
if (type_var.as_str() == Some("deposit")) {
feeCost = Value::Str("0".into());
}
let mut feeCurrencyId: Value = self.safe_string2(transaction.clone(), Value::Str("fee_asset".into()), Value::Str("fee_ccy".into()), &[]); // https://github.com/ccxt/ccxt/issues/25153
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeCost, &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCurrencyId, &[]));
m
});
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string2(transaction.clone(), Value::Str("withdraw_id".into()), Value::Str("deposit_id".into()), &[]));
m.insert("txid".to_string(), txid);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("network".to_string(), self.network_id_to_code(&[networkId, code.clone()]));
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), address);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), tag);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("amount".to_string(), amount);
m.insert("currency".to_string(), code);
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction, "status", &[])));
m.insert("updated".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("comment".to_string(), remark);
m.insert("internal".to_string(), internal);
m
});
Value::Null
}
/*
* @method
* @name coinex#transfer
* @description transfer currency internally between wallets on the same account
* @see https://docs.coinex.com/api/v2/assets/transfer/http/transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.symbol] unified ccxt symbol, required when either the fromAccount or toAccount is margin
* @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 amountToPrecision: Value = self.currency_to_precision(code, amount, &[]);
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountsByType, toAccount.clone(), &[toAccount.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), amountToPrecision.clone());
m.insert("from_account_type".to_string(), fromId);
m.insert("to_account_type".to_string(), toId);
m
});
if (fromAccount.as_str() == Some("margin")) || (toAccount.as_str() == Some("margin")) {
let mut symbol: Value = self.safe_string_k(params.clone(), "symbol", &[]);
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" transfer() the symbol parameter must be defined for a margin account".into()))));
}
params = self.omit(params.clone(), Value::Str("symbol".into()), &[]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market".into(), self.market_id(symbol)); }
}
if (fromAccount.as_str() != Some("spot")) && (toAccount.as_str() != Some("spot")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" transfer() can only be between spot and swap, or spot and margin, either the fromAccount or toAccount must be spot".into()))));
}
let __ws_arg_58 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_post_assets_transfer(&[__ws_arg_58]).await;
let __ws_arg_59 = self.parse_transfer(response, &[currency]);
let __ws_arg_60 = self.parse_number(amountToPrecision, &[]);
return self.extend(__ws_arg_59, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), __ws_arg_60);
m.insert("fromAccount".to_string(), fromAccount);
m.insert("toAccount".to_string(), toAccount);
m
})]);
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("ok".into()));
m.insert("SUCCESS".to_string(), Value::Str("ok".into()));
m.insert("OK".to_string(), Value::Str("ok".into()));
m.insert("finished".to_string(), Value::Str("ok".into()));
m.insert("FINISHED".to_string(), Value::Str("ok".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "created_at", &[]);
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "ccy", &[]);
let mut fromId: Value = self.safe_string_k(transfer.clone(), "from_account_type", &[]);
let mut toId: Value = self.safe_string_k(transfer.clone(), "to_account_type", &[]);
let mut accountsById: Value = self.safe_dict_k(self.options.clone(), "accountsById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("amount".to_string(), self.safe_number_k(transfer.clone(), "amount", &[]));
m.insert("fromAccount".to_string(), self.safe_string(accountsById.clone(), fromId.clone(), &[fromId.clone()]));
m.insert("toAccount".to_string(), self.safe_string(accountsById, toId.clone(), &[toId.clone()]));
m.insert("status".to_string(), self.parse_transfer_status(self.safe_string2(transfer, Value::Str("code".into()), Value::Str("status".into()), &[])));
m
});
Value::Null
}
/*
* @method
* @name coinex#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://docs.coinex.com/api/v2/assets/transfer/http/list-transfer-history
* @param {string} code unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfer structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] 'cross' or 'isolated' for fetching transfers to and from your margin account
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn fetch_transfers(&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;
}
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchTransfers() requires a code argument".into()))));
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchTransfers".into()), &[params.clone()]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("transfer_type".into(), Value::Str("MARGIN".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("transfer_type".into(), Value::Str("FUTURES".into())); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".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 __destr_tmp = self.handle_until_option(Value::Str("end_time".into()), request.clone(), params.clone(), &[]); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let __ws_arg_61 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_assets_transfer_history(&[__ws_arg_61]).await;
//
// {
// "data": [
// {
// "created_at": 1715848480646,
// "from_account_type": "SPOT",
// "to_account_type": "FUTURES",
// "ccy": "USDT",
// "amount": "10",
// "status": "finished"
// },
// ],
// "pagination": {
// "total": 8,
// "has_next": false
// },
// "code": 0,
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_transfers(data, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name coinex#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-withdrawal-history
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawal structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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("ccy".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_62 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_assets_withdraw(&[__ws_arg_62]).await;
//
// {
// "data": [
// {
// "withdraw_id": 259364,
// "created_at": 1701323541548,
// "withdraw_method": "ON_CHAIN",
// "ccy": "USDT",
// "amount": "23.845744",
// "actual_amount": "22.445744",
// "chain": "TRC20",
// "tx_fee": "1.4",
// "fee_asset": "USDT",
// "fee_amount": "1.4",
// "to_address": "T8t5i2454dhdhnnnGdi49vMbihvY",
// "memo": "",
// "tx_id": "1237623941964de9954ed2e36640228d78765c1026",
// "confirmations": 18,
// "explorer_address_url": "https://tronscan.org/#/address",
// "explorer_tx_url": "https://tronscan.org/#/transaction",
// "remark": "",
// "status": "finished"
// },
// ],
// "pagination": {
// "total": 9,
// "has_next": true
// },
// "code": 0,
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_transactions(data, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name coinex#fetchDeposits
* @description fetch all deposits made to an account
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-deposit-history
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposit structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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("ccy".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_63 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_assets_deposit_history(&[__ws_arg_63]).await;
//
// {
// "data": [
// {
// "deposit_id": 5173806,
// "created_at": 1714021652557,
// "tx_id": "d9f47d2550397c635cb89a8963118f8fe78ef048bc8b6f0caaeaa7dc6",
// "tx_id_display": "",
// "ccy": "USDT",
// "chain": "TRC20",
// "deposit_method": "ON_CHAIN",
// "amount": "30",
// "actual_amount": "",
// "to_address": "TYewD2pVWDUwfNr9A",
// "confirmations": 20,
// "status": "FINISHED",
// "tx_explorer_url": "https://tronscan.org/#/transaction",
// "to_addr_explorer_url": "https://tronscan.org/#/address",
// "remark": ""
// },
// ],
// "paginatation": {
// "total": 8,
// "has_next": true
// },
// "code": 0,
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_transactions(data, &[currency, since, limit]);
Value::Null
}
pub fn parse_isolated_borrow_rate(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "market": "BTCUSDT",
// "ccy": "USDT",
// "leverage": 10,
// "min_amount": "60",
// "max_amount": "500000",
// "daily_interest_rate": "0.001"
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "market", &[]);
market = self.safe_market(&[marketId, market.clone(), Value::Null, Value::Str("spot".into())]);
let mut currency: Value = self.safe_string_k(info.clone(), "ccy", &[]);
let mut rate: Value = self.safe_number_k(info.clone(), "daily_interest_rate", &[]);
let mut baseRate: Value = Value::Null;
let mut quoteRate: Value = Value::Null;
if (currency.as_str() == market.as_map().and_then(|__m| __m.get("baseId")).cloned().unwrap_or(Value::Null).as_str()) {
baseRate = rate.clone();
} else if (currency.as_str() == market.as_map().and_then(|__m| __m.get("quoteId")).cloned().unwrap_or(Value::Null).as_str()) {
quoteRate = rate;
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("base".to_string(), market.as_map().and_then(|__m| __m.get("base")).cloned().unwrap_or(Value::Null));
m.insert("baseRate".to_string(), baseRate);
m.insert("quote".to_string(), market.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null));
m.insert("quoteRate".to_string(), quoteRate);
m.insert("period".to_string(), Value::Int(86400000));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("info".to_string(), info);
m
});
Value::Null
}
/*
* @method
* @name coinex#fetchIsolatedBorrowRate
* @description fetch the rate of interest to borrow a currency for margin trading
* @see https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-interest-limit
* @param {string} symbol unified symbol of the market to fetch the borrow rate for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.code unified currency code
* @returns {object} an [isolated borrow rate structure]{@link https://docs.ccxt.com/?id=isolated-borrow-rate-structure}
*/
pub async fn fetch_isolated_borrow_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 code: Value = self.safe_string_k(params.clone(), "code", &[]);
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchIsolatedBorrowRate() requires a code parameter".into()))));
}
params = self.omit(params.clone(), Value::Str("code".into()), &[]);
let mut currency: Value = self.currency(code);
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_64 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_assets_margin_interest_limit(&[__ws_arg_64]).await;
//
// {
// "code": 0,
// "data": {
// "market": "BTCUSDT",
// "ccy": "USDT",
// "leverage": 10,
// "min_amount": "60",
// "max_amount": "500000",
// "daily_interest_rate": "0.001"
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_isolated_borrow_rate(data, &[market]);
Value::Null
}
/*
* @method
* @name coinex#fetchBorrowInterest
* @description fetch the interest owed by the user for borrowing currency for margin trading
* @see https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-borrow-history
* @param {string} [code] unified currency code
* @param {string} [symbol] unified market symbol when fetch interest in isolated markets
* @param {int} [since] the earliest time in ms to fetch borrrow interest for
* @param {int} [limit] the maximum number of structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/?id=borrow-interest-structure}
*/
pub async fn fetch_borrow_interest(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut symbol = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, 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("market".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_65 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_assets_margin_borrow_history(&[__ws_arg_65]).await;
//
// {
// "data": [
// {
// "borrow_id": 2642934,
// "created_at": 1654761016000,
// "market": "BTCUSDT",
// "ccy": "USDT",
// "daily_interest_rate": "0.001",
// "expired_at": 1655625016000,
// "borrow_amount": "100",
// "to_repaied_amount": "0",
// "is_auto_renew": false,
// "status": "finish"
// },
// ],
// "pagination": {
// "total": 4,
// "has_next": true
// },
// "code": 0,
// "message": "OK"
// }
//
let mut rows: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut interest: Value = self.parse_borrow_interests(rows, &[market]);
return self.filter_by_currency_since_limit(interest, &[code, since, limit]);
Value::Null
}
pub fn parse_borrow_interest(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "borrow_id": 2642934,
// "created_at": 1654761016000,
// "market": "BTCUSDT",
// "ccy": "USDT",
// "daily_interest_rate": "0.001",
// "expired_at": 1655625016000,
// "borrow_amount": "100",
// "to_repaied_amount": "0",
// "is_auto_renew": false,
// "status": "finish"
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "market", &[]);
market = self.safe_market(&[marketId, market.clone(), Value::Null, Value::Str("spot".into())]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "expired_at", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(info.clone(), "ccy", &[]), &[]));
m.insert("interest".to_string(), self.safe_number_k(info.clone(), "to_repaied_amount", &[]));
m.insert("interestRate".to_string(), self.safe_number_k(info.clone(), "daily_interest_rate", &[]));
m.insert("amountBorrowed".to_string(), self.safe_number_k(info, "borrow_amount", &[]));
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
Value::Null
}
/*
* @method
* @name coinex#borrowIsolatedMargin
* @description create a loan to borrow margin
* @see https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-borrow
* @param {string} symbol unified market symbol, required for coinex
* @param {string} code unified currency code of the currency to borrow
* @param {float} amount the amount to borrow
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.isAutoRenew] whether to renew the margin loan automatically or not, default is false
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn borrow_isolated_margin(&mut self, mut symbol: Value, mut code: 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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut currency: Value = self.currency(code.clone());
let mut isAutoRenew: Value = self.safe_bool2(params.clone(), Value::Str("isAutoRenew".into()), Value::Str("is_auto_renew".into()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("isAutoRenew".into()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("borrow_amount".to_string(), self.currency_to_precision(code, amount.clone(), &[]));
m.insert("is_auto_renew".to_string(), isAutoRenew);
m
});
let __ws_arg_66 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_post_assets_margin_borrow(&[__ws_arg_66]).await;
//
// {
// "code": 0,
// "data": {
// "borrow_id": 13784021,
// "market": "BTCUSDT",
// "ccy": "USDT",
// "daily_interest_rate": "0.001",
// "expired_at": 1717299948340,
// "borrow_amount": "60",
// "to_repaied_amount": "60.0025",
// "status": "loan"
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut transaction: Value = self.parse_margin_loan(data, &[currency]);
return self.extend(transaction, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount);
m.insert("symbol".to_string(), symbol);
m
})]);
Value::Null
}
/*
* @method
* @name coinex#repayIsolatedMargin
* @description repay borrowed margin and interest
* @see https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-repay
* @param {string} symbol unified market symbol, required for coinex
* @param {string} code unified currency code of the currency to repay
* @param {float} amount the amount to repay
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.borrow_id] extra parameter that is not required
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn repay_isolated_margin(&mut self, mut symbol: Value, mut code: 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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), self.currency_to_precision(code, amount.clone(), &[]));
m
});
let __ws_arg_67 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_post_assets_margin_repay(&[__ws_arg_67]).await;
//
// {
// "code": 0,
// "data": {},
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut transaction: Value = self.parse_margin_loan(data, &[currency]);
return self.extend(transaction, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount);
m.insert("symbol".to_string(), symbol);
m
})]);
Value::Null
}
pub fn parse_margin_loan(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "borrow_id": 13784021,
// "market": "BTCUSDT",
// "ccy": "USDT",
// "daily_interest_rate": "0.001",
// "expired_at": 1717299948340,
// "borrow_amount": "60",
// "to_repaied_amount": "60.0025",
// "status": "loan"
// }
//
let mut currencyId: Value = self.safe_string_k(info.clone(), "ccy", &[]);
let mut marketId: Value = self.safe_string_k(info.clone(), "market", &[]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "expired_at", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(info.clone(), "borrow_id", &[]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "borrow_amount", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[Value::Null, Value::Null, Value::Str("spot".into())]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("info".to_string(), info);
m
});
Value::Null
}
/*
* @method
* @name coinex#fetchDepositWithdrawFee
* @description fetch the fee for deposits and withdrawals
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/get-deposit-withdrawal-config
* @param {string} code unified currency code
* @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_deposit_withdraw_fee(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_68 = self.extend(request, &[params]);
let mut response: Value = self.v2_public_get_assets_deposit_withdraw_config(&[__ws_arg_68]).await;
//
// {
// "code": 0,
// "data": {
// "asset": {
// "ccy": "USDT",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "inter_transfer_enabled": true,
// "is_st": false
// },
// "chains": [
// {
// "chain": "TRC20",
// "min_deposit_amount": "2.4",
// "min_withdraw_amount": "2.4",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "deposit_delay_minutes": 0,
// "safe_confirmations": 10,
// "irreversible_confirmations": 20,
// "deflation_rate": "0",
// "withdrawal_fee": "2.4",
// "withdrawal_precision": 6,
// "memo": "",
// "is_memo_required_for_deposit": false,
// "explorer_asset_url": "https://tronscan.org/#/token20/TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
// },
// ]
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_withdraw_fee(data, &[currency]);
Value::Null
}
/*
* @method
* @name coinex#fetchDepositWithdrawFees
* @description fetch the fees for deposits and withdrawals
* @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-all-deposit-withdrawal-config
* @param {string[]} [codes] list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = 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 response: Value = self.v2_public_get_assets_all_deposit_withdraw_config(&[params]).await;
//
// {
// "code": 0,
// "data": [
// {
// "asset": {
// "ccy": "CET",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "inter_transfer_enabled": true,
// "is_st": false
// },
// "chains": [
// {
// "chain": "CSC",
// "min_deposit_amount": "0.8",
// "min_withdraw_amount": "8",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "deposit_delay_minutes": 0,
// "safe_confirmations": 10,
// "irreversible_confirmations": 20,
// "deflation_rate": "0",
// "withdrawal_fee": "0.026",
// "withdrawal_precision": 8,
// "memo": "",
// "is_memo_required_for_deposit": false,
// "explorer_asset_url": ""
// },
// ]
// }
// ],
// "message": "OK"
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[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_563: bool = true;
while { if !__for_first_563 { 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_563 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut item: Value = data.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 asset: Value = self.safe_dict_k(item.clone(), "asset", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyId: Value = self.safe_string_k(asset, "ccy", &[]);
if (currencyId == Value::Null) {
continue;
}
let mut code: Value = self.safe_currency_code(currencyId, &[]);
if (codes == Value::Null) || self.in_array(code.clone(), codes.clone()).as_bool() == Some(true) {
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), self.parse_deposit_withdraw_fee(item, &[])); }
}
}
}
}
return result;
Value::Null
}
pub fn parse_deposit_withdraw_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "asset": {
// "ccy": "USDT",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "inter_transfer_enabled": true,
// "is_st": false
// },
// "chains": [
// {
// "chain": "TRC20",
// "min_deposit_amount": "2.4",
// "min_withdraw_amount": "2.4",
// "deposit_enabled": true,
// "withdraw_enabled": true,
// "deposit_delay_minutes": 0,
// "safe_confirmations": 10,
// "irreversible_confirmations": 20,
// "deflation_rate": "0",
// "withdrawal_fee": "2.4",
// "withdrawal_precision": 6,
// "memo": "",
// "is_memo_required_for_deposit": false,
// "explorer_asset_url": "https://tronscan.org/#/token20/TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
// },
// ]
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
let mut chains: Value = self.safe_list_k(fee.clone(), "chains", &[Value::from(vec![])]);
let mut asset: Value = self.safe_dict_k(fee, "asset", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_564: bool = true;
while { if !__for_first_564 { 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_564 = false; i.as_f64().unwrap_or(f64::NAN) < ((chains.len() as i64) as f64) } {
let mut entry: Value = chains.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 isWithdrawEnabled: Value = self.safe_bool_k(entry.clone(), "withdraw_enabled", &[]);
if (isWithdrawEnabled.as_bool() == Some(true)) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".into())), &Value::Str("fee".into()), self.safe_number_k(entry.clone(), "withdrawal_fee", &[]));
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".into())), &Value::Str("percentage".into()), Value::Bool(false));
let mut networkId: Value = self.safe_string_k(entry.clone(), "chain", &[]);
if (networkId != Value::Null) && (networkId.as_str() != Some("")) {
let mut currencyId: Value = self.safe_string_k(asset.clone(), "ccy", &[]);
let mut feeCode: Value = self.safe_currency_code(currencyId, &[currency.clone()]);
let mut networkCode: Value = self.network_id_to_code(&[networkId, feeCode]);
if (networkCode != Value::Null) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("networks".into())), &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), self.safe_number_k(entry, "withdrawal_fee", &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
}));
}
}
}
}
}
return result;
Value::Null
}
/*
* @method
* @name coinex#fetchLeverage
* @description fetch the set leverage for a market
* @see https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-interest-limit
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.code unified currency code
* @returns {object} a [leverage structure]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverage(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut code: Value = self.safe_string_k(params.clone(), "code", &[]);
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchLeverage() requires a code parameter".into()))));
}
params = self.omit(params.clone(), Value::Str("code".into()), &[]);
let mut currency: Value = self.currency(code);
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("ccy".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_69 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_assets_margin_interest_limit(&[__ws_arg_69]).await;
//
// {
// "code": 0,
// "data": {
// "market": "BTCUSDT",
// "ccy": "USDT",
// "leverage": 10,
// "min_amount": "50",
// "max_amount": "500000",
// "daily_interest_rate": "0.001"
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(data, &[market]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "market": "BTCUSDT",
// "ccy": "USDT",
// "leverage": 10,
// "min_amount": "50",
// "max_amount": "500000",
// "daily_interest_rate": "0.001"
// }
//
let mut marketId: Value = self.safe_string_k(leverage.clone(), "market", &[]);
let mut leverageValue: Value = self.safe_integer_k(leverage.clone(), "leverage", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market, Value::Null, Value::Str("spot".into())]));
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue);
m
});
Value::Null
}
/*
* @method
* @name coinex#fetchPositionHistory
* @description fetches historical positions
* @see https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
* @param {string} symbol unified contract symbol
* @param {int} [since] the earliest time in ms to fetch positions for
* @param {int} [limit] the maximum amount of records to fetch, default is 10
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch positions for
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position_history(&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.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m.insert("market".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()); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".into(), since.clone()); }
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".into()), request.clone(), params.clone(), &[]); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let __ws_arg_70 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_futures_finished_position(&[__ws_arg_70]).await;
//
// {
// "code": 0,
// "data": [
// {
// "position_id": 305891033,
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "side": "long",
// "margin_mode": "cross",
// "open_interest": "0.0001",
// "close_avbl": "0.0001",
// "ath_position_amount": "0.0001",
// "unrealized_pnl": "0",
// "realized_pnl": "-0.00311684",
// "avg_entry_price": "62336.8",
// "cml_position_value": "6.23368",
// "max_position_value": "6.23368",
// "created_at": 1715152208041,
// "updated_at": 1715152208041,
// "take_profit_price": "0",
// "stop_loss_price": "0",
// "take_profit_type": "",
// "stop_loss_type": "",
// "settle_price": "62336.8",
// "settle_value": "6.23368",
// "leverage": "3",
// "margin_avbl": "2.07789333",
// "ath_margin_size": "2.07789333",
// "position_margin_rate": "2.40545879023305655728",
// "maintenance_margin_rate": "0.005",
// "maintenance_margin_value": "0.03118094",
// "liq_price": "0",
// "bkr_price": "0",
// "adl_level": 1
// }
// ],
// "message": "OK",
// "pagination": {
// "has_next": false
// }
// }
//
let mut records: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut positions: Value = self.parse_positions(records, &[]);
return self.filter_by_symbol_since_limit(positions, &[symbol, since, limit]);
Value::Null
}
/*
* @method
* @name coinex#closePosition
* @description closes an open position for a market
* @see https://docs.coinex.com/api/v2/futures/position/http/close-position
* @param {string} symbol unified CCXT market symbol
* @param {string} [side] buy or sell, not used by coinex
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.type required by coinex, one of: limit, market, maker_only, ioc or fok, default is *market*
* @param {string} [params.price] the price to fulfill the order, ignored in market orders
* @param {string} [params.amount] the amount to trade in units of the base currency
* @param {string} [params.clientOrderId] the client id of the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = 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 type_var: Value = self.safe_string_k(params.clone(), "type", &[Value::Str("market".into())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m.insert("type".to_string(), type_var);
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client_id".into()), Value::Str("clientOrderId".into()), &[]);
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_id".into(), clientOrderId); }
}
params = self.omit(params.clone(), Value::Str("clientOrderId".into()), &[]);
let __ws_arg_71 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_post_futures_close_position(&[__ws_arg_71]).await;
//
// {
// "code": 0,
// "data": {
// "amount": "0.0001",
// "client_id": "",
// "created_at": 1729666043969,
// "fee": "0.00335858",
// "fee_ccy": "USDT",
// "filled_amount": "0.0001",
// "filled_value": "6.717179",
// "last_filled_amount": "0.0001",
// "last_filled_price": "67171.79",
// "maker_fee_rate": "0",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "order_id": 155477479761,
// "price": "0",
// "realized_pnl": "-0.001823",
// "side": "sell",
// "taker_fee_rate": "0.0005",
// "type": "market",
// "unfilled_amount": "0",
// "updated_at": 1729666043969
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[market]);
Value::Null
}
pub fn handle_margin_mode_and_params(&self, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut defaultValue = get_arg(optional_args, 1, Value::Null);
/*
* @ignore
* @method
* @description marginMode specified by params["marginMode"], this.options["marginMode"], this.options["defaultMarginMode"], params["margin"] = true or this.options["defaultType"] = 'margin'
* @param {object} params extra parameters specific to the exchange API endpoint
* @returns {Array} the marginMode in lowercase
*/
let mut defaultType: Option<String> = self.safe_string_k(self.options.clone(), "defaultType", &[]).as_str().map(str::to_owned);
let mut isMargin: Value = self.safe_bool_k(params.clone(), "margin", &[Value::Bool(false)]);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.super_handle_margin_mode_and_params(methodName, params.clone(), defaultValue); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (marginMode == Value::Null) {
if (defaultType.as_deref() == Some("margin")) || (isMargin.as_bool() == Some(true)) {
marginMode = Value::Str("isolated".into());
}
}
return Value::from(vec![marginMode, params]);
Value::Null
}
pub fn nonce(&self) -> Value {
return self.milliseconds();
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 mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
path = self.implode_params(path.clone(), params.clone());
let mut version: Value = get_value(&api, &Value::Int(0));
let mut requestUrl: Value = get_value(&api, &Value::Int(1));
let mut url: Value = add(&Value::Str(format!("{}{}", add(&add(&get_value(&self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), &requestUrl), &Value::Str("/".into())), &version), Value::Str("/".into())).into()), &path);
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut nonce: Value = to_string_val(&self.nonce());
if (method.as_str() == Some("POST")) {
let mut parts: Value = split(&path, &Value::Str("/".into()));
let mut firstPart: Option<String> = self.safe_string(parts.clone(), Value::Int(0), &[Value::Str("".into())]).as_str().map(str::to_owned);
let mut numParts: Value = get_array_length(&parts);
let mut lastPart: Value = self.safe_string(parts, subtract(&numParts, &Value::Int(1)), &[Value::Str("".into())]);
let mut lastWords: Value = split(&lastPart, &Value::Str("_".into()));
let mut numWords: Value = Value::Int(lastWords.len() as i64);
let mut lastWord: Option<String> = self.safe_string(lastWords, (match (&(numWords), &(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("".into())]).as_str().map(str::to_owned);
if (firstPart.as_deref() == Some("order")) && ((lastWord.as_deref() == Some("limit")) || (lastWord.as_deref() == Some("market"))) {
// inject in implicit API calls
// POST /order/limit - Place limit orders
// POST /order/market - Place market orders
// POST /order/stop/limit - Place stop limit orders
// POST /order/stop/market - Place stop market orders
// POST /perpetual/v1/order/put_limit - Place limit orders
// POST /perpetual/v1/order/put_market - Place market orders
// POST /perpetual/v1/order/put_stop_limit - Place stop limit orders
// POST /perpetual/v1/order/put_stop_market - Place stop market orders
let mut clientOrderId: Option<String> = self.safe_string_k(params, "client_id", &[]).as_str().map(str::to_owned);
if (clientOrderId.is_none()) {
let mut defaultId: Value = Value::Str("x-167673045".into());
let mut brokerId: Value = self.safe_value_k(self.options.clone(), "brokerId", &[defaultId]);
add_element_to_object(&mut query, &Value::Str("client_id".into()), Value::Str(format!("{}{}", add(&brokerId, &Value::Str("_".into())), self.uuid16(&[])).into()));
}
}
}
if (requestUrl.as_str() == Some("perpetualPrivate")) {
self.check_required_credentials(&[]);
query = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access_id".to_string(), self.apiKey.clone());
m.insert("timestamp".to_string(), nonce.clone());
m
}), &[query.clone()]);
query = self.keysort(query.clone(), &[]);
let mut urlencoded: Value = self.rawencode(query.clone(), &[]);
let mut signature: Value = self.hash(self.encode(Value::Str(format!("{}{}", Value::Str(format!("{}{}", urlencoded, Value::Str("&secret_key=".into())).into()), self.secret.clone()).into())), Value::Str("sha256".into()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Authorization".to_string(), to_lower(&signature));
m.insert("AccessId".to_string(), self.apiKey.clone());
m
});
if (method.as_str() == Some("GET")) || (method.as_str() == Some("PUT")) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), urlencoded).into())).into());
} else {
if let Value::Dict(__d) = &mut headers { std::sync::Arc::make_mut(__d).insert("Content-Type".into(), Value::Str("application/x-www-form-urlencoded".into())); }
body = urlencoded.clone();
}
} else if (requestUrl.as_str() == Some("public")) || (requestUrl.as_str() == Some("perpetualPublic")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into())).into());
}
} else {
if (version.as_str() == Some("v1")) {
self.check_required_credentials(&[]);
query = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("access_id".to_string(), self.apiKey.clone());
m.insert("tonce".to_string(), nonce.clone());
m
}), &[query.clone()]);
query = self.keysort(query.clone(), &[]);
let mut urlencoded: Value = self.rawencode(query.clone(), &[]);
let mut signature: Value = self.hash(self.encode(Value::Str(format!("{}{}", Value::Str(format!("{}{}", urlencoded, Value::Str("&secret_key=".into())).into()), self.secret.clone()).into())), Value::Str("md5".into()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Authorization".to_string(), to_upper(&signature));
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
if (method.as_str() == Some("GET")) || (method.as_str() == Some("DELETE")) || (method.as_str() == Some("PUT")) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), urlencoded).into())).into());
} else {
body = json_stringify(&query);
}
} else if (version.as_str() == Some("v2")) {
self.check_required_credentials(&[]);
query = self.keysort(query.clone(), &[]);
let mut urlencoded: Value = self.rawencode(query.clone(), &[]);
let mut preparedString: Value = add(&Value::Str(format!("{}{}", add(&add(&method, &Value::Str("/".into())), &version), Value::Str("/".into())).into()), &path);
if (method.as_str() == Some("POST")) {
body = json_stringify(&query);
preparedString = Value::Str(format!("{}{}", preparedString, body).into());
} else if (urlencoded.as_str() != Some("")) {
preparedString = Value::Str(format!("{}{}", preparedString, Value::Str(format!("{}{}", Value::Str("?".into()), urlencoded).into())).into());
}
preparedString = Value::Str(format!("{}{}", preparedString, Value::Str(format!("{}{}", nonce, self.secret.clone()).into())).into());
let mut signature: Value = self.hash(self.encode(preparedString), Value::Str("sha256".into()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m.insert("Accept".to_string(), Value::Str("application/json".into()));
m.insert("X-COINEX-KEY".to_string(), self.apiKey.clone());
m.insert("X-COINEX-SIGN".to_string(), signature);
m.insert("X-COINEX-TIMESTAMP".to_string(), nonce);
m
});
if (method.as_str() != Some("POST")) {
if (urlencoded.as_str() != Some("")) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), urlencoded).into())).into());
}
}
}
}
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(), body);
m.insert("headers".to_string(), headers);
m
});
Value::Null
}
pub fn handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
let mut code: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
let mut message: Value = self.safe_string_k(response, "message", &[Value::Str("".into())]);
if (code.as_str() != Some("0")) || ((message.as_str() != Some("Success")) && (message.as_str() != Some("Succeeded")) && (to_lower(&message).as_str() != Some("ok")) && (data == Value::Null)) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message).into());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), code, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
/*
* @method
* @name coinex#fetchMarginAdjustmentHistory
* @description fetches the history of margin added or reduced from contract isolated positions
* @see https://docs.coinex.com/api/v2/futures/position/http/list-position-margin-history
* @param {string} symbol unified market symbol
* @param {string} [type] not used by coinex fetchMarginAdjustmentHistory
* @param {int} [since] timestamp in ms of the earliest change to fetch
* @param {int} [limit] the maximum amount of changes to fetch, default is 10
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest change to fetch
* @param {int} [params.positionId] the id of the position that you want to retrieve margin adjustment history for
* @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn fetch_margin_adjustment_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut type_var = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMarginAdjustmentHistory() requires a symbol argument".into()))));
}
let mut positionId: Value = self.safe_integer2(params.clone(), Value::Str("positionId".into()), Value::Str("position_id".into()), &[]);
params = self.omit(params.clone(), Value::Str("positionId".into()), &[]);
if (positionId == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMarginAdjustmentHistory() requires a positionId parameter".into()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("market_type".to_string(), Value::Str("FUTURES".into()));
m.insert("position_id".to_string(), positionId);
m
});
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".into()), request.clone(), params.clone(), &[]); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".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 __ws_arg_72 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_futures_position_margin_history(&[__ws_arg_72]).await;
//
// {
// "code": 0,
// "data": [
// {
// "bkr_pirce": "24698.56000000000000005224",
// "created_at": 1715489978697,
// "leverage": "3",
// "liq_price": "24822.67336683417085432386",
// "margin_avbl": "3.634928",
// "margin_change": "-1.5",
// "margin_mode": "isolated",
// "market": "BTCUSDT",
// "market_type": "FUTURES",
// "open_interest": "0.0001",
// "position_id": 306458800,
// "settle_price": "61047.84"
// },
// ],
// "message": "OK",
// "pagination": {
// "has_next": true
// }
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut modifications: Value = self.parse_margin_modifications(data, &[Value::Null, Value::Str("market".into()), Value::Str("swap".into())]);
return self.filter_by_symbol_since_limit(modifications, &[symbol, since, limit]);
Value::Null
}
}