// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct 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);
// compatibility for sandbox/testnet options in userConfig
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for 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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on 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[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders_for_symbols" => self.cancel_orders_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_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[4.min(args.len())..]),
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"custom_handle_margin_mode_and_params" => self.custom_handle_margin_mode_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"edit_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[3.min(args.len())..]),
"fetch_accounts" => self.fetch_accounts(&args[..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_settlement_history" => self.fetch_settlement_history(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"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_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_settlement" => self.parse_settlement(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_settlements" => self.parse_settlements(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_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[1.min(args.len())..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_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[1.min(args.len())..]),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for 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".into()));
m.insert("name".to_string(), Value::Str("Crypto.com".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("MT".into())]));
m.insert("version".to_string(), Value::Str("v2".into()));
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".into()));
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".into()));
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".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15m".to_string(), Value::Str("15m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("12h".to_string(), Value::Str("12h".into()));
m.insert("1d".to_string(), Value::Str("1D".into()));
m.insert("1w".to_string(), Value::Str("7D".into()));
m.insert("2w".to_string(), Value::Str("14D".into()));
m.insert("1M".to_string(), Value::Str("1M".into()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/1294454/147792121-38ed5e36-c229-48d6-b49a-48d05fc19ed4.jpeg".into()));
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".into()));
m.insert("v2".to_string(), Value::Str("https://uat-api.3ona.co/v2".into()));
m.insert("derivatives".to_string(), Value::Str("https://uat-api.3ona.co/v2".into()));
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".into()));
m.insert("v1".to_string(), Value::Str("https://api.crypto.com/exchange/v1".into()));
m.insert("v2".to_string(), Value::Str("https://api.crypto.com/v2".into()));
m.insert("derivatives".to_string(), Value::Str("https://deriv-api.crypto.com/v1".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://crypto.com/".into()));
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".into()));
m.insert("discount".to_string(), Value::Float(0.75));
m
}));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html".into()), Value::Str("https://exchange-docs.crypto.com/spot/index.html".into()), Value::Str("https://exchange-docs.crypto.com/derivatives/index.html".into())]));
m.insert("fees".to_string(), Value::Str("https://crypto.com/exchange/document/fees-limits".into()));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("public/get-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/user-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/user-balance-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/amend-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(4)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-all-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-order-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(1)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-subaccount-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-subaccount-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-currency-networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-withdrawal-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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/get-fee-credit-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/fiat/fiat-deposit-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/fiat/fiat-deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/fiat/fiat-withdraw-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/fiat/fiat-create-withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/fiat/fiat-transaction-quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/fiat/fiat-transaction-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/fiat/fiat-get-bank-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/change-isolated-margin-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/bot/create-trading-bot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/bot/update-trading-bot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/bot/terminate-trading-bot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/bot/pause-trading-bot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/bot/resume-trading-bot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/bot/get-trading-bots".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/bot/get-trading-bot-executions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-withdrawal-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-currency-networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/export/create-export-request".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/export/get-export-requests".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/export/download-export-output".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-account-summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-all-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-order-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-order-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(1)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-subaccount-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-subaccount-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/otc/get-otc-user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/otc/get-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/otc/get-trade-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/otc/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("public/get-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-cancel-on-disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/user-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/user-balance-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/cancel-all-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(2)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/convert-collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-order-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(1)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/create-subaccount-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-subaccount-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("private/get-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(10)).as_f64(), (Value::Int(3)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
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".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.005".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.0025".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000".into()), &[]), self.parse_number(Value::Str("0.0015".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("250000".into()), &[]), self.parse_number(Value::Str("0.001".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000".into()), &[]), self.parse_number(Value::Str("0.0008".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500000".into()), &[]), self.parse_number(Value::Str("0.00065".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("100000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("250000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])])]));
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000".into()), &[]), self.parse_number(Value::Str("0.004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000".into()), &[]), self.parse_number(Value::Str("0.0025".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("250000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000".into()), &[]), self.parse_number(Value::Str("0.0018".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500000".into()), &[]), self.parse_number(Value::Str("0.001".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.0005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25000000".into()), &[]), self.parse_number(Value::Str("0.0004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("100000000".into()), &[]), self.parse_number(Value::Str("0.00035".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("250000000".into()), &[]), self.parse_number(Value::Str("0.00031".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000000".into()), &[]), self.parse_number(Value::Str("0.00025".into()), &[])])]));
m
}));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("spot".into()));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("funding".to_string(), Value::Str("SPOT".into()));
m.insert("spot".to_string(), Value::Str("SPOT".into()));
m.insert("margin".to_string(), Value::Str("MARGIN".into()));
m.insert("derivatives".to_string(), Value::Str("DERIVATIVES".into()));
m.insert("swap".to_string(), Value::Str("DERIVATIVES".into()));
m.insert("future".to_string(), Value::Str("DERIVATIVES".into()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BEP20".to_string(), Value::Str("BSC".into()));
m.insert("ERC20".to_string(), Value::Str("ETH".into()));
m.insert("TRC20".to_string(), Value::Str("TRON".into()));
m.insert("ARBITRUM".to_string(), Value::Str("ARB".into()));
m
}));
m.insert("broker".to_string(), Value::Str("CCXT".into()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(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".into()));
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".into()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
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".into()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
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".into()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("213".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("219".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("306".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("314".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("315".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("325".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("415".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("10001".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("10002".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("10003".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("10004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("10005".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("10006".to_string(), Value::Str("DDoSProtection".into()).clone());
m.insert("10007".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("10008".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("10009".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("20001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("20002".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("20005".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("30003".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("30004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("30005".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("30006".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30007".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30008".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30009".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30010".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("30013".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30014".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30016".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30017".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30023".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30024".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("30025".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("40001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40002".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40003".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40005".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40006".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40007".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40101".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("40102".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("40103".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("40104".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("40107".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("40401".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("40801".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("42901".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("43005".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("43003".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("43004".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("43012".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("50001".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("9010001".to_string(), Value::Str("OnMaintenance".into()).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 !(self.check_required_credentials(&[Value::Bool(false)]).as_bool() == Some(true)) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut skipFetchCurrenciesparamsSkipFetchCurrenciesVariable = self.handle_option_bool_and_params(params, Value::Str("fetchCurrencies".into()), Value::Str("skipFetchCurrencies".into()), &[Value::Bool(false)]);
let mut skipFetchCurrencies: Value = skipFetchCurrenciesparamsSkipFetchCurrenciesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSkipFetchCurrencies: Value = skipFetchCurrenciesparamsSkipFetchCurrenciesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
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(&[paramsSkipFetchCurrencies]).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 Value::Int(erString.as_str().and_then(|__s| __s.find("SYS_ERROR")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyMap: Value = self.safe_dict_k(resultData, "currency_map", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut enhancedArray: Value = self.add_key_in_array_items(currencyMap, Value::Str("_coin_id".into()));
return self.parse_currencies(enhancedArray);
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::from(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_587: bool = true;
while { if !__for_first_587 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_587 = false; j.as_f64().unwrap_or(f64::NAN) < ((chains.len() as i64) as f64) } {
let mut chain: Value = chains.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.safe_string_k(chain.clone(), "network_id", &[]);
let mut network: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if (network != Value::Null) {
if let Value::Dict(__d) = &mut networks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&network), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), networkId);
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, "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);
m.insert("code".to_string(), code);
m.insert("name".to_string(), self.safe_string_k(currency, "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".into()));
m.insert("networks".to_string(), networks);
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]).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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(resultResponse, "data", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_588: bool = true;
while { if !__for_first_588 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_588 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut market: Value = data.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut inst_type: Option<String> = self.safe_string_k(market.clone(), "inst_type", &[]).as_str().map(str::to_owned);
let mut spot: Value = Value::Bool(inst_type.as_deref() == Some("CCY_PAIR"));
let mut swap: Value = Value::Bool(inst_type.as_deref() == Some("PERPETUAL_SWAP"));
let mut future: Value = Value::Bool(inst_type.as_deref() == Some("FUTURE"));
let mut option: Value = Value::Bool(inst_type.as_deref() == Some("WARRANT"));
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 = (if matches!(&spot, Value::Bool(true)) { Value::Null } else { quoteId.clone() });
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
continue;
}
let mut settle: Value = (if matches!(&spot, Value::Bool(true)) { Value::Null } else { self.safe_currency_code(settleId.clone(), &[]) });
let mut optionType: Value = self.safe_string_lower_k(market.clone(), "put_call", &[]);
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 = (if (expiryString != Value::Null) { (match &expiryString { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null }) } else { Value::Null });
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut type_var: Value = Value::Null;
let mut contract: Value = Value::Null;
if (inst_type.as_deref() == Some("CCY_PAIR")) {
type_var = Value::Str("spot".into());
contract = Value::Bool(false);
} else if (inst_type.as_deref() == Some("PERPETUAL_SWAP")) {
type_var = Value::Str("swap".into());
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), quote).into());
contract = Value::Bool(true);
} else if (inst_type.as_deref() == Some("FUTURE")) {
type_var = Value::Str("future".into());
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), quote).into()), Value::Str("-".into())).into()), self.yymmdd(expiry.clone(), &[])).into());
contract = Value::Bool(true);
} else if (inst_type.as_deref() == Some("WARRANT")) {
type_var = Value::Str("option".into());
let mut symbolOptionType: Value = (if (optionType.as_str() == Some("call")) { Value::Str("C".into()) } else { Value::Str("P".into()) });
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), quote).into()), Value::Str("-".into())).into()), self.yymmdd(expiry.clone(), &[])).into()), Value::Str("-".into())).into()), strike).into()), Value::Str("-".into())).into()), symbolOptionType).into());
contract = Value::Bool(true);
}
let mut isLinear: Value = (if (contract.as_bool() == Some(true)) { Value::Bool(true) } else { Value::Null });
let mut isInverse: Value = (if (contract.as_bool() == Some(true)) { Value::Bool(false) } else { 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);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), settle);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), type_var);
m.insert("spot".to_string(), spot);
m.insert("margin".to_string(), (Value::Bool((marginBuyEnabled.as_bool() == Some(true)) || (marginSellEnabled.as_bool() == Some(true)))));
m.insert("swap".to_string(), swap);
m.insert("future".to_string(), future);
m.insert("option".to_string(), option);
m.insert("active".to_string(), self.safe_bool_k(market.clone(), "tradable", &[]));
m.insert("contract".to_string(), contract);
m.insert("linear".to_string(), isLinear);
m.insert("inverse".to_string(), isInverse);
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));
m.insert("strike".to_string(), self.parse_number(strike, &[]));
m.insert("optionType".to_string(), optionType);
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".into()), &[]));
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);
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 (self.markets.clone() == 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 (symbols != Value::Null) {
let mut symbol: Value = Value::Null;
if (matches!(&symbols, Value::Arr(_))) {
let mut symbolsLength: f64 = ((symbols.len() as i64) as f64);
if symbolsLength > ((1i64) as f64) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchTickers() symbols argument cannot contain more than 1 symbol".into()))));
}
symbol = symbols.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
} else {
symbol = symbols.clone();
}
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("instrument_name".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let __ws_arg_0 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
return self.parse_tickers(data, &[symbols]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolValue: Value = self.symbol(symbol.clone());
let mut tickers: Value = self.fetch_tickers(&[Value::from(vec![symbolValue.clone()]), params]).await;
let mut ticker: Value = self.safe_dict(tickers, symbolValue, &[]);
return ticker;
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOrders".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("instrument_name".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_time".into(), until); }
}
let __ws_arg_1 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data, "data", &[Value::from(vec![])]);
return self.parse_orders(orders, &[market, since, limit]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_ts".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("count".into(), limit.clone()); }
}
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_ts".into(), until); }
}
let __ws_arg_2 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market, since, limit]);
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".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), Value::Int(300)]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("timeframe".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut limitResolved: Value = limit.clone();
if (limit != Value::Null) && (limit.as_f64().unwrap_or(f64::NAN) > ((300i64) as f64)) {
limitResolved = Value::Int(300);
}
if (limitResolved != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("count".into(), limitResolved.clone()); }
}
let mut now: Value = self.microseconds();
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[now]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_ts".into(), (match (&(since), &((match (&(duration), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null })); }
if (limitResolved != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_ts".into(), self.sum(&[since.clone(), (match (&((match (&(duration), &(limitResolved)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })])); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_ts".into(), until.clone()); }
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_ts".into(), until); }
}
let __ws_arg_3 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
return self.parse_ohlc_vs(data, &[market, timeframe, since, limitResolved]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) && (limit.as_f64() != Some(0.0)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("depth".into(), crate::runtime::Math::min(&limit, &Value::Int(50))); }; // max 50
}
let __ws_arg_4 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
let mut orderBook: Value = self.safe_dict(data, Value::Int(0), &[]);
let mut timestamp: Value = self.safe_integer_k(orderBook.clone(), "t", &[]);
return self.parse_order_book(orderBook, symbol, &[timestamp]);
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, "data", &[Value::from(vec![])]);
let mut positionBalances: Value = self.safe_list(data.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), Value::Str("position_balances".into()), &[Value::from(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_589: bool = true;
while { if !__for_first_589 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_589 = false; i.as_f64().unwrap_or(f64::NAN) < ((positionBalances.len() as i64) as f64) } {
let mut balance: Value = self.safe_dict(positionBalances.clone(), i.clone(), &[]);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "instrument_name", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string_k(balance.clone(), "quantity", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(balance, "reserved_qty", &[])); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v1_private_post_private_user_balance(&[params]).await;
return self.parse_balance(response);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id);
m
});
let __ws_arg_5 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[market]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
let mut market: Value = self.market(symbol.clone());
let mut uppercaseType: Value = to_upper(&type_var);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), to_upper(&side));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount));
m
});
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("STOP_LIMIT")) || (uppercaseType.as_str() == Some("TAKE_PROFIT_LIMIT")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price.clone())); }
}
let mut broker: Value = self.safe_string_k(self.options.clone(), "broker", &[Value::Str("CCXT".into())]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("broker_id".into(), broker); }
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("createOrder".into()), &[market, params]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginModeparamsValueVariable = self.custom_handle_margin_mode_and_params(Value::Str("createOrder".into()), &[paramsMarketType]);
let mut marginMode: Value = marginModeparamsValueVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsValue: Value = marginModeparamsValueVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (marketType.as_str() == Some("margin")) || (marginMode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("spot_margin".into(), Value::Str("MARGIN".into())); }
} else if (marketType.as_str() == Some("spot")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("spot_margin".into(), Value::Str("SPOT".into())); }
}
let mut timeInForce: Value = self.safe_string_upper2(paramsValue.clone(), Value::Str("timeInForce".into()), Value::Str("time_in_force".into()), &[]);
if (timeInForce != Value::Null) {
if (timeInForce.as_str() == Some("GTC")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("GOOD_TILL_CANCEL".into())); }
} else if (timeInForce.as_str() == Some("IOC")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("IMMEDIATE_OR_CANCEL".into())); }
} else if (timeInForce.as_str() == Some("FOK")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("FILL_OR_KILL".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), timeInForce.clone()); }
}
}
let mut postOnly: Value = self.safe_bool_k(paramsValue.clone(), "postOnly", &[Value::Bool(false)]);
if (postOnly.as_bool() == Some(true)) || (timeInForce.as_str() == Some("PO")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("exec_inst".into(), Value::from(vec![Value::Str("POST_ONLY".into())])); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("GOOD_TILL_CANCEL".into())); }
}
let mut triggerPrice: Value = self.safe_string_n(paramsValue.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("ref_price".into())]), &[]);
let mut stopLossPrice: Value = self.safe_number_k(paramsValue.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_number_k(paramsValue.clone(), "takeProfitPrice", &[]);
let mut isTrigger: bool = triggerPrice != Value::Null;
let mut isStopLossTrigger: bool = stopLossPrice != Value::Null;
let mut isTakeProfitTrigger: bool = takeProfitPrice != Value::Null;
if isTrigger {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("ref_price".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone())); }
let mut priceString: Value = self.number_to_string(price);
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("STOP_LIMIT")) || (uppercaseType.as_str() == Some("TAKE_PROFIT_LIMIT")) {
if (side.as_str() == Some("buy")) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LIMIT".into())); }
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT_LIMIT".into())); }
}
}
} else {
if (side.as_str() == Some("buy")) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LOSS".into())); }
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LOSS".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT".into())); }
}
}
}
} else if isStopLossTrigger {
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("STOP_LIMIT")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LOSS".into())); }
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("ref_price".into(), self.price_to_precision(symbol.clone(), stopLossPrice)); }
} else if isTakeProfitTrigger {
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("TAKE_PROFIT_LIMIT")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT".into())); }
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("ref_price".into(), self.price_to_precision(symbol, takeProfitPrice)); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), uppercaseType); }
}
let mut paramsOmitted: Value = self.omit(paramsValue, Value::from(vec![Value::Str("postOnly".into()), Value::Str("clientOrderId".into()), Value::Str("timeInForce".into()), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("takeProfitPrice".into())]), &[]);
return self.extend(request, &[paramsOmitted]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_order_request(symbol, type_var, side, amount, &[price, params]);
let mut response: Value = self.v1_private_post_private_create_order(&[request]).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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_590: bool = true;
while { if !__for_first_590 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_590 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut rawOrder: Value = self.safe_dict(orders.clone(), i.clone(), &[]);
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, "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_advanced_order_request(marketId, type_var, side, amount, &[price, orderParams]);
append_to_array(&mut ordersRequests, orderRequest);
}
}
let mut contigency: Value = self.safe_string_k(params.clone(), "contingency_type", &[Value::Str("LIST".into())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contingency_type".to_string(), contigency);
m.insert("order_list".to_string(), ordersRequests);
m
});
let __ws_arg_6 = self.extend(request, &[params]);
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, "result", &[Value::from(vec![])]);
let mut listId: Value = self.safe_string_k(result.clone(), "list_id", &[]);
if (listId != Value::Null) {
let mut ocoOrders: Value = Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), listId);
m
})]);
return self.parse_orders(ocoOrders, &[]);
}
return self.parse_orders(result, &[]);
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 (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
// 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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), to_upper(&side));
m
});
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("STOP_LIMIT")) || (uppercaseType.as_str() == Some("TAKE_PROFIT_LIMIT")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price.clone())); }
}
let mut broker: Value = self.safe_string_k(self.options.clone(), "broker", &[Value::Str("CCXT".into())]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("broker_id".into(), broker); }
let mut timeInForce: Value = self.safe_string_upper2(params.clone(), Value::Str("timeInForce".into()), Value::Str("time_in_force".into()), &[]);
if (timeInForce != Value::Null) {
if (timeInForce.as_str() == Some("GTC")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("GOOD_TILL_CANCEL".into())); }
} else if (timeInForce.as_str() == Some("IOC")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("IMMEDIATE_OR_CANCEL".into())); }
} else if (timeInForce.as_str() == Some("FOK")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("FILL_OR_KILL".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), timeInForce.clone()); }
}
}
let mut postOnly: Value = self.safe_bool_k(params.clone(), "postOnly", &[Value::Bool(false)]);
if (postOnly.as_bool() == Some(true)) || (timeInForce.as_str() == Some("PO")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("exec_inst".into(), Value::from(vec![Value::Str("POST_ONLY".into())])); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), Value::Str("GOOD_TILL_CANCEL".into())); }
}
let mut triggerPrice: Value = self.safe_string_n(params.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("ref_price".into())]), &[]);
let mut stopLossPrice: Option<f64> = self.safe_number_k(params.clone(), "stopLossPrice", &[]).as_f64();
let mut takeProfitPrice: Option<f64> = self.safe_number_k(params.clone(), "takeProfitPrice", &[]).as_f64();
let mut isTrigger: bool = triggerPrice != Value::Null;
let mut isStopLossTrigger: bool = stopLossPrice.is_some();
let mut isTakeProfitTrigger: bool = takeProfitPrice.is_some();
if isTrigger {
let mut priceString: Value = self.number_to_string(price.clone());
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("STOP_LIMIT")) || (uppercaseType.as_str() == Some("TAKE_PROFIT_LIMIT")) {
if (side.as_str() == Some("buy")) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LIMIT".into())); }
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT_LIMIT".into())); }
}
}
} else {
if (side.as_str() == Some("buy")) {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LOSS".into())); }
}
} else {
if is_true(&crate::precise::Precise::stringLt(&priceString, &triggerPrice)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LOSS".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT".into())); }
}
}
}
} else if isStopLossTrigger {
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("STOP_LIMIT")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP_LOSS".into())); }
}
} else if isTakeProfitTrigger {
if (uppercaseType.as_str() == Some("LIMIT")) || (uppercaseType.as_str() == Some("TAKE_PROFIT_LIMIT")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT_LIMIT".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("TAKE_PROFIT".into())); }
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), uppercaseType.clone()); }
}
let mut isMarketBuy: bool = (side.as_str() == Some("buy")) && ((uppercaseType.as_str() == Some("MARKET")) || (uppercaseType.as_str() == Some("STOP_LOSS")) || (uppercaseType.as_str() == Some("TAKE_PROFIT")));
let mut paramsMarketBuy: Value = params.clone();
if isMarketBuy {
// use createmarketBuy logic here
let mut quoteAmount: Value = Value::Null;
let mut createMarketBuyOrderRequiresPriceparamsCreateMarketBuyVariable = self.handle_option_bool_and_params(params, Value::Str("createOrder".into()), Value::Str("createMarketBuyOrderRequiresPrice".into()), &[Value::Bool(true)]);
let mut createMarketBuyOrderRequiresPrice: Value = createMarketBuyOrderRequiresPriceparamsCreateMarketBuyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsCreateMarketBuy: Value = createMarketBuyOrderRequiresPriceparamsCreateMarketBuyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut cost: Value = self.safe_number2(paramsCreateMarketBuy.clone(), Value::Str("cost".into()), Value::Str("notional".into()), &[]);
paramsMarketBuy = self.omit(paramsCreateMarketBuy, Value::Str("cost".into()), &[]);
if (cost != Value::Null) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost);
} else if is_true(&createMarketBuyOrderRequiresPrice) {
if (price == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument".into()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price);
let mut costRequest: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
quoteAmount = self.cost_to_precision(symbol.clone(), costRequest);
}
} else {
quoteAmount = self.cost_to_precision(symbol.clone(), amount.clone());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("notional".into(), quoteAmount); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.amount_to_precision(symbol, amount)); }
}
let mut paramsOmitted: Value = self.omit(paramsMarketBuy, Value::from(vec![Value::Str("postOnly".into()), Value::Str("clientOrderId".into()), Value::Str("timeInForce".into()), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("takeProfitPrice".into())]), &[]);
return self.extend(request, &[paramsOmitted]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = self.edit_order_request(id, symbol, amount, &[price, params]);
let mut response: Value = self.v1_private_post_private_amend_order(&[request]).await;
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result, &[]);
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 (id != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("order_id".into(), id.clone()); }
} else {
let mut originalClientOrderId: Value = self.safe_string2(params.clone(), Value::Str("orig_client_oid".into()), Value::Str("clientOrderId".into()), &[]);
if (originalClientOrderId == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" editOrder() requires an id argument or orig_client_oid parameter".into()))));
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orig_client_oid".into(), originalClientOrderId); }
}
}
let mut paramsOmitted: Value = (if (id == Value::Null) { self.omit(params.clone(), Value::from(vec![Value::Str("orig_client_oid".into()), Value::Str("clientOrderId".into())]), &[]) } else { params });
if (amount == Value::Null) || (price == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), 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".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("new_quantity".into(), self.amount_to_precision(symbol.clone(), amount)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("new_price".into(), self.price_to_precision(symbol, price)); }
return self.extend(request, &[paramsOmitted]);
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 (self.markets.clone() == 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 (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("instrument_name".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let __ws_arg_7 = self.extend(request, &[params]);
let mut response: Value = self.v1_private_post_private_cancel_all_orders(&[__ws_arg_7]).await;
return Value::from(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
}), &[])]);
Value::Null
}
/*
* @method
* @name 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id);
m
});
let __ws_arg_8 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result, &[market]);
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrders() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut orderRequests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_591: bool = true;
while { if !__for_first_591 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_591 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
let mut id: Value = ids.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut order: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("order_id".to_string(), to_string_val(&id));
m
});
append_to_array(&mut orderRequests, order);
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contingency_type".to_string(), Value::Str("LIST".into()));
m.insert("order_list".to_string(), orderRequests);
m
});
let __ws_arg_9 = self.extend(request, &[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, "result", &[Value::from(vec![])]);
return self.parse_orders(result, &[market, Value::Null, Value::Null, params]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut orderRequests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_592: bool = true;
while { if !__for_first_592 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_592 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut order: Value = self.safe_dict(orders.clone(), i.clone(), &[]);
let mut id: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut symbol: Value = self.safe_string_k(order, "symbol", &[]);
let mut market: Value = self.market(symbol);
let mut orderItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("order_id".to_string(), to_string_val(&id));
m
});
append_to_array(&mut orderRequests, orderItem);
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contingency_type".to_string(), Value::Str("LIST".into()));
m.insert("order_list".to_string(), orderRequests);
m
});
let __ws_arg_10 = self.extend(request, &[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, "result", &[Value::from(vec![])]);
return self.parse_orders(result, &[Value::Null, Value::Null, Value::Null, params]);
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 (self.markets.clone() == 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 (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("instrument_name".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let __ws_arg_11 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data, "data", &[Value::from(vec![])]);
return self.parse_orders(orders, &[market, since, limit]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchMyTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.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 (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("instrument_name".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_time".into(), until); }
}
let __ws_arg_12 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market, since, limit]);
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 get_index_of(&addressString, &Value::Str("?".into())).as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
{ let __destr_tmp = split(&addressString, &Value::Str("?".into())); address = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); rawTag = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut splitted: Value = split(&rawTag, &Value::Str("=".into()));
tag = splitted.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
} else {
address = addressString;
}
return Value::from(vec![address, tag]);
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 {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tag] memo / destination tag, required for currencies in options['withdrawTagRequiredCurrencies']
* @returns {object} a [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 params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut tagWithdrawTagparamsWithdrawTagVariable = self.handle_param_string(params, Value::Str("tag".into()), &[]);
let mut tagWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone(), code.clone(), tagWithdrawTag.clone()]);
if (self.markets.clone() == 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(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), amount);
m.insert("address".to_string(), address);
m
});
if (tagWithdrawTag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("address_tag".into(), tagWithdrawTag); }
}
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(paramsWithdrawTag);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.network_code_to_id(networkCode, &[code]);
if (networkId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("network_id".into(), networkId); }
}
let __ws_arg_13 = self.extend(request, &[paramsNetworkCode]);
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, "result", &[]);
return self.parse_transaction(result, &[currency]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.safe_currency(code, &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_14 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut addresses: Value = self.safe_list_k(data, "deposit_address_list", &[Value::from(vec![])]);
let mut addressesLength: f64 = ((addresses.len() as i64) as f64);
if (addressesLength == 0.0) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddressesByNetwork() generating address...".into()))));
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_593: bool = true;
while { if !__for_first_593 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_593 = false; i.as_f64().unwrap_or(f64::NAN) < 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, &[]);
let mut addresstagVariable = self.parse_address(addressString);
let mut address: Value = addresstagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut tag: Value = addresstagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
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, responseCode.clone()]);
if (network != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&network), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), value);
m.insert("currency".to_string(), responseCode);
m.insert("network".to_string(), network.clone());
m.insert("address".to_string(), address);
m.insert("tag".to_string(), tag);
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 networkParam: Value = self.safe_string_upper_k(params.clone(), "network", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("network".into())]), &[]);
let mut depositAddressesRaw: Value = self.fetch_deposit_addresses_by_network(code, &[paramsOmitted]).await;
let mut depositAddresses: Value = depositAddressesRaw;
if (networkParam != Value::Null) {
let mut network: Value = self.safe_string(self.networkAliases.clone(), networkParam.clone(), &[networkParam.clone()]);
if (in_op(&depositAddresses, &network)) {
return depositAddresses.as_map().and_then(|__m| network.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
}
}
let mut keys: Value = object_keys(&depositAddresses);
return get_value(&depositAddresses, &keys.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
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 (self.markets.clone() == 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 (code != Value::Null) {
currency = self.safe_currency(code, &[]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
// 90 days date range
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_ts".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("page_size".into(), limit.clone()); }
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_ts".into(), until); }
}
let __ws_arg_15 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut depositList: Value = self.safe_list_k(data, "deposit_list", &[Value::from(vec![])]);
return self.parse_transactions(depositList, &[currency, since, limit]);
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 (self.markets.clone() == 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 (code != Value::Null) {
currency = self.safe_currency(code, &[]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
// 90 days date range
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_ts".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("page_size".into(), limit.clone()); }
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_ts".into(), until); }
}
let __ws_arg_16 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut withdrawalList: Value = self.safe_list_k(data, "withdrawal_list", &[Value::from(vec![])]);
return self.parse_transactions(withdrawalList, &[currency, since, limit]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Str("_".into())]);
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(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), self.safe_number_k(ticker.clone(), "h", &[]));
m.insert("low".to_string(), self.safe_number_k(ticker.clone(), "l", &[]));
m.insert("bid".to_string(), self.safe_number_k(ticker.clone(), "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);
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(), (if (marketResolved.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null).as_str() == Some("USD")) { self.safe_string_k(ticker.clone(), "vv", &[]) } else { Value::Null }));
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
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".into()), Value::Str("create_time".into()), &[]);
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("i".into()), Value::Str("instrument_name".into()), &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Str("_".into())]);
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".into()), Value::Str("trade_id".into()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "order_id", &[]));
m.insert("side".to_string(), self.safe_string_lower2(trade.clone(), Value::Str("s".into()), Value::Str("side".into()), &[]));
m.insert("takerOrMaker".to_string(), self.safe_string_lower_k(trade.clone(), "taker_side", &[]));
m.insert("price".to_string(), self.safe_number2(trade.clone(), Value::Str("p".into()), Value::Str("traded_price".into()), &[]));
m.insert("amount".to_string(), self.safe_number2(trade, Value::Str("q".into()), Value::Str("traded_quantity".into()), &[]));
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, &[]));
m.insert("cost".to_string(), self.parse_number(crate::precise::Precise::stringNeg(&feeCostString), &[]));
m
}));
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_integer_k(ohlcv.clone(), "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, "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".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("FILLED".to_string(), Value::Str("closed".into()));
m.insert("REJECTED".to_string(), Value::Str("rejected".into()));
m.insert("EXPIRED".to_string(), Value::Str("expired".into()));
m
});
return self.safe_string(statuses, 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".into()));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Str("IOC".into()));
m.insert("FILL_OR_KILL".to_string(), Value::Str("FOK".into()));
m
});
return self.safe_string(timeInForces, 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: Option<i64> = self.safe_integer_k(order.clone(), "code", &[]).as_i64();
if (code.is_some()) && (code != Some(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".into()));
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, &[market.clone()]);
let mut execInst: Value = self.safe_list_k(order.clone(), "exec_inst", &[]);
let mut postOnly: Value = Value::Null;
if (execInst != Value::Null) {
postOnly = Value::Bool(false);
{
let mut i: Value = Value::Int(0);
let mut __for_first_594: bool = true;
while { if !__for_first_594 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_594 = false; i.as_f64().unwrap_or(f64::NAN) < ((execInst.len() as i64) as f64) } {
let mut inst: Option<String> = self.safe_string(execInst.clone(), i.clone(), &[]).as_str().map(str::to_owned);
if (inst.as_deref() == Some("POST_ONLY")) {
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));
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);
m.insert("type".to_string(), self.safe_string_lower_k(order.clone(), "order_type", &[]));
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);
m.insert("side".to_string(), self.safe_string_lower_k(order.clone(), "side", &[]));
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, &[]));
m.insert("cost".to_string(), self.safe_number_k(order, "cumulative_fee", &[]));
m
}));
m.insert("trades".to_string(), Value::from(vec![]));
m
}), &[market]);
Value::Null
}
pub fn parse_deposit_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("pending".into()));
m.insert("1".to_string(), Value::Str("ok".into()));
m.insert("2".to_string(), Value::Str("failed".into()));
m.insert("3".to_string(), Value::Str("pending".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_withdrawal_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("pending".into()));
m.insert("1".to_string(), Value::Str("pending".into()));
m.insert("2".to_string(), Value::Str("failed".into()));
m.insert("3".to_string(), Value::Str("pending".into()));
m.insert("4".to_string(), Value::Str("failed".into()));
m.insert("5".to_string(), Value::Str("ok".into()));
m.insert("6".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
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 (matches!(&transaction, Value::Dict(__d) if __d.contains_key("client_wid"))) {
type_var = Value::Str("withdrawal".into());
status = self.parse_withdrawal_status(rawStatus.clone()).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
} else {
type_var = Value::Str("deposit".into());
status = self.parse_deposit_status(rawStatus).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
}
let mut addressString: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut addresstagVariable = self.parse_address(addressString);
let mut address: Value = addresstagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut tag: Value = addresstagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency]);
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 (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);
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));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), address);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), tag.clone());
m.insert("tagTo".to_string(), tag);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), code);
m.insert("status".to_string(), status);
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, "client_wid", &[]));
m.insert("fee".to_string(), fee);
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: Option<String> = self.safe_string_k(self.options.clone(), "defaultType", &[]).as_str().map(str::to_owned);
let mut isMargin: Value = self.safe_bool_k(params.clone(), "margin", &[Value::Bool(false)]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("margin".into()), &[]);
let mut marginMode: Value = Value::Null;
let mut paramsMarginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(methodName, &[paramsOmitted]); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); paramsMarginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (marginMode != Value::Null) {
if (marginMode.as_str() != Some("cross")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" only cross margin is supported".into()))));
}
} else {
if (defaultType.as_deref() == Some("margin")) || (isMargin.as_bool() == Some(true)) {
marginMode = Value::Str("cross".into());
}
}
return Value::from(vec![marginMode, paramsMarginMode]);
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);
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
//
// {
// "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::from(vec![])]);
let mut networkListLength: f64 = ((networkList.len() as i64) as f64);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee);
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 (networkList != Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_595: bool = true;
while { if !__for_first_595 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_595 = false; i.as_f64().unwrap_or(f64::NAN) < networkListLength } {
let mut networkInfo: Value = self.safe_dict(networkList.clone(), i.clone(), &[]);
let mut networkId: Value = self.safe_string_k(networkInfo.clone(), "network_id", &[]);
let mut currencyCode: Value = (match currency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut networkCode: Value = self.network_id_to_code(&[networkId, currencyCode]);
if (networkCode != Value::Null) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("networks".into())), &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("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 (networkListLength == 1.0) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".into())), &Value::Str("fee".into()), self.safe_number_k(networkInfo, "withdrawal_fee", &[]));
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".into())), &Value::Str("percentage".into()), 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v1_private_post_private_get_currency_networks(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "result", &[]);
let mut currencyMap: Value = self.safe_list_k(data, "currency_map", &[]);
return self.parse_deposit_withdraw_fees(currencyMap, &[codes, Value::Str("full_name".into())]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.safe_currency(code, &[]);
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_time".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_time".into(), until); }
}
let __ws_arg_17 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ledger: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
return self.parse_ledger(ledger, &[currency, since, limit]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "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()]);
let mut currencyResolved: Value = self.safe_currency(currencyId, &[currency]);
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".into()))) {
direction = Value::Str("out".into());
amount = crate::precise::Precise::stringAbs(&amount);
} else {
direction = Value::Str("in".into());
}
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);
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, "journal_type", &[])).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("currency".to_string(), code);
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), 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
}), &[currencyResolved]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Option<String> {
let mut ledgerType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TRADING".to_string(), Value::Str("trade".into()));
m.insert("TRADE_FEE".to_string(), Value::Str("fee".into()));
m.insert("WITHDRAW_FEE".to_string(), Value::Str("fee".into()));
m.insert("WITHDRAW".to_string(), Value::Str("withdrawal".into()));
m.insert("DEPOSIT".to_string(), Value::Str("deposit".into()));
m.insert("ROLLBACK_WITHDRAW".to_string(), Value::Str("rollback".into()));
m.insert("ROLLBACK_DEPOSIT".to_string(), Value::Str("rollback".into()));
m.insert("FUNDING".to_string(), Value::Str("fee".into()));
m.insert("REALIZED_PNL".to_string(), Value::Str("trade".into()));
m.insert("INSURANCE_FUND".to_string(), Value::Str("insurance".into()));
m.insert("SOCIALIZED_LOSS".to_string(), Value::Str("trade".into()));
m.insert("LIQUIDATION_FEE".to_string(), Value::Str("fee".into()));
m.insert("SESSION_RESET".to_string(), Value::Str("reset".into()));
m.insert("ADJUSTMENT".to_string(), Value::Str("adjustment".into()));
m.insert("SESSION_SETTLE".to_string(), Value::Str("settlement".into()));
m.insert("UNCOVERED_LOSS".to_string(), Value::Str("trade".into()));
m.insert("ADMIN_ADJUSTMENT".to_string(), Value::Str("adjustment".into()));
m.insert("DELIST".to_string(), Value::Str("delist".into()));
m.insert("SETTLEMENT_FEE".to_string(), Value::Str("fee".into()));
m.insert("AUTO_CONVERSION".to_string(), Value::Str("conversion".into()));
m.insert("MANUAL_CONVERSION".to_string(), Value::Str("conversion".into()));
m
});
return self.safe_string(ledgerType, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
/*
* @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 (self.markets.clone() == 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, "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, "sub_account_list", &[Value::from(vec![])]);
append_to_array(&mut accounts, masterAccount);
return self.parse_accounts(accounts, &[params]);
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);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut type_var: Value = Value::Null;
let mut paramsMarketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchSettlementHistory".into()), &[market.clone(), params]); type_var = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); paramsMarketType = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
self.check_required_argument(Value::Str("fetchSettlementHistory".into()), type_var.clone(), Value::Str("type".into()), &[Value::from(vec![Value::Str("future".into()), Value::Str("option".into()), Value::Str("WARRANT".into()), Value::Str("FUTURE".into())])]);
if (type_var.as_str() == Some("option")) {
type_var = Value::Str("WARRANT".into());
}
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, &[paramsMarketType]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
let mut settlements: Value = self.parse_settlements(data, &[market]);
let mut sorted: Value = self.sort_by(settlements, Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
pub fn parse_settlement(&self, mut settlement: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "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, &[market]));
m.insert("price".to_string(), self.safe_number_k(settlement, "v", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
Value::Null
}
pub fn parse_settlements(&self, mut settlements: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// {
// "i": "BTCUSD-230526",
// "x": 1685088000000,
// "v": "26464.1",
// "t": 1685087999500
// }
// ]
//
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_596: bool = true;
while { if !__for_first_596 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_596 = false; i.as_f64().unwrap_or(f64::NAN) < ((settlements.len() as i64) as f64) } {
append_to_array(&mut result, self.parse_settlement(settlements.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[market.clone()]));
}
}
return 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate() supports swap contracts only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("valuation_type".to_string(), Value::Str("estimated_funding_rate".into()));
m.insert("count".to_string(), Value::Int(1));
m
});
let __ws_arg_19 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
let mut entry: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(entry, &[market]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "v": "-0.000001884",
// "t": 1687892400000
// },
//
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "t", &[]);
let mut fundingTimestamp: Value = Value::Null;
if (timestamp != Value::Null) {
fundingTimestamp = (match (&(math_ceil(&(match ((timestamp).as_f64(), (Value::Int(3600000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))), &(Value::Int(3600000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }); // 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]));
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));
m.insert("fundingRate".to_string(), self.safe_number_k(contract, "v", &[]));
m.insert("fundingTimestamp".to_string(), fundingTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTimestamp));
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".into()));
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone()]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() supports swap contracts only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("valuation_type".to_string(), Value::Str("funding_hist".into()));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_ts".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("count".into(), limit.clone()); }
}
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_ts".into(), until); }
}
let __ws_arg_20 = self.extend(request, &[paramsOmitted]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "data", &[Value::from(vec![])]);
let mut marketId: Value = self.safe_string_k(result, "instrument_name", &[]);
let mut rates: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_597: bool = true;
while { if !__for_first_597 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_597 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "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, "v", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates, Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[self.safe_string_k(market, "symbol", &[]), since, limit]);
Value::Null
}
/*
* @method
* @name 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_21 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result, "data", &[Value::from(vec![])]);
return self.parse_position(self.safe_dict(data, Value::Int(0), &[]), &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbolsNormalized != Value::Null) {
let mut symbol: Value = Value::Null;
if (matches!(&symbolsNormalized, Value::Arr(_))) {
let mut symbolsLength: f64 = ((symbolsNormalized.len() as i64) as f64);
if symbolsLength > ((1i64) as f64) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchPositions() symbols argument cannot contain more than 1 symbol".into()))));
}
symbol = symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
} else {
symbol = symbolsNormalized;
}
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("instrument_name".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let __ws_arg_22 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positions: Value = self.safe_list_k(responseResult, "data", &[Value::from(vec![])]);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_598: bool = true;
while { if !__for_first_598 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_598 = false; i.as_f64().unwrap_or(f64::NAN) < ((positions.len() as i64) as f64) } {
let mut entry: Value = positions.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = self.safe_string_k(entry.clone(), "instrument_name", &[]);
let mut marketInner: Value = self.safe_market(&[marketId, Value::Null, Value::Null, Value::Str("contract".into())]);
append_to_array(&mut result, self.parse_position(entry, &[marketInner]));
}
}
return self.filter_by_array_positions(result, Value::Str("symbol".into()), &[Value::Null]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone(), market, Value::Null, Value::Str("contract".into())]);
let mut symbol: Value = self.safe_symbol(marketId, &[marketResolved.clone(), Value::Null, Value::Str("contract".into())]);
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);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("hedged".to_string(), Value::Null);
m.insert("side".to_string(), (if is_true(&crate::precise::Precise::stringGt(&amount, &Value::Str("0".into()))) { Value::Str("long".into()) } else { Value::Str("short".into()) }));
m.insert("contracts".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&amount), &[]));
m.insert("contractSize".to_string(), marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null));
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, "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: f64 = ((3i64) as f64);
if level.as_f64().unwrap_or(f64::NAN) >= maxLevel {
return to_string_val(&object);
}
if matches!(&object, Value::Str(_)) {
return object;
}
let mut returnString: Value = Value::Str("".into());
let mut paramsKeys: Value = Value::Null;
if (matches!(&object, Value::Arr(_))) {
paramsKeys = object.clone();
} else {
let mut objectKeys: Value = object_keys(&object);
paramsKeys = self.sort(objectKeys, &[]);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_600: bool = true;
while { if !__for_first_600 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_600 = false; i.as_f64().unwrap_or(f64::NAN) < ((paramsKeys.len() as i64) as f64) } {
let mut key: Value = paramsKeys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
returnString = Value::Str(format!("{}{}", returnString, key).into());
let mut value: Value = get_value(&object, &key);
let mut value: Value = get_value(&object, &key);
if (value.as_str() == Some("undefined")) {
returnString = Value::Str(format!("{}{}", returnString, Value::Str("null".into())).into());
} else if (matches!(&value, Value::Arr(_))) {
{
let mut j: Value = Value::Int(0);
let mut __for_first_599: bool = true;
while { if !__for_first_599 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_599 = false; j.as_f64().unwrap_or(f64::NAN) < ((value.len() as i64) as f64) } {
returnString = Value::Str(format!("{}{}", returnString, self.params_to_string(value.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), (match (&(level), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }))).into());
}
}
} 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), Value::Str("MARKET".into()));
m
});
let mut type_var: Value = self.safe_string_upper_k(params.clone(), "type", &[]);
let mut price: Value = self.safe_string_k(params.clone(), "price", &[]);
if (type_var != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), type_var); }
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), price)); }
}
let __ws_arg_23 = self.extend(request, &[params]);
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, "result", &[]);
return self.parse_order(result, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_24 = self.extend(request, &[params]);
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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(data, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v1_private_post_private_get_fee_rate(&[params]).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, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fees(result);
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
});
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("info".into(), response.clone()); }
{
let mut i: Value = Value::Int(0);
let mut __for_first_601: bool = true;
while { if !__for_first_601 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_601 = false; i.as_f64().unwrap_or(f64::NAN) < ((self.symbols.len() as i64) as f64) } {
let mut symbol: Value = self.symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(symbol.clone());
let mut isSwap: Value = market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null);
let mut takerFeeKey: Value = Value::Str("effective_spot_taker_rate_bps".into());
if (isSwap.as_bool() == Some(true)) {
takerFeeKey = Value::Str("effective_deriv_taker_rate_bps".into());
}
let mut makerFeeKey: Value = Value::Str("effective_spot_maker_rate_bps".into());
if (isSwap.as_bool() == Some(true)) {
makerFeeKey = Value::Str("effective_deriv_maker_rate_bps".into());
}
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, &[]), &Value::Str("10000".into())), &[]));
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string(response.clone(), takerFeeKey, &[]), &Value::Str("10000".into())), &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), tradingFee); }
}
}
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, &[market]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), symbol);
m.insert("maker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string_k(fee.clone(), "effective_maker_rate_bps", &[]), &Value::Str("10000".into())), &[]));
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string_k(fee, "effective_taker_rate_bps", &[]), &Value::Str("10000".into())), &[]));
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::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut requestHeaders: Value = Value::Null;
let mut requestBody: Value = Value::Null;
let mut type_var: Value = self.safe_string(api.clone(), Value::Int(0), &[]);
let mut access: Option<String> = self.safe_string(api, Value::Int(1), &[]).as_str().map(str::to_owned);
let mut apiUrl: Value = self.safe_string(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), type_var, &[]);
if (apiUrl == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", apiUrl, Value::Str("/".into())).into()), path).into());
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
if (access.as_deref() == Some("public")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into())).into());
}
} else {
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, Value::Int(0));
let mut payload: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", path, nonce).into()), self.apiKey.clone()).into()), strSortKey).into()), nonce).into());
let mut signature: Value = self.hmac(self.encode(payload), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[]);
let mut paramsKeysLength: f64 = ((paramsKeys.len() as i64) as f64);
requestBody = self.json(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), nonce.clone());
m.insert("method".to_string(), path);
m.insert("params".to_string(), params);
m.insert("api_key".to_string(), self.apiKey.clone());
m.insert("sig".to_string(), signature);
m.insert("nonce".to_string(), nonce);
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 (paramsKeysLength == 0.0) {
let mut paramsString: Value = Value::Str("{}".into());
let mut arrayString: Value = Value::Str("[]".into());
requestBody = replace_str(&requestBody, &arrayString, ¶msString);
}
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), requestBody);
m.insert("headers".to_string(), requestHeaders);
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, "code", &[]);
if (errorCode.as_str() != Some("0")) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode, feedback);
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body)));
}
return Value::Null;
Value::Null
}
}