// 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 CryptocomCore {
pub exchange: crate::exchange::Exchange,
}
impl CryptocomCore {
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 = CryptocomCore::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 CryptocomCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_order(self, order, &[market.clone()])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::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 CryptocomCore.
CryptocomCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_ledger_entry(self, entry, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_currency(self, currency)
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_account(self, account)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptocomCore.
CryptocomCore::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 CryptocomCore.
CryptocomCore::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 CryptocomCore.
CryptocomCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for CryptocomCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders_for_symbols" => self.cancel_orders_for_symbols(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_advanced_order_request" => self.create_advanced_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"custom_handle_margin_mode_and_params" => self.custom_handle_margin_mode_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_order_request" => self.edit_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..).unwrap_or(&[]).to_vec()[..]),
"fetch_accounts" => self.fetch_accounts(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(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_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_settlement_history" => self.fetch_settlement_history(&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_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"params_to_string" => self.params_to_string(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_account" => self.parse_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_address" => self.parse_address(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_status" => self.parse_deposit_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_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_settlement" => self.parse_settlement(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_settlements" => self.parse_settlements(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_time_in_force" => self.parse_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_trading_fees" => self.parse_trading_fees(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_withdrawal_status" => self.parse_withdrawal_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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 CryptocomCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for CryptocomCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl CryptocomCore {
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("cryptocom".to_string()));
m.insert("name".to_string(), Value::Str("Crypto.com".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("MT".to_string())]));
m.insert("version".to_string(), Value::Str("v2".to_string()));
m.insert("rateLimit".to_string(), Value::Int(10));
m.insert("certified".to_string(), Value::Bool(true));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Bool(false));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("cancelOrdersForSymbols".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
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("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Bool(false));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Str("emulated".to_string()));
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(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".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("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(true));
m.insert("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(false));
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("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(false));
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("1m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1D".to_string()));
m.insert("1w".to_string(), Value::Str("7D".to_string()));
m.insert("2w".to_string(), Value::Str("14D".to_string()));
m.insert("1M".to_string(), Value::Str("1M".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/1294454/147792121-38ed5e36-c229-48d6-b49a-48d05fc19ed4.jpeg".to_string()));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Str("https://uat-api.3ona.co/exchange/v1".to_string()));
m.insert("v2".to_string(), Value::Str("https://uat-api.3ona.co/v2".to_string()));
m.insert("derivatives".to_string(), Value::Str("https://uat-api.3ona.co/v2".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base".to_string(), Value::Str("https://api.crypto.com".to_string()));
m.insert("v1".to_string(), Value::Str("https://api.crypto.com/exchange/v1".to_string()));
m.insert("v2".to_string(), Value::Str("https://api.crypto.com/v2".to_string()));
m.insert("derivatives".to_string(), Value::Str("https://deriv-api.crypto.com/v1".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://crypto.com/".to_string()));
m.insert("referral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Str("https://crypto.com/exch/kdacthrnxt".to_string()));
m.insert("discount".to_string(), Value::Float(0.75));
m
}));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html".to_string()), Value::Str("https://exchange-docs.crypto.com/spot/index.html".to_string()), Value::Str("https://exchange-docs.crypto.com/derivatives/index.html".to_string())]));
m.insert("fees".to_string(), Value::Str("https://crypto.com/exchange/document/fees-limits".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base".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("v1/public/get-announcements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
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("public/auth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("public/get-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("public/get-book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-candlestick".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-valuations".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-expired-settlement-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("public/get-insurance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-announcements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-risk-parameters".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("public/staking/get-conversion-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private/set-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/user-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/user-balance-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/amend-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(4), &Value::Int(3)));
m
}));
m.insert("private/create-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/cancel-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/cancel-all-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("private/get-open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("private/get-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("private/change-account-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-subaccount-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-subaccount-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-currency-networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-withdrawal-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/get-instrument-fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/fiat/fiat-deposit-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/fiat/fiat-deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/fiat/fiat-withdraw-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/fiat/fiat-create-withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/fiat/fiat-transaction-quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/fiat/fiat-transaction-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/fiat/fiat-get-bank-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/staking/stake".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/unstake".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/get-staking-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/get-staking-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/get-open-stake".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/get-stake-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/get-reward-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/convert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/get-open-convert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/staking/get-convert-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("private/create-isolated-margin-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/change-isolated-margin-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
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("public/auth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-candlestick".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/margin/get-transfer-currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/margin/get-load-currenices".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/respond-heartbeat".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("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private/set-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-withdrawal-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-currency-networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/export/create-export-request".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/export/get-export-requests".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/export/download-export-output".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-account-summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/cancel-all-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/create-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("private/get-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("private/get-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-subaccount-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-subaccount-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/otc/get-otc-user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/otc/get-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/otc/request-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("private/otc/accept-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("private/otc/get-quote-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/otc/get-trade-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/otc/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m
}));
m
}));
m
}));
m.insert("derivatives".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("public/auth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("public/get-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("public/get-book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-candlestick".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-valuations".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/get-expired-settlement-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("public/get-insurance".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("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private/set-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/user-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/user-balance-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/create-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/cancel-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/cancel-all-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("private/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/convert-collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("private/get-open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("private/get-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("private/change-account-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/create-subaccount-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-subaccount-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("private/get-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
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(), self.parse_number(Value::Str("0.0025".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.005".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.0025".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000".to_string()), &[]), self.parse_number(Value::Str("0.0015".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("250000".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.0008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.00065".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("250000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])])]));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000".to_string()), &[]), self.parse_number(Value::Str("0.004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000".to_string()), &[]), self.parse_number(Value::Str("0.0025".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("250000".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.0018".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0.00035".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("250000000".to_string()), &[]), self.parse_number(Value::Str("0.00031".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000000".to_string()), &[]), self.parse_number(Value::Str("0.00025".to_string()), &[])])]));
m
}));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("spot".to_string()));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("funding".to_string(), Value::Str("SPOT".to_string()));
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("margin".to_string(), Value::Str("MARGIN".to_string()));
m.insert("derivatives".to_string(), Value::Str("DERIVATIVES".to_string()));
m.insert("swap".to_string(), Value::Str("DERIVATIVES".to_string()));
m.insert("future".to_string(), Value::Str("DERIVATIVES".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRON".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("ARB".to_string()));
m
}));
m.insert("broker".to_string(), Value::Str("CCXT".to_string()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
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::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
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("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("iceberg".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
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(10));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(1));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(100));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(1));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(1));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(300));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m.insert("fetchCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private".to_string(), Value::Bool(true));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USD_STABLE_COIN".to_string(), Value::Str("USDC".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("213".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("219".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("306".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("314".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("315".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("325".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("415".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("10002".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10003".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10005".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10006".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("10007".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("10008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10009".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20002".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("20005".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("30003".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("30004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30010".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30013".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30023".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30024".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30025".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("40001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40101".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("40102".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("40103".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("40104".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("40107".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("40401".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("40801".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("42901".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("43005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("43003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("43004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("43012".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("50001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("9010001".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-currency-networks
* @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
}));
// this endpoint requires authentication
if !is_true(&self.check_required_credentials(&[Value::Bool(false)])) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut skipFetchCurrencies: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchCurrencies".to_string()), Value::Str("skipFetchCurrencies".to_string()), &[Value::Bool(false)]); skipFetchCurrencies = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&skipFetchCurrencies) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
response = self.v1_private_post_private_get_currency_networks(&[params.clone()]).await;
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
let mut erString: Value = self.exception_message(e.clone(), &[]);
if is_greater_than_or_equal(&get_index_of(&erString, &Value::Str("SYS_ERROR".to_string())), &Value::Int(0)) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
panic!("{}", e);
}
//
// {
// "id": "1747502328559",
// "method": "private/get-currency-networks",
// "code": "0",
// "result": {
// "update_time": "1747502281000",
// "currency_map": {
// "USDT": {
// "full_name": "Tether USD",
// "default_network": "ETH",
// "network_list": [
// {
// "network_id": "ETH",
// "withdrawal_fee": "10.00000000",
// "withdraw_enabled": true,
// "min_withdrawal_amount": "20.0",
// "deposit_enabled": true,
// "confirmation_required": "32"
// },
// {
// "network_id": "CRONOS",
// "withdrawal_fee": "0.18000000",
// "withdraw_enabled": true,
// "min_withdrawal_amount": "0.35",
// "deposit_enabled": true,
// "confirmation_required": "15"
// },
// {
// "network_id": "SOL",
// "withdrawal_fee": "5.31000000",
// "withdraw_enabled": true,
// "min_withdrawal_amount": "10.62",
// "deposit_enabled": true,
// "confirmation_required": "1"
// }
// ]
// }
// }
// }
// }
//
let mut resultData: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyMap: Value = self.safe_dict_k(resultData.clone(), "currency_map", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut enhancedArray: Value = self.add_key_in_array_items(currencyMap.clone(), Value::Str("_coin_id".to_string()));
return self.parse_currencies(enhancedArray.clone());
Value::Null
}
pub fn parse_currency(&self, mut currency: Value) -> Value {
let mut id: Value = self.safe_string_k(currency.clone(), "_coin_id", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut chains: Value = self.safe_list_k(currency.clone(), "network_list", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_590: bool = true;
while { if !__for_first_590 { j = add(&j, &Value::Int(1)); } __for_first_590 = 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(), "network_id", &[]);
let mut network: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if !is_equal(&network, &Value::Null) {
add_element_to_object(&mut networks, &network, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), network.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(chain.clone(), "deposit_enabled", &[Value::Bool(false)]));
m.insert("withdraw".to_string(), self.safe_bool_k(chain.clone(), "withdraw_enabled", &[Value::Bool(false)]));
m.insert("fee".to_string(), self.safe_number_k(chain.clone(), "withdrawal_fee", &[]));
m.insert("precision".to_string(), Value::Null);
m.insert("limits".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("min".to_string(), self.safe_number_k(chain.clone(), "min_withdrawal_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), currency.clone());
m.insert("id".to_string(), id.clone());
m.insert("code".to_string(), code.clone());
m.insert("name".to_string(), self.safe_string_k(currency.clone(), "full_name", &[]));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
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
}));
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m.insert("networks".to_string(), networks.clone());
m
}));
Value::Null
}
/*
* @method
* @name cryptocom#fetchMarkets
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-instruments
* @description retrieves data on all markets for cryptocom
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.v1_public_get_public_get_instruments(&[params.clone()]).await;
//
// {
// "id": 1,
// "method": "public/get-instruments",
// "code": 0,
// "result": {
// "data": [
// {
// "symbol": "BTC_USDT",
// "inst_type": "CCY_PAIR",
// "display_name": "BTC/USDT",
// "base_ccy": "BTC",
// "quote_ccy": "USDT",
// "quote_decimals": 2,
// "quantity_decimals": 5,
// "price_tick_size": "0.01",
// "qty_tick_size": "0.00001",
// "max_leverage": "50",
// "tradable": true,
// "expiry_timestamp_ms": 0,
// "beta_product": false,
// "margin_buy_enabled": false,
// "margin_sell_enabled": true
// },
// {
// "symbol": "RUNEUSD-PERP",
// "inst_type": "PERPETUAL_SWAP",
// "display_name": "RUNEUSD Perpetual",
// "base_ccy": "RUNE",
// "quote_ccy": "USD",
// "quote_decimals": 3,
// "quantity_decimals": 1,
// "price_tick_size": "0.001",
// "qty_tick_size": "0.1",
// "max_leverage": "50",
// "tradable": true,
// "expiry_timestamp_ms": 0,
// "beta_product": false,
// "underlying_symbol": "RUNEUSD-INDEX",
// "contract_size": "1",
// "margin_buy_enabled": false,
// "margin_sell_enabled": false
// },
// {
// "symbol": "ETHUSD-230825",
// "inst_type": "FUTURE",
// "display_name": "ETHUSD Futures 20230825",
// "base_ccy": "ETH",
// "quote_ccy": "USD",
// "quote_decimals": 2,
// "quantity_decimals": 4,
// "price_tick_size": "0.01",
// "qty_tick_size": "0.0001",
// "max_leverage": "100",
// "tradable": true,
// "expiry_timestamp_ms": 1692950400000,
// "beta_product": false,
// "underlying_symbol": "ETHUSD-INDEX",
// "contract_size": "1",
// "margin_buy_enabled": false,
// "margin_sell_enabled": false
// },
// {
// "symbol": "BTCUSD-230630-CW30000",
// "inst_type": "WARRANT",
// "display_name": "BTCUSD-230630-CW30000",
// "base_ccy": "BTC",
// "quote_ccy": "USD",
// "quote_decimals": 3,
// "quantity_decimals": 0,
// "price_tick_size": "0.001",
// "qty_tick_size": "10",
// "max_leverage": "50",
// "tradable": true,
// "expiry_timestamp_ms": 1688112000000,
// "beta_product": false,
// "underlying_symbol": "BTCUSD-INDEX",
// "put_call": "CALL",
// "strike": "30000",
// "contract_size": "0.0001",
// "margin_buy_enabled": false,
// "margin_sell_enabled": false
// },
// ]
// }
// }
//
let mut resultResponse: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(resultResponse.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_591: bool = true;
while { if !__for_first_591 { i = add(&i, &Value::Int(1)); } __for_first_591 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut market: Value = get_value(&data, &i);
let mut market: Value = get_value(&data, &i);
let mut inst_type: Value = self.safe_string_k(market.clone(), "inst_type", &[]);
let mut spot: Value = Value::Bool(is_equal(&inst_type, &Value::Str("CCY_PAIR".to_string())));
let mut swap: Value = Value::Bool(is_equal(&inst_type, &Value::Str("PERPETUAL_SWAP".to_string())));
let mut future: Value = Value::Bool(is_equal(&inst_type, &Value::Str("FUTURE".to_string())));
let mut option: Value = Value::Bool(is_equal(&inst_type, &Value::Str("WARRANT".to_string())));
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 settleId: Value = ternary(is_true(&spot), Value::Null, quoteId.clone());
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settle: Value = ternary(is_true(&spot), Value::Null, self.safe_currency_code(settleId.clone(), &[]));
let mut optionType: Value = self.safe_string_lower(market.clone(), Value::Str("put_call".to_string()), &[]);
let mut strike: Value = self.safe_string_k(market.clone(), "strike", &[]);
let mut marginBuyEnabled: Value = self.safe_bool_k(market.clone(), "margin_buy_enabled", &[]);
let mut marginSellEnabled: Value = self.safe_bool_k(market.clone(), "margin_sell_enabled", &[]);
let mut expiryString: Value = self.omit_zero(self.safe_string_k(market.clone(), "expiry_timestamp_ms", &[]));
let mut expiry: Value = ternary(is_true(&(!is_equal(&expiryString, &Value::Null))), crate::runtime::parse_int(&expiryString), Value::Null);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut type_var: Value = Value::Null;
let mut contract: Value = Value::Null;
if is_equal(&inst_type, &Value::Str("CCY_PAIR".to_string())) {
type_var = Value::Str("spot".to_string());
contract = Value::Bool(false);
} else if is_equal(&inst_type, &Value::Str("PERPETUAL_SWAP".to_string())) {
type_var = Value::Str("swap".to_string());
symbol = add(&add(&symbol, &Value::Str(":".to_string())), "e);
contract = Value::Bool(true);
} else if is_equal(&inst_type, &Value::Str("FUTURE".to_string())) {
type_var = Value::Str("future".to_string());
symbol = add(&add(&add(&add(&symbol, &Value::Str(":".to_string())), "e), &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[]));
contract = Value::Bool(true);
} else if is_equal(&inst_type, &Value::Str("WARRANT".to_string())) {
type_var = Value::Str("option".to_string());
let mut symbolOptionType: Value = ternary(is_true(&(is_equal(&optionType, &Value::Str("call".to_string())))), Value::Str("C".to_string()), Value::Str("P".to_string()));
symbol = add(&add(&add(&add(&add(&add(&add(&add(&symbol, &Value::Str(":".to_string())), "e), &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[])), &Value::Str("-".to_string())), &strike), &Value::Str("-".to_string())), &symbolOptionType);
contract = Value::Bool(true);
}
let mut isLinear: Value = ternary(is_true(&(is_equal(&contract, &Value::Bool(true)))), Value::Bool(true), Value::Null);
let mut isInverse: Value = ternary(is_true(&(is_equal(&contract, &Value::Bool(true)))), Value::Bool(false), Value::Null);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), Value::Bool((is_true(&(is_equal(&marginBuyEnabled, &Value::Bool(true)))) || is_true(&(is_equal(&marginSellEnabled, &Value::Bool(true)))))));
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), future.clone());
m.insert("option".to_string(), option.clone());
m.insert("active".to_string(), self.safe_bool_k(market.clone(), "tradable", &[]));
m.insert("contract".to_string(), contract.clone());
m.insert("linear".to_string(), isLinear.clone());
m.insert("inverse".to_string(), isInverse.clone());
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contract_size", &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), self.parse_number(strike.clone(), &[]));
m.insert("optionType".to_string(), optionType.clone());
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), self.parse_number(self.safe_string_k(market.clone(), "price_tick_size", &[]), &[]));
m.insert("amount".to_string(), self.parse_number(self.safe_string_k(market.clone(), "qty_tick_size", &[]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "max_leverage", &[]));
m
}));
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("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
}
/*
* @method
* @name cryptocom#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
* @see https://exchange-docs.crypto.com/derivatives/index.html#public-get-tickers
* @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;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut symbol: Value = 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(" fetchTickers() 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("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_public_get_public_get_tickers(&[__ws_arg_0]).await;
//
// {
// "id": -1,
// "method": "public/get-tickers",
// "code": 0,
// "result": {
// "data": [
// {
// "i": "AVAXUSD-PERP",
// "h": "13.209",
// "l": "12.148",
// "a": "13.209",
// "v": "1109.8",
// "vv": "14017.33",
// "c": "0.0732",
// "b": "13.210",
// "k": "13.230",
// "oi": "10888.9",
// "t": 1687402657575
// },
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
return self.parse_tickers(data.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchTicker
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @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;
}
symbol = self.symbol(symbol.clone());
let mut tickers: Value = self.fetch_tickers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return self.safe_value(tickers.clone(), symbol.clone(), &[]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-history
* @param {string} symbol unified market symbol of the market the orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for, max date range is one day
* @param {int} [limit] the maximum number of order structures to retrieve, default 100 max 100
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrders".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_dynamic(Value::Str("fetchOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".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 mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_time".to_string()), until.clone());
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_order_history(&[__ws_arg_1]).await;
//
// {
// "id": 1686881486183,
// "method": "private/get-order-history",
// "code": 0,
// "result": {
// "data": [
// {
// "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
// "order_id": "6142909895014042762",
// "client_oid": "4e918597-1234-4321-8201-a7577e1e1d91",
// "order_type": "MARKET",
// "time_in_force": "GOOD_TILL_CANCEL",
// "side": "SELL",
// "exec_inst": [ ],
// "quantity": "0.00024",
// "order_value": "5.7054672",
// "maker_fee_rate": "0",
// "taker_fee_rate": "0",
// "avg_price": "25023.97",
// "trigger_price": "0",
// "ref_price": "0",
// "ref_price_type": "NULL_VAL",
// "cumulative_quantity": "0.00024",
// "cumulative_value": "6.0057528",
// "cumulative_fee": "0.001501438200",
// "status": "FILLED",
// "update_user_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
// "order_date": "2023-06-15",
// "instrument_name": "BTC_USD",
// "fee_instrument_name": "USD",
// "create_time": 1686805465891,
// "create_time_ns": "1686805465891812578",
// "update_time": 1686805465891
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchTrades
* @description get a list of the most recent trades for a particular symbol
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-trades
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch, maximum date range is one day
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTrades".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_dynamic(Value::Str("fetchTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".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_ts".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("count".to_string()), limit.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_ts".to_string()), until.clone());
}
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_public_get_public_get_trades(&[__ws_arg_2]).await;
//
// {
// "id": -1,
// "method": "public/get-trades",
// "code": 0,
// "result": {
// "data": [
// {
// "s": "sell",
// "p": "26386.00",
// "q": "0.00453",
// "t": 1686944282062,
// "tn" : 1704476468851524373,
// "d": "4611686018455979970",
// "i": "BTC_USD"
// },
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-candlestick
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(300)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("timeframe".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
if !is_equal(&limit, &Value::Null) {
if is_greater_than(&limit, &Value::Int(300)) {
limit = Value::Int(300);
}
add_element_to_object(&mut request, &Value::Str("count".to_string()), limit.clone());
}
let mut now: Value = self.microseconds();
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[now.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_ts".to_string()), subtract(&since, &multiply(&duration, &Value::Int(1000))));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_ts".to_string()), self.sum(&[since.clone(), multiply(&multiply(&duration, &limit), &Value::Int(1000))]));
} else {
add_element_to_object(&mut request, &Value::Str("end_ts".to_string()), until.clone());
}
} else {
add_element_to_object(&mut request, &Value::Str("end_ts".to_string()), until.clone());
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_public_get_public_get_candlestick(&[__ws_arg_3]).await;
//
// {
// "id": -1,
// "method": "public/get-candlestick",
// "code": 0,
// "result": {
// "interval": "1m",
// "data": [
// {
// "o": "26949.89",
// "h": "26957.64",
// "l": "26948.24",
// "c": "26950.00",
// "v": "0.0670",
// "t": 1687237080000
// },
// ],
// "instrument_name": "BTC_USD"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the number of order book entries to return, max 50
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if is_true(&(!is_equal(&limit, &Value::Null))) && is_true(&(!is_equal(&limit, &Value::Int(0)))) {
add_element_to_object(&mut request, &Value::Str("depth".to_string()), crate::runtime::Math::min(&limit, &Value::Int(50))); // max 50
}
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_public_get_public_get_book(&[__ws_arg_4]).await;
//
// {
// "id": -1,
// "method": "public/get-book",
// "code": 0,
// "result": {
// "depth": 3,
// "data": [
// {
// "bids": [ [ "30025.00", "0.00004", "1" ], [ "30020.15", "0.02498", "1" ], [ "30020.00", "0.00004", "1" ] ],
// "asks": [ [ "30025.01", "0.04090", "1" ], [ "30025.70", "0.01000", "1" ], [ "30026.94", "0.02681", "1" ] ],
// "t": 1687491287380
// }
// ],
// "instrument_name": "BTC_USD"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
let mut orderBook: Value = self.safe_value(data.clone(), Value::Int(0), &[]);
let mut timestamp: Value = self.safe_integer_k(orderBook.clone(), "t", &[]);
return self.parse_order_book(orderBook.clone(), symbol.clone(), &[timestamp.clone()]);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut responseResult: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(responseResult.clone(), "data", &[Value::List(vec![])]);
let mut positionBalances: Value = self.safe_value(get_value(&data, &Value::Int(0)), Value::Str("position_balances".to_string()), &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_592: bool = true;
while { if !__for_first_592 { i = add(&i, &Value::Int(1)); } __for_first_592 = false; is_less_than(&i, &get_array_length(&positionBalances)) } {
let mut balance: Value = get_value(&positionBalances, &i);
let mut balance: Value = get_value(&positionBalances, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "instrument_name", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "quantity", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "reserved_qty", &[]));
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 cryptocom#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-user-balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v1_private_post_private_user_balance(&[params.clone()]).await;
return self.parse_balance(response.clone());
Value::Null
}
/*
* @method
* @name cryptocom#fetchOrder
* @description fetches information on an order made by the user
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-detail
* @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(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id.clone());
m
});
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_order_detail(&[__ws_arg_5]).await;
//
// {
// "id": 1686872583882,
// "method": "private/get-order-detail",
// "code": 0,
// "result": {
// "account_id": "ae075bef-1234-4321-bd6g-bb9007252a63",
// "order_id": "6142909895025252686",
// "client_oid": "CCXT_c2d2152cc32d40a3ae7fbf",
// "order_type": "LIMIT",
// "time_in_force": "GOOD_TILL_CANCEL",
// "side": "BUY",
// "exec_inst": [ ],
// "quantity": "0.00020",
// "limit_price": "20000.00",
// "order_value": "4",
// "avg_price": "0",
// "trigger_price": "0",
// "ref_price": "0",
// "cumulative_quantity": "0",
// "cumulative_value": "0",
// "cumulative_fee": "0",
// "status": "ACTIVE",
// "update_user_id": "ae075bef-1234-4321-bd6g-bb9007252a63",
// "order_date": "2023-06-15",
// "instrument_name": "BTC_USD",
// "fee_instrument_name": "BTC",
// "create_time": 1686870220684,
// "create_time_ns": "1686870220684239675",
// "update_time": 1686870220684
// }
// }
//
let mut order: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
pub 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 uppercaseType: Value = to_upper(&type_var);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), to_upper(&side));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT_LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut broker: Value = self.safe_string_k(self.options.clone(), "broker", &[Value::Str("CCXT".to_string())]);
add_element_to_object(&mut request, &Value::Str("broker_id".to_string()), broker.clone());
let mut marketType: Value = Value::Null;
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("createOrder".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.custom_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_true(&(is_equal(&marketType, &Value::Str("margin".to_string())))) || is_true(&(!is_equal(&marginMode, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("spot_margin".to_string()), Value::Str("MARGIN".to_string()));
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
add_element_to_object(&mut request, &Value::Str("spot_margin".to_string()), Value::Str("SPOT".to_string()));
}
let mut timeInForce: Value = self.safe_string_upper2(params.clone(), Value::Str("timeInForce".to_string()), Value::Str("time_in_force".to_string()), &[]);
if !is_equal(&timeInForce, &Value::Null) {
if is_equal(&timeInForce, &Value::Str("GTC".to_string())) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("GOOD_TILL_CANCEL".to_string()));
} else if is_equal(&timeInForce, &Value::Str("IOC".to_string())) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("IMMEDIATE_OR_CANCEL".to_string()));
} else if is_equal(&timeInForce, &Value::Str("FOK".to_string())) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("FILL_OR_KILL".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), timeInForce.clone());
}
}
let mut postOnly: Value = self.safe_bool_k(params.clone(), "postOnly", &[Value::Bool(false)]);
if is_true(&(is_equal(&postOnly, &Value::Bool(true)))) || is_true(&(is_equal(&timeInForce, &Value::Str("PO".to_string())))) {
add_element_to_object(&mut request, &Value::Str("exec_inst".to_string()), Value::List(vec![Value::Str("POST_ONLY".to_string())]));
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("GOOD_TILL_CANCEL".to_string()));
}
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("ref_price".to_string())]), &[]);
let mut stopLossPrice: Value = self.safe_number_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_number_k(params.clone(), "takeProfitPrice", &[]);
let mut isTrigger: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossTrigger: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isTakeProfitTrigger: bool = !is_equal(&takeProfitPrice, &Value::Null);
if is_true(&isTrigger) {
add_element_to_object(&mut request, &Value::Str("ref_price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
let mut priceString: Value = self.number_to_string(price.clone());
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT_LIMIT".to_string())))) {
if is_equal(&side, &Value::Str("buy".to_string())) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LIMIT".to_string()));
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT_LIMIT".to_string()));
}
}
} else {
if is_equal(&side, &Value::Str("buy".to_string())) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LOSS".to_string()));
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LOSS".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT".to_string()));
}
}
}
} else if is_true(&isStopLossTrigger) {
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LOSS".to_string()));
}
add_element_to_object(&mut request, &Value::Str("ref_price".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
} else if is_true(&isTakeProfitTrigger) {
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT_LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT".to_string()));
}
add_element_to_object(&mut request, &Value::Str("ref_price".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), uppercaseType.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("postOnly".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("timeInForce".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 cryptocom#createOrder
* @description create a trade order
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market', 'limit', 'stop_loss', 'stop_limit', 'take_profit', 'take_profit_limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK' or 'PO'
* @param {string} [params.ref_price_type] 'MARK_PRICE', 'INDEX_PRICE', 'LAST_PRICE' which trigger price type to use, default is MARK_PRICE
* @param {float} [params.triggerPrice] price to trigger a trigger order
* @param {float} [params.stopLossPrice] price to trigger a stop-loss trigger order
* @param {float} [params.takeProfitPrice] price to trigger a take-profit trigger order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = self.v1_private_post_private_create_order(&[request.clone()]).await;
//
// {
// "id": 1686804664362,
// "method": "private/create-order",
// "code" : 0,
// "result": {
// "order_id": "6540219377766741832",
// "client_oid": "CCXT_d6ef7c3db6c1495aa8b757"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#createOrders
* @description create a list of trade orders
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-list
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-oco
* @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 exchange 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 i: Value = Value::Int(0);
let mut __for_first_593: bool = true;
while { if !__for_first_593 { i = add(&i, &Value::Int(1)); } __for_first_593 = 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 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_dict_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_advanced_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut contigency: Value = self.safe_string_k(params.clone(), "contingency_type", &[Value::Str("LIST".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contingency_type".to_string(), contigency.clone());
m.insert("order_list".to_string(), ordersRequests.clone());
m
});
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_create_order_list(&[__ws_arg_6]).await;
//
// {
// "id": 12,
// "method": "private/create-order-list",
// "code": 10001,
// "result": {
// "result_list": [
// {
// "index": 0,
// "code": 0,
// "order_id": "2015106383706015873",
// "client_oid": "my_order_0001"
// },
// {
// "index": 1,
// "code": 20007,
// "message": "INVALID_REQUEST",
// "client_oid": "my_order_0002"
// }
// ]
// }
// }
//
// {
// "id" : 1698068111133,
// "method" : "private/create-order-list",
// "code" : 0,
// "result" : [ {
// "code" : 0,
// "index" : 0,
// "client_oid" : "1698068111133_0",
// "order_id" : "6142909896519488206"
// }, {
// "code" : 306,
// "index" : 1,
// "client_oid" : "1698068111133_1",
// "message" : "INSUFFICIENT_AVAILABLE_BALANCE",
// "order_id" : "6142909896519488207"
// } ]
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::List(vec![])]);
let mut listId: Value = self.safe_string_k(result.clone(), "list_id", &[]);
if !is_equal(&listId, &Value::Null) {
let mut ocoOrders: Value = Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), listId.clone());
m
})]);
return self.parse_orders(ocoOrders.clone(), &[]);
}
return self.parse_orders(result.clone(), &[]);
Value::Null
}
pub fn create_advanced_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()))));
}
// differs slightly from createOrderRequest
// since the advanced order endpoint requires a different set of parameters
// namely here we don't support ref_price or spot_margin
// and market-buy orders need to send notional instead of quantity
let mut market: Value = self.market(symbol.clone());
let mut uppercaseType: Value = to_upper(&type_var);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), to_upper(&side));
m
});
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT_LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut broker: Value = self.safe_string_k(self.options.clone(), "broker", &[Value::Str("CCXT".to_string())]);
add_element_to_object(&mut request, &Value::Str("broker_id".to_string()), broker.clone());
let mut timeInForce: Value = self.safe_string_upper2(params.clone(), Value::Str("timeInForce".to_string()), Value::Str("time_in_force".to_string()), &[]);
if !is_equal(&timeInForce, &Value::Null) {
if is_equal(&timeInForce, &Value::Str("GTC".to_string())) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("GOOD_TILL_CANCEL".to_string()));
} else if is_equal(&timeInForce, &Value::Str("IOC".to_string())) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("IMMEDIATE_OR_CANCEL".to_string()));
} else if is_equal(&timeInForce, &Value::Str("FOK".to_string())) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("FILL_OR_KILL".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), timeInForce.clone());
}
}
let mut postOnly: Value = self.safe_bool_k(params.clone(), "postOnly", &[Value::Bool(false)]);
if is_true(&(is_equal(&postOnly, &Value::Bool(true)))) || is_true(&(is_equal(&timeInForce, &Value::Str("PO".to_string())))) {
add_element_to_object(&mut request, &Value::Str("exec_inst".to_string()), Value::List(vec![Value::Str("POST_ONLY".to_string())]));
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("GOOD_TILL_CANCEL".to_string()));
}
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("ref_price".to_string())]), &[]);
let mut stopLossPrice: Value = self.safe_number_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_number_k(params.clone(), "takeProfitPrice", &[]);
let mut isTrigger: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossTrigger: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isTakeProfitTrigger: bool = !is_equal(&takeProfitPrice, &Value::Null);
if is_true(&isTrigger) {
let mut priceString: Value = self.number_to_string(price.clone());
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT_LIMIT".to_string())))) {
if is_equal(&side, &Value::Str("buy".to_string())) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LIMIT".to_string()));
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT_LIMIT".to_string()));
}
}
} else {
if is_equal(&side, &Value::Str("buy".to_string())) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LOSS".to_string()));
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LOSS".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT".to_string()));
}
}
}
} else if is_true(&isStopLossTrigger) {
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_LOSS".to_string()));
}
} else if is_true(&isTakeProfitTrigger) {
if is_true(&(is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT_LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT_LIMIT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT".to_string()));
}
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), uppercaseType.clone());
}
if is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) && is_true(&(is_true(&(is_equal(&uppercaseType, &Value::Str("MARKET".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_LOSS".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT".to_string())))))) {
// use createmarketBuy logic here
let mut quoteAmount: Value = Value::Null;
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_number2(params.clone(), Value::Str("cost".to_string()), Value::Str("notional".to_string()), &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if !is_equal(&cost, &Value::Null) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost.clone());
} else if is_true(&createMarketBuyOrderRequiresPrice) {
if is_equal(&price, &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 (quote quantity) 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 costRequest: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
quoteAmount = self.cost_to_precision(symbol.clone(), costRequest.clone());
}
} else {
quoteAmount = self.cost_to_precision(symbol.clone(), amount.clone());
}
add_element_to_object(&mut request, &Value::Str("notional".to_string()), quoteAmount.clone());
} else {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("postOnly".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("timeInForce".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 cryptocom#editOrder
* @description edit a trade order
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-amend-order
* @param {string} id order id
* @param {string} symbol unified market symbol of the order to edit
* @param {string} [type] not used by cryptocom editOrder
* @param {string} [side] not used by cryptocom editOrder
* @param {float} amount (mandatory) how much of the currency you want to trade in units of the base currency
* @param {float} price (mandatory) the price for the order, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] the original client order id of the order to edit, required if id is not provided
* @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(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = self.edit_order_request(id.clone(), symbol.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = self.v1_private_post_private_amend_order(&[request.clone()]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result.clone(), &[]);
Value::Null
}
pub fn edit_order_request(&self, mut id: Value, mut symbol: 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
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&id, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), id.clone());
} else {
let mut originalClientOrderId: Value = self.safe_string2(params.clone(), Value::Str("orig_client_oid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if is_equal(&originalClientOrderId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires an id argument or orig_client_oid parameter".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("orig_client_oid".to_string()), originalClientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("orig_client_oid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
}
}
if is_true(&(is_equal(&amount, &Value::Null))) || is_true(&(is_equal(&price, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires both amount and price arguments. If you do not want to change the amount or price, you should pass the original values".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("new_quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
add_element_to_object(&mut request, &Value::Str("new_price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#cancelAllOrders
* @description cancel all open orders
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-all-orders
* @param {string} [symbol] unified market symbol of the orders to cancel
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} Returns exchange raw message{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_cancel_all_orders(&[__ws_arg_7]).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 cryptocom#cancelOrder
* @description cancels an open order
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order
* @param {string} id the order id of the order to cancel
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id.clone());
m
});
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_cancel_order(&[__ws_arg_8]).await;
//
// {
// "id": 1686882846638,
// "method": "private/cancel-order",
// "code": 0,
// "message": "NO_ERROR",
// "result": {
// "client_oid": "CCXT_c2d2152cc32d40a3ae7fbf",
// "order_id": "6142909895025252686"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#cancelOrders
* @description cancel multiple orders
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order-list-list
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&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 orderRequests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_594: bool = true;
while { if !__for_first_594 { i = add(&i, &Value::Int(1)); } __for_first_594 = false; is_less_than(&i, &get_array_length(&ids)) } {
let mut id: Value = get_value(&ids, &i);
let mut id: Value = get_value(&ids, &i);
let mut order: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("order_id".to_string(), to_string_val(&id));
m
});
append_to_array(&mut orderRequests, order.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contingency_type".to_string(), Value::Str("LIST".to_string()));
m.insert("order_list".to_string(), orderRequests.clone());
m
});
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_cancel_order_list(&[__ws_arg_9]).await;
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[market.clone(), Value::Null, Value::Null, params.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#cancelOrdersForSymbols
* @description cancel multiple orders for multiple symbols
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order-list-list
* @param {CancellationRequest[]} orders each order should contain the parameters required by cancelOrder namely id and symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders_for_symbols(&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 orderRequests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_595: bool = true;
while { if !__for_first_595 { i = add(&i, &Value::Int(1)); } __for_first_595 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = get_value(&orders, &i);
let mut order: Value = get_value(&orders, &i);
let mut id: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut market: Value = self.market(symbol.clone());
let mut orderItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("order_id".to_string(), to_string_val(&id));
m
});
append_to_array(&mut orderRequests, orderItem.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contingency_type".to_string(), Value::Str("LIST".to_string()));
m.insert("order_list".to_string(), orderRequests.clone());
m
});
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_cancel_order_list(&[__ws_arg_10]).await;
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[Value::Null, Value::Null, Value::Null, params.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-open-orders
* @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
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_open_orders(&[__ws_arg_11]).await;
//
// {
// "id": 1686806134961,
// "method": "private/get-open-orders",
// "code": 0,
// "result": {
// "data": [
// {
// "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
// "order_id": "6530219477767564494",
// "client_oid": "CCXT_7ce730f0388441df9bc218",
// "order_type": "LIMIT",
// "time_in_force": "GOOD_TILL_CANCEL",
// "side": "BUY",
// "exec_inst": [ ],
// "quantity": "0.00020",
// "limit_price": "20000.00",
// "order_value": "4",
// "avg_price": "0",
// "trigger_price": "0",
// "ref_price": "0",
// "cumulative_quantity": "0",
// "cumulative_value": "0",
// "cumulative_fee": "0",
// "status": "ACTIVE",
// "update_user_id": "ce075bef-1234-4321-bd6g-gg9007252e63",
// "order_date": "2023-06-15",
// "instrument_name": "BTC_USD",
// "fee_instrument_name": "BTC",
// "create_time": 1686806053992,
// "create_time_ns": "1686806053992921880",
// "update_time": 1686806053993
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchMyTrades
* @description fetch all trades made by the user
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-trades
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for, maximum date range is one day
* @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 for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {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(&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("fetchMyTrades".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_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Int(100)]).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("instrument_name".to_string()), get_value(&market, &Value::Str("id".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 mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_time".to_string()), until.clone());
}
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_trades(&[__ws_arg_12]).await;
//
// {
// "id": 1686942003520,
// "method": "private/get-trades",
// "code": 0,
// "result": {
// "data": [
// {
// "account_id": "ds075abc-1234-4321-bd6g-ff9007252r63",
// "event_date": "2023-06-16",
// "journal_type": "TRADING",
// "side": "BUY",
// "instrument_name": "BTC_USD",
// "fees": "-0.0000000525",
// "trade_id": "6142909898247428343",
// "trade_match_id": "4611686018455978480",
// "create_time": 1686941992887,
// "traded_price": "26347.16",
// "traded_quantity": "0.00021",
// "fee_instrument_name": "BTC",
// "client_oid": "d1c70a60-810e-4c92-b2a0-72b931cb31e0",
// "taker_side": "TAKER",
// "order_id": "6142909895036331486",
// "create_time_ns": "1686941992887207066"
// }
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_address(&self, mut addressString: Value) -> Value {
let mut address: Value = Value::Null;
let mut tag: Value = Value::Null;
let mut rawTag: Value = Value::Null;
if is_greater_than(&get_index_of(&addressString, &Value::Str("?".to_string())), &Value::Int(0)) {
{ let __destr_tmp = split(&addressString, &Value::Str("?".to_string())); address = get_value(&__destr_tmp, &Value::Int(0)); rawTag = get_value(&__destr_tmp, &Value::Int(1)); }
let mut splitted: Value = split(&rawTag, &Value::Str("=".to_string()));
tag = get_value(&splitted, &Value::Int(1));
} else {
address = addressString.clone();
}
return Value::List(vec![address.clone(), tag.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#withdraw
* @description make a withdrawal
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-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
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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)); }
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.safe_currency(code.clone(), &[]); // for instance, USDC is not inferred from markets but it's still available
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), amount.clone());
m.insert("address".to_string(), address.clone());
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("address_tag".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)); }
let mut networkId: Value = self.network_code_to_id(networkCode.clone(), &[code.clone()]);
if !is_equal(&networkId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("network_id".to_string()), networkId.clone());
}
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_create_withdrawal(&[__ws_arg_13]).await;
//
// {
// "id":-1,
// "method":"private/create-withdrawal",
// "code":0,
// "result": {
// "id": 2220,
// "amount": 1,
// "fee": 0.0004,
// "symbol": "BTC",
// "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
// "client_wid": "my_withdrawal_002",
// "create_time":1607063412000
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
return self.parse_transaction(result.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchDepositAddressesByNetwork
* @description fetch a dictionary of addresses for a currency, indexed by network
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-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
* @returns {object} a dictionary of [address structures]{@link https://docs.ccxt.com/?id=address-structure} indexed by the network
*/
pub async fn fetch_deposit_addresses_by_network(&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.safe_currency(code.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_deposit_address(&[__ws_arg_14]).await;
//
// {
// "id": 1234555011221,
// "method": "private/get-deposit-address",
// "code": 0,
// "result": {
// "deposit_address_list": [
// {
// "currency": "BTC",
// "create_time": 1686730755000,
// "id": "3737377",
// "address": "3N9afggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
// "status":"1",
// "network": "BTC"
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut addresses: Value = self.safe_list_k(data.clone(), "deposit_address_list", &[Value::List(vec![])]);
let mut addressesLength: Value = get_array_length(&addresses);
if is_equal(&addressesLength, &Value::Int(0)) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchDepositAddressesByNetwork() generating address...".to_string()))));
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_596: bool = true;
while { if !__for_first_596 { i = add(&i, &Value::Int(1)); } __for_first_596 = false; is_less_than(&i, &addressesLength) } {
let mut value: Value = self.safe_dict(addresses.clone(), i.clone(), &[]);
let mut addressString: Value = self.safe_string_k(value.clone(), "address", &[]);
let mut currencyId: Value = self.safe_string_k(value.clone(), "currency", &[]);
let mut responseCode: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut addresstagVariable = self.parse_address(addressString.clone());
let mut address: Value = get_value(&addresstagVariable, &Value::Int(0));
let mut tag: Value = get_value(&addresstagVariable, &Value::Int(1));
self.check_address(&[address.clone()]);
let mut networkId: Value = self.safe_string_k(value.clone(), "network", &[]);
let mut network: Value = self.network_id_to_code(&[networkId.clone(), responseCode.clone()]);
if !is_equal(&network, &Value::Null) {
add_element_to_object(&mut result, &network, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), value.clone());
m.insert("currency".to_string(), responseCode.clone());
m.insert("network".to_string(), network.clone());
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m
}));
}
}
}
return result;
Value::Null
}
/*
* @method
* @name cryptocom#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-deposit-address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut network: Value = self.safe_string_upper(params.clone(), Value::Str("network".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("network".to_string())]), &[]);
let mut depositAddressesRaw: Value = self.fetch_deposit_addresses_by_network(code.clone(), &[params.clone()]).await;
let mut depositAddresses: Value = depositAddressesRaw.clone();
if is_true(&Value::Bool(in_op(&depositAddresses, &network))) {
return get_value(&depositAddresses, &network);
}
let mut keys: Value = object_keys(&depositAddresses);
return get_value(&depositAddresses, &get_value(&keys, &Value::Int(0)));
Value::Null
}
/*
* @method
* @name cryptocom#fetchDeposits
* @description fetch all deposits made to an account
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-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 deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @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 currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&code, &Value::Null) {
currency = self.safe_currency(code.clone(), &[]);
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
// 90 days date range
add_element_to_object(&mut request, &Value::Str("start_ts".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_ts".to_string()), until.clone());
}
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_deposit_history(&[__ws_arg_15]).await;
//
// {
// "id": 1688701375714,
// "method": "private/get-deposit-history",
// "code": 0,
// "result": {
// "deposit_list": [
// {
// "currency": "BTC",
// "fee": 0,
// "create_time": 1688023659000,
// "id": "6201135",
// "update_time": 1688178509000,
// "amount": 0.00114571,
// "address": "1234fggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
// "status": "1",
// "txid": "f0ae4202b76eb999c301eccdde44dc639bee42d1fdd5974105286ca3393f6065/2"
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut depositList: Value = self.safe_list_k(data.clone(), "deposit_list", &[Value::List(vec![])]);
return self.parse_transactions(depositList.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-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 withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @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 currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&code, &Value::Null) {
currency = self.safe_currency(code.clone(), &[]);
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
// 90 days date range
add_element_to_object(&mut request, &Value::Str("start_ts".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_ts".to_string()), until.clone());
}
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_withdrawal_history(&[__ws_arg_16]).await;
//
// {
// "id": 1688613879534,
// "method": "private/get-withdrawal-history",
// "code": 0,
// "result": {
// "withdrawal_list": [
// {
// "currency": "BTC",
// "client_wid": "",
// "fee": 0.0005,
// "create_time": 1688613850000,
// "id": "5275977",
// "update_time": 1688613850000,
// "amount": 0.0005,
// "address": "1234NMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn",
// "status": "1",
// "txid": "",
// "network_id": "BTC"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut withdrawalList: Value = self.safe_list_k(data.clone(), "withdrawal_list", &[Value::List(vec![])]);
return self.parse_transactions(withdrawalList.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTicker
//
// {
// "i": "BTC_USD",
// "h": "30821.45",
// "l": "28685.11",
// "a": "30446.00",
// "v": "1767.8734",
// "vv": "52436726.42",
// "c": "0.0583",
// "b": "30442.00",
// "k": "30447.66",
// "t": 1687403045415
// }
//
// fetchTickers
//
// {
// "i": "AVAXUSD-PERP",
// "h": "13.209",
// "l": "12.148",
// "a": "13.209",
// "v": "1109.8",
// "vv": "14017.33",
// "c": "0.0732",
// "b": "13.210",
// "k": "13.230",
// "oi": "10888.9",
// "t": 1687402657575
// }
//
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "i", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string())]);
let mut last: Value = self.safe_string_k(ticker.clone(), "a", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_number_k(ticker.clone(), "h", &[]));
m.insert("low".to_string(), self.safe_number_k(ticker.clone(), "l", &[]));
m.insert("bid".to_string(), self.safe_number_k(ticker.clone(), "b", &[]));
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), self.safe_number_k(ticker.clone(), "k", &[]));
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), self.safe_string_k(ticker.clone(), "c", &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "v", &[]));
m.insert("quoteVolume".to_string(), ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("quote".to_string())), &Value::Str("USD".to_string())))), self.safe_string_k(ticker.clone(), "vv", &[]), Value::Null));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades
//
// {
// "s": "sell",
// "p": "26386.00",
// "q": "0.00453",
// "tn": 1686944282062,
// "tn": 1704476468851524373,
// "d": "4611686018455979970",
// "i": "BTC_USD"
// }
//
// fetchMyTrades
//
// {
// "account_id": "ds075abc-1234-4321-bd6g-ff9007252r63",
// "event_date": "2023-06-16",
// "journal_type": "TRADING",
// "side": "BUY",
// "instrument_name": "BTC_USD",
// "fees": "-0.0000000525",
// "trade_id": "6142909898247428343",
// "trade_match_id": "4611686018455978480",
// "create_time": 1686941992887,
// "traded_price": "26347.16",
// "traded_quantity": "0.00021",
// "fee_instrument_name": "BTC",
// "client_oid": "d1c70a60-1234-4c92-b2a0-72b931cb31e0",
// "taker_side": "TAKER",
// "order_id": "6142909895036331486",
// "create_time_ns": "1686941992887207066"
// }
//
let mut timestamp: Value = self.safe_integer2(trade.clone(), Value::Str("t".to_string()), Value::Str("create_time".to_string()), &[]);
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("i".to_string()), Value::Str("instrument_name".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string())]);
let mut feeCurrency: Value = self.safe_string_k(trade.clone(), "fee_instrument_name", &[]);
let mut feeCostString: Value = self.safe_string_k(trade.clone(), "fees", &[]);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("d".to_string()), Value::Str("trade_id".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "order_id", &[]));
m.insert("side".to_string(), self.safe_string_lower2(trade.clone(), Value::Str("s".to_string()), Value::Str("side".to_string()), &[]));
m.insert("takerOrMaker".to_string(), self.safe_string_lower(trade.clone(), Value::Str("taker_side".to_string()), &[]));
m.insert("price".to_string(), self.safe_number2(trade.clone(), Value::Str("p".to_string()), Value::Str("traded_price".to_string()), &[]));
m.insert("amount".to_string(), self.safe_number2(trade.clone(), Value::Str("q".to_string()), Value::Str("traded_quantity".to_string()), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(feeCurrency.clone(), &[]));
m.insert("cost".to_string(), self.parse_number(crate::precise::Precise::stringNeg(&feeCostString), &[]));
m
}));
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_integer_k(ohlcv.clone(), "t", &[]), self.safe_number_k(ohlcv.clone(), "o", &[]), self.safe_number_k(ohlcv.clone(), "h", &[]), self.safe_number_k(ohlcv.clone(), "l", &[]), self.safe_number_k(ohlcv.clone(), "c", &[]), self.safe_number_k(ohlcv.clone(), "v", &[])]);
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("ACTIVE".to_string(), Value::Str("open".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("FILLED".to_string(), Value::Str("closed".to_string()));
m.insert("REJECTED".to_string(), Value::Str("rejected".to_string()));
m.insert("EXPIRED".to_string(), Value::Str("expired".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GOOD_TILL_CANCEL".to_string(), Value::Str("GTC".to_string()));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Str("IOC".to_string()));
m.insert("FILL_OR_KILL".to_string(), Value::Str("FOK".to_string()));
m
});
return self.safe_string(timeInForces.clone(), timeInForce.clone(), &[timeInForce.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder, cancelOrder
//
// {
// "order_id": "6540219377766741832",
// "client_oid": "CCXT_d6ef7c3db6c1495aa8b757"
// }
//
// fetchOpenOrders, fetchOrder, fetchOrders
//
// {
// "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
// "order_id": "6530219477767564494",
// "client_oid": "CCXT_7ce730f0388441df9bc218",
// "order_type": "LIMIT",
// "time_in_force": "GOOD_TILL_CANCEL",
// "side": "BUY",
// "exec_inst": [ ],
// "quantity": "0.00020",
// "limit_price": "20000.00",
// "order_value": "4",
// "avg_price": "0",
// "trigger_price": "0",
// "ref_price": "0",
// "cumulative_quantity": "0",
// "cumulative_value": "0",
// "cumulative_fee": "0",
// "status": "ACTIVE",
// "update_user_id": "ce075bef-1234-4321-bd6g-gg9007252e63",
// "order_date": "2023-06-15",
// "instrument_name": "BTC_USD",
// "fee_instrument_name": "BTC",
// "create_time": 1686806053992,
// "create_time_ns": "1686806053992921880",
// "update_time": 1686806053993
// }
//
// createOrders
// {
// "code" : 306,
// "index" : 1,
// "client_oid" : "1698068111133_1",
// "message" : "INSUFFICIENT_AVAILABLE_BALANCE",
// "order_id" : "6142909896519488207"
// }
//
let mut code: Value = self.safe_integer_k(order.clone(), "code", &[]);
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(!is_equal(&code, &Value::Int(0)))) {
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client_oid", &[]));
m.insert("info".to_string(), order.clone());
m.insert("status".to_string(), Value::Str("rejected".to_string()));
m
}), &[]);
}
let mut created: Value = self.safe_integer_k(order.clone(), "create_time", &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "instrument_name", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut execInst: Value = self.safe_value_k(order.clone(), "exec_inst", &[]);
let mut postOnly: Value = Value::Null;
if !is_equal(&execInst, &Value::Null) {
postOnly = Value::Bool(false);
{
let mut i: Value = Value::Int(0);
let mut __for_first_597: bool = true;
while { if !__for_first_597 { i = add(&i, &Value::Int(1)); } __for_first_597 = false; is_less_than(&i, &get_array_length(&execInst)) } {
let mut inst: Value = get_value(&execInst, &i);
let mut inst: Value = get_value(&execInst, &i);
if is_equal(&inst, &Value::Str("POST_ONLY".to_string())) {
postOnly = Value::Bool(true);
break;
}
}
}
}
let mut feeCurrency: Value = self.safe_string_k(order.clone(), "fee_instrument_name", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client_oid", &[]));
m.insert("timestamp".to_string(), created.clone());
m.insert("datetime".to_string(), self.iso8601(created.clone()));
m.insert("lastTradeTimestamp".to_string(), self.safe_integer_k(order.clone(), "update_time", &[]));
m.insert("status".to_string(), self.parse_order_status(self.safe_string_k(order.clone(), "status", &[])));
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), self.safe_string_lower(order.clone(), Value::Str("order_type".to_string()), &[]));
m.insert("timeInForce".to_string(), self.parse_time_in_force(self.safe_string_k(order.clone(), "time_in_force", &[])));
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("side".to_string(), self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]));
m.insert("price".to_string(), self.safe_number_k(order.clone(), "limit_price", &[]));
m.insert("amount".to_string(), self.safe_number_k(order.clone(), "quantity", &[]));
m.insert("filled".to_string(), self.safe_number_k(order.clone(), "cumulative_quantity", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("average".to_string(), self.safe_number_k(order.clone(), "avg_price", &[]));
m.insert("cost".to_string(), self.safe_number_k(order.clone(), "cumulative_value", &[]));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(feeCurrency.clone(), &[]));
m.insert("cost".to_string(), self.safe_number_k(order.clone(), "cumulative_fee", &[]));
m
}));
m.insert("trades".to_string(), Value::List(vec![]));
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_deposit_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("pending".to_string()));
m.insert("1".to_string(), Value::Str("ok".to_string()));
m.insert("2".to_string(), Value::Str("failed".to_string()));
m.insert("3".to_string(), Value::Str("pending".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_withdrawal_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("pending".to_string()));
m.insert("1".to_string(), Value::Str("pending".to_string()));
m.insert("2".to_string(), Value::Str("failed".to_string()));
m.insert("3".to_string(), Value::Str("pending".to_string()));
m.insert("4".to_string(), Value::Str("failed".to_string()));
m.insert("5".to_string(), Value::Str("ok".to_string()));
m.insert("6".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.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
//
// {
// "currency": "BTC",
// "fee": 0,
// "create_time": 1688023659000,
// "id": "6201135",
// "update_time": 1688178509000,
// "amount": 0.00114571,
// "address": "1234fggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
// "status": "1",
// "txid": "f0ae4202b76eb999c301eccdde44dc639bee42d1fdd5974105286ca3393f6065/2"
// }
//
// fetchWithdrawals
//
// {
// "currency": "BTC",
// "client_wid": "",
// "fee": 0.0005,
// "create_time": 1688613850000,
// "id": "5775977",
// "update_time": 1688613850000,
// "amount": 0.0005,
// "address": "1234NMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn",
// "status": "1",
// "txid": "",
// "network_id": "BTC"
// }
//
// withdraw
//
// {
// "id": 2220,
// "amount": 1,
// "fee": 0.0004,
// "symbol": "BTC",
// "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
// "client_wid": "my_withdrawal_002",
// "create_time":1607063412000
// }
//
let mut type_var: Value = Value::Null;
let mut rawStatus: Value = self.safe_string_k(transaction.clone(), "status", &[]);
let mut status: Value = Value::Null;
if is_true(&Value::Bool(in_op(&transaction, &Value::Str("client_wid".to_string())))) {
type_var = Value::Str("withdrawal".to_string());
status = self.parse_withdrawal_status(rawStatus.clone());
} else {
type_var = Value::Str("deposit".to_string());
status = self.parse_deposit_status(rawStatus.clone());
}
let mut addressString: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut addresstagVariable = self.parse_address(addressString.clone());
let mut address: Value = get_value(&addresstagVariable, &Value::Int(0));
let mut tag: Value = get_value(&addresstagVariable, &Value::Int(1));
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "create_time", &[]);
let mut feeCost: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
let mut fee: Value = Value::Null;
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("cost".to_string(), feeCost.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_string_k(transaction.clone(), "id", &[]));
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "txid", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), 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(), tag.clone());
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), status.clone());
m.insert("updated".to_string(), self.safe_integer_k(transaction.clone(), "update_time", &[]));
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), self.safe_string_k(transaction.clone(), "client_wid", &[]));
m.insert("fee".to_string(), fee.clone());
m
});
Value::Null
}
pub fn custom_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
}));
/*
* @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)]);
params = self.omit(params.clone(), Value::Str("margin".to_string()), &[]);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(methodName.clone(), &[params.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_equal(&marginMode, &Value::Str("cross".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" only cross margin is supported".to_string()))));
}
} else {
if is_true(&(is_equal(&defaultType, &Value::Str("margin".to_string())))) || is_true(&(is_equal(&isMargin, &Value::Bool(true)))) {
marginMode = Value::Str("cross".to_string());
}
}
return Value::List(vec![marginMode.clone(), params.clone()]);
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);
//
// {
// "full_name": "Alchemix",
// "default_network": "ETH",
// "network_list": [
// {
// "network_id": "ETH",
// "withdrawal_fee": "0.25000000",
// "withdraw_enabled": true,
// "min_withdrawal_amount": "0.5",
// "deposit_enabled": true,
// "confirmation_required": "0"
// }
// ]
// }
//
let mut networkList: Value = self.safe_list_k(fee.clone(), "network_list", &[Value::List(vec![])]);
let mut networkListLength: Value = get_array_length(&networkList);
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
});
if !is_equal(&networkList, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_598: bool = true;
while { if !__for_first_598 { i = add(&i, &Value::Int(1)); } __for_first_598 = false; is_less_than(&i, &networkListLength) } {
let mut networkInfo: Value = get_value(&networkList, &i);
let mut networkInfo: Value = get_value(&networkList, &i);
let mut networkId: Value = self.safe_string_k(networkInfo.clone(), "network_id", &[]);
let mut currencyCode: Value = self.safe_string_k(currency.clone(), "code", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), currencyCode.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("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("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), self.safe_number_k(networkInfo.clone(), "withdrawal_fee", &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m
}));
}
if is_equal(&networkListLength, &Value::Int(1)) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".to_string())), &Value::Str("fee".to_string()), self.safe_number_k(networkInfo.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));
}
}
}
}
return result;
Value::Null
}
/*
* @method
* @name cryptocom#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-currency-networks
* @param {string[]|undefined} codes list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list 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.v1_private_post_private_get_currency_networks(&[params.clone()]).await;
let mut data: Value = self.safe_value_k(response.clone(), "result", &[]);
let mut currencyMap: Value = self.safe_list_k(data.clone(), "currency_map", &[]);
return self.parse_deposit_withdraw_fees(currencyMap.clone(), &[codes.clone(), Value::Str("full_name".to_string())]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-transactions
* @param {string} [code] unified currency code
* @param {int} [since] timestamp in ms of the earliest ledger entry
* @param {int} [limit] max number of ledger entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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.safe_currency(code.clone(), &[]);
}
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 mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_time".to_string()), until.clone());
}
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_transactions(&[__ws_arg_17]).await;
//
// {
// "id": 1686813195698,
// "method": "private/get-transactions",
// "code": 0,
// "result": {
// "data": [
// {
// "account_id": "ce075cef-1234-4321-bd6e-gf9007351e64",
// "event_date": "2023-06-15",
// "journal_type": "TRADING",
// "journal_id": "6530219460124075091",
// "transaction_qty": "6.0091224",
// "transaction_cost": "6.0091224",
// "realized_pnl": "0",
// "order_id": "6530219477766741833",
// "trade_id": "6530219495775954765",
// "trade_match_id": "4611686018455865176",
// "event_timestamp_ms": 1686804665013,
// "event_timestamp_ns": "1686804665013642422",
// "client_oid": "CCXT_d6ea7c5db6c1495aa8b758",
// "taker_side": "",
// "side": "BUY",
// "instrument_name": "USD"
// },
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ledger: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
return self.parse_ledger(ledger.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "account_id": "ce075cef-1234-4321-bd6e-gf9007351e64",
// "event_date": "2023-06-15",
// "journal_type": "TRADING",
// "journal_id": "6530219460124075091",
// "transaction_qty": "6.0091224",
// "transaction_cost": "6.0091224",
// "realized_pnl": "0",
// "order_id": "6530219477766741833",
// "trade_id": "6530219495775954765",
// "trade_match_id": "4611686018455865176",
// "event_timestamp_ms": 1686804665013,
// "event_timestamp_ns": "1686804665013642422",
// "client_oid": "CCXT_d6ea7c5db6c1495aa8b758",
// "taker_side": "",
// "side": "BUY",
// "instrument_name": "USD"
// }
//
let mut timestamp: Value = self.safe_integer_k(item.clone(), "event_timestamp_ms", &[]);
let mut currencyId: Value = self.safe_string_k(item.clone(), "instrument_name", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut amount: Value = self.safe_string_k(item.clone(), "transaction_qty", &[]);
let mut direction: Value = Value::Null;
if is_true(&crate::precise::Precise::stringLt(&amount, &Value::Str("0".to_string()))) {
direction = Value::Str("out".to_string());
amount = crate::precise::Precise::stringAbs(&amount);
} else {
direction = Value::Str("in".to_string());
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string_k(item.clone(), "order_id", &[]));
m.insert("direction".to_string(), direction.clone());
m.insert("account".to_string(), self.safe_string_k(item.clone(), "account_id", &[]));
m.insert("referenceId".to_string(), self.safe_string_k(item.clone(), "trade_id", &[]));
m.insert("referenceAccount".to_string(), self.safe_string_k(item.clone(), "trade_match_id", &[]));
m.insert("type".to_string(), self.parse_ledger_entry_type(self.safe_string_k(item.clone(), "journal_type", &[])));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m
}));
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut ledgerType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TRADING".to_string(), Value::Str("trade".to_string()));
m.insert("TRADE_FEE".to_string(), Value::Str("fee".to_string()));
m.insert("WITHDRAW_FEE".to_string(), Value::Str("fee".to_string()));
m.insert("WITHDRAW".to_string(), Value::Str("withdrawal".to_string()));
m.insert("DEPOSIT".to_string(), Value::Str("deposit".to_string()));
m.insert("ROLLBACK_WITHDRAW".to_string(), Value::Str("rollback".to_string()));
m.insert("ROLLBACK_DEPOSIT".to_string(), Value::Str("rollback".to_string()));
m.insert("FUNDING".to_string(), Value::Str("fee".to_string()));
m.insert("REALIZED_PNL".to_string(), Value::Str("trade".to_string()));
m.insert("INSURANCE_FUND".to_string(), Value::Str("insurance".to_string()));
m.insert("SOCIALIZED_LOSS".to_string(), Value::Str("trade".to_string()));
m.insert("LIQUIDATION_FEE".to_string(), Value::Str("fee".to_string()));
m.insert("SESSION_RESET".to_string(), Value::Str("reset".to_string()));
m.insert("ADJUSTMENT".to_string(), Value::Str("adjustment".to_string()));
m.insert("SESSION_SETTLE".to_string(), Value::Str("settlement".to_string()));
m.insert("UNCOVERED_LOSS".to_string(), Value::Str("trade".to_string()));
m.insert("ADMIN_ADJUSTMENT".to_string(), Value::Str("adjustment".to_string()));
m.insert("DELIST".to_string(), Value::Str("delist".to_string()));
m.insert("SETTLEMENT_FEE".to_string(), Value::Str("fee".to_string()));
m.insert("AUTO_CONVERSION".to_string(), Value::Str("conversion".to_string()));
m.insert("MANUAL_CONVERSION".to_string(), Value::Str("conversion".to_string()));
m
});
return self.safe_string(ledgerType.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-accounts
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/?id=account-structure} indexed by the account type
*/
pub async fn fetch_accounts(&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.v1_private_post_private_get_accounts(&[params.clone()]).await;
//
// {
// "id": 1234567894321,
// "method": "private/get-accounts",
// "code": 0,
// "result": {
// "master_account": {
// "uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
// "user_uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
// "enabled": true,
// "tradable": true,
// "name": "YOUR_NAME",
// "country_code": "CAN",
// "phone_country_code": "CAN",
// "incorp_country_code": "",
// "margin_access": "DEFAULT",
// "derivatives_access": "DEFAULT",
// "create_time": 1656445188000,
// "update_time": 1660794567262,
// "two_fa_enabled": true,
// "kyc_level": "ADVANCED",
// "suspended": false,
// "terminated": false,
// "spot_enabled": false,
// "margin_enabled": false,
// "derivatives_enabled": false
// },
// "sub_account_list": []
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut masterAccount: Value = self.safe_dict_k(result.clone(), "master_account", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut accounts: Value = self.safe_list_k(result.clone(), "sub_account_list", &[Value::List(vec![])]);
append_to_array(&mut accounts, masterAccount.clone());
return self.parse_accounts(accounts.clone(), &[params.clone()]);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(account.clone(), "uuid", &[]));
m.insert("type".to_string(), self.safe_string_k(account.clone(), "label", &[]));
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), account.clone());
m
});
Value::Null
}
/*
* @method
* @name cryptocom#fetchSettlementHistory
* @description fetches historical settlement records
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-expired-settlement-price
* @param {string} symbol unified market symbol of the settlement history
* @param {int} [since] timestamp in ms
* @param {int} [limit] number of records
* @param {object} [params] exchange specific params
* @param {int} [params.type] 'future', 'option'
* @returns {object[]} a list of [settlement history objects]{@link https://docs.ccxt.com/?id=settlement-history-structure}
*/
pub async fn fetch_settlement_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchSettlementHistory".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
self.check_required_argument(Value::Str("fetchSettlementHistory".to_string()), type_var.clone(), Value::Str("type".to_string()), &[Value::List(vec![Value::Str("future".to_string()), Value::Str("option".to_string()), Value::Str("WARRANT".to_string()), Value::Str("FUTURE".to_string())])]);
if is_equal(&type_var, &Value::Str("option".to_string())) {
type_var = Value::Str("WARRANT".to_string());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_type".to_string(), to_upper(&type_var));
m
});
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_public_get_public_get_expired_settlement_price(&[__ws_arg_18]).await;
//
// {
// "id": -1,
// "method": "public/get-expired-settlement-price",
// "code": 0,
// "result": {
// "data": [
// {
// "i": "BTCUSD-230526",
// "x": 1685088000000,
// "v": "26464.1",
// "t": 1685087999500
// }
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
let mut settlements: Value = self.parse_settlements(data.clone(), market.clone());
let mut sorted: Value = self.sort_by(settlements.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_settlement(&self, mut settlement: Value, mut market: Value) -> Value {
//
// {
// "i": "BTCUSD-230526",
// "x": 1685088000000,
// "v": "26464.1",
// "t": 1685087999500
// }
//
let mut timestamp: Value = self.safe_integer_k(settlement.clone(), "x", &[]);
let mut marketId: Value = self.safe_string_k(settlement.clone(), "i", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), settlement.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("price".to_string(), self.safe_number_k(settlement.clone(), "v", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
pub fn parse_settlements(&self, mut settlements: Value, mut market: Value) -> Value {
//
// [
// {
// "i": "BTCUSD-230526",
// "x": 1685088000000,
// "v": "26464.1",
// "t": 1685087999500
// }
// ]
//
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_599: bool = true;
while { if !__for_first_599 { i = add(&i, &Value::Int(1)); } __for_first_599 = false; is_less_than(&i, &get_array_length(&settlements)) } {
append_to_array(&mut result, self.parse_settlement(get_value(&settlements, &i), market.clone()));
}
}
return result;
Value::Null
}
/*
* @method
* @name cryptocom#fetchFundingRate
* @description fetches historical funding rates
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-valuations
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-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("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("valuation_type".to_string(), Value::Str("estimated_funding_rate".to_string()));
m.insert("count".to_string(), Value::Int(1));
m
});
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_public_get_public_get_valuations(&[__ws_arg_19]).await;
//
// {
// "id": -1,
// "method": "public/get-valuations",
// "code": 0,
// "result": {
// "data": [
// {
// "v": "-0.000001884",
// "t": 1687892400000
// },
// ],
// "instrument_name": "BTCUSD-PERP"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
let mut entry: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(entry.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "v": "-0.000001884",
// "t": 1687892400000
// },
//
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "t", &[]);
let mut fundingTimestamp: Value = Value::Null;
if !is_equal(×tamp, &Value::Null) {
fundingTimestamp = multiply(&math_ceil(÷(×tamp, &Value::Int(3600000))), &Value::Int(3600000)); // end of the next hour
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(Value::Null, &[market.clone()]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "v", &[]));
m.insert("fundingTimestamp".to_string(), fundingTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTimestamp.clone()));
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), Value::Null);
m.insert("nextFundingDatetime".to_string(), Value::Null);
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), Value::Str("1h".to_string()));
m
});
Value::Null
}
/*
* @method
* @name cryptocom#fetchFundingRateHistory
* @description fetches historical funding rates
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-valuations
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures] to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&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()]).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(" fetchFundingRateHistory() supports swap contracts only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("valuation_type".to_string(), Value::Str("funding_hist".to_string()));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_ts".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("count".to_string()), limit.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end_ts".to_string()), until.clone());
}
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_public_get_public_get_valuations(&[__ws_arg_20]).await;
//
// {
// "id": -1,
// "method": "public/get-valuations",
// "code": 0,
// "result": {
// "data": [
// {
// "v": "-0.000001884",
// "t": 1687892400000
// },
// ],
// "instrument_name": "BTCUSD-PERP"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
let mut marketId: Value = self.safe_string_k(result.clone(), "instrument_name", &[]);
let mut rates: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_600: bool = true;
while { if !__for_first_600 { i = add(&i, &Value::Int(1)); } __for_first_600 = 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(), "t", &[]);
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(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "v", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchPosition
* @description fetch data on a single open contract trade position
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions
* @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("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_positions(&[__ws_arg_21]).await;
//
// {
// "id": 1688015952050,
// "method": "private/get-positions",
// "code": 0,
// "result": {
// "data": [
// {
// "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
// "quantity": "0.0001",
// "cost": "3.02392",
// "open_pos_cost": "3.02392",
// "open_position_pnl": "-0.0010281328",
// "session_pnl": "-0.0010281328",
// "update_timestamp_ms": 1688015919091,
// "instrument_name": "BTCUSD-PERP",
// "type": "PERPETUAL_SWAP"
// }
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::List(vec![])]);
return self.parse_position(self.safe_dict(data.clone(), Value::Int(0), &[]), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchPositions
* @description fetch all open positions
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position 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;
}
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 = 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("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_positions(&[__ws_arg_22]).await;
//
// {
// "id": 1688015952050,
// "method": "private/get-positions",
// "code": 0,
// "result": {
// "data": [
// {
// "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
// "quantity": "0.0001",
// "cost": "3.02392",
// "open_pos_cost": "3.02392",
// "open_position_pnl": "-0.0010281328",
// "session_pnl": "-0.0010281328",
// "update_timestamp_ms": 1688015919091,
// "instrument_name": "BTCUSD-PERP",
// "type": "PERPETUAL_SWAP"
// }
// ]
// }
// }
//
let mut responseResult: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positions: Value = self.safe_list_k(responseResult.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_601: bool = true;
while { if !__for_first_601 { i = add(&i, &Value::Int(1)); } __for_first_601 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut entry: Value = get_value(&positions, &i);
let mut entry: Value = get_value(&positions, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "instrument_name", &[]);
let mut marketInner: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, Value::Str("contract".to_string())]);
append_to_array(&mut result, self.parse_position(entry.clone(), &[marketInner.clone()]));
}
}
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[Value::Null, Value::Bool(false)]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
// "quantity": "0.0001",
// "cost": "3.02392",
// "open_pos_cost": "3.02392",
// "open_position_pnl": "-0.0010281328",
// "session_pnl": "-0.0010281328",
// "update_timestamp_ms": 1688015919091,
// "instrument_name": "BTCUSD-PERP",
// "type": "PERPETUAL_SWAP"
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "instrument_name", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "update_timestamp_ms", &[]);
let mut amount: Value = self.safe_string_k(position.clone(), "quantity", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("hedged".to_string(), Value::Null);
m.insert("side".to_string(), ternary(is_true(&crate::precise::Precise::stringGt(&amount, &Value::Str("0".to_string()))), Value::Str("long".to_string()), Value::Str("short".to_string())));
m.insert("contracts".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&amount), &[]));
m.insert("contractSize".to_string(), get_value(&market, &Value::Str("contractSize".to_string())));
m.insert("entryPrice".to_string(), Value::Null);
m.insert("markPrice".to_string(), Value::Null);
m.insert("notional".to_string(), Value::Null);
m.insert("leverage".to_string(), Value::Null);
m.insert("collateral".to_string(), self.safe_number_k(position.clone(), "open_pos_cost", &[]));
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "cost", &[]));
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "open_position_pnl", &[]));
m.insert("liquidationPrice".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn nonce(&self) -> Value {
return self.milliseconds();
Value::Null
}
pub fn params_to_string(&self, mut object: Value, mut level: Value) -> Value {
let mut maxLevel: Value = Value::Int(3);
if is_greater_than_or_equal(&level, &maxLevel) {
return to_string_val(&object);
}
if is_string(&object) {
return object;
}
let mut returnString: Value = Value::Str("".to_string());
let mut paramsKeys: Value = Value::Null;
if is_true(&Value::Bool(is_array(&object))) {
paramsKeys = object.clone();
} else {
let mut objectKeys: Value = object_keys(&object);
paramsKeys = self.sort(objectKeys.clone(), &[]);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_603: bool = true;
while { if !__for_first_603 { i = add(&i, &Value::Int(1)); } __for_first_603 = false; is_less_than(&i, &get_array_length(¶msKeys)) } {
let mut key: Value = get_value(¶msKeys, &i);
let mut key: Value = get_value(¶msKeys, &i);
returnString = add(&returnString, &key);
let mut value: Value = get_value(&object, &key);
let mut value: Value = get_value(&object, &key);
if is_equal(&value, &Value::Str("undefined".to_string())) {
returnString = add(&returnString, &Value::Str("null".to_string()));
} else if is_true(&Value::Bool(is_array(&value))) {
{
let mut j: Value = Value::Int(0);
let mut __for_first_602: bool = true;
while { if !__for_first_602 { j = add(&j, &Value::Int(1)); } __for_first_602 = false; is_less_than(&j, &get_array_length(&value)) } {
returnString = add(&returnString, &self.params_to_string(get_value(&value, &j), add(&level, &Value::Int(1))));
}
}
} else {
returnString = add(&returnString, &to_string_val(&value));
}
}
}
return returnString;
Value::Null
}
/*
* @method
* @name cryptocom#closePositions
* @description closes open positions for a market
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
* @param {string} symbol Unified CCXT market symbol
* @param {string} [side] not used by cryptocom.closePositions
* @param {object} [params] extra parameters specific to the exchange API endpoint
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {string} [params.type] LIMIT or MARKET
* @param {number} [params.price] for limit orders only
* @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/?id=position-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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("type".to_string(), Value::Str("MARKET".to_string()));
m
});
let mut type_var: Value = self.safe_string_upper(params.clone(), Value::Str("type".to_string()), &[]);
let mut price: Value = self.safe_string_k(params.clone(), "price", &[]);
if !is_equal(&type_var, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), type_var.clone());
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(get_value(&market, &Value::Str("symbol".to_string())), price.clone()));
}
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_close_position(&[__ws_arg_23]).await;
//
// {
// "id" : 1700830813298,
// "method" : "private/close-position",
// "code" : 0,
// "result" : {
// "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
// "order_id" : "6142909897021751347"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-instrument-fee-rate
* @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("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v1_private_post_private_get_instrument_fee_rate(&[__ws_arg_24]).await;
//
// {
// "id": 1,
// "code": 0,
// "method": "private/staking/unstake",
// "result": {
// "staking_id": "1",
// "instrument_name": "SOL.staked",
// "status": "NEW",
// "quantity": "1",
// "underlying_inst_name": "SOL",
// "reason": "NO_ERROR"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptocom#fetchTradingFees
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-fee-rate
* @description fetch the trading fees for multiple markets
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v1_private_post_private_get_fee_rate(&[params.clone()]).await;
//
// {
// "id": 1,
// "method": "/private/get-fee-rate",
// "code": 0,
// "result": {
// "spot_tier": "3",
// "deriv_tier": "3",
// "effective_spot_maker_rate_bps": "6.5",
// "effective_spot_taker_rate_bps": "6.9",
// "effective_deriv_maker_rate_bps": "1.1",
// "effective_deriv_taker_rate_bps": "3"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fees(result.clone());
Value::Null
}
pub fn parse_trading_fees(&self, mut response: Value) -> Value {
//
// {
// "spot_tier": "3",
// "deriv_tier": "3",
// "effective_spot_maker_rate_bps": "6.5",
// "effective_spot_taker_rate_bps": "6.9",
// "effective_deriv_maker_rate_bps": "1.1",
// "effective_deriv_taker_rate_bps": "3"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut result, &Value::Str("info".to_string()), response.clone());
{
let mut i: Value = Value::Int(0);
let mut __for_first_604: bool = true;
while { if !__for_first_604 { i = add(&i, &Value::Int(1)); } __for_first_604 = false; is_less_than(&i, &get_array_length(&self.symbols)) } {
let mut symbol: Value = get_value(&self.symbols, &i);
let mut market: Value = self.market(symbol.clone());
let mut isSwap: Value = get_value(&market, &Value::Str("swap".to_string()));
let mut takerFeeKey: Value = ternary(is_true(&(is_equal(&isSwap, &Value::Bool(true)))), Value::Str("effective_deriv_taker_rate_bps".to_string()), Value::Str("effective_spot_taker_rate_bps".to_string()));
let mut makerFeeKey: Value = ternary(is_true(&(is_equal(&isSwap, &Value::Bool(true)))), Value::Str("effective_deriv_maker_rate_bps".to_string()), Value::Str("effective_spot_maker_rate_bps".to_string()));
let mut tradingFee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string(response.clone(), makerFeeKey.clone(), &[]), &Value::Str("10000".to_string())), &[]));
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string(response.clone(), takerFeeKey.clone(), &[]), &Value::Str("10000".to_string())), &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
add_element_to_object(&mut result, &symbol, tradingFee.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);
//
// {
// "instrument_name": "BTC_USD",
// "effective_maker_rate_bps": "6.5",
// "effective_taker_rate_bps": "6.9"
// }
//
let mut marketId: Value = self.safe_string_k(fee.clone(), "instrument_name", &[]);
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.parse_number(crate::precise::Precise::stringDiv(&self.safe_string_k(fee.clone(), "effective_maker_rate_bps", &[]), &Value::Str("10000".to_string())), &[]));
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string_k(fee.clone(), "effective_taker_rate_bps", &[]), &Value::Str("10000".to_string())), &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut type_var: Value = self.safe_string(api.clone(), Value::Int(0), &[]);
let mut access: Value = self.safe_string(api.clone(), Value::Int(1), &[]);
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &type_var), &Value::Str("/".to_string())), &path);
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
if is_equal(&access, &Value::Str("public".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 {
self.check_required_credentials(&[]);
let mut nonce: Value = to_string_val(&self.nonce());
let mut requestParams: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[params.clone()]);
let mut paramsKeys: Value = object_keys(&requestParams);
let mut strSortKey: Value = self.params_to_string(requestParams.clone(), Value::Int(0));
let mut payload: Value = add(&add(&add(&add(&path, &nonce), &self.apiKey), &strSortKey), &nonce);
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[]);
let mut paramsKeysLength: Value = get_array_length(¶msKeys);
body = self.json(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), nonce.clone());
m.insert("method".to_string(), path.clone());
m.insert("params".to_string(), params.clone());
m.insert("api_key".to_string(), self.apiKey.clone());
m.insert("sig".to_string(), signature.clone());
m.insert("nonce".to_string(), nonce.clone());
m
}));
// fix issue https://github.com/ccxt/ccxt/issues/11179
// php always encodes dictionaries as arrays
// if an array is empty, php will put it in square brackets
// python and js will put it in curly brackets
// the code below checks and replaces those brackets in empty requests
if is_equal(¶msKeysLength, &Value::Int(0)) {
let mut paramsString: Value = Value::Str("{}".to_string());
let mut arrayString: Value = Value::Str("[]".to_string());
body = replace_str(&body, &arrayString, ¶msString);
}
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
if !is_equal(&errorCode, &Value::Str("0".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" ".to_string())), &body)));
}
return Value::Null;
Value::Null
}
}