#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
use crate::exchange::CallDynamicChecked;
pub struct LbankCore {
pub exchange: crate::exchange::Exchange,
}
impl LbankCore {
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 = LbankCore::describe(self);
self.initialize_properties(described);
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for LbankCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
LbankCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
LbankCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
LbankCore::parse_order(self, order, &[market])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
LbankCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
LbankCore::parse_balance(self, response)
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
LbankCore::parse_funding_rate(self, rate, &[market])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
LbankCore::parse_currency(self, currency)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
LbankCore::parse_transaction(self, transaction, &[currency])
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
LbankCore::parse_deposit_withdraw_fee(self, fee, &[currency])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
LbankCore::sign(self, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
LbankCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for LbankCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).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[4.min(args.len())..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_address_default" => self.fetch_deposit_address_default(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_address_supplement" => self.fetch_deposit_address_supplement(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_default" => self.fetch_order_default(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_supplement" => self.fetch_order_supplement(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_private_deposit_withdraw_fees" => self.fetch_private_deposit_withdraw_fees(&args[..]).await,
"fetch_private_transaction_fees" => self.fetch_private_transaction_fees(&args[..]).await,
"fetch_public_deposit_withdraw_fees" => self.fetch_public_deposit_withdraw_fees(&args[..]).await,
"fetch_public_transaction_fees" => self.fetch_public_transaction_fees(&args[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(&args[..]).await,
"fetch_swap_markets" => self.fetch_swap_markets(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_transaction_fees" => self.fetch_transaction_fees(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null),
args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_public_deposit_withdraw_fees" => self.parse_public_deposit_withdraw_fees(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for LbankCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for LbankCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl LbankCore {
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("lbank".into()));
m.insert("name".to_string(), Value::Str("LBank".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("CN".into())]));
m.insert("version".to_string(), Value::Str("v2".into()));
m.insert("rateLimit".to_string(), Value::Int(20));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Bool(false));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Null);
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopLimitOrder".to_string(), Value::Bool(false));
m.insert("createStopMarketOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Str("emulated".into()));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactionFees".to_string(), Value::Bool(true));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("minute1".into()));
m.insert("5m".to_string(), Value::Str("minute5".into()));
m.insert("15m".to_string(), Value::Str("minute15".into()));
m.insert("30m".to_string(), Value::Str("minute30".into()));
m.insert("1h".to_string(), Value::Str("hour1".into()));
m.insert("2h".to_string(), Value::Str("hour2".into()));
m.insert("4h".to_string(), Value::Str("hour4".into()));
m.insert("6h".to_string(), Value::Str("hour6".into()));
m.insert("8h".to_string(), Value::Str("hour8".into()));
m.insert("12h".to_string(), Value::Str("hour12".into()));
m.insert("1d".to_string(), Value::Str("day1".into()));
m.insert("1w".to_string(), Value::Str("week1".into()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/1294454/38063602-9605e28a-3302-11e8-81be-64b1e53c4cfb.jpg".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("rest".to_string(), Value::Str("https://api.lbank.info".into()));
m.insert("contract".to_string(), Value::Str("https://lbkperp.lbank.com".into()));
m
}));
m.insert("api2".to_string(), Value::Str("https://api.lbkex.com".into()));
m.insert("www".to_string(), Value::Str("https://www.lbank.com".into()));
m.insert("doc".to_string(), Value::Str("https://www.lbank.com/en-US/docs/index.html".into()));
m.insert("fees".to_string(), Value::Str("https://support.lbank.site/hc/en-gb/articles/900000535703-Trading-Fees-From-14-00-on-April-7-2020-UTC-8-".into()));
m.insert("referral".to_string(), Value::Str("https://www.lbank.com/login/?icode=7QCY".into()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencyPairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("accuracy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("usdToCny".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("assetConfigs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("withdrawConfigs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match (&(Value::Float(2.5)), &(Value::Float(1.5))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }));
m
}));
m.insert("timestamp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("incrDepth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/system_ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/incrDepth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("supplement/system_status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("user_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("subscribe/get_key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("subscribe/refresh_key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("subscribe/destroy_key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("get_deposit_address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("deposit_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("create_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("batch_create_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_clientOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("orders_info_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("order_transaction_detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("transaction_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("orders_info_no_deal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("withdrawCancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("withdraws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/user_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/deposit_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/withdraws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/get_deposit_address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/add_deposit_address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/asset_detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/customer_trade_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/api_Restrictions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/system_ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/create_order_test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("supplement/create_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("supplement/cancel_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("supplement/cancel_order_by_symbol".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("supplement/orders_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/orders_info_no_deal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/orders_info_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/user_info_account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("supplement/transaction_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/wallet/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/wallet/deposit_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/wallet/withdraws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/trade/orders_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/trade/orders_info_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m
}));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cfd/openApi/v1/pub/getTime".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("cfd/openApi/v1/pub/instrument".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("cfd/openApi/v1/pub/marketData".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("cfd/openApi/v1/pub/marketOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), self.parse_number(Value::Str("0.001".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.001".into()), &[]));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("XBT".to_string(), Value::Str("XBT".into()));
m.insert("HIT".to_string(), Value::Str("Hiver".into()));
m.insert("VET_ERC20".to_string(), Value::Str("VEN".into()));
m.insert("PNT".to_string(), Value::Str("Penta".into()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cacheSecretAsPem".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("spotPublicGetTrades".into()));
m
}));
m.insert("fetchTransactionFees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("fetchPrivateTransactionFees".into()));
m
}));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("fetchPrivateDepositWithdrawFees".into()));
m
}));
m.insert("fetchDepositAddress".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("fetchDepositAddressDefault".into()));
m
}));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("spotPrivatePostSupplementCreateOrder".into()));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("fetchOrderSupplement".into()));
m
}));
m.insert("fetchBalance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("spotPrivatePostSupplementUserInfo".into()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ERC20".to_string(), Value::Str("erc20".into()));
m.insert("TRC20".to_string(), Value::Str("trc20".into()));
m.insert("OMNI".to_string(), Value::Str("omni".into()));
m.insert("ASA".to_string(), Value::Str("asa".into()));
m.insert("BEP20".to_string(), Value::Str("bep20(bsc)".into()));
m.insert("HT".to_string(), Value::Str("heco".into()));
m.insert("BNB".to_string(), Value::Str("bep2".into()));
m.insert("BTC".to_string(), Value::Str("btc".into()));
m.insert("DOGE".to_string(), Value::Str("dogecoin".into()));
m.insert("MATIC".to_string(), Value::Str("matic".into()));
m.insert("POLYGON".to_string(), Value::Str("matic".into()));
m.insert("OEC".to_string(), Value::Str("oec".into()));
m.insert("BTCTRON".to_string(), Value::Str("btctron".into()));
m.insert("XRP".to_string(), Value::Str("xrp".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("erc20".to_string(), Value::Str("ERC20".into()));
m.insert("trc20".to_string(), Value::Str("TRC20".into()));
m.insert("TRX".to_string(), Value::Str("TRC20".into()));
m.insert("bep20(bsc)".to_string(), Value::Str("BEP20".into()));
m.insert("bep20".to_string(), Value::Str("BEP20".into()));
m
}));
m.insert("defaultNetworks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USDT".to_string(), Value::Str("TRC20".into()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(false));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(false));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(2));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(200));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(200));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(2000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m
})]);
Value::Null
}
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let type_varparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchTime".into()), &[Value::Null, params]).as_array().cloned().unwrap_or_default();
let mut type_var: Value = type_varparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
response = self.contract_public_get_cfd_open_api_v1_pub_get_time(&[paramsMarketType.clone()]).await;
} else {
response = self.spot_public_get_timestamp(&[paramsMarketType]).await;
}
return self.safe_integer_k(response, "data", &[]);
Value::Null
}
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.spot_public_get_withdraw_configs(&[params]).await;
let mut currenciesData: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut grouped: Value = self.group_by(currenciesData, Value::Str("assetCode".into()), &[]);
let mut values: Value = Value::Array(grouped.as_map().map(|__m| __m.values().cloned().collect()).unwrap_or_default());
return self.parse_currencies(values);
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut id: Option<String> = self.safe_string_opt(self.safe_dict(rawCurrency.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), Value::Str("assetCode".into()), &[]); let mut code: Value = self.safe_currency_code(id.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut networks: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: i64 = 0;
let mut __for_first_917: bool = true;
while { if !__for_first_917 { j += 1; } __for_first_917 = false; j < (rawCurrency.len() as i64) } {
let mut networkEntry: Value = self.safe_dict(rawCurrency.clone(), Value::Int(j), &[]);
let mut networkId: Option<String> = self.safe_string_k_opt(networkEntry.clone(), "chain", &[]);
if (networkId.is_none()) {
networkId = self.safe_string_k_opt(networkEntry.clone(), "assetCode", &[]); }
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone().map(Value::from).unwrap_or(Value::Null), code.clone()]);
if (networkCode != Value::Null) {
networks.insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId.map(Value::from).unwrap_or(Value::Null));
m.insert("network".to_string(), networkCode.clone());
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(networkEntry.clone(), "min", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(networkEntry.clone(), "minTransfer", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), self.safe_bool_k(networkEntry.clone(), "canWithDraw", &[]));
m.insert("fee".to_string(), self.safe_number_k(networkEntry.clone(), "fee", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(networkEntry.clone(), "transferAmtScale", &[])]), &[]));
m.insert("info".to_string(), networkEntry);
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("code".to_string(), code);
m.insert("precision".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("name".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), Value::Map(networks));
m.insert("info".to_string(), rawCurrency);
m
}));
Value::Null
}
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 marketsPromises: Value = Value::from(vec![self.fetch_spot_markets(&[params.clone()]).await, self.fetch_swap_markets(&[params]).await]);
let mut resolvedMarkets: Value = promise_all(&marketsPromises).await;
let mut spotMarkets: Value = self.safe_value(resolvedMarkets.clone(), Value::Int(0), &[]);
let mut swapMarkets: Value = self.safe_value(resolvedMarkets, Value::Int(1), &[]);
return self.array_concat(spotMarkets, swapMarkets);
Value::Null
}
pub async fn fetch_spot_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.spot_public_get_accuracy(&[params]).await;
let mut data: Vec<Value> = self.safe_list_k(response, "data", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut result: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_918: bool = true;
while { if !__for_first_918 { i += 1; } __for_first_918 = false; i < (data.len() as i64) } {
let mut market: Value = data.get(i as usize).cloned().unwrap_or(Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(market.clone(), "symbol", &[]);
let mut parts: Vec<Value> = Value::Array(if let Some(__s) = marketId.as_deref() { __s.split("_").map(Value::from).collect() } else { Vec::new() }).as_array().cloned().unwrap_or_default();
let mut baseId: Value = parts.get(0).cloned().unwrap_or(Value::Null);
let mut quoteId: Value = parts.get(1).cloned().unwrap_or(Value::Null);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
continue;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
result.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settle".to_string(), Value::Null);
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".into()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool(true));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("contractSize".to_string(), Value::Null);
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quantityAccuracy", &[])]), &[]));
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "priceAccuracy", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minTranQua", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
}));
}
}
return Value::from(result);
Value::Null
}
pub async fn fetch_swap_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 request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("productGroup".to_string(), Value::Str("SwapU".into()));
m
});
let __ws_arg_0 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.contract_public_get_cfd_open_api_v1_pub_instrument(&[__ws_arg_0]).await;
let mut data: Vec<Value> = self.safe_list_k(response, "data", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut result: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_919: bool = true;
while { if !__for_first_919 { i += 1; } __for_first_919 = false; i < (data.len() as i64) } {
let mut market: Value = data.get(i as usize).cloned().unwrap_or(Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(market.clone(), "symbol", &[]);
let mut baseId: Option<String> = self.safe_string_k_opt(market.clone(), "baseCurrency", &[]);
let mut settleId: Option<String> = self.safe_string_k_opt(market.clone(), "clearCurrency", &[]);
let mut quoteId: Value = settleId.clone().map(Value::from).unwrap_or(Value::Null);
let mut base: Value = self.safe_currency_code(baseId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
continue;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), quote).into());
result.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), quote);
m.insert("baseId".to_string(), baseId.map(Value::from).unwrap_or(Value::Null));
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId.map(Value::from).unwrap_or(Value::Null));
m.insert("type".to_string(), Value::Str("swap".into()));
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("contractSize".to_string(), self.safe_number_k(market.clone(), "volumeMultiple", &[]));
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.safe_number_k(market.clone(), "volumeTick", &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "priceTick", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minOrderVolume", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxOrderVolume", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minOrderCost", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
}));
}
}
return Value::from(result);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "timestamp", &[]);
if (timestamp == Value::Null) {
timestamp = self.safe_timestamp_k(ticker.clone(), "lastTime", &[]);
}
let mut marketId: Option<String> = self.safe_string_k_opt(ticker.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone().map(Value::from).unwrap_or(Value::Null), &[market.clone()]);
let mut tickerData: Value = self.safe_dict_k(ticker.clone(), "ticker", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut data: Value = (if matches!((self.safe_bool_k(marketResolved.clone(), "contract", &[Value::Bool(false)])), Value::Bool(true)) { ticker.clone() } else { tickerData });
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), self.safe_string2(data.clone(), Value::Str("high".into()), Value::Str("highestPrice".into()), &[]));
m.insert("low".to_string(), self.safe_string2(data.clone(), Value::Str("low".into()), Value::Str("lowestPrice".into()), &[]));
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_string_k(data.clone(), "openPrice", &[]));
m.insert("close".to_string(), Value::Null);
m.insert("last".to_string(), self.safe_string2(data.clone(), Value::Str("latest".into()), Value::Str("lastPrice".into()), &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), self.safe_string_k(data.clone(), "change", &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string2(data.clone(), Value::Str("vol".into()), Value::Str("volume".into()), &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(data, "turnover", &[]));
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if matches!(self.safe_bool_k(market.clone(), "swap", &[Value::Bool(false)]), Value::Bool(true)) {
let mut responseForSwap: Value = self.fetch_tickers(&[Value::from(vec![market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)]), params.clone()]).await;
let mut swapTicker: Value = self.safe_dict(responseForSwap, market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), &[]);
return swapTicker;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_1 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_public_get_ticker24hr(&[__ws_arg_1]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut first: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(first, &[market]);
Value::Null
}
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
if (symbolsNormalized != Value::Null) {
let mut symbolsLength: f64 = ((symbolsNormalized.len() as i64) as f64);
if symbolsLength > ((0i64) as f64) {
market = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
}
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let type_varparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchTickers".into()), &[market, params]).as_array().cloned().unwrap_or_default();
let mut type_var: Value = type_varparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
request.insert("productGroup".into(), Value::Str("SwapU".into()));
let __ws_arg_2 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.contract_public_get_cfd_open_api_v1_pub_market_data(&[__ws_arg_2]).await;
} else {
request.insert("symbol".into(), Value::Str("all".into()));
let __ws_arg_3 = self.extend(Value::Map(request), &[paramsMarketType]);
response = self.spot_public_get_ticker24hr(&[__ws_arg_3]).await;
}
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_tickers(data, &[symbolsNormalized]);
Value::Null
}
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(60) } else { limit });
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let type_varparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchOrderBook".into()), &[market.clone(), params]).as_array().cloned().unwrap_or_default();
let mut type_var: Value = type_varparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
request.insert("depth".into(), limitResolved.clone());
let __ws_arg_4 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.contract_public_get_cfd_open_api_v1_pub_market_order(&[__ws_arg_4]).await;
} else {
request.insert("size".into(), limitResolved);
let __ws_arg_5 = self.extend(Value::Map(request), &[paramsMarketType]);
response = self.spot_public_get_depth(&[__ws_arg_5]).await;
}
let mut orderbook: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.milliseconds();
if matches!(self.safe_bool_k(market.clone(), "swap", &[Value::Bool(false)]), Value::Bool(true)) {
return self.parse_order_book(orderbook.clone(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), &[timestamp.clone(), Value::Str("bids".into()), Value::Str("asks".into()), Value::Str("price".into()), Value::Str("volume".into())]);
}
return self.parse_order_book(orderbook, market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), &[timestamp, Value::Str("bids".into()), Value::Str("asks".into())]);
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 timestamp: Option<i64> = self.safe_integer2(trade.clone(), Value::Str("date_ms".into()), Value::Str("time".into()), &[]).as_i64();
if (timestamp.is_none()) {
timestamp = self.safe_integer_k(trade.clone(), "dealTime", &[]).as_i64();
}
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("amount".into()), Value::Str("qty".into()), &[]);
if (amountString == Value::Null) {
amountString = self.safe_string_k(trade.clone(), "dealQuantity", &[]);
}
let mut priceString: Option<String> = self.safe_string_k_opt(trade.clone(), "price", &[]);
if (priceString.is_none()) {
priceString = self.safe_string_k_opt(trade.clone(), "dealPrice", &[]);
}
let mut costString: Option<String> = self.safe_string_k_opt(trade.clone(), "quoteQty", &[]);
if (costString.is_none()) {
costString = self.safe_string_k_opt(trade.clone(), "dealVolumePrice", &[]);
}
let mut side: Value = self.safe_string2(trade.clone(), Value::Str("tradeType".into()), Value::Str("type".into()), &[]);
let mut type_var: Value = Value::Null;
let mut takerOrMaker: Value = Value::Null;
if (side != Value::Null) {
let mut parts: Value = Value::Array(if let Some(__s) = side.as_str() { __s.split("_").map(Value::from).collect() } else { Vec::new() });
side = self.safe_string(parts.clone(), Value::Int(0), &[]);
let mut typePart: Option<String> = self.safe_string(parts, Value::Int(1), &[]).as_str().map(str::to_owned);
type_var = Value::Str("limit".into());
takerOrMaker = Value::Str("taker".into());
if (typePart.is_some()) {
if (typePart.as_deref() == Some("market")) {
type_var = Value::Str("market".into());
} else if (typePart.as_deref() == Some("maker")) {
takerOrMaker = Value::Str("maker".into());
}
}
}
let mut id: Value = self.safe_string2(trade.clone(), Value::Str("tid".into()), Value::Str("id".into()), &[]);
if (id == Value::Null) {
id = self.safe_string_k(trade.clone(), "txUuid", &[]);
}
let mut order: Option<String> = self.safe_string_k_opt(trade.clone(), "orderUuid", &[]);
let mut symbol: Value = self.safe_symbol(Value::Null, &[market.clone()]);
let mut fee: Value = Value::Null;
let mut feeCost: Option<String> = self.safe_string_k_opt(trade.clone(), "tradeFee", &[]);
if (feeCost.is_some()) {
let mut feeCurr: Value = (if (side.as_str() == Some("buy")) { self.safe_string_k(market.clone(), "base", &[]) } else { self.safe_string_k(market.clone(), "quote", &[]) });
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.map(Value::from).unwrap_or(Value::Null));
m.insert("currency".to_string(), feeCurr);
m.insert("rate".to_string(), self.safe_string_k(trade.clone(), "tradeFeeRate", &[]));
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("symbol".to_string(), symbol);
m.insert("id".to_string(), id);
m.insert("order".to_string(), order.map(Value::from).unwrap_or(Value::Null));
m.insert("type".to_string(), type_var);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("side".to_string(), side);
m.insert("price".to_string(), priceString.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amountString);
m.insert("cost".to_string(), costString.map(Value::from).unwrap_or(Value::Null));
m.insert("fee".to_string(), fee);
m.insert("info".to_string(), trade);
m
}), &[market]);
Value::Null
}
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
request.insert("time".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("size".into(), crate::runtime::Math::min(&limit, &Value::Int(600)));
} else {
request.insert("size".into(), Value::Int(600)); }
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchTrades", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options, "method", &[Value::Str("spotPublicGetTrades".into())]);
let mut method: Option<String> = self.safe_string_k(params.clone(), "method", &[defaultMethod]).as_str().map(str::to_owned);
let mut paramsOmitted: Value = self.omit(params, Value::Str("method".into()), &[]);
let mut response: Value = Value::Null;
if (method.as_deref() == Some("spotPublicGetSupplementTrades")) {
let __ws_arg_6 = self.extend(Value::Map(request.clone()), &[paramsOmitted.clone()]);
response = self.spot_public_get_supplement_trades(&[__ws_arg_6]).await;
} else {
let __ws_arg_7 = self.extend(Value::Map(request), &[paramsOmitted]);
response = self.spot_public_get_trades(&[__ws_arg_7]).await;
}
let mut trades: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market, since, limit]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_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, Value::Int(5), &[])]);
Value::Null
}
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut limitResolved: Value = self.parse_to_int((if (limit == Value::Null) { Value::Int(100) } else { crate::runtime::Math::min(&limit, &Value::Int(2000)) }));
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut now: Value = self.milliseconds();
let mut defaultSince: Value = (match (&(now), &(((match (&((match (&(duration), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y),
_ => Value::Null })), &(limitResolved)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })))) { (Value::Int(x),
Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
let mut sinceResolved: Value = defaultSince.clone();
let mut parsedSince: Value = self.parse_to_int((match ((defaultSince).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
if (since != Value::Null) {
sinceResolved = since.clone();
parsedSince = self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
}
let mut parsedLimit: Value = crate::runtime::Math::min(&(match (&(limitResolved), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y),
_ => Value::Null }), &Value::Int(2000)); let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m.insert("time".to_string(), parsedSince);
m.insert("size".to_string(), parsedLimit);
m
});
let __ws_arg_8 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_public_get_kline(&[__ws_arg_8]).await;
let mut ohlcvs: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_ohlc_vs(ohlcvs, &[market, timeframe, sinceResolved, limitResolved]);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut timestamp: Option<i64> = self.safe_integer_k(response.clone(), "ts", &[]).as_i64();
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m
});
let mut data: Value = self.safe_dict_k(response, "data", &[]);
let mut toBtc: Value = self.safe_dict_k(data.clone(), "toBtc", &[]);
if (toBtc != Value::Null) {
let mut used: Value = self.safe_dict_k(data.clone(), "freeze", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut free: Value = self.safe_dict_k(data.clone(), "free", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencies: Vec<Value> = Value::Array(free.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).as_array().cloned().unwrap_or_default();
{
let mut i: i64 = 0;
let mut __for_first_920: bool = true;
while { if !__for_first_920 { i += 1; } __for_first_920 = false; i < (currencies.len() as i64) } {
let mut currencyId: Value = currencies.get(i as usize).cloned().unwrap_or(Value::Null);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string(used.clone(), currencyId.clone(), &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string(free.clone(), currencyId.clone(), &[])); }
if (code != Value::Null) {
result.insert(crate::runtime::stringify_param(&code), account.clone());
}
}
}
return self.safe_balance(Value::Map(result.clone()));
}
let mut balances: Value = self.safe_list_k(data.clone(), "balances", &[]);
if (balances != Value::Null) {
{
let mut i: i64 = 0;
let mut __for_first_921: bool = true;
while { if !__for_first_921 { i += 1; } __for_first_921 = false; i < (balances.len() as i64) } {
let mut item: Value = self.safe_dict(balances.clone(), Value::Int(i), &[]);
let mut currencyId: Option<String> = self.safe_string_k_opt(item.clone(), "asset", &[]);
let mut codeInner: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(item.clone(), "free", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(item.clone(), "locked", &[])); }
if (codeInner != Value::Null) {
result.insert(crate::runtime::stringify_param(&codeInner), account.clone());
}
}
}
return self.safe_balance(Value::Map(result.clone()));
}
let mut isArray: bool = matches!(&data, Value::Arr(_));
if isArray {
{
let mut i: i64 = 0;
let mut __for_first_922: bool = true;
while { if !__for_first_922 { i += 1; } __for_first_922 = false; i < (data.len() as i64) } {
let mut item: Value = self.safe_dict(data.clone(), Value::Int(i), &[]);
let mut currencyId: Option<String> = self.safe_string_k_opt(item.clone(), "coin", &[]);
let mut codeInner: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(item.clone(), "usableAmt", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(item, "freezeAmt", &[])); }
if (codeInner != Value::Null) {
result.insert(crate::runtime::stringify_param(&codeInner), account);
}
}
}
return self.safe_balance(Value::Map(result.clone()));
}
return self.safe_balance(Value::Map(result));
Value::Null
}
pub fn parse_funding_rate(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(ticker.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market]);
let mut markPrice: Value = self.safe_number_k(ticker.clone(), "markedPrice", &[]);
let mut indexPrice: Value = self.safe_number_k(ticker.clone(), "underlyingPrice", &[]);
let mut fundingRate: Value = self.safe_number_k(ticker.clone(), "fundingRate", &[]);
let mut fundingTime: Option<i64> = self.safe_integer_k(ticker.clone(), "nextFeeTime", &[]).as_i64();
let mut positionFeeTime: Value = self.safe_integer_k(ticker.clone(), "positionFeeTime", &[]);
let mut intervalString: Value = Value::Null;
if (positionFeeTime != Value::Null) {
let mut interval: Value = self.parse_to_int((match (((match ((positionFeeTime).as_f64(), (Value::Int(60)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })).as_f64(), (Value::Int(60)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
intervalString = Value::Str(format!("{}{}", Value::Str(format!("{}", interval).into()), Value::Str("h".into())).into());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), ticker);
m.insert("symbol".to_string(), symbol);
m.insert("markPrice".to_string(), markPrice);
m.insert("indexPrice".to_string(), indexPrice);
m.insert("fundingRate".to_string(), fundingRate);
m.insert("fundingTimestamp".to_string(), Value::from(fundingTime));
m.insert("fundingDatetime".to_string(), self.iso8601(Value::from(fundingTime)));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), Value::Null);
m.insert("nextFundingDatetime".to_string(), Value::Null);
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), intervalString);
m
});
Value::Null
}
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut responseForSwap: Value = self.fetch_funding_rates(&[Value::from(vec![market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)]), params]).await;
let mut fundingRate: Value = self.safe_dict(responseForSwap, market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), &[]);
return fundingRate;
Value::Null
}
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("productGroup".to_string(), Value::Str("SwapU".into()));
m
});
let __ws_arg_9 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.contract_public_get_cfd_open_api_v1_pub_market_data(&[__ws_arg_9]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_funding_rates(data, &[symbolsNormalized]);
Value::Null
}
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __params_empty = indexmap::IndexMap::new();
let params = params.as_map().unwrap_or(&__params_empty);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchBalance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options, "method", &[Value::Str("spotPrivatePostSupplementUserInfo".into())]);
let mut method: Option<String> = (match params.get("method") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => defaultMethod }).as_str().map(str::to_owned);
let mut response: Value = Value::Null;
if (method.as_deref() == Some("spotPrivatePostSupplementUserInfoAccount")) {
response = self.spot_private_post_supplement_user_info_account(&[]).await;
} else if (method.as_deref() == Some("spotPrivatePostUserInfo")) {
response = self.spot_private_post_user_info(&[]).await;
} else {
response = self.spot_private_post_supplement_user_info(&[]).await;
}
let mut balanceResponse: Value = (if (response == Value::Null) { Value::Map({
let mut m = indexmap::IndexMap::new();
m
}) } else { response });
let mut balanceResult: Value = self.parse_balance(balanceResponse);
if (balanceResult == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" fetchBalance() returned empty response".into()))));
}
return balanceResult;
Value::Null
}
pub fn parse_trading_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(fee.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), symbol);
m.insert("maker".to_string(), self.safe_number_k(fee.clone(), "makerCommission", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee, "takerCommission", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
Value::Null
}
pub async fn fetch_trading_fee(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol.clone()).as_map().cloned().unwrap_or_default();
let __ws_arg_10 = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m
})]);
let mut result: Value = self.fetch_trading_fees(&[__ws_arg_10]).await;
let mut fee: Value = self.safe_dict(result, symbol, &[]);
return fee;
Value::Null
}
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_11 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_supplement_customer_trade_fee(&[__ws_arg_11]).await;
let mut fees: Vec<Value> = self.safe_list_k(response, "data", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_923: bool = true;
while { if !__for_first_923 { i += 1; } __for_first_923 = false; i < (fees.len() as i64) } {
let mut fee: indexmap::IndexMap<String, Value> = self.parse_trading_fee(fees.get(i as usize).cloned().unwrap_or(Value::Null), &[]).as_map().cloned().unwrap_or_default();
let mut symbol: Value = fee.get("symbol").cloned().unwrap_or(Value::Null);
if (symbol != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), Value::Map(fee)); }
}
}
}
return result;
Value::Null
}
pub async fn create_market_buy_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !matches!(self.safe_bool_k(market, "spot", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketBuyOrderWithCost() supports spot orders only".into()))));
}
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("createMarketBuyOrderRequiresPrice".into(), Value::Bool(false)); }
return self.create_order(symbol, Value::Str("market".into()), Value::Str("buy".into()), cost, &[Value::Null, params]).await;
Value::Null
}
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut clientOrderId: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("custom_id".into()), Value::Str("clientOrderId".into()), &[]);
let mut postOnly: bool = self.safe_bool_k_opt(params.clone(), "postOnly", &[Value::Bool(false)]).unwrap_or(false);
let mut timeInForce: Option<String> = self.safe_string_upper_k(params.clone(), "timeInForce", &[]).as_str().map(str::to_owned);
let mut paramsRequest: Value = self.omit(params, Value::from(vec![Value::Str("custom_id".into()), Value::Str("clientOrderId".into()), Value::Str("timeInForce".into()), Value::Str("postOnly".into())]), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut ioc: bool = timeInForce.as_deref() == Some("IOC");
let mut fok: bool = timeInForce.as_deref() == Some("FOK");
let mut maker: bool = postOnly || (timeInForce.as_deref() == Some("PO"));
if (type_var.as_str() == Some("market")) && (ioc || fok || maker) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder () does not allow market FOK, IOC, or postOnly orders. Only limit IOC, FOK, and postOnly orders are allowed".into()))));
}
if (type_var.as_str() == Some("limit")) {
request.insert("type".into(), side.clone());
request.insert("price".into(), self.price_to_precision(symbol.clone(), price.clone()));
request.insert("amount".into(), self.amount_to_precision(symbol.clone(), amount.clone()));
if ioc {
request.insert("type".into(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", side, Value::Str("_".into())).into()), Value::Str("ioc".into())).into()));
} else if fok {
request.insert("type".into(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", side, Value::Str("_".into())).into()), Value::Str("fok".into())).into()));
} else if maker {
request.insert("type".into(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", side, Value::Str("_".into())).into()), Value::Str("maker".into())).into()));
}
} else if (type_var.as_str() == Some("market")) {
if (side.as_str() == Some("sell")) {
request.insert("type".into(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", side, Value::Str("_".into())).into()), Value::Str("market".into())).into()));
request.insert("amount".into(), self.amount_to_precision(symbol.clone(), amount.clone()));
} else if (side.as_str() == Some("buy")) {
request.insert("type".into(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", side, Value::Str("_".into())).into()), Value::Str("market".into())).into()));
let mut quoteAmount: Value = Value::Null;
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp: Vec<Value> = self.handle_option_bool_and_params(paramsRequest.clone(), Value::Str("createOrder".into()), Value::Str("createMarketBuyOrderRequiresPrice".into()), &[Value::Bool(true)]).as_array().cloned().unwrap_or_default(); createMarketBuyOrderRequiresPrice = __destr_tmp.get(0).cloned().unwrap_or(Value::Null);
paramsRequest = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }
let mut cost: Value = self.safe_number_k(paramsRequest.clone(), "cost", &[]);
paramsRequest = self.omit(paramsRequest.clone(), Value::Str("cost".into()), &[]);
if (cost != Value::Null) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost);
} else if createMarketBuyOrderRequiresPrice.as_bool() == Some(true) {
if (price == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument".into()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price);
let mut costRequest: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
quoteAmount = self.cost_to_precision(symbol.clone(), costRequest);
}
} else {
quoteAmount = self.cost_to_precision(symbol, amount);
}
request.insert("price".into(), quoteAmount);
}
}
if (clientOrderId.is_some()) {
request.insert("custom_id".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
}
let mut options: Value = self.safe_dict_k(self.options.clone(), "createOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options, "method", &[Value::Str("spotPrivatePostSupplementCreateOrder".into())]);
let mut method: Option<String> = self.safe_string_k(paramsRequest.clone(), "method", &[defaultMethod]).as_str().map(str::to_owned);
let mut paramsOmitted: Value = self.omit(paramsRequest, Value::Str("method".into()), &[]);
let mut response: Value = Value::Null;
if (method.as_deref() == Some("spotPrivatePostCreateOrder")) {
let __ws_arg_12 = self.extend(Value::Map(request.clone()), &[paramsOmitted.clone()]);
response = self.spot_private_post_create_order(&[__ws_arg_12]).await;
} else {
let __ws_arg_13 = self.extend(Value::Map(request), &[paramsOmitted]);
response = self.spot_private_post_supplement_create_order(&[__ws_arg_13]).await;
}
let mut result: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(result.clone(), "order_id", &[]));
m.insert("info".to_string(), result);
m
}), &[market]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("-1".to_string(), Value::Str("canceled".into()));
m.insert("0".to_string(), Value::Str("open".into()));
m.insert("1".to_string(), Value::Str("open".into()));
m.insert("2".to_string(), Value::Str("closed".into()));
m.insert("3".to_string(), Value::Str("canceled".into()));
m.insert("4".to_string(), Value::Str("closed".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut id: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("orderId".into()), Value::Str("order_id".into()), &[]);
let mut clientOrderId: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("clientOrderId".into()), Value::Str("custom_id".into()), &[]);
let mut timestamp: Option<i64> = self.safe_integer2(order.clone(), Value::Str("time".into()), Value::Str("create_time".into()), &[]).as_i64();
let mut rawStatus: Option<String> = self.safe_string_k_opt(order.clone(), "status", &[]);
let mut marketId: Option<String> = self.safe_string_k_opt(order.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut timeInForce: Value = Value::Null;
let mut postOnly: Value = Value::Bool(false);
let mut type_var: String = "limit".to_string();
let mut rawType: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("type".into()), Value::Str("tradeType".into()), &[]); let mut parts: Value = Value::Array(if let Some(__s) = rawType.as_deref() { __s.split("_").map(Value::from).collect() } else { Vec::new() });
let mut side: Option<String> = self.safe_string_opt(parts.clone(), Value::Int(0), &[]);
let mut typePart: Option<String> = self.safe_string(parts, Value::Int(1), &[]).as_str().map(str::to_owned); if (typePart.as_deref() == Some("market")) {
type_var = "market".to_string();
}
if (typePart.as_deref() == Some("maker")) {
postOnly = Value::Bool(true);
timeInForce = Value::Str("PO".into());
}
if (typePart.as_deref() == Some("ioc")) {
timeInForce = Value::Str("IOC".into());
}
if (typePart.as_deref() == Some("fok")) {
timeInForce = Value::Str("FOK".into());
}
let mut price: Option<String> = self.safe_string_k_opt(order.clone(), "price", &[]);
let mut costString: Option<String> = self.safe_string_k_opt(order.clone(), "cummulativeQuoteQty", &[]);
let mut amountString: Value = Value::Null;
if (rawType.as_deref() != Some("buy_market")) {
amountString = self.safe_string2(order.clone(), Value::Str("origQty".into()), Value::Str("amount".into()), &[]);
}
let mut filledString: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("executedQty".into()), Value::Str("deal_amount".into()), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("clientOrderId".to_string(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_order_status(rawStatus.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), Value::from(type_var));
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), postOnly);
m.insert("side".to_string(), side.map(Value::from).unwrap_or(Value::Null));
m.insert("price".to_string(), price.map(Value::from).unwrap_or(Value::Null));
m.insert("triggerPrice".to_string(), Value::Null);
m.insert("cost".to_string(), costString.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amountString);
m.insert("filled".to_string(), filledString.map(Value::from).unwrap_or(Value::Null));
m.insert("remaining".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("info".to_string(), order);
m.insert("average".to_string(), Value::Null);
m
}), &[marketResolved]);
Value::Null
}
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut method: Value = self.safe_string_k(params.clone(), "method", &[]);
if (method == Value::Null) {
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
method = self.safe_string_k(options, "method", &[Value::Str("fetchOrderSupplement".into())]);
}
if (method.as_str() == Some("fetchOrderSupplement")) {
return self.fetch_order_supplement(id.clone(), &[symbol.clone(), params.clone()]).await;
}
return self.fetch_order_default(id, &[symbol, params]).await;
Value::Null
}
pub async fn fetch_order_supplement(&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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m.insert("orderId".to_string(), id);
m
});
let __ws_arg_14 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_supplement_orders_info(&[__ws_arg_14]).await;
let mut result: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result, &[]);
Value::Null
}
pub async fn fetch_order_default(&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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m.insert("order_id".to_string(), id.clone());
m
});
let __ws_arg_15 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_orders_info(&[__ws_arg_15]).await;
let mut result: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut numOrders: f64 = ((result.len() as i64) as f64);
if (numOrders == 1.0) {
return self.parse_order(self.safe_dict(result, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), &[]);
} else {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() can only fetch one order at a time".into()))));
}
Value::Null
}
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut sinceValue: Value = self.safe_integer_k(params.clone(), "start_date", &[since]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("start_date".into()), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("size".into(), limit.clone());
}
if (sinceValue != Value::Null) {
request.insert("start_date".into(), self.ymd(sinceValue.clone(), &[Value::Str("-".into())])); request.insert("end_date".into(), self.ymd((match (&(sinceValue), &(Value::Int(86400000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y),
_ => Value::Null }), &[Value::Str("-".into())])); }
let __ws_arg_16 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.spot_private_post_transaction_history(&[__ws_arg_16]).await;
let mut trades: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market, sinceValue, limit]);
Value::Null
}
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(100) } else { limit });
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("current_page".to_string(), Value::Int(1));
m.insert("page_length".to_string(), limitResolved.clone());
m
});
let __ws_arg_17 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_supplement_orders_info_history(&[__ws_arg_17]).await;
let mut result: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(result, "orders", &[Value::from(vec![])]);
return self.parse_orders(orders, &[market, since, limitResolved]);
Value::Null
}
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenOrders() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(100) } else { limit });
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("current_page".to_string(), Value::Int(1));
m.insert("page_length".to_string(), limitResolved.clone());
m
});
let __ws_arg_18 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_supplement_orders_info_no_deal(&[__ws_arg_18]).await;
let mut result: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(result, "orders", &[Value::from(vec![])]);
return self.parse_orders(orders, &[market, since, limitResolved]);
Value::Null
}
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut clientOrderId: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("origClientOrderId".into()), Value::Str("clientOrderId".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("origClientOrderId".into()), Value::Str("clientOrderId".into())]), &[]);
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m.insert("orderId".to_string(), id);
m
});
if (clientOrderId.is_some()) {
request.insert("origClientOrderId".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
}
let __ws_arg_19 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.spot_private_post_supplement_cancel_order(&[__ws_arg_19]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[]);
Value::Null
}
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_20 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_supplement_cancel_order_by_symbol(&[__ws_arg_20]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_orders(data, &[]);
Value::Null
}
pub fn get_network_code_for_currency(&self, mut currencyCode: Value, mut params: Value) -> Option<String> {
let mut defaultNetworks: Value = self.safe_dict_k(self.options.clone(), "defaultNetworks", &[]);
let mut defaultNetwork: Value = self.safe_string_upper(defaultNetworks, currencyCode, &[]);
let mut networks: Value = self.safe_dict_k(self.options.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networkParam: Value = self.safe_string_upper_k(params, "network", &[defaultNetwork]); let mut networkCode: Value = (if (networkParam != Value::Null) { self.safe_string(self.networkAliases.clone(), networkParam.clone(), &[networkParam.clone()]) } else { Value::Null });
return self.safe_string(networks, networkCode.clone(), &[networkCode.clone()]).as_str().map(str::to_owned);
}
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchDepositAddress", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options, "method", &[Value::Str("fetchDepositAddressDefault".into())]);
let mut method: Option<String> = self.safe_string_k(params.clone(), "method", &[defaultMethod]).as_str().map(str::to_owned);
let mut paramsOmitted: Value = self.omit(params, Value::Str("method".into()), &[]);
let mut response: Value = Value::Null;
if (method.as_deref() == Some("fetchDepositAddressSupplement")) {
response = self.fetch_deposit_address_supplement(code.clone(), &[paramsOmitted.clone()]).await;
} else {
response = self.fetch_deposit_address_default(code, &[paramsOmitted]).await;
}
return response;
Value::Null
}
pub async fn fetch_deposit_address_default(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: indexmap::IndexMap<String, Value> = self.currency(code.clone()).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("assetCode".to_string(), currency.get("id").cloned().unwrap_or(Value::Null));
m
});
let mut network: Value = self.get_network_code_for_currency(code.clone(), params.clone()).map(Value::from).unwrap_or(Value::Null);
let mut paramsOmitted: Value = (if (network != Value::Null) { self.omit(params.clone(), Value::Str("network".into()), &[]) } else { params });
if (network != Value::Null) {
request.insert("netWork".into(), network); }
let __ws_arg_21 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.spot_private_post_get_deposit_address(&[__ws_arg_21]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut address: Option<String> = self.safe_string_k_opt(result.clone(), "address", &[]);
let mut tag: Option<String> = self.safe_string_k_opt(result.clone(), "memo", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), self.network_id_to_code(&[self.safe_string_k(result, "netWork", &[]), code]));
m.insert("address".to_string(), address.map(Value::from).unwrap_or(Value::Null));
m.insert("tag".to_string(), tag.map(Value::from).unwrap_or(Value::Null));
m
});
Value::Null
}
pub async fn fetch_deposit_address_supplement(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: indexmap::IndexMap<String, Value> = self.currency(code.clone()).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), currency.get("id").cloned().unwrap_or(Value::Null));
m
});
let mut networks: Value = self.safe_dict_k(self.options.clone(), "networks", &[]);
let mut network: Value = self.safe_string_upper_k(params.clone(), "network", &[]);
if (network != Value::Null) {
network = self.safe_string(self.networkAliases.clone(), network.clone(), &[network.clone()]);
}
network = self.safe_string(networks, network.clone(), &[network.clone()]);
let mut paramsOmitted: Value = (if (network != Value::Null) { self.omit(params.clone(), Value::Str("network".into()), &[]) } else { params });
if (network != Value::Null) {
request.insert("networkName".into(), network);
}
let __ws_arg_22 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.spot_private_post_supplement_get_deposit_address(&[__ws_arg_22]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut address: Option<String> = self.safe_string_k_opt(result.clone(), "address", &[]);
let mut tag: Option<String> = self.safe_string_k_opt(result, "memo", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m.insert("currency".to_string(), code);
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.map(Value::from).unwrap_or(Value::Null));
m.insert("tag".to_string(), tag.map(Value::from).unwrap_or(Value::Null));
m
});
Value::Null
}
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let tagWithdrawTagparamsWithdrawTagVariable: Vec<Value> = self.handle_param_string(params, Value::Str("tag".into()), &[]).as_array().cloned().unwrap_or_default();
let mut tagWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.get(1).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone(), code.clone(), tagWithdrawTag.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut fee: Option<String> = self.safe_string_k_opt(paramsWithdrawTag.clone(), "fee", &[]);
let mut paramsOmitted: Value = self.omit(paramsWithdrawTag, Value::Str("fee".into()), &[]);
self.check_required_argument(Value::Str("withdraw".into()), fee.clone().map(Value::from).unwrap_or(Value::Null), Value::Str("fee".into()), &[]);
let mut currency: indexmap::IndexMap<String, Value> = self.currency(code).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("address".to_string(), address);
m.insert("coin".to_string(), currency.get("id").cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), amount);
m.insert("fee".to_string(), fee.map(Value::from).unwrap_or(Value::Null));
m
});
if (tagWithdrawTag != Value::Null) {
request.insert("memo".into(), tagWithdrawTag);
}
let mut network: Value = self.safe_string_upper2(paramsOmitted.clone(), Value::Str("network".into()), Value::Str("networkName".into()), &[]);
if (network != Value::Null) {
network = self.safe_string(self.networkAliases.clone(), network.clone(), &[network.clone()]);
}
let mut paramsOmitted2: Value = self.omit(paramsOmitted, Value::from(vec![Value::Str("network".into()), Value::Str("networkName".into())]), &[]);
let mut networks: Value = self.safe_dict_k(self.options.clone(), "networks", &[]);
let mut networkId: Value = self.safe_string(networks, network.clone(), &[network.clone()]);
if (networkId != Value::Null) {
request.insert("networkName".into(), networkId);
}
let __ws_arg_23 = self.extend(Value::Map(request), &[paramsOmitted2]);
let mut response: Value = self.spot_private_post_supplement_withdraw(&[__ws_arg_23]).await;
let mut result: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), result.clone());
m.insert("id".to_string(), self.safe_string_k(result, "withdrawId", &[]));
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value, mut type_var: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1".to_string(), Value::Str("pending".into()));
m.insert("2".to_string(), Value::Str("ok".into()));
m.insert("3".to_string(), Value::Str("failed".into()));
m.insert("4".to_string(), Value::Str("canceled".into()));
m.insert("5".to_string(), Value::Str("transfer".into()));
m
}));
m.insert("withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1".to_string(), Value::Str("pending".into()));
m.insert("2".to_string(), Value::Str("canceled".into()));
m.insert("3".to_string(), Value::Str("failed".into()));
m.insert("4".to_string(), Value::Str("ok".into()));
m
}));
m
});
return self.safe_string(self.safe_dict(Value::Map(statuses), type_var, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut id: Option<String> = self.safe_string_k_opt(transaction.clone(), "id", &[]);
let mut type_var: Value = Value::Null;
if (id.is_none()) {
type_var = Value::Str("deposit".into());
} else {
type_var = Value::Str("withdrawal".into());
}
let mut txid: Option<String> = self.safe_string_k_opt(transaction.clone(), "txId", &[]);
let mut timestamp: Option<i64> = self.safe_integer2(transaction.clone(), Value::Str("insertTime".into()), Value::Str("applyTime".into()), &[]).as_i64();
let mut address: Option<String> = self.safe_string_k_opt(transaction.clone(), "address", &[]);
let mut addressFrom: Value = Value::Null;
let mut addressTo: Value = Value::Null;
if (type_var.as_str() == Some("deposit")) {
addressFrom = address.clone().map(Value::from).unwrap_or(Value::Null);
} else {
addressTo = address.clone().map(Value::from).unwrap_or(Value::Null);
}
let mut amount: Value = self.safe_number_k(transaction.clone(), "amount", &[]);
let mut currencyId: Option<String> = self.safe_string2_opt(transaction.clone(), Value::Str("coin".into()), Value::Str("coid".into()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]);
let mut status: Value = self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[]), type_var.clone()).map(Value::from).unwrap_or(Value::Null);
let mut fee: Value = Value::Null;
let mut feeCost: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
if (feeCost != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost);
m.insert("currency".to_string(), code.clone());
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("txid".to_string(), txid.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("network".to_string(), self.network_id_to_code(&[self.safe_string_k(transaction, "networkName", &[]), code.clone()]));
m.insert("address".to_string(), address.map(Value::from).unwrap_or(Value::Null));
m.insert("addressTo".to_string(), addressTo);
m.insert("addressFrom".to_string(), addressFrom);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("amount".to_string(), amount);
m.insert("currency".to_string(), code);
m.insert("status".to_string(), status.clone());
m.insert("updated".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), (Value::Bool(status.as_str() == Some("transfer"))));
m.insert("fee".to_string(), fee);
m
});
Value::Null
}
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
request.insert("coin".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (since != Value::Null) {
request.insert("startTime".into(), since.clone());
}
let __ws_arg_24 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_supplement_deposit_history(&[__ws_arg_24]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut deposits: Value = self.safe_list_k(data, "depositOrders", &[Value::from(vec![])]);
return self.parse_transactions(deposits, &[currency, since, limit]);
Value::Null
}
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
request.insert("coin".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (since != Value::Null) {
request.insert("startTime".into(), since.clone());
}
let __ws_arg_25 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_private_post_supplement_withdraws(&[__ws_arg_25]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut withdraws: Value = self.safe_list_k(data, "withdraws", &[Value::from(vec![])]);
return self.parse_transactions(withdraws, &[currency, since, limit]);
Value::Null
}
pub async fn fetch_transaction_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut isAuthorized: Value = self.check_required_credentials(&[Value::Bool(false)]);
if isAuthorized.as_bool() == Some(true) {
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchTransactionFees", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options, "method", &[Value::Str("fetchPrivateTransactionFees".into())]);
let mut method: Option<String> = self.safe_string_k(params.clone(), "method", &[defaultMethod]).as_str().map(str::to_owned);
let mut paramsOmitted: Value = self.omit(params.clone(), Value::Str("method".into()), &[]);
if (method.as_deref() == Some("fetchPublicTransactionFees")) {
return self.fetch_public_transaction_fees(&[paramsOmitted.clone()]).await;
}
return self.fetch_private_transaction_fees(&[paramsOmitted]).await;
}
return self.fetch_public_transaction_fees(&[params]).await;
Value::Null
}
pub async fn fetch_private_transaction_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.spot_private_post_supplement_user_info(&[]).await;
let mut result: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut withdrawFees: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_925: bool = true;
while { if !__for_first_925 { i += 1; } __for_first_925 = false; i < (result.len() as i64) } {
let mut entry: Value = self.safe_dict(result.clone(), Value::Int(i), &[]);
let mut code: Value = self.safe_currency_code(self.safe_string_k(entry.clone(), "coin", &[]), &[]);
let mut networkList: Value = self.safe_list_k(entry, "networkList", &[Value::from(vec![])]);
if (code != Value::Null) {
withdrawFees.insert(crate::runtime::stringify_param(&code), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
{
let mut j: i64 = 0;
let mut __for_first_924: bool = true;
while { if !__for_first_924 { j += 1; } __for_first_924 = false; j < (networkList.len() as i64) } {
let mut networkEntry: Value = self.safe_dict(networkList.clone(), Value::Int(j), &[]);
let mut fee: Value = self.safe_number_k(networkEntry.clone(), "withdrawFee", &[]);
if (fee != Value::Null) {
let mut networkCode: Value = self.network_id_to_code(&[self.safe_string_k(networkEntry, "name", &[]), code.clone()]);
if (networkCode != Value::Null) {
if (code != Value::Null) && (networkCode != Value::Null) {
let mut feesForCode: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
feesForCode.insert(crate::runtime::stringify_param(&networkCode), fee);
let __ws_arg_26 = self.safe_dict(Value::Map(withdrawFees.clone()), code.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_26, &[Value::Map(feesForCode)]); withdrawFees.insert(crate::runtime::stringify_param(&code), __be_tmp); }
}
}
}
}
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map(withdrawFees));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("info".to_string(), response);
m
});
Value::Null
}
pub async fn fetch_public_transaction_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut code: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("coin".into()), Value::Str("assetCode".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("coin".into()), Value::Str("assetCode".into())]), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (code.is_some()) {
let mut currency: indexmap::IndexMap<String, Value> = self.currency(code.clone().map(Value::from).unwrap_or(Value::Null)).as_map().cloned().unwrap_or_default();
request.insert("assetCode".into(), currency.get("id").cloned().unwrap_or(Value::Null));
}
let __ws_arg_27 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.spot_public_get_withdraw_configs(&[__ws_arg_27]).await;
let mut result: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut withdrawFees: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_926: bool = true;
while { if !__for_first_926 { i += 1; } __for_first_926 = false; i < (result.len() as i64) } {
let mut item: Value = self.safe_dict(result.clone(), Value::Int(i), &[]);
let mut canWithdraw: Option<String> = self.safe_string_k(item.clone(), "canWithDraw", &[]).as_str().map(str::to_owned);
if (canWithdraw.as_deref() == Some("true")) {
let mut codeInner: Value = self.safe_currency_code(self.safe_string_k(item.clone(), "assetCode", &[]), &[]);
let mut network: Value = self.network_id_to_code(&[self.safe_string_k(item.clone(), "chain", &[]), codeInner.clone()]);
if (network == Value::Null) {
network = codeInner.clone();
}
let mut fee: Option<String> = self.safe_string_k_opt(item, "fee", &[]);
if (codeInner != Value::Null) && (network != Value::Null) {
let mut feesForCode: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
feesForCode.insert(crate::runtime::stringify_param(&network), self.parse_number(fee.map(Value::from).unwrap_or(Value::Null), &[]));
let __ws_arg_28 = self.safe_dict(Value::Map(withdrawFees.clone()), codeInner.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_28, &[Value::Map(feesForCode)]); withdrawFees.insert(crate::runtime::stringify_param(&codeInner), __be_tmp); }
}
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map(withdrawFees));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("info".to_string(), response);
m
});
Value::Null
}
pub async fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut isAuthorized: Value = self.check_required_credentials(&[Value::Bool(false)]);
if isAuthorized.as_bool() == Some(true) {
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchDepositWithdrawFees", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options, "method", &[Value::Str("fetchPrivateDepositWithdrawFees".into())]);
let mut method: Option<String> = self.safe_string_k(params.clone(), "method", &[defaultMethod]).as_str().map(str::to_owned);
let mut paramsOmitted: Value = self.omit(params.clone(), Value::Str("method".into()), &[]);
if (method.as_deref() == Some("fetchPublicDepositWithdrawFees")) {
return self.fetch_public_deposit_withdraw_fees(&[codes.clone(), paramsOmitted.clone()]).await;
}
return self.fetch_private_deposit_withdraw_fees(&[codes.clone(), paramsOmitted]).await;
}
return self.fetch_public_deposit_withdraw_fees(&[codes, params]).await;
Value::Null
}
pub async fn fetch_private_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.spot_private_post_supplement_user_info(&[params]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_deposit_withdraw_fees(data, &[codes, Value::Str("coin".into())]);
Value::Null
}
pub async fn fetch_public_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_29 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.spot_public_get_withdraw_configs(&[__ws_arg_29]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_public_deposit_withdraw_fees(data, &[codes]);
Value::Null
}
pub fn parse_public_deposit_withdraw_fees(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let __response_empty = Vec::new();
let response = response.as_array().unwrap_or(&__response_empty);
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_927: bool = true;
while { if !__for_first_927 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_927 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut fee: Value = response.get((i).as_i64().unwrap_or(-1) as usize).cloned().unwrap_or(Value::Null);
let mut canWithdraw: bool = self.safe_bool_k_opt(fee.clone(), "canWithDraw", &[Value::Bool(false)]).unwrap_or(false);
if canWithdraw {
let mut code: Value = self.safe_currency_code(self.safe_string_k(fee.clone(), "assetCode", &[]), &[]);
if (code != Value::Null) && ((codes == Value::Null) || self.in_array(code.clone(), codes.clone()).as_bool() == Some(true)) {
let mut withdrawFee: Value = self.safe_number_k(fee.clone(), "fee", &[]);
if (withdrawFee != Value::Null) {
let mut resultValue: Value = self.safe_dict(Value::Map(result.clone()), code.clone(), &[]);
if (resultValue == Value::Null) {
result.insert(crate::runtime::stringify_param(&code), self.deposit_withdraw_fee(Value::from(vec![fee.clone()])));
} else {
let mut infoList: Value = self.array_concat(resultValue.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::from(vec![fee.clone()]));
result.insert(crate::runtime::stringify_param(&code), self.extend(resultValue, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), infoList);
m
})]));
}
let mut networkCode: Value = self.network_id_to_code(&[self.safe_string_k(fee, "chain", &[]), code.clone()]);
if (networkCode != Value::Null) {
let mut networkFees: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
networkFees.insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee.clone());
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
}));
let __ws_arg_30 = self.safe_dict(self.safe_dict(Value::Map(result.clone()), code.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), Value::Str("networks".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networks: Value = self.extend(__ws_arg_30, &[Value::Map(networkFees)]);
let __ws_arg_31 = self.safe_dict(Value::Map(result.clone()), code.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_31, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("networks".to_string(), networks);
m
})]); result.insert(crate::runtime::stringify_param(&code), __be_tmp); }
} else {
let __ws_arg_32 = self.safe_dict(Value::Map(result.clone()), code.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_32, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
})]); result.insert(crate::runtime::stringify_param(&code), __be_tmp); }
}
}
}
}
}
}
return Value::Map(result);
Value::Null
}
pub fn parse_deposit_withdraw_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
let mut result: indexmap::IndexMap<String, Value> = self.deposit_withdraw_fee(fee.clone()).as_map().cloned().unwrap_or_default();
let mut code: Value = (match currency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut networkList: Value = self.safe_list_k(fee, "networkList", &[Value::from(vec![])]);
{
let mut j: i64 = 0;
let mut __for_first_928: bool = true;
while { if !__for_first_928 { j += 1; } __for_first_928 = false; j < (networkList.len() as i64) } {
let mut networkEntry: Value = self.safe_dict(networkList.clone(), Value::Int(j), &[]);
let mut networkCode: Value = self.network_id_to_code(&[self.safe_string_k(networkEntry.clone(), "name", &[]), code.clone()]);
let mut withdrawFee: Value = self.safe_number_k(networkEntry.clone(), "withdrawFee", &[]);
let mut isDefault: bool = self.safe_bool_k_opt(networkEntry, "isDefault", &[Value::Bool(false)]).unwrap_or(false);
if (withdrawFee != Value::Null) {
if isDefault {
result.insert("withdraw".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee.clone());
m.insert("percentage".to_string(), Value::Null);
m
}));
}
if (networkCode != Value::Null) {
let mut networkFees: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
networkFees.insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
}));
let __ws_arg_33 = self.safe_dict(Value::Map(result.clone()), Value::Str("networks".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_33, &[Value::Map(networkFees)]); result.insert("networks".into(), __be_tmp); }
}
}
}
}
return Value::Map(result);
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __api_empty = Vec::new();
let api = api.as_array().unwrap_or(&__api_empty);
let mut paramsOmitted: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut apiUrl: Option<String> = self.safe_string_opt(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), Value::Str("rest".into()), &[]);
if (apiUrl.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", apiUrl.map(Value::from).unwrap_or(Value::Null), Value::Str("/".into())).into()), self.version.clone()).into()), Value::Str("/".into())).into()), self.implode_params(path.clone(), params.clone())).into());
if (api.get(0).cloned().unwrap_or(Value::Null).as_str() == Some("spot")) {
url = Value::Str(format!("{}{}", url, Value::Str(".do".into())).into());
} else {
let mut contractUrl: Option<String> = self.safe_string_opt(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), Value::Str("contract".into()), &[]);
if (contractUrl.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
url = Value::Str(format!("{}{}", Value::Str(format!("{}{}", contractUrl.map(Value::from).unwrap_or(Value::Null), Value::Str("/".into())).into()), self.implode_params(path, params)).into());
}
if (api.get(1).cloned().unwrap_or(Value::Null).as_str() == Some("public")) {
if ((Value::Array(paramsOmitted.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).len() as i64) as f64) > ((0i64) as f64) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(self.keysort(paramsOmitted.clone(), &[]), &[])).into())).into());
}
} else {
self.check_required_credentials(&[]);
let mut timestamp: Value = Value::Str(format!("{}", self.milliseconds()).into());
let mut echostr: Value = Value::Str(format!("{}{}", self.uuid22(&[]), self.uuid16(&[])).into());
let mut signedQuery: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api_key".to_string(), self.apiKey.clone());
m
}), &[paramsOmitted]);
let mut signatureMethod: Value = Value::Null;
if ((self.secret.len() as i64) as f64) > ((32i64) as f64) {
signatureMethod = Value::Str("RSA".into());
} else {
signatureMethod = Value::Str("HmacSHA256".into());
}
let mut finalSig: Value = signatureMethod.clone(); let __ws_arg_34 = self.keysort(self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("echostr".to_string(), echostr.clone());
m.insert("signature_method".to_string(), finalSig);
m.insert("timestamp".to_string(), timestamp.clone());
m
}), &[signedQuery.clone()]), &[]);
let mut auth: Value = self.rawencode(__ws_arg_34, &[]);
let mut encoded: Value = self.encode(auth);
let mut uppercaseHash: Value = (self.hash(encoded, Value::Str("md5".into()), &[])).as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null);
let mut sign: Value = Value::Str("".into());
if (signatureMethod.as_str() == Some("RSA")) {
let mut cacheSecretAsPem: bool = self.safe_bool_k_opt(self.options.clone(), "cacheSecretAsPem", &[Value::Bool(true)]).unwrap_or(true);
let mut pem: Value = Value::Null;
if cacheSecretAsPem {
let mut cachedPem: Option<String> = self.safe_string_k_opt(self.options.clone(), "pem", &[]);
if (cachedPem.is_none()) {
pem = self.convert_secret_to_pem(self.encode(self.secret.clone())).map(Value::from).unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut self.options.clone() { std::sync::Arc::make_mut(__d).insert("pem".into(), pem.clone()); }
} else {
pem = cachedPem.map(Value::from).unwrap_or(Value::Null);
}
} else {
pem = self.convert_secret_to_pem(self.encode(self.secret.clone())).map(Value::from).unwrap_or(Value::Null);
}
sign = rsa(uppercaseHash.clone(), pem, Value::Str("sha256".into()));
} else if (signatureMethod.as_str() == Some("HmacSHA256")) {
sign = self.hmac(self.encode(uppercaseHash), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[]);
}
if let Value::Dict(__d) = &mut signedQuery { std::sync::Arc::make_mut(__d).insert("sign".into(), sign); }
let mut bodySigned: Value = self.urlencode(self.keysort(signedQuery, &[]), &[]);
let mut headersSigned: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".into()));
m.insert("timestamp".to_string(), timestamp);
m.insert("signature_method".to_string(), signatureMethod);
m.insert("echostr".to_string(), echostr);
m
});
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), bodySigned);
m.insert("headers".to_string(), Value::Map(headersSigned));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), Value::Null);
m.insert("headers".to_string(), Value::Null);
m
});
Value::Null
}
pub fn convert_secret_to_pem(&self, mut secret: Value) -> Option<String> {
let mut secretLength: Value = get_array_length(&secret);
let mut fullLines: Value = self.parse_to_int((match ((secretLength).as_f64(), (Value::Int(64)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
let mut pem: Value = Value::Str("-----BEGIN PRIVATE KEY-----\n".into()); {
let mut i: Value = Value::Int(0);
let mut __for_first_929: bool = true;
while { if !__for_first_929 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_929 = false; i.as_f64().unwrap_or(f64::NAN) <= fullLines.as_f64().unwrap_or(f64::NAN) } {
let mut start: Value = (match (&(i), &(Value::Int(64))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
let mut end: Value = self.sum(&[start.clone(), Value::Int(64)]);
pem = Value::Str(format!("{}{}", pem, Value::Str(format!("{}{}", (match (&(self.secret.clone()), (match &(start) { Value::Int(__n) => Some(*__n), Value::Float(__f) => Some(*__f as i64), Value::Str(__s) => __s.parse::<i64>().ok(), Value::Bool(__b) => Some(if *__b { 1 } else { 0 }), _ => None }).unwrap_or(0),
(match &(end) { Value::Int(__n) => Some(*__n), Value::Float(__f) => Some(*__f as i64), Value::Str(__s) => __s.parse::<i64>().ok(), Value::Bool(__b) => Some(if *__b { 1 } else { 0 }), _ => None })) { (Value::Str(__sv), __b, __e) => match (__sv.chars().count() as i64) { __l => match (if __b < 0 { (__l + __b).max(0) } else { __b.min(__l) },
match __e { None => __l, Some(__k) => if __k < 0 { (__l + __k).max(0) } else { __k.min(__l) } }) { (__i, __j) => if __i <= __j { Value::Str(__sv.chars().skip(__i as usize).take((__j - __i) as usize).collect::<String>().into()) } else { Value::Str(String::new().into()) } } }, (Value::Arr(__a), __b,
__e) => match (__a.len() as i64) { __l => match (if __b < 0 { (__l + __b).max(0) } else { __b.min(__l) }, match __e { None => __l, Some(__k) => if __k < 0 { (__l + __k).max(0) } else { __k.min(__l) } }) { (__i, __j) => if __i <= __j { Value::Array(__a[__i as usize..__j as usize].to_vec()) } else { Value::Array(vec![]) } } },
_ => Value::Null }), Value::Str("\n".into())).into())).into()); }
}
return Value::Str(format!("{}{}", pem, Value::Str("-----END PRIVATE KEY-----".into())).into()).as_str().map(str::to_owned);
}
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 (response == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" parseBalance() returned empty response".into()))));
}
let mut success: Option<String> = self.safe_string_k(response.clone(), "result", &[]).as_str().map(str::to_owned);
if (success.as_deref() == Some("false")) || (success.is_none()) {
let mut errorCode: Option<String> = self.safe_string_k_opt(response.clone(), "error_code", &[]);
let mut message: Value = self.safe_string(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("10000".to_string(), Value::Str("Internal error".into()));
m.insert("10001".to_string(), Value::Str("The required parameters can not be empty".into()));
m.insert("10002".to_string(), Value::Str("Validation failed".into()));
m.insert("10003".to_string(), Value::Str("Invalid parameter".into()));
m.insert("10004".to_string(), Value::Str("Request too frequent".into()));
m.insert("10005".to_string(), Value::Str("Secret key does not exist".into()));
m.insert("10006".to_string(), Value::Str("User does not exist".into()));
m.insert("10007".to_string(), Value::Str("Invalid signature".into()));
m.insert("10008".to_string(), Value::Str("Invalid Trading Pair".into()));
m.insert("10009".to_string(), Value::Str("Price and/or Amount are required for limit order".into()));
m.insert("10010".to_string(), Value::Str("Price and/or Amount must be less than minimum requirement".into()));
m.insert("10013".to_string(), Value::Str("The amount is too small".into()));
m.insert("10014".to_string(), Value::Str("Insufficient amount of money in the account".into()));
m.insert("10015".to_string(), Value::Str("Invalid order type".into()));
m.insert("10016".to_string(), Value::Str("Insufficient account balance".into()));
m.insert("10017".to_string(), Value::Str("Server Error".into()));
m.insert("10018".to_string(), Value::Str("Page size should be between 1 and 50".into()));
m.insert("10019".to_string(), Value::Str("Cancel NO more than 3 orders in one request".into()));
m.insert("10020".to_string(), Value::Str("Volume < 0.001".into()));
m.insert("10021".to_string(), Value::Str("Price < 0.01".into()));
m.insert("10022".to_string(), Value::Str("Invalid authorization".into()));
m.insert("10023".to_string(), Value::Str("Market Order is not supported yet".into()));
m.insert("10024".to_string(), Value::Str("User cannot trade on this pair".into()));
m.insert("10025".to_string(), Value::Str("Order has been filled".into()));
m.insert("10026".to_string(), Value::Str("Order has been cancelld".into()));
m.insert("10027".to_string(), Value::Str("Order is cancelling".into()));
m.insert("10028".to_string(), Value::Str("Wrong query time".into()));
m.insert("10029".to_string(), Value::Str("from is not in the query time".into()));
m.insert("10030".to_string(), Value::Str("from do not match the transaction type of inqury".into()));
m.insert("10031".to_string(), Value::Str("echostr length must be valid and length must be from 30 to 40".into()));
m.insert("10033".to_string(), Value::Str("Failed to create order".into()));
m.insert("10036".to_string(), Value::Str("customID duplicated".into()));
m.insert("10100".to_string(), Value::Str("Has no privilege to withdraw".into()));
m.insert("10101".to_string(), Value::Str("Invalid fee rate to withdraw".into()));
m.insert("10102".to_string(), Value::Str("Too little to withdraw".into()));
m.insert("10103".to_string(), Value::Str("Exceed daily limitation of withdraw".into()));
m.insert("10104".to_string(), Value::Str("Cancel was rejected".into()));
m.insert("10105".to_string(), Value::Str("Request has been cancelled".into()));
m.insert("10106".to_string(), Value::Str("None trade time".into()));
m.insert("10107".to_string(), Value::Str("Start price exception".into()));
m.insert("10108".to_string(), Value::Str("can not create order".into()));
m.insert("10109".to_string(), Value::Str("wallet address is not mapping".into()));
m.insert("10110".to_string(), Value::Str("transfer fee is not mapping".into()));
m.insert("10111".to_string(), Value::Str("mount > 0".into()));
m.insert("10112".to_string(), Value::Str("fee is too lower".into()));
m.insert("10113".to_string(), Value::Str("transfer fee is 0".into()));
m.insert("10600".to_string(), Value::Str("intercepted by replay attacks filter, check timestamp".into()));
m.insert("10601".to_string(), Value::Str("Interface closed unavailable".into()));
m.insert("10701".to_string(), Value::Str("invalid asset code".into()));
m.insert("10702".to_string(), Value::Str("not allowed deposit".into()));
m
}), errorCode.clone().map(Value::from).unwrap_or(Value::Null), &[json_stringify(&response)]);
let mut ErrorClass: Value = self.safe_value(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("10001".to_string(), Value::Str("BadRequest".into()));
m.insert("10002".to_string(), Value::Str("AuthenticationError".into()));
m.insert("10003".to_string(), Value::Str("BadRequest".into()));
m.insert("10004".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("10005".to_string(), Value::Str("AuthenticationError".into()));
m.insert("10006".to_string(), Value::Str("AuthenticationError".into()));
m.insert("10007".to_string(), Value::Str("AuthenticationError".into()));
m.insert("10008".to_string(), Value::Str("BadSymbol".into()));
m.insert("10009".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10010".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10013".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10014".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("10015".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10016".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("10017".to_string(), Value::Str("ExchangeError".into()));
m.insert("10018".to_string(), Value::Str("BadRequest".into()));
m.insert("10019".to_string(), Value::Str("BadRequest".into()));
m.insert("10020".to_string(), Value::Str("BadRequest".into()));
m.insert("10021".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10022".to_string(), Value::Str("PermissionDenied".into()));
m.insert("10023".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10024".to_string(), Value::Str("PermissionDenied".into()));
m.insert("10025".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10026".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10027".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10028".to_string(), Value::Str("BadRequest".into()));
m.insert("10029".to_string(), Value::Str("BadRequest".into()));
m.insert("10030".to_string(), Value::Str("BadRequest".into()));
m.insert("10031".to_string(), Value::Str("InvalidNonce".into()));
m.insert("10033".to_string(), Value::Str("ExchangeError".into()));
m.insert("10036".to_string(), Value::Str("DuplicateOrderId".into()));
m.insert("10100".to_string(), Value::Str("PermissionDenied".into()));
m.insert("10101".to_string(), Value::Str("BadRequest".into()));
m.insert("10102".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("10103".to_string(), Value::Str("ExchangeError".into()));
m.insert("10104".to_string(), Value::Str("ExchangeError".into()));
m.insert("10105".to_string(), Value::Str("ExchangeError".into()));
m.insert("10106".to_string(), Value::Str("BadRequest".into()));
m.insert("10107".to_string(), Value::Str("BadRequest".into()));
m.insert("10108".to_string(), Value::Str("ExchangeError".into()));
m.insert("10109".to_string(), Value::Str("InvalidAddress".into()));
m.insert("10110".to_string(), Value::Str("ExchangeError".into()));
m.insert("10111".to_string(), Value::Str("BadRequest".into()));
m.insert("10112".to_string(), Value::Str("BadRequest".into()));
m.insert("10113".to_string(), Value::Str("BadRequest".into()));
m.insert("10600".to_string(), Value::Str("BadRequest".into()));
m.insert("10601".to_string(), Value::Str("ExchangeError".into()));
m.insert("10701".to_string(), Value::Str("BadSymbol".into()));
m.insert("10702".to_string(), Value::Str("PermissionDenied".into()));
m
}), errorCode.map(Value::from).unwrap_or(Value::Null), &[Value::Str("ExchangeError".into())]);
panic!("{}", crate::exchange_errors::create_error(&crate::runtime::stringify_param(&(ErrorClass)), &crate::runtime::stringify_param(&(message))));
}
return Value::Null;
Value::Null
}
}