// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
pub struct CryptomusCore {
pub exchange: crate::exchange::Exchange,
}
impl CryptomusCore {
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 = CryptomusCore::describe(self);
self.initialize_properties(described);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for CryptomusCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptomusCore.
CryptomusCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptomusCore.
CryptomusCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptomusCore.
CryptomusCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptomusCore.
CryptomusCore::parse_market(self, market)
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptomusCore.
CryptomusCore::parse_balance(self, response)
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptomusCore.
CryptomusCore::parse_currency(self, 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 CryptomusCore.
CryptomusCore::sign(self, path, &[api.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on CryptomusCore.
CryptomusCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for CryptomusCore {
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_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_canceled_and_closed_orders" => self.fetch_canceled_and_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"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_fee_tiers" => self.parse_fee_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for CryptomusCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for CryptomusCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl CryptomusCore {
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("cryptomus".to_string()));
m.insert("name".to_string(), Value::Str("Cryptomus".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("CA".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v2".to_string()));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(false));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(false));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("cancelWithdraw".to_string(), Value::Bool(false));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createConvertTrade".to_string(), Value::Bool(false));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrder".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("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(false));
m.insert("createOrderWithTakeProfitAndStopLossWs".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopLimitOrder".to_string(), Value::Bool(false));
m.insert("createStopLossOrder".to_string(), Value::Bool(false));
m.insert("createStopMarketOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(false));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(false));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(false));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(false));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(false));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(false));
m.insert("fetchConvertQuote".to_string(), Value::Bool(false));
m.insert("fetchConvertTrade".to_string(), Value::Bool(false));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
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(false));
m.insert("fetchDeposits".to_string(), Value::Bool(false));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
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("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarginModes".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("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(false));
m.insert("fetchOHLCV".to_string(), Value::Bool(false));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrder".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(false));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(false));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(false));
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(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(false));
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("repayMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".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(false));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/cce42038-d22e-49bc-8a9a-b9c92a2859a0".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.cryptomus.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api.cryptomus.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://cryptomus.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://doc.cryptomus.com/personal".to_string()));
m.insert("fees".to_string(), Value::Str("https://cryptomus.com/tariffs".to_string()));
m.insert("referral".to_string(), Value::Str("https://app.cryptomus.com/signup/?ref=JRP4yj".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2/user-api/exchange/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/exchange/market/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/exchange/market/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/exchange/market/order-book/{currencyPair}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/exchange/market/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/exchange/market/trades/{currencyPair}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2/user-api/exchange/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/exchange/orders/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/exchange/account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/exchange/account/tariffs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/payment/services".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/payout/services".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/transaction/list".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("v2/user-api/exchange/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user-api/exchange/orders/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2/user-api/exchange/orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
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("percentage".to_string(), Value::Bool(true));
m.insert("feeSide".to_string(), Value::Str("get".to_string()));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.02".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.02".to_string()), &[]));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BEP20".to_string(), Value::Str("bsc".to_string()));
m.insert("DASH".to_string(), Value::Str("dash".to_string()));
m.insert("POLYGON".to_string(), Value::Str("polygon".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("arbitrum".to_string()));
m.insert("SOL".to_string(), Value::Str("sol".to_string()));
m.insert("TON".to_string(), Value::Str("ton".to_string()));
m.insert("ERC20".to_string(), Value::Str("eth".to_string()));
m.insert("TRC20".to_string(), Value::Str("tron".to_string()));
m.insert("LTC".to_string(), Value::Str("ltc".to_string()));
m.insert("XMR".to_string(), Value::Str("xmr".to_string()));
m.insert("BCH".to_string(), Value::Str("bch".to_string()));
m.insert("DOGE".to_string(), Value::Str("doge".to_string()));
m.insert("AVAX".to_string(), Value::Str("avalanche".to_string()));
m.insert("BTC".to_string(), Value::Str("btc".to_string()));
m.insert("RUB".to_string(), Value::Str("rub".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bsc".to_string(), Value::Str("BEP20".to_string()));
m.insert("dash".to_string(), Value::Str("DASH".to_string()));
m.insert("polygon".to_string(), Value::Str("POLYGON".to_string()));
m.insert("arbitrum".to_string(), Value::Str("ARBITRUM".to_string()));
m.insert("sol".to_string(), Value::Str("SOL".to_string()));
m.insert("ton".to_string(), Value::Str("TON".to_string()));
m.insert("eth".to_string(), Value::Str("ERC20".to_string()));
m.insert("tron".to_string(), Value::Str("TRC20".to_string()));
m.insert("ltc".to_string(), Value::Str("LTC".to_string()));
m.insert("xmr".to_string(), Value::Str("XMR".to_string()));
m.insert("bch".to_string(), Value::Str("BCH".to_string()));
m.insert("doge".to_string(), Value::Str("DOGE".to_string()));
m.insert("avalanche".to_string(), Value::Str("AVAX".to_string()));
m.insert("btc".to_string(), Value::Str("BTC".to_string()));
m.insert("rub".to_string(), Value::Str("RUB".to_string()));
m
}));
m.insert("fetchOrderBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("level".to_string(), Value::Int(0));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("500".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("6".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("Insufficient funds.".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("Minimum amount 15 USDT".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(false));
m.insert("uid".to_string(), Value::Bool(true));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name cryptomus#fetchMarkets
* @description retrieves data on all markets for the exchange
* @see https://doc.cryptomus.com/personal/market-cap/tickers
* @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.public_get_v2_user_api_exchange_markets(&[params.clone()]).await;
//
// {
// "result": [
// {
// "id": "01JHN5EFT64YC4HR9KCGM5M65D",
// "symbol": "POL_USDT",
// "baseCurrency": "POL",
// "quoteCurrency": "USDT",
// "baseMinSize": "1.00000000",
// "quoteMinSize": "5.00000000",
// "baseMaxSize": "50000.00000000",
// "quoteMaxSize": "10000000000.00000000",
// "basePrec": "1",
// "quotePrec": "4"
// },
// ...
// ]
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_markets(result.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
//
// {
// "id": "01JHN5EFT64YC4HR9KCGM5M65D",
// "symbol": "POL_USDT",
// "baseCurrency": "POL",
// "quoteCurrency": "USDT",
// "baseMinSize": "1.00000000",
// "quoteMinSize": "5.00000000",
// "baseMaxSize": "50000.00000000",
// "quoteMaxSize": "10000000000.00000000",
// "basePrec": "1",
// "quotePrec": "4"
// }
//
let mut marketId: Value = self.safe_string_k(market.clone(), "symbol", &[]);
if is_equal(&marketId, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseMarket() missing marketId".to_string()))));
}
let mut parts: Value = split(&marketId, &Value::Str("_".to_string()));
let mut baseId: Value = get_value(&parts, &Value::Int(0));
let mut quoteId: Value = get_value(&parts, &Value::Int(1));
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut fees: Value = self.safe_dict_k(self.fees.clone(), "trading", &[]);
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.clone());
m.insert("symbol".to_string(), add(&add(&base, &Value::Str("/".to_string())), "e));
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("active".to_string(), Value::Bool(true));
m.insert("type".to_string(), Value::Str("spot".to_string()));
m.insert("subType".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("settle".to_string(), Value::Null);
m.insert("settleId".to_string(), Value::Null);
m.insert("contractSize".to_string(), Value::Null);
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("taker".to_string(), self.safe_number_k(fees.clone(), "taker", &[]));
m.insert("maker".to_string(), self.safe_number_k(fees.clone(), "maker", &[]));
m.insert("percentage".to_string(), self.safe_bool_k(fees.clone(), "percentage", &[]));
m.insert("tierBased".to_string(), Value::Null);
m.insert("feeSide".to_string(), self.safe_string_k(fees.clone(), "feeSide", &[]));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quotePrec", &[])]), &[]));
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "basePrec", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "quoteMinSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "quoteMaxSize", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "baseMinSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "baseMaxSize", &[]));
m
}));
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name cryptomus#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://doc.cryptomus.com/personal/market-cap/assets
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_v1_exchange_market_assets(&[params.clone()]).await;
//
// {
// 'state': '0',
// 'result': [
// {
// 'currency_code': 'USDC',
// 'network_code': 'bsc',
// 'can_withdraw': true,
// 'can_deposit': true,
// 'min_withdraw': '1.00000000',
// 'max_withdraw': '10000000.00000000',
// 'max_deposit': '10000000.00000000',
// 'min_deposit': '1.00000000'
// },
// ...
// ]
// }
//
let mut coins: Value = self.safe_list_k(response.clone(), "result", &[]);
let mut groupedById: Value = self.group_by(coins.clone(), Value::Str("currency_code".to_string()), &[]);
let mut groupedArray: Value = object_values(&groupedById);
return self.parse_currencies(groupedArray.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
// currency here is array of networks
let mut id: Value = Value::Null; // all entries have same id, as they were grouped by
let mut code: Value = Value::Null;
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_605: bool = true;
while { if !__for_first_605 { i = add(&i, &Value::Int(1)); } __for_first_605 = false; is_less_than(&i, &get_array_length(&rawCurrency)) } {
let mut networkEntry: Value = get_value(&rawCurrency, &i);
let mut networkEntry: Value = get_value(&rawCurrency, &i);
// set ID on first loop
if is_equal(&id, &Value::Null) {
id = self.safe_string_k(networkEntry.clone(), "currency_code", &[]);
code = self.safe_currency_code(id.clone(), &[]);
}
let mut networkId: Value = self.safe_string_k(networkEntry.clone(), "network_code", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
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(networkEntry.clone(), "min_withdraw", &[]));
m.insert("max".to_string(), self.safe_number_k(networkEntry.clone(), "max_withdraw", &[]));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(networkEntry.clone(), "min_deposit", &[]));
m.insert("max".to_string(), self.safe_number_k(networkEntry.clone(), "max_deposit", &[]));
m
}));
m
}));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(networkEntry.clone(), "can_deposit", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(networkEntry.clone(), "can_withdraw", &[]));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("info".to_string(), networkEntry.clone());
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("code".to_string(), code.clone());
m.insert("networks".to_string(), networks.clone());
m.insert("info".to_string(), rawCurrency.clone());
m
}));
Value::Null
}
/*
* @method
* @name cryptomus#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://doc.cryptomus.com/personal/market-cap/tickers
* @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.public_get_v1_exchange_market_tickers(&[params.clone()]).await;
//
// {
// "data": [
// {
// "currency_pair": "MATIC_USDT",
// "last_price": "0.342",
// "base_volume": "1676.84092771",
// "quote_volume": "573.48033609043"
// },
// ...
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_tickers(data.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "currency_pair": "XMR_USDT",
// "last_price": "158.04829772",
// "base_volume": "0.35185785",
// "quote_volume": "55.523761128544"
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "currency_pair", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut last: Value = self.safe_string_k(ticker.clone(), "last_price", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), Value::Null);
m.insert("low".to_string(), Value::Null);
m.insert("bid".to_string(), Value::Null);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), Value::Null);
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "base_volume", &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "quote_volume", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptomus#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://doc.cryptomus.com/personal/market-cap/orderbook
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.level] 0 or 1 or 2 or 3 or 4 or 5 - the level of volume
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencyPair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut level: Value = Value::Int(0);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrderBook".to_string()), Value::Str("level".to_string()), &[level.clone()]); level = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("level".to_string()), level.clone());
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v1_exchange_market_order_book_currency_pair(&[__ws_arg_0]).await;
//
// {
// "data": {
// "timestamp": "1730138702",
// "bids": [
// {
// "price": "2250.00",
// "quantity": "1.00000"
// }
// ],
// "asks": [
// {
// "price": "2428.69",
// "quantity": "0.16470"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_timestamp(data.clone(), Value::Str("timestamp".to_string()), &[]);
return self.parse_order_book(data.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Str("price".to_string()), Value::Str("quantity".to_string())]);
Value::Null
}
/*
* @method
* @name cryptomus#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://doc.cryptomus.com/personal/market-cap/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
* @param {int} [limit] the maximum amount of trades to fetch (maximum value is 100)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencyPair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v1_exchange_market_trades_currency_pair(&[__ws_arg_1]).await;
//
// {
// "data": [
// {
// "trade_id": "01J829C3RAXHXHR09HABGQ1YAT",
// "price": "2315.6320500000000000",
// "base_volume": "21.9839623057260000",
// "quote_volume": "0.0094937200000000",
// "timestamp": 1726653796,
// "type": "sell"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
let mut dataList: Value = Value::List(vec![]);
if !is_equal(&data, &Value::Null) {
dataList = data.clone();
}
return self.parse_trades(dataList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "trade_id": "01J017Q6B3JGHZRP9D2NZHVKFX",
// "price": "59498.63487492",
// "base_volume": "94.00784310",
// "quote_volume": "0.00158000",
// "timestamp": 1718028573,
// "type": "sell"
// }
//
let mut timestamp: Value = self.safe_timestamp(trade.clone(), Value::Str("timestamp".to_string()), &[]);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(trade.clone(), "trade_id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("side".to_string(), self.safe_string_k(trade.clone(), "type", &[]));
m.insert("price".to_string(), self.safe_string_k(trade.clone(), "price", &[]));
m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "quote_volume", &[]));
m.insert("cost".to_string(), self.safe_string_k(trade.clone(), "base_volume", &[]));
m.insert("takerOrMaker".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("order".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.insert("info".to_string(), trade.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptomus#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://doc.cryptomus.com/personal/converts/balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v2_user_api_exchange_account_balance(&[__ws_arg_2]).await;
//
// {
// "result": [
// {
// "ticker": "AVAX",
// "available": "0.00000000",
// "held": "0.00000000"
// }
// ]
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_balance(result.clone());
Value::Null
}
pub fn parse_balance(&self, mut balance: Value) -> Value {
//
// {
// "ticker": "AVAX",
// "available": "0.00000000",
// "held": "0.00000000"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), balance.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_606: bool = true;
while { if !__for_first_606 { i = add(&i, &Value::Int(1)); } __for_first_606 = false; is_less_than(&i, &get_array_length(&balance)) } {
let mut balanceEntry: Value = get_value(&balance, &i);
let mut balanceEntry: Value = get_value(&balance, &i);
let mut currencyId: Value = self.safe_string_k(balanceEntry.clone(), "ticker", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balanceEntry.clone(), "available", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balanceEntry.clone(), "held", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name cryptomus#createOrder
* @description create a trade order
* @see https://doc.cryptomus.com/personal/exchange/market-order-creation
* @see https://doc.cryptomus.com/personal/exchange/limit-order-creation
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit' or for spot
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders (only for limit orders)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.cost] *market buy only* the quote quantity that can be used as an alternative for the amount
* @param {string} [params.clientOrderId] a unique identifier for the order (optional)
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("direction".to_string(), side.clone());
m.insert("tag".to_string(), Value::Str("ccxt".to_string()));
m
});
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderId.clone());
}
let mut sideBuy: bool = is_equal(&side, &Value::Str("buy".to_string()));
let mut amountToString: Value = self.number_to_string(amount.clone());
let mut priceToString: Value = self.number_to_string(price.clone());
let mut cost: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("cost".to_string()), &[]); cost = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("market".to_string())) {
if is_true(&sideBuy) {
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("createMarketBuyOrderRequiresPrice".to_string()), &[Value::Bool(true)]); createMarketBuyOrderRequiresPrice = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&createMarketBuyOrderRequiresPrice) {
if is_true(&(is_equal(&price, &Value::Null))) && is_true(&(is_equal(&cost, &Value::Null))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option of param to false and pass the cost to spend in the amount argument".to_string()))));
} else if is_equal(&cost, &Value::Null) {
cost = crate::precise::Precise::stringMul(&amountToString, &priceToString);
}
} else {
cost = ternary(is_true(&(!is_equal(&cost, &Value::Null) && !is_equal(&cost, &Value::Str("".to_string())))), cost.clone(), amountToString.clone());
}
add_element_to_object(&mut request, &Value::Str("value".to_string()), cost.clone());
} else {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), amountToString.clone());
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_v2_user_api_exchange_orders_market(&[__ws_arg_3]).await;
} else if is_equal(&type_var, &Value::Str("limit".to_string())) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" createOrder() requires a price parameter for a ".to_string())), &type_var), &Value::Str(" order".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), amountToString.clone());
add_element_to_object(&mut request, &Value::Str("price".to_string()), price.clone());
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_v2_user_api_exchange_orders(&[__ws_arg_4]).await;
} else {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a type parameter (limit or market)".to_string()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name cryptomus#cancelOrder
* @description cancels an open limit order
* @see https://doc.cryptomus.com/personal/exchange/limit-order-cancellation
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in (not used in cryptomus)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_delete_v2_user_api_exchange_orders_order_id(&[__ws_arg_5]).await;
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[]);
Value::Null
}
/*
* @method
* @name cryptomus#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://doc.cryptomus.com/personal/exchange/history-of-completed-orders
* @param {string} symbol unified market symbol of the market orders were made in (not used in cryptomus)
* @param {int} [since] the earliest time in ms to fetch orders for (not used in cryptomus)
* @param {int} [limit] the maximum number of order structures to retrieve (not used in cryptomus)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.direction] order direction 'buy' or 'sell'
* @param {string} [params.order_id] order id
* @param {string} [params.client_order_id] client order id
* @param {string} [params.limit] A special parameter that sets the maximum number of records the request will return
* @param {string} [params.offset] A special parameter that sets the number of records from the beginning of the list
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_and_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("market".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v2_user_api_exchange_orders_history(&[__ws_arg_6]).await;
//
// {
// "result": [
// {
// "id": "01JEXAPY04JDFBVFC2D23BCKMK",
// "type": "market",
// "direction": "sell",
// "symbol": "TRX_USDT",
// "quantity": "67.5400000000000000",
// "filledQuantity": "67.5400000000000000",
// "filledValue": "20.0053480000000000",
// "state": "completed",
// "internalState": "filled",
// "createdAt": "2024-12-12 11:40:19",
// "finishedAt": "2024-12-12 11:40:21",
// "deal": {
// "id": "01JEXAPZ9C9TWENPFZJASZ1YD2",
// "state": "completed",
// "createdAt": "2024-12-12 11:40:21",
// "completedAt": "2024-12-12 11:40:21",
// "averageFilledPrice": "0.2962000000000000",
// "transactions": [
// {
// "id": "01JEXAPZ9C9TWENPFZJASZ1YD3",
// "tradeRole": "taker",
// "filledPrice": "0.2962000000000000",
// "filledQuantity": "67.5400000000000000",
// "filledValue": "20.0053480000000000",
// "fee": "0.0000000000000000",
// "feeCurrency": "USDT",
// "committedAt": "2024-12-12 11:40:21"
// }
// ]
// }
// },
// ...
// ]
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
let mut orders: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_607: bool = true;
while { if !__for_first_607 { i = add(&i, &Value::Int(1)); } __for_first_607 = false; is_less_than(&i, &get_array_length(&result)) } {
let mut order: Value = get_value(&result, &i);
let mut order: Value = get_value(&result, &i);
append_to_array(&mut orders, self.parse_order(order.clone(), &[market.clone()]));
}
}
return orders;
Value::Null
}
/*
* @method
* @name cryptomus#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://doc.cryptomus.com/personal/exchange/list-of-active-orders
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for (not used in cryptomus)
* @param {int} [limit] the maximum number of open orders structures to retrieve (not used in cryptomus)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.direction] order direction 'buy' or 'sell'
* @param {string} [params.order_id] order id
* @param {string} [params.client_order_id] client order id
* @param {string} [params.limit] A special parameter that sets the maximum number of records the request will return
* @param {string} [params.offset] A special parameter that sets the number of records from the beginning of the list
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v2_user_api_exchange_orders(&[__ws_arg_7]).await;
//
// {
// "result": [
// {
// "id": "01JFFG72CBRDP68K179KC9DSTG",
// "direction": "sell",
// "symbol": "BTC_USDT",
// "price": "102.0130000000000000",
// "quantity": "0.0005000000000000",
// "value": "0.0510065000000000",
// "filledQuantity": "0.0000000000000000",
// "filledValue": "0.0000000000000000",
// "createdAt": "2024-12-19 09:02:51",
// "clientOrderId": "987654321",
// "stopLossPrice": "101.12"
// },
// ...
// ]
// }
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[market.clone(), Value::Null, Value::Null]);
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
// {
// "order_id": "01JEXAFCCC5ZVJPZAAHHDKQBNG"
// }
//
// fetchOrders
// {
// "id": "01JEXAPY04JDFBVFC2D23BCKMK",
// "type": "market",
// "direction": "sell",
// "symbol": "TRX_USDT",
// "quantity": "67.5400000000000000",
// "filledQuantity": "67.5400000000000000",
// "filledValue": "20.0053480000000000",
// "state": "completed",
// "internalState": "filled",
// "createdAt": "2024-12-12 11:40:19",
// "finishedAt": "2024-12-12 11:40:21",
// "deal": {
// "id": "01JEXAPZ9C9TWENPFZJASZ1YD2",
// "state": "completed",
// "createdAt": "2024-12-12 11:40:21",
// "completedAt": "2024-12-12 11:40:21",
// "averageFilledPrice": "0.2962000000000000",
// "transactions": [
// {
// "id": "01JEXAPZ9C9TWENPFZJASZ1YD3",
// "tradeRole": "taker",
// "filledPrice": "0.2962000000000000",
// "filledQuantity": "67.5400000000000000",
// "filledValue": "20.0053480000000000",
// "fee": "0.0000000000000000",
// "feeCurrency": "USDT",
// "committedAt": "2024-12-12 11:40:21"
// }
// ]
// }
// },
// ...
//
// fetchOpenOrders
// {
// "id": "01JFFG72CBRDP68K179KC9DSTG",
// "direction": "sell",
// "symbol": "BTC_USDT",
// "price": "102.0130000000000000",
// "quantity": "0.0005000000000000",
// "value": "0.0510065000000000",
// "filledQuantity": "0.0000000000000000",
// "filledValue": "0.0000000000000000",
// "createdAt": "2024-12-19 09:02:51",
// "clientOrderId": "987654321",
// "stopLossPrice": "101.12"
// }
//
let mut id: Value = self.safe_string2(order.clone(), Value::Str("order_id".to_string()), Value::Str("id".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut dateTime: Value = self.safe_string_k(order.clone(), "createdAt", &[]);
let mut timestamp: Value = self.parse8601(dateTime.clone());
let mut deal: Value = self.safe_dict_k(order.clone(), "deal", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut averageFilledPrice: Value = self.safe_number_k(deal.clone(), "averageFilledPrice", &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(order.clone(), "direction", &[]);
let mut price: Value = self.safe_number_k(order.clone(), "price", &[]);
let mut transaction: Value = self.safe_list_k(deal.clone(), "transactions", &[Value::List(vec![])]);
let mut fee: Value = Value::Null;
let mut firstTx: Value = self.safe_dict(transaction.clone(), Value::Int(0), &[]);
let mut feeCurrency: Value = self.safe_string_k(firstTx.clone(), "feeCurrency", &[]);
if !is_equal(&feeCurrency, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(feeCurrency.clone(), &[]));
m.insert("cost".to_string(), self.safe_number_k(firstTx.clone(), "fee", &[]));
m
});
}
if is_equal(&price, &Value::Null) {
price = self.safe_number_k(firstTx.clone(), "filledPrice", &[]);
}
let mut amount: Value = self.safe_number_k(order.clone(), "quantity", &[]);
let mut cost: Value = self.safe_number_k(order.clone(), "value", &[]);
let mut status: Value = self.parse_order_status(&[self.safe_string_k(order.clone(), "state", &[])]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "clientOrderId", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), Value::Null);
m.insert("postOnly".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("stopPrice".to_string(), self.safe_string_k(order.clone(), "stopLossPrice", &[]));
m.insert("triggerPrice".to_string(), self.safe_string_k(order.clone(), "stopLossPrice", &[]));
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("average".to_string(), averageFilledPrice.clone());
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "filledQuantity", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("trades".to_string(), Value::Null);
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_order_status(&self, optional_args: &[Value]) -> Value {
let mut status = get_arg(optional_args, 0, Value::Null);
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("active".to_string(), Value::Str("open".to_string()));
m.insert("completed".to_string(), Value::Str("closed".to_string()));
m.insert("partially_completed".to_string(), Value::Str("open".to_string()));
m.insert("cancelled".to_string(), Value::Str("canceled".to_string()));
m.insert("expired".to_string(), Value::Str("expired".to_string()));
m.insert("failed".to_string(), Value::Str("failed".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name cryptomus#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://trade-docs.coinlist.co/?javascript--nodejs#list-fees
* @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
}));
let mut response: Value = self.private_get_v2_user_api_exchange_account_tariffs(&[params.clone()]).await;
//
// {
// result: {
// equivalent_currency_code: 'USD',
// current_tariff_step: {
// step: '0',
// from_turnover: '0.00000000',
// maker_percent: '0.08',
// taker_percent: '0.1'
// },
// tariff_steps: [
// {
// step: '0',
// from_turnover: '0.00000000',
// maker_percent: '0.08',
// taker_percent: '0.1'
// },
// {
// step: '1',
// from_turnover: '100001.00000000',
// maker_percent: '0.06',
// taker_percent: '0.095'
// },
// {
// step: '2',
// from_turnover: '250001.00000000',
// maker_percent: '0.055',
// taker_percent: '0.085'
// },
// {
// step: '3',
// from_turnover: '500001.00000000',
// maker_percent: '0.05',
// taker_percent: '0.075'
// },
// {
// step: '4',
// from_turnover: '2500001.00000000',
// maker_percent: '0.04',
// taker_percent: '0.07'
// }
// ],
// daily_turnover: '0.00000000',
// monthly_turnover: '77.52062617',
// circulation_funds: '25.48900443'
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currentFeeTier: Value = self.safe_dict_k(data.clone(), "current_tariff_step", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut makerFee: Value = self.safe_string_k(currentFeeTier.clone(), "maker_percent", &[]);
let mut takerFee: Value = self.safe_string_k(currentFeeTier.clone(), "taker_percent", &[]);
makerFee = crate::precise::Precise::stringDiv(&makerFee, &Value::Str("100".to_string()));
takerFee = crate::precise::Precise::stringDiv(&takerFee, &Value::Str("100".to_string()));
let mut feeTiers: Value = self.safe_list_k(data.clone(), "tariff_steps", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut tiers: Value = self.parse_fee_tiers(feeTiers.clone(), &[]);
let mut symbols: Value = self.symbols.clone();
if is_equal(&symbols, &Value::Null) {
return result;
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_608: bool = true;
while { if !__for_first_608 { i = add(&i, &Value::Int(1)); } __for_first_608 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
add_element_to_object(&mut result, &symbol, 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(makerFee.clone(), &[]));
m.insert("taker".to_string(), self.parse_number(takerFee.clone(), &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("tiers".to_string(), tiers.clone());
m
}));
}
}
return result;
Value::Null
}
pub fn parse_fee_tiers(&self, mut feeTiers: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut takerFees: Value = Value::List(vec![]);
let mut makerFees: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_609: bool = true;
while { if !__for_first_609 { i = add(&i, &Value::Int(1)); } __for_first_609 = false; is_less_than(&i, &get_array_length(&feeTiers)) } {
let mut tier: Value = get_value(&feeTiers, &i);
let mut tier: Value = get_value(&feeTiers, &i);
let mut turnover: Value = self.safe_number_k(tier.clone(), "from_turnover", &[]);
let mut taker: Value = self.safe_string_k(tier.clone(), "taker_percent", &[]);
let mut maker: Value = self.safe_string_k(tier.clone(), "maker_percent", &[]);
maker = crate::precise::Precise::stringDiv(&maker, &Value::Str("100".to_string()));
taker = crate::precise::Precise::stringDiv(&taker, &Value::Str("100".to_string()));
append_to_array(&mut makerFees, Value::List(vec![turnover.clone(), self.parse_number(maker.clone(), &[])]));
append_to_array(&mut takerFees, Value::List(vec![turnover.clone(), self.parse_number(taker.clone(), &[])]));
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), makerFees.clone());
m.insert("taker".to_string(), takerFees.clone());
m
});
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut endpoint: Value = self.implode_params(path.clone(), params.clone());
params = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &endpoint);
if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut jsonParams: Value = Value::Str("".to_string());
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("userId".to_string(), self.uid.clone());
m
});
if !is_equal(&method, &Value::Str("GET".to_string())) {
body = self.json(params.clone());
jsonParams = body.clone();
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
} else {
let mut query: Value = self.urlencode(params.clone(), &[]);
if !is_equal(&get_array_length(&query), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &query));
}
}
let mut jsonParamsBase64: Value = self.string_to_base64(jsonParams.clone(), &[]);
let mut stringToSign: Value = add(&jsonParamsBase64, &self.secret);
let mut signature: Value = self.hash(self.encode(stringToSign.clone()), Value::Str("md5".to_string()), &[]);
add_element_to_object(&mut headers, &Value::Str("sign".to_string()), signature.clone());
} else {
let mut query: Value = self.urlencode(params.clone(), &[]);
if !is_equal(&get_array_length(&query), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &query));
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
if is_true(&Value::Bool(in_op(&response, &Value::Str("code".to_string())))) {
let mut code: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
} else if is_true(&Value::Bool(in_op(&response, &Value::Str("message".to_string())))) {
//
// {"message":"Minimum amount 15 USDT","state":1}
//
let mut message: Value = self.safe_string_k(response.clone(), "message", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}