// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
pub struct 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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinexCore.
CoinexCore::sign(self, path, &[api.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on 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.get(2..).unwrap_or(&[]).to_vec()[..]).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.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_deposit_address" => self.create_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"edit_orders" => self.edit_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_interest" => self.fetch_borrow_interest(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_markets" => self.fetch_contract_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fee" => self.fetch_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_financial_balance" => self.fetch_financial_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_interval" => self.fetch_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_isolated_borrow_rate" => self.fetch_isolated_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_adjustment_history" => self.fetch_margin_adjustment_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_balance" => self.fetch_margin_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position_history" => self.fetch_position_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_balance" => self.fetch_spot_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transfers" => self.fetch_transfers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"handle_margin_mode_and_params" => self.handle_margin_mode_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"modify_margin_helper" => self.modify_margin_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"nonce" => self.nonce(),
"parse_borrow_interest" => self.parse_borrow_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_interval" => self.parse_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_isolated_borrow_rate" => self.parse_isolated_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_loan" => self.parse_margin_loan(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(2..).unwrap_or(&[]).to_vec()[..]).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.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for 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".to_string()));
m.insert("name".to_string(), Value::Str("CoinEx".to_string()));
m.insert("version".to_string(), Value::Str("v2".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("CN".to_string())]));
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".to_string()));
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".to_string()));
m.insert("3m".to_string(), Value::Str("3min".to_string()));
m.insert("5m".to_string(), Value::Str("5min".to_string()));
m.insert("15m".to_string(), Value::Str("15min".to_string()));
m.insert("30m".to_string(), Value::Str("30min".to_string()));
m.insert("1h".to_string(), Value::Str("1hour".to_string()));
m.insert("2h".to_string(), Value::Str("2hour".to_string()));
m.insert("4h".to_string(), Value::Str("4hour".to_string()));
m.insert("6h".to_string(), Value::Str("6hour".to_string()));
m.insert("12h".to_string(), Value::Str("12hour".to_string()));
m.insert("1d".to_string(), Value::Str("1day".to_string()));
m.insert("3d".to_string(), Value::Str("3day".to_string()));
m.insert("1w".to_string(), Value::Str("1week".to_string()));
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".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.coinex.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api.coinex.com".to_string()));
m.insert("perpetualPublic".to_string(), Value::Str("https://api.coinex.com/perpetual".to_string()));
m.insert("perpetualPrivate".to_string(), Value::Str("https://api.coinex.com/perpetual".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.coinex.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://docs.coinex.com/api/v2".to_string()));
m.insert("fees".to_string(), Value::Str("https://www.coinex.com/fees".to_string()));
m.insert("referral".to_string(), Value::Str("https://www.coinex.com/register?refer_code=yw5fz".to_string()));
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
}));
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
}));
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".to_string()));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("defaultType".to_string(), Value::Str("spot".to_string()));
m.insert("defaultSubType".to_string(), Value::Str("linear".to_string()));
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".to_string()));
m.insert("margin".to_string(), Value::Str("MARGIN".to_string()));
m.insert("swap".to_string(), Value::Str("FUTURES".to_string()));
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SPOT".to_string(), Value::Str("spot".to_string()));
m.insert("MARGIN".to_string(), Value::Str("margin".to_string()));
m.insert("FUTURES".to_string(), Value::Str("swap".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRC20".to_string()));
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
m.insert("BRC20".to_string(), Value::Str("BRC20".to_string()));
m.insert("SOL".to_string(), Value::Str("SOL".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("BSV".to_string(), Value::Str("BSV".to_string()));
m.insert("AVAXC".to_string(), Value::Str("AVA_C".to_string()));
m.insert("AVAXX".to_string(), Value::Str("AVA".to_string()));
m.insert("SUI".to_string(), Value::Str("SUI".to_string()));
m.insert("ACA".to_string(), Value::Str("ACA".to_string()));
m.insert("CHZ".to_string(), Value::Str("CHILIZ".to_string()));
m.insert("ADA".to_string(), Value::Str("ADA".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBITRUM".to_string()));
m.insert("ARBITRUM_NOVA".to_string(), Value::Str("ARBITRUM_NOVA".to_string()));
m.insert("OP".to_string(), Value::Str("OPTIMISM".to_string()));
m.insert("APT".to_string(), Value::Str("APTOS".to_string()));
m.insert("ATOM".to_string(), Value::Str("ATOM".to_string()));
m.insert("FTM".to_string(), Value::Str("FTM".to_string()));
m.insert("BCH".to_string(), Value::Str("BCH".to_string()));
m.insert("ASTR".to_string(), Value::Str("ASTR".to_string()));
m.insert("LTC".to_string(), Value::Str("LTC".to_string()));
m.insert("MATIC".to_string(), Value::Str("MATIC".to_string()));
m.insert("CRONOS".to_string(), Value::Str("CRONOS".to_string()));
m.insert("DASH".to_string(), Value::Str("DASH".to_string()));
m.insert("DOT".to_string(), Value::Str("DOT".to_string()));
m.insert("ETC".to_string(), Value::Str("ETC".to_string()));
m.insert("ETHW".to_string(), Value::Str("ETHPOW".to_string()));
m.insert("FIL".to_string(), Value::Str("FIL".to_string()));
m.insert("ZIL".to_string(), Value::Str("ZIL".to_string()));
m.insert("DOGE".to_string(), Value::Str("DOGE".to_string()));
m.insert("TIA".to_string(), Value::Str("CELESTIA".to_string()));
m.insert("SEI".to_string(), Value::Str("SEI".to_string()));
m.insert("XRP".to_string(), Value::Str("XRP".to_string()));
m.insert("XMR".to_string(), Value::Str("XMR".to_string()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(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".to_string()));
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".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".to_string()));
m
}));
m
}));
m.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".to_string()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("23".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("24".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("25".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("34".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("35".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("36".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("213".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("107".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("158".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("600".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("601".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("602".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("606".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3008".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("3109".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("3127".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3157".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("3600".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("3606".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3610".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("3612".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3613".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3614".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3615".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3616".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3617".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3618".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3619".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3620".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3621".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3622".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3627".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3628".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3629".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3632".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3633".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3634".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("3635".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("4001".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("4002".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("4003".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("4004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("4005".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("4006".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("4007".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("4008".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("4009".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("4010".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("4011".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("4017".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("4115".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("4117".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("4123".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("4130".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("4158".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("4213".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("4512".to_string(), Value::Str("PermissionDenied".to_string()).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".to_string()).clone());
m.insert("service too busy".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("Service is not available during funding fee settlement".to_string(), Value::Str("OperationFailed".to_string()).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.clone()]).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.clone(), "data", &[Value::List(vec![])]);
return self.parse_currencies(data.clone());
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::List(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_549: bool = true;
while { if !__for_first_549 { j = add(&j, &Value::Int(1)); } __for_first_549 = false; is_less_than(&j, &get_array_length(&chains)) } {
let mut chain: Value = get_value(&chains, &j);
let mut chain: Value = get_value(&chains, &j);
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 is_equal(&networkId, &Value::Null) {
continue;
}
let mut network: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("name".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("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.clone());
m
});
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, network.clone());
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId.clone());
m.insert("code".to_string(), code.clone());
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.clone(), "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.clone());
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m.insert("info".to_string(), coin.clone());
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::List(vec![self.fetch_spot_markets(params.clone()).await, self.fetch_contract_markets(params.clone()).await]);
let mut promises: Value = promise_all(&promisesUnresolved).await;
let mut spotMarkets: Value = get_value(&promises, &Value::Int(0));
let mut swapMarkets: Value = get_value(&promises, &Value::Int(1));
return self.array_concat(spotMarkets.clone(), swapMarkets.clone());
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.clone()]).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.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_550: bool = true;
while { if !__for_first_550 { i = add(&i, &Value::Int(1)); } __for_first_550 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut market: Value = get_value(&markets, &i);
let mut market: Value = get_value(&markets, &i);
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 = add(&add(&base, &Value::Str("/".to_string())), "e);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".to_string()));
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.clone());
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.clone()]).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.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_551: bool = true;
while { if !__for_first_551 { i = add(&i, &Value::Int(1)); } __for_first_551 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut entry: Value = get_value(&markets, &i);
let mut entry: Value = get_value(&markets, &i);
let mut fees: Value = self.fees.clone();
let mut leverages: Value = self.safe_list_k(entry.clone(), "leverage", &[Value::List(vec![])]);
let mut subType: Value = self.safe_string_k(entry.clone(), "contract_type", &[]);
let mut linear: Value = Value::Bool(is_equal(&subType, &Value::Str("linear".to_string())));
let mut inverse: Value = Value::Bool(is_equal(&subType, &Value::Str("inverse".to_string())));
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 = ternary(is_true(&(is_equal(&subType, &Value::Str("linear".to_string())))), Value::Str("USDT".to_string()), baseId.clone());
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut symbol: Value = add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
let mut leveragesLength: Value = get_array_length(&leverages);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), Value::Str("swap".to_string()));
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.clone());
m.insert("inverse".to_string(), inverse.clone());
m.insert("taker".to_string(), get_value(&get_value(&fees, &Value::Str("trading".to_string())), &Value::Str("taker".to_string())));
m.insert("maker".to_string(), get_value(&get_value(&fees, &Value::Str("trading".to_string())), &Value::Str("maker".to_string())));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
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.clone(), subtract(&leveragesLength, &Value::Int(1)), &[]));
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.clone());
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 = ternary(is_true(&(Value::Bool(in_op(&ticker, &Value::Str("mark_price".to_string()))))), Value::Str("swap".to_string()), Value::Str("spot".to_string()));
let mut marketId: Value = self.safe_string_k(ticker.clone(), "market", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
// 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 = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))), Value::Null, 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.clone());
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.clone());
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.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(result.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut symbol: Value = self.safe_value(symbols.clone(), Value::Int(0), &[]);
market = self.market(symbol.clone());
}
let mut marketTypequeryVariable = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]);
let mut marketType: Value = get_value(&marketTypequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marketTypequeryVariable, &Value::Int(1));
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.v2_public_get_futures_ticker(&[query.clone()]).await;
} else {
response = self.v2_public_get_spot_ticker(&[query.clone()]).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.clone(), "data", &[Value::List(vec![])]);
return self.parse_tickers(data.clone(), &[symbols.clone()]);
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.clone()]).await;
//
// {
// "code": 0,
// "data": {
// "timestamp": 1711699867777
// },
// "message": "OK"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_integer_k(data.clone(), "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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("limit".to_string(), limit.clone());
m.insert("interval".to_string(), Value::Str("0".to_string()));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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.clone(), &[params.clone()]);
response = self.v2_public_get_spot_depth(&[__ws_arg_3]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut depth: Value = self.safe_dict_k(data.clone(), "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.clone(), symbol.clone(), &[timestamp.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// Spot 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 !is_equal(&market, &Value::Null) {
defaultType = get_value(&market, &Value::Str("type".to_string()));
}
let mut marketId: Value = self.safe_string_k(trade.clone(), "market", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, defaultType.clone()]);
let mut feeCostString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
let mut fee: Value = Value::Null;
if !is_equal(&feeCostString, &Value::Null) {
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "fee_ccy", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString.clone());
m.insert("currency".to_string(), feeCurrencyCode.clone());
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.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
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.clone(), "deal_money", &[]));
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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.clone(), &[params.clone()]);
response = self.v2_public_get_spot_deals(&[__ws_arg_5]).await;
}
return self.parse_trades(get_value(&response, &Value::Str("data".to_string())), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
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.clone(), &[params.clone()]);
response = self.v2_public_get_futures_market(&[__ws_arg_7]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(result.clone(), &[market.clone()]);
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 is_equal(&self.markets, &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".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("swap".to_string())) {
response = self.v2_public_get_futures_market(&[params.clone()]).await;
} else {
response = self.v2_public_get_spot_market(&[params.clone()]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_552: bool = true;
while { if !__for_first_552 { i = add(&i, &Value::Int(1)); } __for_first_552 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "market", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, type_var.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
add_element_to_object(&mut result, &symbol, self.parse_trading_fee(entry.clone(), &[market.clone()]));
}
}
return result;
Value::Null
}
pub fn parse_trading_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_value_k(fee.clone(), "market", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), self.safe_number_k(fee.clone(), "maker_fee_rate", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee.clone(), "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::List(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.clone(), "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".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("period".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v2_private_get_assets_margin_balance(&[params.clone()]).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.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_553: bool = true;
while { if !__for_first_553 { i = add(&i, &Value::Int(1)); } __for_first_553 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut entry: Value = get_value(&balances, &i);
let mut entry: Value = get_value(&balances, &i);
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.clone(), "base_ccy", &[]);
let mut baseCurrencyCode: Value = self.safe_currency_code(baseCurrencyId.clone(), &[]);
add_element_to_object(&mut baseAccount, &Value::Str("free".to_string()), self.safe_string_k(free.clone(), "base_ccy", &[]));
add_element_to_object(&mut baseAccount, &Value::Str("used".to_string()), self.safe_string_k(used.clone(), "base_ccy", &[]));
let mut baseDebt: Value = self.safe_string_k(loan.clone(), "base_ccy", &[]);
let mut baseInterest: Value = self.safe_string_k(interest.clone(), "base_ccy", &[]);
add_element_to_object(&mut baseAccount, &Value::Str("debt".to_string()), crate::precise::Precise::stringAdd(&baseDebt, &baseInterest));
if !is_equal(&baseCurrencyCode, &Value::Null) {
add_element_to_object(&mut result, &baseCurrencyCode, baseAccount.clone());
}
}
}
return self.safe_balance(result.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v2_private_get_assets_spot_balance(&[params.clone()]).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.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_554: bool = true;
while { if !__for_first_554 { i = add(&i, &Value::Int(1)); } __for_first_554 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut entry: Value = get_value(&balances, &i);
let mut entry: Value = get_value(&balances, &i);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(entry.clone(), "available", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(entry.clone(), "frozen", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v2_private_get_assets_futures_balance(&[params.clone()]).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.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_555: bool = true;
while { if !__for_first_555 { i = add(&i, &Value::Int(1)); } __for_first_555 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut entry: Value = get_value(&balances, &i);
let mut entry: Value = get_value(&balances, &i);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(entry.clone(), "available", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(entry.clone(), "frozen", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v2_private_get_assets_financial_balance(&[params.clone()]).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.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_556: bool = true;
while { if !__for_first_556 { i = add(&i, &Value::Int(1)); } __for_first_556 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut entry: Value = get_value(&balances, &i);
let mut entry: Value = get_value(&balances, &i);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(entry.clone(), "available", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(entry.clone(), "frozen", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name 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".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBalance".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isMargin: bool = is_true(&(!is_equal(&marginMode, &Value::Null))) || is_true(&(is_equal(&marketType, &Value::Str("margin".to_string()))));
if is_equal(&marketType, &Value::Str("swap".to_string())) {
return self.fetch_swap_balance(&[params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("financial".to_string())) {
return self.fetch_financial_balance(&[params.clone()]).await;
} else if is_true(&isMargin) {
return self.fetch_margin_balance(&[params.clone()]).await;
} else {
return self.fetch_spot_balance(&[params.clone()]).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".to_string()));
m.insert("open".to_string(), Value::Str("open".to_string()));
m.insert("not_deal".to_string(), Value::Str("open".to_string()));
m.insert("part_deal".to_string(), Value::Str("open".to_string()));
m.insert("done".to_string(), Value::Str("closed".to_string()));
m.insert("cancel".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), 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 is_equal(&updatedTimestamp, &Value::Int(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(order.clone(), Value::Str("market_type".to_string()), &[defaultType.clone()]);
if is_equal(&orderType, &Value::Str("futures".to_string())) {
orderType = Value::Str("swap".to_string());
}
let mut marketType: Value = ternary(is_true(&(is_equal(&orderType, &Value::Str("swap".to_string())))), Value::Str("swap".to_string()), Value::Str("spot".to_string()));
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut feeCurrencyId: Value = self.safe_string_k(order.clone(), "fee_ccy", &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
if is_equal(&feeCurrency, &Value::Null) {
feeCurrency = get_value(&market, &Value::Str("quote".to_string()));
}
let mut side: Value = self.safe_string_k(order.clone(), "side", &[]);
if is_equal(&side, &Value::Str("long".to_string())) {
side = Value::Str("buy".to_string());
} else if is_equal(&side, &Value::Str("short".to_string())) {
side = Value::Str("sell".to_string());
}
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "client_id", &[]);
if is_equal(&clientOrderId, &Value::Str("".to_string())) {
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::List(vec![Value::Str("position_id".to_string()), Value::Str("order_id".to_string()), Value::Str("stop_id".to_string())]), &[]));
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("lastTradeTimestamp".to_string(), updatedTimestamp.clone());
m.insert("status".to_string(), self.parse_order_status(rawStatus.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
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.clone());
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.clone());
m.insert("cost".to_string(), self.safe_string2(order.clone(), Value::Str("quote_fee".to_string()), Value::Str("fee".to_string()), &[]));
m
}));
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketBuyOrderWithCost() supports spot orders only".to_string()))));
}
add_element_to_object(&mut params, &Value::Str("createMarketBuyOrderRequiresPrice".to_string()), Value::Bool(false));
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), cost.clone(), &[Value::Null, params.clone()]).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 is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut swap: Value = get_value(&market, &Value::Str("swap".to_string()));
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client_id".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
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: Value = self.safe_string_k(params.clone(), "option", &[]);
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("market".to_string())));
let mut postOnly: Value = self.is_post_only(isMarketOrder.clone(), Value::Bool(is_equal(&option, &Value::Str("maker_only".to_string()))), &[params.clone()]);
let mut timeInForceRaw: Value = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[]);
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[]);
if is_equal(&reduceOnly, &Value::Bool(true)) {
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&self.id, &Value::Str(" createOrder() does not support reduceOnly for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" orders, reduceOnly orders are supported for swap markets only".to_string()))));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if is_equal(&clientOrderId, &Value::Null) {
let mut defaultId: Value = Value::Str("x-167673045".to_string());
let mut brokerId: Value = self.safe_string_k(self.options.clone(), "brokerId", &[defaultId.clone()]);
add_element_to_object(&mut request, &Value::Str("client_id".to_string()), add(&add(&brokerId, &Value::Str("-".to_string())), &self.uuid16(&[])));
} else {
add_element_to_object(&mut request, &Value::Str("client_id".to_string()), clientOrderId.clone());
}
if is_true(&(is_equal(&stopLossPrice, &Value::Null))) && is_true(&(is_equal(&takeProfitPrice, &Value::Null))) {
if !is_equal(&reduceOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("side".to_string()), side.clone());
}
let mut requestType: Value = type_var.clone();
if is_true(&postOnly) {
requestType = Value::Str("maker_only".to_string());
} else if !is_equal(&timeInForceRaw, &Value::Null) {
if is_equal(&timeInForceRaw, &Value::Str("IOC".to_string())) {
requestType = Value::Str("ioc".to_string());
} else if is_equal(&timeInForceRaw, &Value::Str("FOK".to_string())) {
requestType = Value::Str("fok".to_string());
}
}
if !is_true(&isMarketOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
add_element_to_object(&mut request, &Value::Str("type".to_string()), requestType.clone());
}
if is_equal(&swap, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("FUTURES".to_string()));
if is_true(&(!is_equal(&stopLossPrice, &Value::Null) && !is_equal(&stopLossPrice, &Value::Str("".to_string())))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null) && !is_equal(&takeProfitPrice, &Value::Str("".to_string())))) {
if !is_equal(&stopLossPrice, &Value::Null) && !is_equal(&stopLossPrice, &Value::Str("".to_string())) {
add_element_to_object(&mut request, &Value::Str("stop_loss_price".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
add_element_to_object(&mut request, &Value::Str("stop_loss_type".to_string()), self.safe_string_k(params.clone(), "stop_type", &[Value::Str("latest_price".to_string())]));
} else if !is_equal(&takeProfitPrice, &Value::Null) && !is_equal(&takeProfitPrice, &Value::Str("".to_string())) {
add_element_to_object(&mut request, &Value::Str("take_profit_price".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
add_element_to_object(&mut request, &Value::Str("take_profit_type".to_string()), self.safe_string_k(params.clone(), "stop_type", &[Value::Str("latest_price".to_string())]));
}
} else {
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("trigger_price_type".to_string()), self.safe_string_k(params.clone(), "stop_type", &[Value::Str("latest_price".to_string())]));
}
}
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("MARGIN".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("SPOT".to_string()));
}
if is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("createMarketBuyOrderRequiresPrice".to_string()), &[Value::Bool(true)]); createMarketBuyOrderRequiresPrice = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut cost: Value = self.safe_number_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if is_true(&createMarketBuyOrderRequiresPrice) {
if is_true(&(is_equal(&price, &Value::Null))) && is_true(&(is_equal(&cost, &Value::Null))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires 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".to_string()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
let mut quoteAmount: Value = self.parse_to_numeric(crate::precise::Precise::stringMul(&amountString, &priceString));
let mut costRequest: Value = ternary(is_true(&(!is_equal(&cost, &Value::Null))), cost.clone(), quoteAmount.clone());
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.cost_to_precision(symbol.clone(), costRequest.clone()));
}
} else {
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.cost_to_precision(symbol.clone(), amount.clone()));
}
} else {
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("timeInForce".to_string()), Value::Str("postOnly".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
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 is_equal(&self.markets, &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: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
let mut stopLossTriggerPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitTriggerPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut isTriggerOrder: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossTriggerOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitTriggerOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
let mut isStopLossOrTakeProfitTrigger: bool = is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder);
let mut request: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if is_true(&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 is_true(&isTriggerOrder) {
response = self.v2_private_post_futures_stop_order(&[request.clone()]).await;
} else if is_true(&isStopLossOrTakeProfitTrigger) {
if is_true(&isStopLossTriggerOrder) {
response = self.v2_private_post_futures_set_position_stop_loss(&[request.clone()]).await;
} else if is_true(&isTakeProfitTriggerOrder) {
response = self.v2_private_post_futures_set_position_take_profit(&[request.clone()]).await;
}
} else {
if is_equal(&reduceOnly, &Value::Bool(true)) {
response = self.v2_private_post_futures_close_position(&[request.clone()]).await;
} else {
response = self.v2_private_post_futures_order(&[request.clone()]).await;
}
}
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::List(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_557: bool = true;
while { if !__for_first_557 { i = add(&i, &Value::Int(1)); } __for_first_557 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
if is_equal(&symbol, &Value::Null) {
symbol = marketId.clone();
} else {
if !is_equal(&symbol, &marketId) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() requires all orders to have the same symbol".to_string()))));
}
}
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_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_value_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if !is_equal(&type_var, &Value::Str("limit".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" createOrders() does not support ".to_string())), &type_var), &Value::Str(" orders, only limit orders are accepted".to_string()))));
}
reduceOnly = self.safe_value_k(orderParams.clone(), "reduceOnly", &[]);
let mut triggerPrice: Value = self.safe_number2(orderParams.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
let mut stopLossTriggerPrice: Value = self.safe_number_k(orderParams.clone(), "stopLossPrice", &[]);
let mut takeProfitTriggerPrice: Value = self.safe_number_k(orderParams.clone(), "takeProfitPrice", &[]);
isTriggerOrder = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossTriggerOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitTriggerOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
isStopLossOrTakeProfitTrigger = is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder);
let mut orderRequest: Value = self.create_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("orders".to_string(), ordersRequests.clone());
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if is_true(&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 is_true(&isTriggerOrder) {
response = self.v2_private_post_futures_batch_stop_order(&[request.clone()]).await;
} else if is_true(&isStopLossOrTakeProfitTrigger) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() does not support stopLossPrice or takeProfitPrice orders".to_string()))));
} else {
if is_true(&reduceOnly) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() does not support reduceOnly orders".to_string()))));
} else {
response = self.v2_private_post_futures_batch_order(&[request.clone()]).await;
}
}
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_558: bool = true;
while { if !__for_first_558 { i = add(&i, &Value::Int(1)); } __for_first_558 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut status: Value = Value::Null;
let mut code: Value = self.safe_integer_k(entry.clone(), "code", &[]);
if !is_equal(&code, &Value::Null) {
if !is_equal(&code, &Value::Int(0)) {
status = Value::Str("rejected".to_string());
} else {
status = Value::Str("open".to_string());
}
}
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 is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && !is_true(&isTriggerOrder) {
add_element_to_object(&mut entry, &Value::Str("status".to_string()), status.clone());
order = self.parse_order(entry.clone(), &[market.clone()]);
} else {
add_element_to_object(&mut innerData, &Value::Str("status".to_string()), status.clone());
order = self.parse_order(innerData.clone(), &[market.clone()]);
}
append_to_array(&mut results, order.clone());
}
}
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut response: Value = Value::Null;
let mut requestIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_559: bool = true;
while { if !__for_first_559 { i = add(&i, &Value::Int(1)); } __for_first_559 = false; is_less_than(&i, &get_array_length(&ids)) } {
append_to_array(&mut requestIds, crate::runtime::parse_int(&get_value(&ids, &i)));
}
}
if is_equal(&trigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("stop_ids".to_string()), requestIds.clone());
} else {
add_element_to_object(&mut request, &Value::Str("order_ids".to_string()), requestIds.clone());
}
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(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 {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("FUTURES".to_string()));
if is_equal(&trigger, &Value::Bool(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.clone(), &[params.clone()]);
response = self.v2_private_post_futures_cancel_batch_order(&[__ws_arg_13]).await;
}
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_560: bool = true;
while { if !__for_first_560 { i = add(&i, &Value::Int(1)); } __for_first_560 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut item: Value = self.safe_dict_k(entry.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(item.clone(), &[market.clone()]);
append_to_array(&mut results, order.clone());
}
}
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut response: Value = Value::Null;
let mut triggerPrice: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("trigger_price".to_string())]), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string())]), &[]);
let mut isTriggerOrder: bool = !is_equal(&triggerPrice, &Value::Null);
if is_true(&isTriggerOrder) {
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("stop_id".to_string()), self.parse_to_numeric(id.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), self.parse_to_numeric(id.clone()));
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("editOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("MARGIN".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("SPOT".to_string()));
}
if is_true(&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 {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("FUTURES".to_string()));
if is_true(&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.clone(), &[params.clone()]);
response = self.v2_private_post_futures_modify_order(&[__ws_arg_17]).await;
}
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut orderSymbols: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_561: bool = true;
while { if !__for_first_561 { i = add(&i, &Value::Int(1)); } __for_first_561 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
let mut market: Value = self.market(marketId.clone());
if !is_equal(&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_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder.clone(), "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".to_string()), &[orderParams.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); orderParams = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market_type: Value = Value::Str("SPOT".to_string());
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
market_type = Value::Str("FUTURES".to_string());
} else if !is_equal(&marginMode, &Value::Null) {
market_type = Value::Str("MARGIN".to_string());
}
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("market_type".to_string(), market_type.clone());
m
});
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut orderRequest, &Value::Str("amount".to_string()), self.amount_to_precision(marketId.clone(), amount.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut orderRequest, &Value::Str("price".to_string()), self.price_to_precision(marketId.clone(), price.clone()));
}
append_to_array(&mut ordersRequests, self.extend(orderRequest.clone(), &[orderParams.clone()]));
}
}
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.clone(), Value::Int(0), &[]);
let mut firstMarket: Value = self.market(firstSymbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), ordersRequests.clone());
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&firstMarket, &Value::Str("spot".to_string())), &Value::Bool(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.clone(), &[params.clone()]);
response = self.v2_private_post_futures_batch_modify_order(&[__ws_arg_19]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_562: bool = true;
while { if !__for_first_562 { i = add(&i, &Value::Int(1)); } __for_first_562 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut code: Value = self.safe_string_k(entry.clone(), "code", &[]);
let mut message: Value = self.safe_string_k(entry.clone(), "message", &[Value::Str("".to_string())]);
if is_true(&(!is_equal(&code, &Value::Str("0".to_string())))) || is_true(&(is_true(&(!is_equal(&message, &Value::Str("Success".to_string())))) && is_true(&(!is_equal(&message, &Value::Str("Succeeded".to_string())))) && is_true(&(!is_equal(&to_lower(&message), &Value::Str("ok".to_string())))) && is_true(&(is_equal(&data, &Value::Null))))) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &message);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut item: Value = self.safe_dict_k(entry.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(item.clone(), &[]);
append_to_array(&mut result, order.clone());
}
}
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut isTriggerOrder: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut swap: Value = get_value(&market, &Value::Str("swap".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("cancelOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&swap, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("FUTURES".to_string()));
} else {
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("MARGIN".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("SPOT".to_string()));
}
}
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client_id".to_string()), Value::Str("clientOrderId".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut response: Value = Value::Null;
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("client_id".to_string()), clientOrderId.clone());
if is_equal(&isTriggerOrder, &Value::Bool(true)) {
if is_equal(&swap, &Value::Bool(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 is_equal(&swap, &Value::Bool(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 is_equal(&isTriggerOrder, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("stop_id".to_string()), self.parse_to_numeric(id.clone()));
if is_equal(&swap, &Value::Bool(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 {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), self.parse_to_numeric(id.clone()));
if is_equal(&swap, &Value::Bool(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.clone(), &[params.clone()]);
response = self.v2_private_post_spot_cancel_order(&[__ws_arg_27]).await;
}
}
}
let mut data: Value = Value::Null;
if !is_equal(&clientOrderId, &Value::Null) {
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
data = self.safe_dict(get_value(&rows, &Value::Int(0)), Value::Str("data".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
data = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_order(data.clone(), &[market.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("FUTURES".to_string()));
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".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("MARGIN".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("SPOT".to_string()));
}
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_spot_cancel_all_order(&[__ws_arg_29]).await;
}
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[])]);
Value::Null
}
/*
* @method
* @name 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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("order_id".to_string(), self.parse_to_numeric(id.clone()));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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.clone(), &[params.clone()]);
response = self.v2_private_get_spot_order_status(&[__ws_arg_31]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("market".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut isClosed: bool = is_true(&(is_equal(&status, &Value::Str("finished".to_string())))) || is_true(&(is_equal(&status, &Value::Str("closed".to_string()))));
let mut isOpen: bool = is_true(&(is_equal(&status, &Value::Str("pending".to_string())))) || is_true(&(is_equal(&status, &Value::Str("open".to_string()))));
if is_equal(&marketType, &Value::Str("swap".to_string())) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("FUTURES".to_string()));
if is_true(&isClosed) {
if is_equal(&trigger, &Value::Bool(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 is_true(&isOpen) {
if is_equal(&trigger, &Value::Bool(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".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("MARGIN".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("SPOT".to_string()));
}
if is_true(&isClosed) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&status, &Value::Str("pending".to_string())) {
if is_equal(&trigger, &Value::Bool(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.clone(), &[params.clone()]);
response = self.v2_private_get_spot_pending_order(&[__ws_arg_39]).await;
}
}
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
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".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_563: bool = true;
while { if !__for_first_563 { i = add(&i, &Value::Int(1)); } __for_first_563 = false; is_less_than(&i, &get_array_length(&openOrders)) } {
add_element_to_object(get_value_mut(&mut openOrders, &i), &Value::Str("status".to_string()), Value::Str("open".to_string()));
}
}
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".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut network: Value = self.safe_string2(params.clone(), Value::Str("chain".to_string()), Value::Str("network".to_string()), &[]);
if is_equal(&network, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createDepositAddress() requires a network parameter".to_string()))));
}
params = self.omit(params.clone(), Value::Str("network".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("chain".to_string(), self.network_code_to_id(network.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))]));
m
});
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_address(data.clone(), &[currency.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&networkCode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchDepositAddress() requires a \"network\" parameter".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("chain".to_string()), self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))])); // required for on-chain, not required for inter-user transfer
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_address(data.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "address": "1P1JqozxioQwaqPwgMAQdNDYNyaVSqgARq",
// "memo": ""
// }
//
let mut coinAddress: Value = self.safe_string_k(depositAddress.clone(), "address", &[Value::Str("".to_string())]);
let mut parts: Value = split(&coinAddress, &Value::Str(":".to_string()));
let mut address: Value = Value::Null;
let mut tag: Value = Value::Null;
let mut partsLength: Value = get_array_length(&parts);
if is_greater_than(&partsLength, &Value::Int(1)) && !is_equal(&get_value(&parts, &Value::Int(0)), &Value::Str("cfx".to_string())) {
address = get_value(&parts, &Value::Int(0));
tag = get_value(&parts, &Value::Int(1));
} else {
address = coinAddress.clone();
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), self.safe_currency_code(Value::Null, &[currency.clone()]));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), self.safe_string_k(depositAddress.clone(), "memo", &[tag.clone()]));
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("FUTURES".to_string()));
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".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("MARGIN".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("market_type".to_string()), Value::Str("SPOT".to_string()));
}
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_get_spot_user_deals(&[__ws_arg_43]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &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".to_string()), Value::Str("method".to_string()), &[Value::Str("v2PrivateGetFuturesPendingPosition".to_string())]); defaultMethod = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
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".to_string()));
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut symbol: Value = Value::Null;
if is_true(&Value::Bool(is_array(&symbols))) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchPositions() symbols argument cannot contain more than 1 symbol".to_string()))));
}
symbol = get_value(&symbols, &Value::Int(0));
} else {
symbol = symbols.clone();
}
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("market".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut response: Value = Value::Null;
if is_equal(&defaultMethod, &Value::Str("v2PrivateGetFuturesPendingPosition".to_string())) {
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.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_564: bool = true;
while { if !__for_first_564 { i = add(&i, &Value::Int(1)); } __for_first_564 = false; is_less_than(&i, &get_array_length(&position)) } {
append_to_array(&mut result, self.parse_position(get_value(&position, &i), &[market.clone()]));
}
}
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_46 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
return self.parse_position(get_value(&data, &Value::Int(0)), &[market.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "position_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.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]);
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(), get_value(&market, &Value::Str("symbol".to_string())));
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.clone(), "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.clone()));
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.clone(), "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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a symbol argument".to_string()))));
}
marginMode = to_lower(&marginMode);
if !is_equal(&marginMode, &Value::Str("isolated".to_string())) && !is_equal(&marginMode, &Value::Str("cross".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setMarginMode() marginMode argument should be isolated or cross".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("swap".to_string())) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" setMarginMode() supports swap contracts only".to_string()))));
}
let mut leverage: Value = self.safe_integer_k(params.clone(), "leverage", &[]);
let mut maxLeverage: Value = self.safe_integer(get_value(&get_value(&market, &Value::Str("limits".to_string())), &Value::Str("leverage".to_string())), Value::Str("max".to_string()), &[Value::Int(100)]);
if is_equal(&leverage, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a leverage parameter".to_string()))));
}
if is_true(&(is_less_than(&leverage, &Value::Int(1)))) || is_true(&(is_greater_than(&leverage, &maxLeverage))) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&self.id, &Value::Str(" setMarginMode() leverage should be between 1 and ".to_string())), &to_string_val(&maxLeverage)), &Value::Str(" for ".to_string())), &symbol)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m.insert("margin_mode".to_string(), marginMode.clone());
m.insert("leverage".to_string(), leverage.clone());
m
});
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" setLeverage() supports swap contracts only".to_string()))));
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setLeverage".to_string()), &[params.clone(), Value::Str("cross".to_string())]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut minLeverage: Value = self.safe_integer(get_value(&get_value(&market, &Value::Str("limits".to_string())), &Value::Str("leverage".to_string())), Value::Str("min".to_string()), &[Value::Int(1)]);
let mut maxLeverage: Value = self.safe_integer(get_value(&get_value(&market, &Value::Str("limits".to_string())), &Value::Str("leverage".to_string())), Value::Str("max".to_string()), &[Value::Int(100)]);
if is_true(&(is_less_than(&leverage, &minLeverage))) || is_true(&(is_greater_than(&leverage, &maxLeverage))) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&add(&add(&self.id, &Value::Str(" setLeverage() leverage should be between ".to_string())), &to_string_val(&minLeverage)), &Value::Str(" and ".to_string())), &to_string_val(&maxLeverage)), &Value::Str(" for ".to_string())), &symbol)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m.insert("margin_mode".to_string(), marginMode.clone());
m.insert("leverage".to_string(), leverage.clone());
m
});
let __ws_arg_48 = self.extend(request.clone(), &[params.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
add_element_to_object(&mut request, &Value::Str("market".to_string()), join(&marketIds, &Value::Str(",".to_string())));
}
let __ws_arg_49 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
return self.parse_leverage_tiers(data.clone(), &[symbols.clone(), Value::Str("market".to_string())]);
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::List(vec![]);
let mut brackets: Value = self.safe_list_k(info.clone(), "level", &[Value::List(vec![])]);
let mut minNotional: Value = Value::Int(0);
{
let mut i: Value = Value::Int(0);
let mut __for_first_565: bool = true;
while { if !__for_first_565 { i = add(&i, &Value::Int(1)); } __for_first_565 = false; is_less_than(&i, &get_array_length(&brackets)) } {
let mut tier: Value = get_value(&brackets, &i);
let mut tier: Value = get_value(&brackets, &i);
let mut marketId: Value = self.safe_string_k(info.clone(), "market", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut maxNotional: Value = self.safe_number_k(tier.clone(), "amount", &[]);
let mut curr: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))), get_value(&market, &Value::Str("base".to_string())), get_value(&market, &Value::Str("quote".to_string())));
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.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
m.insert("currency".to_string(), curr.clone());
m.insert("minNotional".to_string(), notional.clone());
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.clone());
m
}));
minNotional = maxNotional.clone();
}
}
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut rawAmount: Value = self.amount_to_precision(symbol.clone(), amount.clone());
let mut requestAmount: Value = rawAmount.clone();
if is_equal(&addOrReduce, &Value::Str("reduce".to_string())) {
requestAmount = crate::precise::Precise::stringNeg(&rawAmount);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m.insert("amount".to_string(), requestAmount.clone());
m
});
let __ws_arg_50 = self.extend(request.clone(), &[params.clone()]);
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(response.clone(), Value::Str("message".to_string()), &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&addOrReduce, &Value::Str("reduce".to_string())))), Value::Str("reduce".to_string()), Value::Str("add".to_string()));
let __ws_arg_51 = self.parse_margin_modification(data.clone(), &[market.clone()]);
let __ws_arg_52 = self.parse_number(amount.clone(), &[]);
return self.extend(__ws_arg_51, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), __ws_arg_52);
m.insert("status".to_string(), status.clone());
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".to_string()), Value::Str("created_at".to_string()), &[]);
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.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&change), &[]));
m.insert("total".to_string(), self.safe_number_k(data.clone(), "margin_avbl", &[]));
m.insert("code".to_string(), self.safe_string_k(market.clone(), "quote", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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.clone(), amount.clone(), Value::Str("add".to_string()), &[params.clone()]).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.clone(), amount.clone(), Value::Str("reduce".to_string()), &[params.clone()]).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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m
});
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_53 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_566: bool = true;
while { if !__for_first_566 { i = add(&i, &Value::Int(1)); } __for_first_566 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
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.clone(), &[]);
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.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), self.safe_number_k(entry.clone(), "position_id", &[]));
m.insert("amount".to_string(), self.safe_number_k(entry.clone(), "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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" fetchFundingRate() supports swap contracts only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_54 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(first.clone(), &[market.clone()]);
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.clone(), &[params.clone()]).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.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
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.clone()));
m.insert("nextFundingRate".to_string(), self.safe_number_k(contract.clone(), "next_funding_rate", &[]));
m.insert("nextFundingTimestamp".to_string(), futureFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(futureFundingTimestamp.clone()));
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.clone()));
m
});
Value::Null
}
pub fn parse_funding_interval(&self, mut interval: Value) -> Value {
let mut intervals: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("3600000".to_string(), Value::Str("1h".to_string()));
m.insert("14400000".to_string(), Value::Str("4h".to_string()));
m.insert("28800000".to_string(), Value::Str("8h".to_string()));
m.insert("57600000".to_string(), Value::Str("16h".to_string()));
m.insert("86400000".to_string(), Value::Str("24h".to_string()));
m
});
return self.safe_string(intervals.clone(), interval.clone(), &[interval.clone()]);
Value::Null
}
/*
* @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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut symbol: Value = self.safe_value(symbols.clone(), Value::Int(0), &[]);
market = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" fetchFundingRates() supports swap contracts only".to_string()))));
}
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
add_element_to_object(&mut request, &Value::Str("market".to_string()), join(&marketIds, &Value::Str(",".to_string())));
}
let __ws_arg_55 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
return self.parse_funding_rates(data.clone(), &[symbols.clone()]);
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 = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
self.check_address(&[address.clone()]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("to_address".to_string(), address.clone());
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("memo".to_string()), tag.clone());
}
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))])); // required for on-chain, not required for inter-user transfer
}
let __ws_arg_56 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(transaction.clone(), &[currency.clone()]);
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".to_string()));
m.insert("pass".to_string(), Value::Str("pending".to_string()));
m.insert("audit_required".to_string(), Value::Str("pending".to_string()));
m.insert("processing".to_string(), Value::Str("pending".to_string()));
m.insert("confirming".to_string(), Value::Str("pending".to_string()));
m.insert("not_pass".to_string(), Value::Str("failed".to_string()));
m.insert("cancel".to_string(), Value::Str("canceled".to_string()));
m.insert("finish".to_string(), Value::Str("ok".to_string()));
m.insert("finished".to_string(), Value::Str("ok".to_string()));
m.insert("fail".to_string(), Value::Str("failed".to_string()));
m
});
return self.safe_string(statuses.clone(), 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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.clone(), Value::Int(1000)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_57 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
let mut rates: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_567: bool = true;
while { if !__for_first_567 { i = add(&i, &Value::Int(1)); } __for_first_567 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "market", &[]);
let mut symbolInner: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]);
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.clone());
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "actual_funding_rate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
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 !is_equal(&tag, &Value::Null) {
if is_less_than(&get_array_length(&tag), &Value::Int(1)) {
tag = Value::Null;
}
}
let mut remark: Value = self.safe_string_k(transaction.clone(), "remark", &[]);
if !is_equal(&remark, &Value::Null) {
if is_less_than(&get_array_length(&remark), &Value::Int(1)) {
remark = Value::Null;
}
}
let mut txid: Value = self.safe_string_k(transaction.clone(), "tx_id", &[]);
if !is_equal(&txid, &Value::Null) {
if is_less_than(&get_array_length(&txid), &Value::Int(1)) {
txid = Value::Null;
}
}
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "created_at", &[]);
let mut type_var: Value = ternary(is_true(&(Value::Bool(in_op(&transaction, &Value::Str("withdraw_id".to_string()))))), Value::Str("withdrawal".to_string()), Value::Str("deposit".to_string()));
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: Value = self.safe_string_lower2(transaction.clone(), Value::Str("withdraw_method".to_string()), Value::Str("deposit_method".to_string()), &[]);
let mut internal: Value = Value::Bool(is_equal(&transferMethod, &Value::Str("local".to_string())));
let mut amount: Value = self.safe_number_k(transaction.clone(), "actual_amount", &[]);
if is_equal(&amount, &Value::Null) {
amount = self.safe_number_k(transaction.clone(), "amount", &[]);
}
if is_equal(&type_var, &Value::Str("deposit".to_string())) {
feeCost = Value::Str("0".to_string());
}
let mut feeCurrencyId: Value = self.safe_string2(transaction.clone(), Value::Str("fee_asset".to_string()), Value::Str("fee_ccy".to_string()), &[]); // 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.clone(), &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCurrencyId.clone(), &[]));
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".to_string()), Value::Str("deposit_id".to_string()), &[]));
m.insert("txid".to_string(), txid.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("network".to_string(), self.network_id_to_code(&[networkId.clone(), code.clone()]));
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), address.clone());
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), tag.clone());
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])));
m.insert("updated".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m.insert("comment".to_string(), remark.clone());
m.insert("internal".to_string(), internal.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut amountToPrecision: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[toAccount.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), amountToPrecision.clone());
m.insert("from_account_type".to_string(), fromId.clone());
m.insert("to_account_type".to_string(), toId.clone());
m
});
if is_true(&(is_equal(&fromAccount, &Value::Str("margin".to_string())))) || is_true(&(is_equal(&toAccount, &Value::Str("margin".to_string())))) {
let mut symbol: Value = self.safe_string_k(params.clone(), "symbol", &[]);
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" transfer() the symbol parameter must be defined for a margin account".to_string()))));
}
params = self.omit(params.clone(), Value::Str("symbol".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("market".to_string()), self.market_id(symbol.clone()));
}
if is_true(&(!is_equal(&fromAccount, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(&toAccount, &Value::Str("spot".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" transfer() can only be between spot and swap, or spot and margin, either the fromAccount or toAccount must be spot".to_string()))));
}
let __ws_arg_58 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v2_private_post_assets_transfer(&[__ws_arg_58]).await;
let __ws_arg_59 = self.parse_transfer(response.clone(), &[currency.clone()]);
let __ws_arg_60 = self.parse_number(amountToPrecision.clone(), &[]);
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.clone());
m.insert("toAccount".to_string(), toAccount.clone());
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".to_string()));
m.insert("SUCCESS".to_string(), Value::Str("ok".to_string()));
m.insert("OK".to_string(), Value::Str("ok".to_string()));
m.insert("finished".to_string(), Value::Str("ok".to_string()));
m.insert("FINISHED".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), 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_value_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.clone()));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
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.clone(), toId.clone(), &[toId.clone()]));
m.insert("status".to_string(), self.parse_transfer_status(self.safe_string2(transfer.clone(), Value::Str("code".to_string()), Value::Str("status".to_string()), &[])));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&code, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchTransfers() requires a code argument".to_string()))));
}
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(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchTransfers".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("transfer_type".to_string()), Value::Str("MARGIN".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("transfer_type".to_string()), Value::Str("FUTURES".to_string()));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_61 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
return self.parse_transfers(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_62 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_63 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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.clone(), market.clone(), Value::Null, Value::Str("spot".to_string())]);
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 is_equal(¤cy, &get_value(&market, &Value::Str("baseId".to_string()))) {
baseRate = rate.clone();
} else if is_equal(¤cy, &get_value(&market, &Value::Str("quoteId".to_string()))) {
quoteRate = rate.clone();
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("base".to_string(), get_value(&market, &Value::Str("base".to_string())));
m.insert("baseRate".to_string(), baseRate.clone());
m.insert("quote".to_string(), get_value(&market, &Value::Str("quote".to_string())));
m.insert("quoteRate".to_string(), quoteRate.clone());
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.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut code: Value = self.safe_string_k(params.clone(), "code", &[]);
if is_equal(&code, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchIsolatedBorrowRate() requires a code parameter".to_string()))));
}
params = self.omit(params.clone(), Value::Str("code".to_string()), &[]);
let mut currency: Value = self.currency(code.clone());
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_64 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_isolated_borrow_rate(data.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("market".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_65 = self.extend(request.clone(), &[params.clone()]);
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_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut interest: Value = self.parse_borrow_interests(rows.clone(), &[market.clone()]);
return self.filter_by_currency_since_limit(interest.clone(), &[code.clone(), since.clone(), limit.clone()]);
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.clone(), market.clone(), Value::Null, Value::Str("spot".to_string())]);
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(), get_value(&market, &Value::Str("symbol".to_string())));
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.clone(), "borrow_amount", &[]));
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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 is_equal(&self.markets, &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".to_string()), Value::Str("is_auto_renew".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("isAutoRenew".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("borrow_amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("is_auto_renew".to_string(), isAutoRenew.clone());
m
});
let __ws_arg_66 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut transaction: Value = self.parse_margin_loan(data.clone(), &[currency.clone()]);
return self.extend(transaction.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m.insert("symbol".to_string(), symbol.clone());
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 is_equal(&self.markets, &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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let __ws_arg_67 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut transaction: Value = self.parse_margin_loan(data.clone(), &[currency.clone()]);
return self.extend(transaction.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m.insert("symbol".to_string(), symbol.clone());
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.clone(), &[currency.clone()]));
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "borrow_amount", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[Value::Null, Value::Null, Value::Str("spot".to_string())]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), info.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_68 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_withdraw_fee(data.clone(), &[currency.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v2_public_get_assets_all_deposit_withdraw_config(&[params.clone()]).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.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_568: bool = true;
while { if !__for_first_568 { i = add(&i, &Value::Int(1)); } __for_first_568 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut item: Value = get_value(&data, &i);
let mut item: Value = get_value(&data, &i);
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.clone(), "ccy", &[]);
if is_equal(¤cyId, &Value::Null) {
continue;
}
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
if is_equal(&codes, &Value::Null) || is_true(&self.in_array(code.clone(), codes.clone())) {
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, self.parse_deposit_withdraw_fee(item.clone(), &[]));
}
}
}
}
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::List(vec![])]);
let mut asset: Value = self.safe_dict_k(fee.clone(), "asset", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_569: bool = true;
while { if !__for_first_569 { i = add(&i, &Value::Int(1)); } __for_first_569 = false; is_less_than(&i, &get_array_length(&chains)) } {
let mut entry: Value = get_value(&chains, &i);
let mut entry: Value = get_value(&chains, &i);
let mut isWithdrawEnabled: Value = self.safe_bool_k(entry.clone(), "withdraw_enabled", &[]);
if is_equal(&isWithdrawEnabled, &Value::Bool(true)) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".to_string())), &Value::Str("fee".to_string()), self.safe_number_k(entry.clone(), "withdrawal_fee", &[]));
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".to_string())), &Value::Str("percentage".to_string()), Value::Bool(false));
let mut networkId: Value = self.safe_string_k(entry.clone(), "chain", &[]);
if is_true(&(!is_equal(&networkId, &Value::Null))) && is_true(&(!is_equal(&networkId, &Value::Str("".to_string())))) {
let mut currencyId: Value = self.safe_string_k(asset.clone(), "ccy", &[]);
let mut feeCode: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), feeCode.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("networks".to_string())), &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.clone(), "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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut code: Value = self.safe_string_k(params.clone(), "code", &[]);
if is_equal(&code, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchLeverage() requires a code parameter".to_string()))));
}
params = self.omit(params.clone(), Value::Str("code".to_string()), &[]);
let mut currency: Value = self.currency(code.clone());
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_69 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "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.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("spot".to_string())]));
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_70 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
let mut positions: Value = self.parse_positions(records.clone(), &[]);
return self.filter_by_symbol_since_limit(positions.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut type_var: Value = self.safe_string_k(params.clone(), "type", &[Value::Str("market".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m.insert("type".to_string(), type_var.clone());
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client_id".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("client_id".to_string()), clientOrderId.clone());
}
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
let __ws_arg_71 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
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: Value = self.safe_string_k(self.options.clone(), "defaultType", &[]);
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.clone(), params.clone(), defaultValue.clone()); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
if is_true(&(is_equal(&defaultType, &Value::Str("margin".to_string())))) || is_true(&(is_equal(&isMargin, &Value::Bool(true)))) {
marginMode = Value::Str("isolated".to_string());
}
}
return Value::List(vec![marginMode.clone(), params.clone()]);
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::List(vec![]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
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(&add(&add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &requestUrl), &Value::Str("/".to_string())), &version), &Value::Str("/".to_string())), &path);
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut nonce: Value = to_string_val(&self.nonce());
if is_equal(&method, &Value::Str("POST".to_string())) {
let mut parts: Value = split(&path, &Value::Str("/".to_string()));
let mut firstPart: Value = self.safe_string(parts.clone(), Value::Int(0), &[Value::Str("".to_string())]);
let mut numParts: Value = get_array_length(&parts);
let mut lastPart: Value = self.safe_string(parts.clone(), subtract(&numParts, &Value::Int(1)), &[Value::Str("".to_string())]);
let mut lastWords: Value = split(&lastPart, &Value::Str("_".to_string()));
let mut numWords: Value = get_array_length(&lastWords);
let mut lastWord: Value = self.safe_string(lastWords.clone(), subtract(&numWords, &Value::Int(1)), &[Value::Str("".to_string())]);
if is_true(&(is_equal(&firstPart, &Value::Str("order".to_string())))) && is_true(&(is_equal(&lastWord, &Value::Str("limit".to_string())) || is_equal(&lastWord, &Value::Str("market".to_string())))) {
// 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: Value = self.safe_string_k(params.clone(), "client_id", &[]);
if is_equal(&clientOrderId, &Value::Null) {
let mut defaultId: Value = Value::Str("x-167673045".to_string());
let mut brokerId: Value = self.safe_value_k(self.options.clone(), "brokerId", &[defaultId.clone()]);
add_element_to_object(&mut query, &Value::Str("client_id".to_string()), add(&add(&brokerId, &Value::Str("_".to_string())), &self.uuid16(&[])));
}
}
}
if is_equal(&requestUrl, &Value::Str("perpetualPrivate".to_string())) {
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(add(&add(&urlencoded, &Value::Str("&secret_key=".to_string())), &self.secret)), Value::Str("sha256".to_string()), &[]);
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 is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("PUT".to_string())))) {
url = add(&url, &add(&Value::Str("?".to_string()), &urlencoded));
} else {
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/x-www-form-urlencoded".to_string()));
body = urlencoded.clone();
}
} else if is_equal(&requestUrl, &Value::Str("public".to_string())) || is_equal(&requestUrl, &Value::Str("perpetualPublic".to_string())) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
} else {
if is_equal(&version, &Value::Str("v1".to_string())) {
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(add(&add(&urlencoded, &Value::Str("&secret_key=".to_string())), &self.secret)), Value::Str("md5".to_string()), &[]);
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".to_string()));
m
});
if is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))) || is_true(&(is_equal(&method, &Value::Str("PUT".to_string())))) {
url = add(&url, &add(&Value::Str("?".to_string()), &urlencoded));
} else {
body = self.json(query.clone());
}
} else if is_equal(&version, &Value::Str("v2".to_string())) {
self.check_required_credentials(&[]);
query = self.keysort(query.clone(), &[]);
let mut urlencoded: Value = self.rawencode(query.clone(), &[]);
let mut preparedString: Value = add(&add(&add(&add(&method, &Value::Str("/".to_string())), &version), &Value::Str("/".to_string())), &path);
if is_equal(&method, &Value::Str("POST".to_string())) {
body = self.json(query.clone());
preparedString = add(&preparedString, &body);
} else if !is_equal(&urlencoded, &Value::Str("".to_string())) {
preparedString = add(&preparedString, &add(&Value::Str("?".to_string()), &urlencoded));
}
preparedString = add(&preparedString, &add(&nonce, &self.secret));
let mut signature: Value = self.hash(self.encode(preparedString.clone()), Value::Str("sha256".to_string()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m.insert("Accept".to_string(), Value::Str("application/json".to_string()));
m.insert("X-COINEX-KEY".to_string(), self.apiKey.clone());
m.insert("X-COINEX-SIGN".to_string(), signature.clone());
m.insert("X-COINEX-TIMESTAMP".to_string(), nonce.clone());
m
});
if !is_equal(&method, &Value::Str("POST".to_string())) {
if !is_equal(&urlencoded, &Value::Str("".to_string())) {
url = add(&url, &add(&Value::Str("?".to_string()), &urlencoded));
}
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
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 is_equal(&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.clone(), "message", &[Value::Str("".to_string())]);
if is_true(&(!is_equal(&code, &Value::Str("0".to_string())))) || is_true(&(is_true(&(!is_equal(&message, &Value::Str("Success".to_string())))) && is_true(&(!is_equal(&message, &Value::Str("Succeeded".to_string())))) && is_true(&(!is_equal(&to_lower(&message), &Value::Str("ok".to_string())))) && is_true(&(is_equal(&data, &Value::Null))))) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &message);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMarginAdjustmentHistory() requires a symbol argument".to_string()))));
}
let mut positionId: Value = self.safe_integer2(params.clone(), Value::Str("positionId".to_string()), Value::Str("position_id".to_string()), &[]);
params = self.omit(params.clone(), Value::Str("positionId".to_string()), &[]);
if is_equal(&positionId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMarginAdjustmentHistory() requires a positionId parameter".to_string()))));
}
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("market_type".to_string(), Value::Str("FUTURES".to_string()));
m.insert("position_id".to_string(), positionId.clone());
m
});
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_72 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::List(vec![])]);
let mut modifications: Value = self.parse_margin_modifications(data.clone(), &[Value::Null, Value::Str("market".to_string()), Value::Str("swap".to_string())]);
return self.filter_by_symbol_since_limit(modifications.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
}