// 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 MudrexCore {
pub exchange: crate::exchange::Exchange,
}
impl MudrexCore {
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 = MudrexCore::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 MudrexCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::parse_position(self, position, &[market.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on MudrexCore.
MudrexCore::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 MudrexCore.
MudrexCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for MudrexCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_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,
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_mark_ohlcv" => self.fetch_mark_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders_by_state" => self.fetch_orders_by_state(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"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_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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()[..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for MudrexCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for MudrexCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl MudrexCore {
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("mudrex".to_string()));
m.insert("name".to_string(), Value::Str("Mudrex".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("IN".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("dex".to_string(), Value::Bool(false));
m.insert("hostname".to_string(), Value::Str("trade.mudrex.com".to_string()));
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(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
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("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("watchOHLCV".to_string(), Value::Bool(true));
m.insert("watchTicker".to_string(), Value::Bool(true));
m.insert("watchTickers".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("3m".to_string(), Value::Str("3t".to_string()));
m.insert("5m".to_string(), Value::Str("5t".to_string()));
m.insert("10m".to_string(), Value::Str("10t".to_string()));
m.insert("15m".to_string(), Value::Str("15t".to_string()));
m.insert("30m".to_string(), Value::Str("30t".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1mth".to_string()));
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/72368864-84ed-43eb-8c75-d4fb77023b42".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://trade.mudrex.com/fapi/v1".to_string()));
m.insert("private".to_string(), Value::Str("https://trade.mudrex.com/fapi/v1".to_string()));
m.insert("market".to_string(), Value::Str("https://trade.mudrex.com/fapi/v1".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://mudrex.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://docs.trade.mudrex.com/docs".to_string()));
m.insert("fees".to_string(), Value::Str("https://docs.trade.mudrex.com".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".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("price/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("price/mark-kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
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
}));
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("futures".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/{asset_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wallet/funds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/funds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/orders/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/positions/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/fee/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/{asset_id}/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("futures/positions/{position_id}/liq-price".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("wallet/futures/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/transfers/inr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/{asset_id}/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("futures/positions/{position_id}/close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("futures/positions/{position_id}/close/partial".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("futures/positions/{position_id}/reverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("futures/positions/{position_id}/add-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("futures/positions/{position_id}/riskorder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("futures/{asset_id}/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("patch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("futures/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/positions/{position_id}/riskorder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("futures/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(false));
m.insert("secret".to_string(), Value::Bool(true));
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("tierBased".to_string(), Value::Bool(false));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.00059".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.00023".to_string()), &[]));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("swap".to_string()));
m.insert("broker".to_string(), Value::Str("42ce8902-8585-448c-a1e8-0371a6ca7ca8".to_string()));
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("400 Invalid trade currency".to_string(), Value::Str("BadRequest".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Invalid trade currency".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("Params error".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("invalid trigger type".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("invalid order type".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("order price out of permissible range".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("quantity not a multiple of the quantity step".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("leverage out of permissible range".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("insufficient balance".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("asset not found".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("leverage not found".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("order not found".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("Rate limit exceeded".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m
}));
m
}));
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 apiUrls: Value = self.safe_dict_k(self.urls.clone(), "api", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut base: Value = self.safe_string(apiUrls.clone(), api.clone(), &[]);
if is_equal(&base, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" unknown API namespace: ".to_string())), &api)));
}
let mut url: Value = add(&add(&base, &Value::Str("/".to_string())), &self.implode_params(path.clone(), params.clone()));
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut requestHeaders: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&headers, &Value::Null) {
requestHeaders = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[headers.clone()]);
}
let mut brokerId: Value = self.safe_string_k(self.options.clone(), "broker", &[]);
if !is_equal(&brokerId, &Value::Null) {
add_element_to_object(&mut requestHeaders, &Value::Str("Partner-Id".to_string()), brokerId.clone());
}
let mut methodUpper: Value = to_upper(&method);
if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
add_element_to_object(&mut requestHeaders, &Value::Str("X-Authentication".to_string()), self.secret.clone());
if is_equal(&methodUpper, &Value::Str("POST".to_string())) || is_equal(&methodUpper, &Value::Str("PATCH".to_string())) || is_equal(&methodUpper, &Value::Str("DELETE".to_string())) {
add_element_to_object(&mut requestHeaders, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
// is_symbol is a query-string flag even on write requests
let mut isSymbol: Value = self.safe_string_k(query.clone(), "is_symbol", &[]);
if !is_equal(&isSymbol, &Value::Null) {
query = self.omit(query.clone(), Value::Str("is_symbol".to_string()), &[]);
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("is_symbol".to_string(), isSymbol.clone());
m
}), &[])));
}
if is_true(&(is_equal(&methodUpper, &Value::Str("DELETE".to_string())))) && is_true(&self.is_empty(query.clone())) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), methodUpper.clone());
m.insert("body".to_string(), Value::Null);
m.insert("headers".to_string(), requestHeaders.clone());
m
});
}
let mut bodyStr: Value = self.json(query.clone());
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), methodUpper.clone());
m.insert("body".to_string(), bodyStr.clone());
m.insert("headers".to_string(), requestHeaders.clone());
m
});
}
}
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), methodUpper.clone());
m.insert("body".to_string(), Value::Null);
m.insert("headers".to_string(), requestHeaders.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) || !is_object(&response) {
return Value::Null;
}
let mut success: Value = self.safe_bool_k(response.clone(), "success", &[Value::Bool(true)]);
if !is_equal(&success, &Value::Bool(true)) {
let mut errors: Value = self.safe_list_k(response.clone(), "errors", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(errors.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut text: Value = self.safe_string_k(first.clone(), "text", &[self.json(response.clone())]);
let mut errCode: Value = self.safe_string_k(first.clone(), "code", &[]);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), text.clone(), add(&add(&self.id, &Value::Str(" ".to_string())), &text));
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errCode.clone(), add(&add(&self.id, &Value::Str(" ".to_string())), &text));
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), text.clone(), add(&add(&self.id, &Value::Str(" ".to_string())), &text));
let mut msg: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &text);
let mut low: Value = to_lower(&text);
if is_equal(&code, &Value::Int(401)) || is_greater_than_or_equal(&get_index_of(&low, &Value::Str("auth".to_string())), &Value::Int(0)) {
panic!("{}", crate::exchange_errors::authentication_error(msg));
}
if is_equal(&code, &Value::Int(429)) || is_greater_than_or_equal(&get_index_of(&low, &Value::Str("rate".to_string())), &Value::Int(0)) {
panic!("{}", crate::exchange_errors::rate_limit_exceeded(msg));
}
if is_greater_than_or_equal(&get_index_of(&low, &Value::Str("insufficient".to_string())), &Value::Int(0)) {
panic!("{}", crate::exchange_errors::insufficient_funds(msg));
}
if is_equal(&code, &Value::Int(400)) {
panic!("{}", crate::exchange_errors::bad_request(msg));
}
panic!("{}", crate::exchange_errors::exchange_error(msg));
}
return Value::Null;
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_timestamp(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name mudrex#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://docs.trade.mudrex.com/docs/historical-kline
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @param {string} [params.price] "mark" to fetch mark price candles
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut priceType: Value = self.safe_string_k(params.clone(), "price", &[]);
params = self.omit(params.clone(), Value::Str("price".to_string()), &[]);
// the endpoint expects the pair in "BASE/QUOTE" format (comma-separated for multiple)
let mut assetPair: Value = add(&add(&get_value(&market, &Value::Str("baseId".to_string())), &Value::Str("/".to_string())), &get_value(&market, &Value::Str("quoteId".to_string())));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("assets".to_string(), assetPair.clone());
m.insert("aggregation".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
// the endpoint requires an explicit time window (in seconds)
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut requestLimit: Value = limit.clone();
if is_equal(&requestLimit, &Value::Null) {
requestLimit = Value::Int(500);
}
let mut now: Value = self.seconds();
let mut startTime: Value = Value::Null;
if !is_equal(&since, &Value::Null) {
startTime = self.parse_to_int(divide(&since, &Value::Int(1000)));
} else {
startTime = subtract(&now, &multiply(&duration, &requestLimit));
}
if is_equal(&startTime, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchOHLCV() missing startTime".to_string()))));
}
let mut endTime: Value = add(&startTime, &multiply(&duration, &requestLimit));
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
endTime = self.parse_to_int(divide(&until, &Value::Int(1000)));
} else if is_greater_than(&endTime, &now) {
endTime = now.clone();
}
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), startTime.clone());
add_element_to_object(&mut request, &Value::Str("end_time".to_string()), endTime.clone());
let mut response: Value = Value::Null;
if is_equal(&priceType, &Value::Str("mark".to_string())) {
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.market_get_price_mark_kline(&[__ws_arg_0]).await;
} else {
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
response = self.market_get_price_kline(&[__ws_arg_1]).await;
}
//
// {
// "success": true,
// "data": {
// "asset_ticks": {
// "btc/usdt": [ [ 1782984660, 60681, 60797.6, 60671.8, 60693.3, 275.741 ] ]
// }
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut assetTicks: Value = self.safe_dict_k(data.clone(), "asset_ticks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ohlcvs: Value = self.safe_list(assetTicks.clone(), to_lower(&assetPair), &[Value::List(vec![])]);
return self.parse_ohlc_vs(ohlcvs.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#fetchMarkOHLCV
* @description fetches historical mark price candlestick data containing the open, high, low, and close price of a market
* @see https://docs.trade.mudrex.com/docs
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_mark_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __ws_arg_2 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), Value::Str("mark".to_string()));
m
})]);
return self.fetch_ohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), __ws_arg_2]).await;
Value::Null
}
/*
* @method
* @name mudrex#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://docs.trade.mudrex.com/docs
* @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](https://docs.ccxt.com/#/?id=ticker-structure)
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("is_symbol".to_string(), Value::Int(1));
m
});
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_asset_id(&[__ws_arg_3]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://docs.trade.mudrex.com/docs
* @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](https://docs.ccxt.com/#/?id=ticker-structure)
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures(&[__ws_arg_4]).await;
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rows: Value = ternary(is_true(&Value::Bool(is_array(&data))), data.clone(), self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]));
let mut resultTickers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_954: bool = true;
while { if !__for_first_954 { i = add(&i, &Value::Int(1)); } __for_first_954 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut t: Value = get_value(&rows, &i);
let mut t: Value = get_value(&rows, &i);
let mut sym: Value = self.safe_string_k(t.clone(), "symbol", &[]);
if is_equal(&sym, &Value::Null) {
continue;
}
let mut m: Value = self.safe_market(&[sym.clone()]);
let mut symbol: Value = get_value(&m, &Value::Str("symbol".to_string()));
if !is_equal(&symbols, &Value::Null) && !is_true(&self.in_array(symbol.clone(), symbols.clone())) {
continue;
}
add_element_to_object(&mut resultTickers, &symbol, self.parse_ticker(t.clone(), &[m.clone()]));
}
}
return self.filter_by_array_tickers(resultTickers.clone(), Value::Str("symbol".to_string()), &[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);
let mut ms: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
market = self.safe_market(&[ms.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut ts: Value = self.milliseconds();
let mut pct: Value = self.safe_number_k(ticker.clone(), "change_perc", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), ts.clone());
m.insert("datetime".to_string(), self.iso8601(ts.clone()));
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(), self.safe_number_k(ticker.clone(), "last_day_price", &[]));
m.insert("close".to_string(), self.safe_number_k(ticker.clone(), "price", &[]));
m.insert("last".to_string(), self.safe_number_k(ticker.clone(), "price", &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), pct.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), Value::Null);
m.insert("quoteVolume".to_string(), self.safe_number_k(ticker.clone(), "volume", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#fetchMarkets
* @description retrieves data on all markets for the exchange
* @see https://docs.trade.mudrex.com/docs
* @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 aggregated: Value = Value::List(vec![]);
let mut offset: Value = Value::Int(0);
let mut pageLimit: Value = Value::Int(100);
let mut paging: Value = Value::Bool(true);
while is_equal(&paging, &Value::Bool(true)) {
let mut q: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), pageLimit.clone());
m.insert("offset".to_string(), offset.clone());
m
}), &[params.clone()]);
let mut response: Value = self.private_get_futures(&[q.clone()]).await;
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut items: Value = Value::List(vec![]);
if is_object(&data) && !is_true(&Value::Bool(is_array(&data))) {
items = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
// hoisted - inline length reads within conditionals become strlen for php, fatal on arrays
let mut itemsLength: Value = get_array_length(&items);
if is_true(&(is_equal(&itemsLength, &Value::Null))) || is_true(&(is_equal(&itemsLength, &Value::Int(0)))) {
items = self.safe_list_k(data.clone(), "results", &[Value::List(vec![])]);
itemsLength = get_array_length(&items);
}
if is_true(&(is_equal(&itemsLength, &Value::Int(0)))) && is_true(&(Value::Bool(in_op(&data, &Value::Str("symbol".to_string()))))) {
items = Value::List(vec![data.clone()]);
}
} else {
items = self.to_array(data.clone());
}
let mut numItems: Value = get_array_length(&items);
if is_true(&(is_equal(&numItems, &Value::Null))) || is_true(&(is_equal(&numItems, &Value::Int(0)))) {
paging = Value::Bool(false);
break;
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_955: bool = true;
while { if !__for_first_955 { i = add(&i, &Value::Int(1)); } __for_first_955 = false; is_less_than(&i, &numItems) } {
append_to_array(&mut aggregated, get_value(&items, &i));
}
}
if is_less_than(&numItems, &pageLimit) {
paging = Value::Bool(false);
} else {
// this.sum keeps the offset numeric across the php transpile, see https://github.com/ccxt/ccxt/pull/29684
offset = self.sum(&[offset.clone(), pageLimit.clone()]);
}
}
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_956: bool = true;
while { if !__for_first_956 { i = add(&i, &Value::Int(1)); } __for_first_956 = false; is_less_than(&i, &get_array_length(&aggregated)) } {
append_to_array(&mut result, self.parse_market(get_value(&aggregated, &i)));
}
}
return result;
Value::Null
}
pub fn parse_market(&self, mut asset: Value) -> Value {
let mut ms: Value = self.safe_string_k(asset.clone(), "symbol", &[]);
let mut base: Value = ms.clone();
if !is_equal(&ms, &Value::Null) && is_true(&Value::Bool(ends_with(&ms, &Value::Str("USDT".to_string())))) {
base = slice(&ms, &Value::Int(0), &negate(&Value::Int(4)));
}
let mut quote: Value = Value::Str("USDT".to_string());
let mut settle: Value = Value::Str("USDT".to_string());
let mut symbol: Value = Value::Null;
if !is_equal(&base, &Value::Null) {
symbol = add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
}
let mut priceStep: Value = self.safe_string_k(asset.clone(), "price_step", &[Value::Str("0.01".to_string())]);
let mut qtyStep: Value = self.safe_string_k(asset.clone(), "quantity_step", &[Value::Str("0.001".to_string())]);
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), ms.clone());
m.insert("lowercaseId".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), base.clone());
m.insert("quoteId".to_string(), Value::Str("USDT".to_string()));
m.insert("settleId".to_string(), Value::Str("USDT".to_string()));
m.insert("type".to_string(), Value::Str("swap".to_string()));
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool(true));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), Value::Bool(true));
m.insert("inverse".to_string(), Value::Bool(false));
m.insert("taker".to_string(), self.safe_number(get_value(&self.fees, &Value::Str("trading".to_string())), Value::Str("taker".to_string()), &[]));
m.insert("maker".to_string(), self.safe_number(get_value(&self.fees, &Value::Str("trading".to_string())), Value::Str("maker".to_string()), &[]));
m.insert("contractSize".to_string(), self.safe_number_k(asset.clone(), "contract_size", &[Value::Int(1)]));
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(qtyStep.clone(), &[]));
m.insert("price".to_string(), self.parse_number(priceStep.clone(), &[]));
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(asset.clone(), "min_contract", &[]));
m.insert("max".to_string(), self.safe_number_k(asset.clone(), "max_contract", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(asset.clone(), "min_price", &[]));
m.insert("max".to_string(), self.safe_number_k(asset.clone(), "max_price", &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(asset.clone(), "min_notional_value", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("info".to_string(), asset.clone());
m.insert("created".to_string(), Value::Null);
m
})]);
Value::Null
}
/*
* @method
* @name mudrex#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.trade.mudrex.com/docs
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'swap' (default) or 'spot' - which wallet balance to fetch
* @param {string} [params.trade_currency] the settlement currency to query the balance for
* @returns {object} a [balance structure](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 type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone(), Value::Str("swap".to_string())]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut requested: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("trade_currency".to_string()), Value::Str("tradeCurrency".to_string()), Value::Str("currency".to_string())]), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trade_currency".to_string()), Value::Str("tradeCurrency".to_string()), Value::Str("currency".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) {
if !is_equal(&requested, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency".to_string()), requested.clone());
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_wallet_funds(&[__ws_arg_5]).await;
} else {
if !is_equal(&requested, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("trade_currency".to_string()), requested.clone());
}
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_futures_funds(&[__ws_arg_6]).await;
}
let mut currency: Value = requested.clone();
if is_equal(¤cy, &Value::Null) {
currency = Value::Str("USDT".to_string());
}
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" fetchBalance() returned empty response".to_string()))));
}
add_element_to_object(&mut response, &Value::Str("currency".to_string()), currency.clone());
return self.parse_balance(response.clone());
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currency: Value = self.safe_string_k(response.clone(), "currency", &[Value::Str("USDT".to_string())]);
let mut timestamp: Value = self.milliseconds();
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
let mut account: Value = self.account();
let mut futuresBalance: Value = self.safe_string_k(data.clone(), "balance", &[]);
if !is_equal(&futuresBalance, &Value::Null) {
// futures wallet: balance is the free/available margin, locked_amount is used, safeBalance derives total
add_element_to_object(&mut account, &Value::Str("free".to_string()), futuresBalance.clone());
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(data.clone(), "locked_amount", &[]));
} else {
// spot wallet: total is the total, withdrawable is free, safeBalance derives used
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(data.clone(), "total", &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(data.clone(), "withdrawable", &[]));
}
add_element_to_object(&mut result, ¤cy, account.clone());
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name mudrex#fetchLeverage
* @description fetch the set leverage for a market
* @see https://docs.trade.mudrex.com/docs
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage structure](https://docs.ccxt.com/#/?id=leverage-structure)
*/
pub async fn fetch_leverage(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("is_symbol".to_string(), Value::Int(1));
m
});
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_asset_id_leverage(&[__ws_arg_7]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("marginMode".to_string(), self.safe_string_lower(data.clone(), Value::Str("margin_type".to_string()), &[]));
m.insert("longLeverage".to_string(), self.safe_number_k(data.clone(), "leverage", &[]));
m.insert("shortLeverage".to_string(), self.safe_number_k(data.clone(), "leverage", &[]));
m
});
Value::Null
}
/*
* @method
* @name mudrex#setLeverage
* @description set the level of leverage for a market
* @see https://docs.trade.mudrex.com/docs
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginType] 'ISOLATED' (default) or 'CROSSED'
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut marginType: Value = self.safe_string_k(params.clone(), "marginType", &[Value::Str("ISOLATED".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("is_symbol".to_string(), Value::Int(1));
m.insert("margin_type".to_string(), marginType.clone());
m.insert("leverage".to_string(), leverage.clone());
m
});
params = self.omit(params.clone(), Value::List(vec![Value::Str("marginType".to_string())]), &[]);
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_futures_asset_id_leverage(&[__ws_arg_8]).await;
return response;
Value::Null
}
/*
* @method
* @name mudrex#createOrder
* @description create a trade order
* @see https://docs.trade.mudrex.com/docs
* @param {string} symbol unified market symbol
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price to fulfill the order, in units of the quote currency (also required for market orders on this exchange)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.leverage] leverage for the order, required if setLeverage() was not called beforehand
* @param {bool} [params.reduceOnly] true if the order is reduce only
* @param {object} [params.takeProfit] *takeProfit object in params* containing the trigger price of the take-profit order attached to this order
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {object} [params.stopLoss] *stopLoss object in params* containing the trigger price of the stop-loss order attached to this order
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {float} [params.takeProfitPrice] the trigger price for a standalone take-profit order on an existing position (requires params.positionId)
* @param {float} [params.stopLossPrice] the trigger price for a standalone stop-loss order on an existing position (requires params.positionId)
* @param {string} [params.positionId] the id of the position the standalone stopLossPrice/takeProfitPrice order is attached to
* @param {string} [params.trade_currency] the settlement currency for the order
* @returns {object} an [order structure](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());
// standalone stop-loss / take-profit orders (stopLossPrice/takeProfitPrice) are attached to
// an existing position through the riskorder endpoint, so a positionId is required
let mut stopLossPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
if is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) {
let mut positionId: Value = self.safe_string2(params.clone(), Value::Str("positionId".to_string()), Value::Str("position_id".to_string()), &[]);
if is_equal(&positionId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a positionId parameter to place a stopLossPrice or takeProfitPrice order".to_string()))));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("positionId".to_string()), Value::Str("position_id".to_string())]), &[]);
let mut riskRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("position_id".to_string(), positionId.clone());
m
});
if !is_equal(&takeProfitPrice, &Value::Null) {
add_element_to_object(&mut riskRequest, &Value::Str("is_takeprofit".to_string()), Value::Bool(true));
add_element_to_object(&mut riskRequest, &Value::Str("takeprofit_price".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
}
if !is_equal(&stopLossPrice, &Value::Null) {
add_element_to_object(&mut riskRequest, &Value::Str("is_stoploss".to_string()), Value::Bool(true));
add_element_to_object(&mut riskRequest, &Value::Str("stoploss_price".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
}
let __ws_arg_9 = self.extend(riskRequest.clone(), &[params.clone()]);
let mut riskResponse: Value = self.private_post_futures_positions_position_id_riskorder(&[__ws_arg_9]).await;
let mut riskData: Value = self.safe_dict_k(riskResponse.clone(), "data", &[riskResponse.clone()]);
return self.parse_order(riskData.clone(), &[market.clone()]);
}
let mut lev: Value = self.safe_integer_k(params.clone(), "leverage", &[Value::Int(1)]);
if is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_equal(&price, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a price argument for market orders".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("is_symbol".to_string(), Value::Int(1));
m.insert("leverage".to_string(), self.number_to_string(lev.clone()));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("order_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m.insert("order_type".to_string(), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("LONG".to_string()), Value::Str("SHORT".to_string())));
m.insert("trigger_type".to_string(), ternary(is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))), Value::Str("MARKET".to_string()), Value::Str("LIMIT".to_string())));
m.insert("reduce_only".to_string(), self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]));
m
});
// mudrex only supports take-profit / stop-loss orders attached to the position-opening order
let mut takeProfit: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut stopLoss: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
if !is_equal(&takeProfit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("is_takeprofit".to_string()), Value::Bool(true));
add_element_to_object(&mut request, &Value::Str("takeprofit_price".to_string()), self.price_to_precision(symbol.clone(), self.safe_string_n(takeProfit.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("price".to_string())]), &[])));
}
if !is_equal(&stopLoss, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("is_stoploss".to_string()), Value::Bool(true));
add_element_to_object(&mut request, &Value::Str("stoploss_price".to_string()), self.price_to_precision(symbol.clone(), self.safe_string_n(stopLoss.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("price".to_string())]), &[])));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("leverage".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("takeProfit".to_string()), Value::Str("stopLoss".to_string())]), &[]);
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_futures_asset_id_order(&[__ws_arg_10]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[response.clone()]);
// the create response omits the order/trigger type, so restore them from the request
add_element_to_object(&mut data, &Value::Str("order_type".to_string()), get_value(&request, &Value::Str("order_type".to_string())));
add_element_to_object(&mut data, &Value::Str("trigger_type".to_string()), get_value(&request, &Value::Str("trigger_type".to_string())));
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#editOrder
* @description edit a trade order
* @see https://docs.trade.mudrex.com/docs
* @param {string} id order id
* @param {string} symbol unified symbol of the market to edit an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} [amount] how much of the currency you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure](https://docs.ccxt.com/#/?id=order-structure)
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id.clone());
m
});
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order_price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_patch_futures_orders_order_id(&[__ws_arg_11]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[response.clone()]);
return self.parse_order(data.clone(), &[market.clone()]);
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("open".to_string(), Value::Str("open".to_string()));
m.insert("created".to_string(), Value::Str("open".to_string()));
m.insert("new".to_string(), Value::Str("open".to_string()));
m.insert("pending".to_string(), Value::Str("open".to_string()));
m.insert("partially_filled".to_string(), Value::Str("open".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("completed".to_string(), Value::Str("closed".to_string()));
m.insert("cancelled".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("rejected".to_string(), Value::Str("rejected".to_string()));
m.insert("expired".to_string(), Value::Str("expired".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut oms: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[oms.clone(), market.clone()]);
let mut oid: Value = self.safe_string2(order.clone(), Value::Str("order_id".to_string()), Value::Str("id".to_string()), &[]);
let mut rawSide: Value = self.safe_string_upper(order.clone(), Value::Str("order_type".to_string()), &[]);
let mut side: Value = Value::Null;
if is_equal(&rawSide, &Value::Str("LONG".to_string())) {
side = Value::Str("buy".to_string());
} else if is_equal(&rawSide, &Value::Str("SHORT".to_string())) {
side = Value::Str("sell".to_string());
}
let mut trig: Value = self.safe_string_upper(order.clone(), Value::Str("trigger_type".to_string()), &[]);
let mut typ: Value = Value::Null;
if is_equal(&trig, &Value::Str("MARKET".to_string())) {
typ = Value::Str("market".to_string());
} else if is_equal(&trig, &Value::Str("LIMIT".to_string())) {
typ = Value::Str("limit".to_string());
}
let mut ts: Value = self.parse8601(self.safe_string_k(order.clone(), "created_at", &[]));
if is_equal(&ts, &Value::Null) {
ts = self.milliseconds();
}
let mut status: Value = self.parse_order_status(self.safe_string_lower(order.clone(), Value::Str("status".to_string()), &[]));
let mut sym: Value = get_value(&market, &Value::Str("symbol".to_string()));
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), oid.clone());
m.insert("clientOrderId".to_string(), Value::Null);
m.insert("timestamp".to_string(), ts.clone());
m.insert("datetime".to_string(), self.iso8601(ts.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), sym.clone());
m.insert("type".to_string(), typ.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(), self.safe_number2(order.clone(), Value::Str("price".to_string()), Value::Str("order_price".to_string()), &[]));
m.insert("stopPrice".to_string(), Value::Null);
m.insert("triggerPrice".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_number2(order.clone(), Value::Str("quantity".to_string()), Value::Str("amount".to_string()), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::List(vec![]));
m.insert("fees".to_string(), Value::List(vec![]));
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), self.safe_bool_k(order.clone(), "reduce_only", &[]));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#cancelOrder
* @description cancels an open order
* @see https://docs.trade.mudrex.com/docs
* @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](https://docs.ccxt.com/#/?id=order-structure)
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id.clone());
m
});
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_delete_futures_orders_order_id(&[__ws_arg_12]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[response.clone()]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#fetchOrder
* @description fetches information on an order made by the user
* @see https://docs.trade.mudrex.com/docs
* @param {string} id the 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](https://docs.ccxt.com/#/?id=order-structure)
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id.clone());
m
});
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_orders_order_id(&[__ws_arg_13]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[response.clone()]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#fetchOrdersByState
* @ignore
* @description fetches a list of orders filtered by their state
* @param {string} state the state of the orders to fetch
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
pub async fn fetch_orders_by_state(&mut self, mut state: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut q: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut q, &Value::Str("limit".to_string()), limit.clone());
}
let mut request: Value = self.extend(q.clone(), &[params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&state, &Value::Str("closed".to_string())) {
response = self.private_get_futures_orders_history(&[request.clone()]).await;
} else {
response = self.private_get_futures_orders(&[request.clone()]).await;
}
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rows: Value = self.to_array(data.clone());
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut orders: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_957: bool = true;
while { if !__for_first_957 { i = add(&i, &Value::Int(1)); } __for_first_957 = false; is_less_than(&i, &get_array_length(&rows)) } {
append_to_array(&mut orders, self.parse_order(get_value(&rows, &i), &[market.clone()]));
}
}
return self.filter_by_symbol_since_limit(orders.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://docs.trade.mudrex.com/docs
* @param {string} [symbol] unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures](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
}));
return self.fetch_orders_by_state(Value::Str("closed".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name mudrex#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://docs.trade.mudrex.com/docs
* @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](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
}));
return self.fetch_orders_by_state(Value::Str("open".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name mudrex#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://docs.trade.mudrex.com/docs
* @param {string} [symbol] unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_orders_by_state(Value::Str("closed".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name mudrex#fetchPositions
* @description fetch all open positions
* @see https://docs.trade.mudrex.com/docs
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.trade_currency] the settlement currency to query positions for
* @returns {object[]} a list of [position structures](https://docs.ccxt.com/#/?id=position-structure)
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut q: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_14 = self.extend(q.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_positions(&[__ws_arg_14]).await;
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
if is_equal(&data, &Value::Null) {
return Value::List(vec![]);
}
let mut rows: Value = self.to_array(data.clone());
let mut outPos: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_958: bool = true;
while { if !__for_first_958 { i = add(&i, &Value::Int(1)); } __for_first_958 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut p: Value = get_value(&rows, &i);
let mut p: Value = get_value(&rows, &i);
let mut symRaw: Value = self.safe_string_k(p.clone(), "symbol", &[]);
let mut m: Value = self.safe_market(&[symRaw.clone()]);
let mut pos: Value = self.parse_position(p.clone(), &[m.clone()]);
append_to_array(&mut outPos, pos.clone());
}
}
return self.filter_by_array_positions(outPos.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
/*
* @method
* @name mudrex#fetchPositionsHistory
* @description fetches the history of closed positions
* @see https://docs.trade.mudrex.com/docs/get-position-history
* @param {string[]} [symbols] a list of unified market symbols
* @param {int} [since] the earliest time in ms to fetch positions for
* @param {int} [limit] the maximum number of position structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.trade_currency] the settlement currency to filter positions by
* @returns {object[]} a list of [position structures](https://docs.ccxt.com/#/?id=position-structure)
*/
pub async fn fetch_positions_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = 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;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_positions_history(&[__ws_arg_15]).await;
//
// {
// "success": true,
// "data": [
// {
// "id": "019f1ed6-...",
// "position_type": "SHORT",
// "status": "CLOSED",
// "leverage": "3",
// "entry_price": "1.3112",
// "closed_price": "1.3395",
// "quantity": "34",
// "pnl": "-0.9622",
// "created_at": "2026-07-01T10:18:57Z",
// "updated_at": "2026-07-01T18:00:21Z",
// "symbol": "CAKEUSDT",
// "trade_currency": "USDT"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut positions: Value = self.parse_positions(data.clone(), &[symbols.clone()]);
return self.filter_by_since_limit(positions.clone(), &[since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
market = self.safe_market(&[Value::Null, market.clone()]);
let mut ms: Value = self.safe_string_k(position.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(ms.clone(), &[market.clone()]);
// open positions use "order_type", closed positions (history) use "position_type"
let mut rawSide: Value = self.safe_string_upper2(position.clone(), Value::Str("order_type".to_string()), Value::Str("position_type".to_string()), &[]);
let mut side: Value = Value::Null;
if is_equal(&rawSide, &Value::Str("LONG".to_string())) {
side = Value::Str("long".to_string());
} else if is_equal(&rawSide, &Value::Str("SHORT".to_string())) {
side = Value::Str("short".to_string());
}
let mut ts: Value = self.parse8601(self.safe_string_k(position.clone(), "updated_at", &[]));
if is_equal(&ts, &Value::Null) {
ts = self.parse8601(self.safe_string_k(position.clone(), "created_at", &[]));
}
let mut quantityString: Value = self.safe_string_k(position.clone(), "quantity", &[]);
let mut entryPriceString: Value = self.safe_string_k(position.clone(), "entry_price", &[]);
let mut contractSizeString: Value = self.safe_string_k(market.clone(), "contractSize", &[Value::Str("1".to_string())]);
let mut notional: Value = Value::Null;
if is_true(&(!is_equal(&quantityString, &Value::Null))) && is_true(&(!is_equal(&entryPriceString, &Value::Null))) {
notional = self.parse_number(crate::precise::Precise::stringMul(&crate::precise::Precise::stringMul(&quantityString, &entryPriceString), &contractSizeString), &[]);
}
let mut initialMargin: Value = self.safe_string_k(position.clone(), "initial_margin", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_k(position.clone(), "id", &[]));
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), ts.clone());
m.insert("datetime".to_string(), self.iso8601(ts.clone()));
m.insert("isolated".to_string(), Value::Bool(true));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("side".to_string(), side.clone());
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "quantity", &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "entry_price", &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "closed_price", &[]));
m.insert("notional".to_string(), notional.clone());
m.insert("leverage".to_string(), self.safe_integer_k(position.clone(), "leverage", &[]));
m.insert("collateral".to_string(), self.parse_number(initialMargin.clone(), &[]));
m.insert("initialMargin".to_string(), self.parse_number(initialMargin.clone(), &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), self.safe_number_k(position.clone(), "maintenance_margin", &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), Value::Null);
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "pnl", &[]));
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liquidation_price", &[]));
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("percentage".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name mudrex#closePosition
* @description closes an open position for a market
* @see https://docs.trade.mudrex.com/docs
* @param {string} symbol unified CCXT market symbol
* @param {string} [side] 'buy' or 'sell', not required by mudrex
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.position_id] the id of the position to close, resolved from the symbol if not provided
* @param {float} [params.amount] the amount to close for a partial close, closes the whole position if not provided
* @returns {object} an [order structure](https://docs.ccxt.com/#/?id=order-structure)
*/
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut positionId: Value = self.safe_string_k(params.clone(), "position_id", &[]);
let mut amount: Value = self.safe_value_k(params.clone(), "amount", &[]);
if is_equal(&positionId, &Value::Null) {
let mut market: Value = self.market(symbol.clone());
let mut positions: Value = self.fetch_positions(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_959: bool = true;
while { if !__for_first_959 { i = add(&i, &Value::Int(1)); } __for_first_959 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut p: Value = get_value(&positions, &i);
let mut p: Value = get_value(&positions, &i);
if !is_equal(&side, &Value::Null) && !is_equal(&get_value(&p, &Value::Str("side".to_string())), &side) {
continue;
}
if is_equal(&get_value(&p, &Value::Str("symbol".to_string())), &get_value(&market, &Value::Str("symbol".to_string()))) {
positionId = self.safe_string_k(p.clone(), "id", &[]);
break;
}
}
}
}
if is_equal(&positionId, &Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(add(&self.id, &Value::Str(" closePosition() could not resolve position_id".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("position_id".to_string(), positionId.clone());
m
});
if !is_equal(&amount, &Value::Null) {
let mut orderType: Value = self.safe_string_upper(params.clone(), Value::Str("order_type".to_string()), &[Value::Str("LIMIT".to_string())]);
add_element_to_object(&mut request, &Value::Str("order_type".to_string()), orderType.clone());
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
let mut lp: Value = self.safe_string_k(params.clone(), "limit_price", &[]);
if is_equal(&orderType, &Value::Str("LIMIT".to_string())) && !is_equal(&lp, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit_price".to_string()), lp.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("order_type".to_string()), Value::Str("limit_price".to_string()), Value::Str("amount".to_string()), Value::Str("position_id".to_string())]), &[]);
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
let mut partialResponse: Value = self.private_post_futures_positions_position_id_close_partial(&[__ws_arg_16]).await;
return partialResponse;
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("position_id".to_string())]), &[]);
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_futures_positions_position_id_close(&[__ws_arg_17]).await;
return response;
Value::Null
}
/*
* @method
* @name mudrex#addMargin
* @description add margin to a position
* @see https://docs.trade.mudrex.com/docs
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.position_id] the id of the position to add margin to, resolved from the symbol if not provided
* @returns {object} a [margin structure](https://docs.ccxt.com/#/?id=add-margin-structure)
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut positionId: Value = self.safe_string_k(params.clone(), "position_id", &[]);
if is_equal(&positionId, &Value::Null) {
let mut positions: Value = self.fetch_positions(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_960: bool = true;
while { if !__for_first_960 { i = add(&i, &Value::Int(1)); } __for_first_960 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut p: Value = get_value(&positions, &i);
let mut p: Value = get_value(&positions, &i);
if is_equal(&get_value(&p, &Value::Str("symbol".to_string())), &symbol) {
positionId = self.safe_string_k(p.clone(), "id", &[]);
break;
}
}
}
}
if is_equal(&positionId, &Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(add(&self.id, &Value::Str(" addMargin() could not resolve position_id".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("position_id".to_string(), positionId.clone());
m.insert("margin".to_string(), self.cost_to_precision(symbol.clone(), amount.clone()));
m
});
params = self.omit(params.clone(), Value::List(vec![Value::Str("position_id".to_string())]), &[]);
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_futures_positions_position_id_add_margin(&[__ws_arg_18]).await;
return response;
Value::Null
}
/*
* @method
* @name mudrex#reduceMargin
* @description remove margin from a position
* @see https://docs.trade.mudrex.com/docs
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure](https://docs.ccxt.com/#/?id=reduce-margin-structure)
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.add_margin(symbol.clone(), negate(&amount), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name mudrex#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.trade.mudrex.com/docs
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trade structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.trade_currency] the settlement currency to filter trades by
* @returns {Trade[]} a list of [trade structures](https://docs.ccxt.com/#/?id=trade-structure)
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_fee_history(&[__ws_arg_19]).await;
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rows: Value = self.to_array(data.clone());
return self.parse_trades(rows.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);
let mut ms: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
market = self.safe_market(&[ms.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut ts: Value = self.parse8601(self.safe_string_k(trade.clone(), "created_at", &[]));
if is_equal(&ts, &Value::Null) {
ts = self.safe_integer_k(trade.clone(), "time", &[]);
}
let mut side: Value = self.safe_string_lower2(trade.clone(), Value::Str("side".to_string()), Value::Str("order_type".to_string()), &[]);
let mut tradeSide: Value = Value::Null;
if is_equal(&side, &Value::Str("buy".to_string())) || is_equal(&side, &Value::Str("long".to_string())) {
tradeSide = Value::Str("buy".to_string());
} else if is_equal(&side, &Value::Str("sell".to_string())) || is_equal(&side, &Value::Str("short".to_string())) {
tradeSide = Value::Str("sell".to_string());
}
let mut feeType: Value = self.safe_string_upper(trade.clone(), Value::Str("fee_type".to_string()), &[]);
let mut takerOrMaker: Value = Value::Null;
if is_equal(&feeType, &Value::Str("TRANSACTION".to_string())) {
takerOrMaker = Value::Str("taker".to_string());
} else if is_equal(&feeType, &Value::Str("REBATE".to_string())) {
takerOrMaker = Value::Str("maker".to_string());
}
let mut fee: Value = Value::Null;
let mut feeCost: Value = self.safe_number_k(trade.clone(), "fee_amount", &[]);
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), self.safe_string_k(trade.clone(), "trade_currency", &[]));
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), ts.clone());
m.insert("datetime".to_string(), self.iso8601(ts.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("execId".to_string()), Value::Str("id".to_string()), &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "order_id", &[]));
m.insert("type".to_string(), self.safe_string_lower(trade.clone(), Value::Str("trigger_type".to_string()), &[]));
m.insert("side".to_string(), tradeSide.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), self.safe_number_k(trade.clone(), "price", &[]));
m.insert("amount".to_string(), self.safe_number2(trade.clone(), Value::Str("size".to_string()), Value::Str("quantity".to_string()), &[]));
m.insert("cost".to_string(), self.safe_number_k(trade.clone(), "transaction_amount", &[]));
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name mudrex#transfer
* @description transfer currency internally between wallets on the same account
* @see https://docs.trade.mudrex.com/docs
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount 'spot' or 'futures'
* @param {string} toAccount 'spot' or 'futures'
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure](https://docs.ccxt.com/#/?id=transfer-structure)
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut mp: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("SPOT".to_string(), Value::Str("SPOT".to_string()));
m.insert("futures".to_string(), Value::Str("FUTURES".to_string()));
m.insert("future".to_string(), Value::Str("FUTURES".to_string()));
m.insert("FUTURES".to_string(), Value::Str("FUTURES".to_string()));
m
});
let mut fw: Value = self.safe_string(mp.clone(), fromAccount.clone(), &[to_upper(&fromAccount)]);
let mut tw: Value = self.safe_string(mp.clone(), toAccount.clone(), &[to_upper(&toAccount)]);
let mut body: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("from_wallet_type".to_string(), fw.clone());
m.insert("to_wallet_type".to_string(), tw.clone());
m.insert("amount".to_string(), self.number_to_string(amount.clone()));
m
});
let mut useInr: bool = false;
if is_equal(&code, &Value::Str("INR".to_string())) {
useInr = true;
} else {
// default USDT does not use the inr path
let mut tradeCurrency: Value = self.safe_string2(params.clone(), Value::Str("trade_currency".to_string()), Value::Str("tradeCurrency".to_string()), &[]);
if is_equal(&tradeCurrency, &Value::Str("INR".to_string())) {
useInr = true;
}
}
let mut response: Value = Value::Null;
if is_true(&useInr) {
let __ws_arg_20 = self.extend(body.clone(), &[params.clone()]);
response = self.private_post_futures_transfers_inr(&[__ws_arg_20]).await;
} else {
let __ws_arg_21 = self.extend(body.clone(), &[params.clone()]);
response = self.private_post_wallet_futures_transfer(&[__ws_arg_21]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[response.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("id".to_string(), self.safe_string_k(data.clone(), "id", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("fromAccount".to_string(), fw.clone());
m.insert("toAccount".to_string(), tw.clone());
m.insert("status".to_string(), Value::Str("ok".to_string()));
m
});
Value::Null
}
}