#![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 CoinbaseCore {
pub exchange: crate::exchange::Exchange,
}
impl CoinbaseCore {
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 = CoinbaseCore::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 CoinbaseCore {
fn nonce(&self, ) -> crate::Value {
CoinbaseCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
CoinbaseCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
CoinbaseCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
CoinbaseCore::parse_order(self, order, &[market])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
CoinbaseCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
CoinbaseCore::parse_position(self, position, &[market])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
CoinbaseCore::parse_deposit_address(self, depositAddress, &[currency])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
CoinbaseCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
CoinbaseCore::parse_transfer(self, transfer, &[currency])
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
CoinbaseCore::parse_account(self, account)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
CoinbaseCore::parse_transaction(self, transaction, &[currency])
}
fn parse_conversion(&self, conversion: crate::Value, from_currency: crate::Value, to_currency: crate::Value) -> crate::Value {
CoinbaseCore::parse_conversion(self, conversion, &[from_currency, to_currency])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
CoinbaseCore::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 {
CoinbaseCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for CoinbaseCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_auth_token" => self.create_auth_token(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"create_convert_trade" => self.create_convert_trade(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,
"create_deposit_address" => self.create_deposit_address(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,
"deposit" => self.deposit(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,
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"fetch_accounts" => self.fetch_accounts(&args[..]).await,
"fetch_accounts_v2" => self.fetch_accounts_v2(&args[..]).await,
"fetch_accounts_v3" => self.fetch_accounts_v3(&args[..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&args[..]).await,
"fetch_canceled_orders" => self.fetch_canceled_orders(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_convert_quote" => self.fetch_convert_quote(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"fetch_convert_trade" => self.fetch_convert_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_currencies_from_cache" => self.fetch_currencies_from_cache(&args[..]).await,
"fetch_deposit" => self.fetch_deposit(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_addresses" => self.fetch_deposit_addresses(&args[..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_method_id" => self.fetch_deposit_method_id(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_method_ids" => self.fetch_deposit_method_ids(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_markets_v2" => self.fetch_markets_v2(&args[..]).await,
"fetch_markets_v3" => self.fetch_markets_v3(&args[..]).await,
"fetch_my_buys" => self.fetch_my_buys(&args[..]).await,
"fetch_my_sells" => self.fetch_my_sells(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_portfolio_details" => self.fetch_portfolio_details(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_portfolios" => self.fetch_portfolios(&args[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_ticker_v2" => self.fetch_ticker_v2(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_ticker_v3" => self.fetch_ticker_v3(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_tickers_v2" => self.fetch_tickers_v2(&args[..]).await,
"fetch_tickers_v3" => self.fetch_tickers_v3(&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_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_transactions_with_method" => self.fetch_transactions_with_method(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"find_account_id" => self.find_account_id(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).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)),
"is_eddsa_api_key" => self.is_eddsa_api_key(),
"nonce" => self.nonce(),
"parse_account" => self.parse_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_contract_market" => self.parse_contract_market(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_conversion" => self.parse_conversion(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_custom_balance" => self.parse_custom_balance(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_deposit_method_id" => self.parse_deposit_method_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_method_ids" => self.parse_deposit_method_ids(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_portfolio_details" => self.parse_portfolio_details(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_spot_market" => self.parse_spot_market(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(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())..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"prepare_account_request" => self.prepare_account_request(&args[..]),
"prepare_account_request_with_currency_code" => self.prepare_account_request_with_currency_code(&args[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"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 CoinbaseCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for CoinbaseCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl CoinbaseCore {
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("coinbase".into()));
m.insert("name".to_string(), Value::Str("Coinbase Advanced".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("US".into())]));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("rateLimit".to_string(), Value::Int(34));
m.insert("version".to_string(), Value::Str("v2".into()));
m.insert("userAgent".to_string(), self.userAgents.as_map().and_then(|__m| __m.get("chrome")).cloned().unwrap_or(Value::Null));
m.insert("headers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CB-VERSION".to_string(), Value::Str("2018-05-30".into()));
m
}));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Bool(true));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createConvertTrade".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(true));
m.insert("createLimitBuyOrder".to_string(), Value::Bool(true));
m.insert("createLimitSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(false));
m.insert("createOrderWithTakeProfitAndStopLossWs".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopMarketOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("deposit".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchConvertQuote".to_string(), Value::Bool(true));
m.insert("fetchConvertTrade".to_string(), Value::Bool(true));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposit".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Str("emulated".into()));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(true));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(true));
m.insert("fetchDepositMethodId".to_string(), Value::Bool(true));
m.insert("fetchDepositMethodIds".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchL2OrderBook".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarginModes".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyBuys".to_string(), Value::Bool(true));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySells".to_string(), Value::Bool(true));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(false));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("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::Str("emulated".into()));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("repayMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
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/40811661-b6eceae2-653a-11e8-829e-10bfadb078cf.jpg".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("rest".to_string(), Value::Str("https://api.coinbase.com".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.coinbase.com".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://docs.cdp.coinbase.com/coinbase-app/introduction/welcome".into()), Value::Str("https://docs.cdp.coinbase.com/coinbase-app/advanced-trade-apis/api-reference".into())]));
m.insert("fees".to_string(), Value::from(vec![Value::Str("https://support.coinbase.com/customer/portal/articles/2109597-buy-sell-bank-transfer-fees".into()), Value::Str("https://www.coinbase.com/advanced-fees".into())]));
m.insert("referral".to_string(), Value::Str("https://www.coinbase.com/join/58cbe25a355148797479dbd2".into()));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("currencies/crypto".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("exchange-rates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("users/{user_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("prices/{symbol}/buy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("prices/{symbol}/sell".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("prices/{symbol}/spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/addresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/addresses/{address_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/addresses/{address_id}/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/transactions/{transaction_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/buys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/buys/{buy_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/sells".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/sells/{sell_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/deposits/{deposit_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/withdrawals/{withdrawal_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("payment-methods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("payment-methods/{payment_method_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("user/auth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("subscriptions/coinbase-one".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/primary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/addresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/transactions/{transaction_id}/complete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/transactions/{transaction_id}/resend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/buys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/buys/{buy_id}/commit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/sells".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/sells/{sell_id}/commit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/deposits/{deposit_id}/commit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/withdrawals/{withdrawal_id}/commit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accounts/{account_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accounts/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m.insert("accounts/{account_id}/transactions/{transaction_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(10.6));
m
}));
m
}));
m
}));
m
}));
m.insert("v3".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("brokerage/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/market/product_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/market/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/market/products/{product_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/market/products/{product_id}/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/market/products/{product_id}/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("brokerage/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/accounts/{account_uuid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/historical/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/historical/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/historical/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/products/{product_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/products/{product_id}/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/products/{product_id}/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/best_bid_ask".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/product_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/transaction_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("brokerage/portfolios".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/portfolios/{portfolio_uuid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/convert/trade/{trade_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/balance_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/positions/{product_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/sweeps".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/intraday/current_margin_window".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/intraday/margin_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/payment_methods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/payment_methods/{payment_method_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/key_permissions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("brokerage/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/batch_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/edit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/edit_preview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/preview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/portfolios".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/portfolios/move_funds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/convert/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/convert/trade/{trade_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/sweeps/schedule".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/intraday/margin_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/orders/close_position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("brokerage/portfolios/{portfolio_uuid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("brokerage/portfolios/{portfolio_uuid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("brokerage/cfm/sweeps".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
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("taker".to_string(), self.parse_number(Value::Str("0.012".into()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.006".into()), &[]));
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.006".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000".into()), &[]), self.parse_number(Value::Str("0.004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000".into()),
&[]), self.parse_number(Value::Str("0.0025".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("100000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.0018".into()), &[])]),
Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0.0016".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75000000".into()), &[]), self.parse_number(Value::Str("0.0012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("250000000".into()), &[]),
self.parse_number(Value::Str("0.0008".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("400000000".into()), &[]), self.parse_number(Value::Str("0.0005".into()), &[])])]));
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000".into()), &[]), self.parse_number(Value::Str("0.0025".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000".into()),
&[]), self.parse_number(Value::Str("0.0015".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("100000".into()), &[]), self.parse_number(Value::Str("0.001".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.0008".into()), &[])]),
Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0.0006".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75000000".into()), &[]), self.parse_number(Value::Str("0.0003".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("250000000".into()), &[]),
self.parse_number(Value::Str("0.0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("400000000".into()), &[]), self.parse_number(Value::Str("0.0".into()), &[])])]));
m
}));
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("two_factor_required".to_string(), Value::Str("AuthenticationError".into()));
m.insert("param_required".to_string(), Value::Str("ExchangeError".into()));
m.insert("validation_error".to_string(), Value::Str("ExchangeError".into()));
m.insert("invalid_request".to_string(), Value::Str("ExchangeError".into()));
m.insert("personal_details_required".to_string(), Value::Str("AuthenticationError".into()));
m.insert("identity_verification_required".to_string(), Value::Str("AuthenticationError".into()));
m.insert("jumio_verification_required".to_string(), Value::Str("AuthenticationError".into()));
m.insert("jumio_face_match_verification_required".to_string(), Value::Str("AuthenticationError".into()));
m.insert("unverified_email".to_string(), Value::Str("AuthenticationError".into()));
m.insert("authentication_error".to_string(), Value::Str("AuthenticationError".into()));
m.insert("unauthorized".to_string(), Value::Str("AuthenticationError".into()));
m.insert("invalid_authentication_method".to_string(), Value::Str("AuthenticationError".into()));
m.insert("invalid_token".to_string(), Value::Str("AuthenticationError".into()));
m.insert("revoked_token".to_string(), Value::Str("AuthenticationError".into()));
m.insert("expired_token".to_string(), Value::Str("AuthenticationError".into()));
m.insert("invalid_scope".to_string(), Value::Str("AuthenticationError".into()));
m.insert("not_found".to_string(), Value::Str("ExchangeError".into()));
m.insert("rate_limit_exceeded".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("resource_exhausted".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("internal_server_error".to_string(), Value::Str("ExchangeError".into()));
m.insert("UNSUPPORTED_ORDER_CONFIGURATION".to_string(), Value::Str("BadRequest".into()));
m.insert("INSUFFICIENT_FUND".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("PERMISSION_DENIED".to_string(), Value::Str("PermissionDenied".into()));
m.insert("INVALID_ARGUMENT".to_string(), Value::Str("BadRequest".into()));
m.insert("PREVIEW_STOP_PRICE_ABOVE_LAST_TRADE_PRICE".to_string(), Value::Str("InvalidOrder".into()));
m.insert("PREVIEW_INSUFFICIENT_FUND".to_string(), Value::Str("InsufficientFunds".into()));
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Insufficient balance in source account".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("request timestamp expired".to_string(), Value::Str("InvalidNonce".into()));
m.insert("order with this orderID was not found".to_string(), Value::Str("OrderNotFound".into()));
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("ONE_MINUTE".into()));
m.insert("5m".to_string(), Value::Str("FIVE_MINUTE".into()));
m.insert("15m".to_string(), Value::Str("FIFTEEN_MINUTE".into()));
m.insert("30m".to_string(), Value::Str("THIRTY_MINUTE".into()));
m.insert("1h".to_string(), Value::Str("ONE_HOUR".into()));
m.insert("2h".to_string(), Value::Str("TWO_HOUR".into()));
m.insert("6h".to_string(), Value::Str("SIX_HOUR".into()));
m.insert("1d".to_string(), Value::Str("ONE_DAY".into()));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CGLD".to_string(), Value::Str("CELO".into()));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mica".to_string(), Value::Bool(true));
m.insert("usePrivate".to_string(), Value::Bool(false));
m.insert("brokerId".to_string(), Value::Str("ccxt".into()));
m.insert("stablePairs".to_string(), Value::from(vec![Value::Str("BUSD-USD".into()), Value::Str("CBETH-ETH".into()), Value::Str("DAI-USD".into()), Value::Str("GUSD-USD".into()), Value::Str("GYEN-USD".into()), Value::Str("PAX-USD".into()), Value::Str("PAX-USDT".into()), Value::Str("USDC-EUR".into()), Value::Str("USDC-GBP".into()),
Value::Str("USDT-EUR".into()), Value::Str("USDT-GBP".into()), Value::Str("USDT-USD".into()), Value::Str("USDT-USDC".into()), Value::Str("WBTC-BTC".into())]));
m.insert("fetchCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("expires".to_string(), Value::Int(5000));
m
}));
m.insert("accounts".to_string(), Value::from(vec![Value::Str("wallet".into()), Value::Str("fiat".into())]));
m.insert("v3Accounts".to_string(), Value::from(vec![Value::Str("ACCOUNT_TYPE_CRYPTO".into()), Value::Str("ACCOUNT_TYPE_FIAT".into())]));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ERC20".to_string(), Value::Str("ethereum".into()));
m.insert("XLM".to_string(), Value::Str("stellar".into()));
m
}));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("advanced".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Str("fetchMarketsV3".into()));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Str("fetchTickerV3".into()));
m.insert("fetchTickers".to_string(), Value::Str("fetchTickersV3".into()));
m.insert("fetchAccounts".to_string(), Value::Str("fetchAccountsV3".into()));
m.insert("fetchBalance".to_string(), Value::Str("v2PrivateGetAccounts".into()));
m.insert("fetchTime".to_string(), Value::Str("v2PublicGetTime".into()));
m.insert("user_native_currency".to_string(), Value::Str("USD".into()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(true));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(true));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(true));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".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(3000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(10000));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".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(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(10000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(10000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(300));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
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::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
}));
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 mut defaultMethod: Value = self.safe_string_k(self.options.clone(), "fetchTime", &[Value::Str("v2PublicGetTime".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("v2PublicGetTime")) {
response = self.v2_public_get_time(&[paramsOmitted.clone()]).await;
response = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
response = self.v3_public_get_brokerage_time(&[paramsOmitted]).await;
}
return self.safe_timestamp2(response, Value::Str("epoch".into()), Value::Str("epochSeconds".into()), &[]);
Value::Null
}
pub async fn fetch_accounts(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut method: Option<String> = self.safe_string_k(self.options.clone(), "fetchAccounts", &[Value::Str("fetchAccountsV3".into())]).as_str().map(str::to_owned);
if (method.as_deref() == Some("fetchAccountsV3")) {
return self.fetch_accounts_v3(&[params.clone()]).await;
}
return self.fetch_accounts_v2(&[params]).await;
Value::Null
}
pub async fn fetch_accounts_v2(&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 paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchAccounts".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_cursor(Value::Str("fetchAccounts".into()), &[Value::Null, Value::Null, Value::Null, paramsPaginate.clone(), Value::Str("next_starting_after".into()), Value::Str("starting_after".into()), Value::Null, Value::Int(100)]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(100));
m
});
let __ws_arg_0 = self.extend(Value::Map(request), &[paramsPaginate.clone()]);
let mut response: Value = self.v2_private_get_accounts(&[__ws_arg_0]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut pagination: Value = self.safe_dict_k(response.clone(), "pagination", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cursor: Option<String> = self.safe_string_k_opt(pagination, "next_starting_after", &[]);
let mut accounts: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut length: Value = Value::Int(accounts.len() as i64);
let mut lastIndex: Value = (match (&(length), &(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 });
if (cursor.is_some()) && (cursor.as_deref() != Some("")) {
let __ws_arg_1 = self.safe_dict(accounts.clone(), lastIndex.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_1, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("next_starting_after".to_string(), cursor.map(Value::from).unwrap_or(Value::Null));
m
})]); add_element_to_object(&mut accounts, &lastIndex, __be_tmp); };
}
return self.parse_accounts(data, &[paramsPaginate]);
Value::Null
}
pub async fn fetch_accounts_v3(&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 paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchAccounts".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_cursor(Value::Str("fetchAccounts".into()), &[Value::Null, Value::Null, Value::Null, paramsPaginate.clone(), Value::Str("cursor".into()), Value::Str("cursor".into()), Value::Null, Value::Int(250)]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(250));
m
});
let __ws_arg_2 = self.extend(Value::Map(request), &[paramsPaginate.clone()]);
let mut response: Value = self.v3_private_get_brokerage_accounts(&[__ws_arg_2]).await;
let mut accounts: Value = self.safe_list_k(response.clone(), "accounts", &[Value::from(vec![])]);
let mut accountsLength: Value = Value::Int(accounts.len() as i64);
let mut cursor: Option<String> = self.safe_string_k_opt(response, "cursor", &[]);
if (accountsLength.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64)) && (cursor.is_some()) && (cursor.as_deref() != Some("")) {
let mut lastIndex: Value = (match (&(accountsLength), &(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 });
let __ws_arg_3 = self.safe_dict(accounts.clone(), lastIndex.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_3, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cursor".to_string(), cursor.map(Value::from).unwrap_or(Value::Null));
m
})]); add_element_to_object(&mut accounts, &lastIndex, __be_tmp); };
}
return self.parse_accounts(accounts, &[paramsPaginate]);
Value::Null
}
pub async fn fetch_portfolios(&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.v3_private_get_brokerage_portfolios(&[params]).await;
let mut portfolios: Vec<Value> = self.safe_list_k(response, "portfolios", &[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_533: bool = true;
while { if !__for_first_533 { i += 1; } __for_first_533 = false; i < (portfolios.len() as i64) } {
let mut portfolio: Value = portfolios.get(i as usize).cloned().unwrap_or(Value::Null);
result.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(portfolio.clone(), "uuid", &[]));
m.insert("type".to_string(), self.safe_string_k(portfolio.clone(), "type", &[]));
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), portfolio);
m
}));
}
}
return Value::from(result);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
let mut active: Option<bool> = self.safe_bool_k_opt(account.clone(), "active", &[]);
let mut currencyIdV3: Option<String> = self.safe_string_k_opt(account.clone(), "currency", &[]);
let mut currency: Value = self.safe_dict_k(account.clone(), "currency", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyId: Value = self.safe_string_k(currency, "code", &[currencyIdV3.map(Value::from).unwrap_or(Value::Null)]);
let mut typeV3: Option<String> = self.safe_string_k_opt(account.clone(), "name", &[]);
let mut typeV2: Value = self.safe_string_k(account.clone(), "type", &[]);
let mut parts: Value = Value::Array(if let Some(__s) = typeV3.as_deref() { __s.split(" ").map(Value::from).collect() } else { Vec::new() });
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string2(account.clone(), Value::Str("id".into()), Value::Str("uuid".into()), &[]));
m.insert("type".to_string(), (if (active.is_some()) { self.safe_string_lower(parts, Value::Int(1), &[]) } else { typeV2 }));
m.insert("code".to_string(), self.safe_currency_code(currencyId, &[]));
m.insert("info".to_string(), account);
m
});
Value::Null
}
pub async fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut accountId: Option<String> = self.safe_string_k_opt(params.clone(), "account_id", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("account_id".into()), &[]);
if (accountId.is_none()) {
self.load_accounts(&[]).await;
{
let mut i: i64 = 0;
let mut __for_first_534: bool = true;
while { if !__for_first_534 { i += 1; } __for_first_534 = false; i < (self.accounts.len() as i64) } {
let mut account: Value = self.accounts.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
if (self.safe_string_k(account.clone(), "code", &[]).as_str() == code.as_str()) && (self.safe_string_k(account.clone(), "type", &[]).as_str() == Some("wallet")) {
accountId = self.safe_string_k_opt(account, "id", &[]);
break;
}
}
}
}
if (accountId.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createDepositAddress() could not find the account with matching currency code ".into())).into()), code).into()), Value::Str(", specify an `account_id` extra param to target specific wallet".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("account_id".to_string(), accountId.clone().map(Value::from).unwrap_or(Value::Null));
m
});
let __ws_arg_4 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v2_private_post_accounts_account_id_addresses(&[__ws_arg_4]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut tag: Option<String> = self.safe_string_k_opt(data.clone(), "destination_tag", &[]);
let mut address: Option<String> = self.safe_string_k_opt(data, "address", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("tag".to_string(), tag.map(Value::from).unwrap_or(Value::Null));
m.insert("address".to_string(), address.map(Value::from).unwrap_or(Value::Null));
m.insert("network".to_string(), Value::Null);
m.insert("info".to_string(), response);
m
});
Value::Null
}
pub async fn fetch_my_sells(&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
}));
let mut request: Value = self.prepare_account_request(&[limit.clone(), params.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut query: Value = self.omit(params, Value::from(vec![Value::Str("account_id".into()), Value::Str("accountId".into())]), &[]);
let __ws_arg_5 = self.extend(request, &[query]);
let mut sells: Value = self.v2_private_get_accounts_account_id_sells(&[__ws_arg_5]).await;
let mut sellsData: Value = self.safe_list_k(sells, "data", &[Value::from(vec![])]);
return self.parse_trades(sellsData, &[Value::Null, since, limit]);
Value::Null
}
pub async fn fetch_my_buys(&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
}));
let mut request: Value = self.prepare_account_request(&[limit.clone(), params.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut query: Value = self.omit(params, Value::from(vec![Value::Str("account_id".into()), Value::Str("accountId".into())]), &[]);
let __ws_arg_6 = self.extend(request, &[query]);
let mut buys: Value = self.v2_private_get_accounts_account_id_buys(&[__ws_arg_6]).await;
let mut buysData: Value = self.safe_list_k(buys, "data", &[Value::from(vec![])]);
return self.parse_trades(buysData, &[Value::Null, since, limit]);
Value::Null
}
pub async fn fetch_transactions_with_method(&mut self, mut method: Value, 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
}));
let requestparamsValueVariable: Vec<Value> = self.prepare_account_request_with_currency_code(&[code, limit.clone(), params]).await.as_array().cloned().unwrap_or_default();
let mut request: Value = requestparamsValueVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsValue: Value = requestparamsValueVariable.get(1).cloned().unwrap_or(Value::Null);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
if (method.as_str() == Some("v2PrivateGetAccountsAccountIdTransactions")) {
let __ws_arg_7 = self.extend(request.clone(), &[paramsValue.clone()]);
response = self.v2_private_get_accounts_account_id_transactions(&[__ws_arg_7]).await;
} else if (method.as_str() == Some("v2PrivateGetAccountsAccountIdWithdrawals")) {
let __ws_arg_8 = self.extend(request.clone(), &[paramsValue.clone()]);
response = self.v2_private_get_accounts_account_id_withdrawals(&[__ws_arg_8]).await;
} else {
let __ws_arg_9 = self.extend(request, &[paramsValue]);
response = self.v2_private_get_accounts_account_id_deposits(&[__ws_arg_9]).await;
}
return self.parse_transactions(self.safe_list_k(response, "data", &[Value::from(vec![])]), &[Value::Null, 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
}));
let currencyTypeparamsCurrencyTypeVariable: Vec<Value> = self.handle_option_string_and_params(params, Value::Str("fetchWithdrawals".into()), Value::Str("currencyType".into()), &[]).as_array().cloned().unwrap_or_default();
let mut currencyType: Value = currencyTypeparamsCurrencyTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsCurrencyType: Value = currencyTypeparamsCurrencyTypeVariable.get(1).cloned().unwrap_or(Value::Null);
if (currencyType.as_str() == Some("crypto")) {
let mut results: Value = self.fetch_transactions_with_method(Value::Str("v2PrivateGetAccountsAccountIdTransactions".into()), &[code.clone(), since.clone(), limit.clone(), paramsCurrencyType.clone()]).await;
return self.to_array(self.filter_by_array(results, Value::Str("type".into()), &[Value::Str("withdrawal".into()), Value::Bool(false)]));
}
return self.fetch_transactions_with_method(Value::Str("v2PrivateGetAccountsAccountIdWithdrawals".into()), &[code, since, limit, paramsCurrencyType]).await;
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
}));
let currencyTypeparamsCurrencyTypeVariable: Vec<Value> = self.handle_option_string_and_params(params, Value::Str("fetchDeposits".into()), Value::Str("currencyType".into()), &[]).as_array().cloned().unwrap_or_default();
let mut currencyType: Value = currencyTypeparamsCurrencyTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsCurrencyType: Value = currencyTypeparamsCurrencyTypeVariable.get(1).cloned().unwrap_or(Value::Null);
if (currencyType.as_str() == Some("crypto")) {
let mut results: Value = self.fetch_transactions_with_method(Value::Str("v2PrivateGetAccountsAccountIdTransactions".into()), &[code.clone(), since.clone(), limit.clone(), paramsCurrencyType.clone()]).await;
return self.to_array(self.filter_by_array(results, Value::Str("type".into()), &[Value::Str("deposit".into()), Value::Bool(false)]));
}
return self.fetch_transactions_with_method(Value::Str("v2PrivateGetAccountsAccountIdDeposits".into()), &[code, since, limit, paramsCurrencyType]).await;
Value::Null
}
pub async fn fetch_deposits_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 results: Value = self.fetch_transactions_with_method(Value::Str("v2PrivateGetAccountsAccountIdTransactions".into()), &[code, since, limit, params]).await;
return self.to_array(self.filter_by_array(results, Value::Str("type".into()), &[Value::from(vec![Value::Str("deposit".into()), Value::Str("withdrawal".into())]), Value::Bool(false)]));
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("created".to_string(), Value::Str("pending".into()));
m.insert("completed".to_string(), Value::Str("ok".into()));
m.insert("canceled".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut transactionType: Option<String> = self.safe_string_k(transaction.clone(), "type", &[]).as_str().map(str::to_owned);
let mut amountAndCurrencyObject: Value = Value::Null;
let mut feeObject: Value = Value::Null;
let mut network: Value = self.safe_dict_k(transaction.clone(), "network", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (transactionType.as_deref() == Some("send")) {
amountAndCurrencyObject = self.safe_dict_k(network.clone(), "transaction_amount", &[]);
feeObject = self.safe_dict_k(network.clone(), "transaction_fee", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
amountAndCurrencyObject = self.safe_dict_k(transaction.clone(), "subtotal", &[]);
feeObject = self.safe_dict_k(transaction.clone(), "fee", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
if (amountAndCurrencyObject == Value::Null) {
amountAndCurrencyObject = self.safe_dict_k(transaction.clone(), "amount", &[]);
}
let mut amountString: Option<String> = self.safe_string_k_opt(amountAndCurrencyObject.clone(), "amount", &[]);
let mut amountStringAbs: Value = crate::precise::Precise::stringAbs(&amountString.clone().map(Value::from).unwrap_or(Value::Null));
let mut status: Value = self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])).map(Value::from).unwrap_or(Value::Null);
if (status == Value::Null) {
let mut committed: bool = self.safe_bool_k_opt(transaction.clone(), "committed", &[Value::Bool(false)]).unwrap_or(false);
status = (if committed { Value::Str("ok".into()) } else { Value::Str("pending".into()) });
}
let mut id: Option<String> = self.safe_string_k_opt(transaction.clone(), "id", &[]);
let mut currencyId: Option<String> = self.safe_string_k_opt(amountAndCurrencyObject, "currency", &[]);
let mut feeCurrencyId: Option<String> = self.safe_string_k_opt(feeObject.clone(), "currency", &[]);
let mut datetime: Option<String> = self.safe_string_k_opt(transaction.clone(), "created_at", &[]);
let mut resource: Option<String> = self.safe_string_k_opt(transaction.clone(), "resource", &[]);
let mut type_var: Value = resource.map(Value::from).unwrap_or(Value::Null);
if !(self.in_array(type_var.clone(), Value::from(vec![Value::Str("deposit".into()), Value::Str("withdrawal".into())])).as_bool() == Some(true)) {
if crate::precise::Precise::stringGt(&amountString.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) {
type_var = Value::Str("deposit".into());
} else if crate::precise::Precise::stringLt(&amountString.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) {
type_var = Value::Str("withdrawal".into());
}
}
let mut toObject: Value = self.safe_dict_k(transaction.clone(), "to", &[]);
let mut addressTo: Option<String> = self.safe_string_k_opt(toObject, "address", &[]);
let mut networkId: Option<String> = self.safe_string_k_opt(network.clone(), "network_name", &[]);
let mut code: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("txid".to_string(), self.safe_string_k(network, "hash", &[id.map(Value::from).unwrap_or(Value::Null)]));
m.insert("timestamp".to_string(), self.parse8601(datetime.clone().map(Value::from).unwrap_or(Value::Null)));
m.insert("datetime".to_string(), datetime.map(Value::from).unwrap_or(Value::Null));
m.insert("network".to_string(), self.network_id_to_code(&[networkId.map(Value::from).unwrap_or(Value::Null), code.clone()]));
m.insert("address".to_string(), addressTo.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("addressTo".to_string(), addressTo.map(Value::from).unwrap_or(Value::Null));
m.insert("addressFrom".to_string(), Value::Null);
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(), self.parse_number(amountStringAbs, &[]));
m.insert("currency".to_string(), code);
m.insert("status".to_string(), status);
m.insert("updated".to_string(), self.parse8601(self.safe_string_k(transaction, "updated_at", &[])));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.safe_number_k(feeObject, "amount", &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCurrencyId.map(Value::from).unwrap_or(Value::Null), &[]));
m
}));
m
});
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 symbol: Value = Value::Null;
let mut totalObject: Value = self.safe_dict_k(trade.clone(), "total", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amountObject: Value = self.safe_dict_k(trade.clone(), "amount", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut subtotalObject: Value = self.safe_dict_k(trade.clone(), "subtotal", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut feeObject: Value = self.safe_dict_k(trade.clone(), "fee", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Option<String> = self.safe_string_k_opt(trade.clone(), "product_id", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market, Value::Str("-".into())]);
if (marketResolved != Value::Null) {
symbol = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
} else {
let mut baseId: Option<String> = self.safe_string_k_opt(amountObject.clone(), "currency", &[]);
let mut quoteId: Option<String> = self.safe_string_k_opt(totalObject, "currency", &[]);
if (baseId.is_some()) && (quoteId.is_some()) {
let mut base: Value = self.safe_currency_code(baseId.map(Value::from).unwrap_or(Value::Null), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.map(Value::from).unwrap_or(Value::Null), &[]);
if (base != Value::Null) && (quote != Value::Null) {
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
}
}
}
let mut sizeInQuote: bool = self.safe_bool_k_opt(trade.clone(), "size_in_quote", &[Value::Bool(false)]).unwrap_or(false);
let mut v3Price: Option<String> = self.safe_string_k_opt(trade.clone(), "price", &[]);
let mut v3Cost: Value = Value::Null;
let mut v3Amount: Value = self.safe_string_k(trade.clone(), "size", &[]);
if sizeInQuote {
v3Cost = v3Amount.clone();
v3Amount = crate::precise::Precise::stringDiv(&v3Amount, &v3Price.clone().map(Value::from).unwrap_or(Value::Null));
}
let mut v3FeeCost: Option<String> = self.safe_string_k_opt(trade.clone(), "commission", &[]);
let mut amountString: Value = self.safe_string_k(amountObject, "amount", &[v3Amount]);
let mut costString: Value = self.safe_string_k(subtotalObject, "amount", &[v3Cost]);
let mut priceString: Value = Value::Null;
let mut cost: Value = Value::Null;
if (costString != Value::Null) && (amountString != Value::Null) {
priceString = crate::precise::Precise::stringDiv(&costString, &amountString);
} else {
priceString = v3Price.map(Value::from).unwrap_or(Value::Null);
}
if (priceString != Value::Null) && (amountString != Value::Null) {
cost = crate::precise::Precise::stringMul(&priceString, &amountString);
let mut contractSize: Option<String> = self.safe_string_k_opt(marketResolved.clone(), "contractSize", &[]);
if (contractSize.is_some()) {
cost = crate::precise::Precise::stringMul(&cost, &contractSize.clone().map(Value::from).unwrap_or(Value::Null));
}
} else {
cost = costString;
}
let mut feeCurrencyId: Option<String> = self.safe_string_k_opt(feeObject.clone(), "currency", &[]);
let mut feeCost: Value = self.safe_number_k(feeObject, "amount", &[self.parse_number(v3FeeCost.map(Value::from).unwrap_or(Value::Null), &[])]);
if (feeCurrencyId.is_none()) && (marketResolved != Value::Null) && (feeCost != Value::Null) {
feeCurrencyId = self.safe_string_k_opt(marketResolved, "quote", &[]);
}
let mut datetime: Option<String> = self.safe_string_n_opt(trade.clone(), Value::from(vec![Value::Str("created_at".into()), Value::Str("trade_time".into()), Value::Str("time".into())]), &[]);
let mut side: Value = self.safe_string_lower2(trade.clone(), Value::Str("resource".into()), Value::Str("side".into()), &[]);
let mut takerOrMaker: Value = self.safe_string_lower_k(trade.clone(), "liquidity_indicator", &[]);
let mut orderId: Option<String> = self.safe_string_k_opt(trade.clone(), "order_id", &[]);
let mut entryId: Option<String> = self.safe_string_k(trade.clone(), "entry_id", &[]).as_str().map(str::to_owned);
if (orderId.is_none()) && (entryId.is_none()) && (self.safe_string_k(trade.clone(), "resource", &[]) == Value::Null) {
if (side.as_str() == Some("buy")) {
side = Value::Str("sell".into());
} else if (side.as_str() == Some("sell")) {
side = Value::Str("buy".into());
}
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string2(trade, Value::Str("id".into()), Value::Str("trade_id".into()), &[]));
m.insert("order".to_string(), orderId.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), self.parse8601(datetime.clone().map(Value::from).unwrap_or(Value::Null)));
m.insert("datetime".to_string(), datetime.map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), (if (side.as_str() == Some("unknown_order_side")) { Value::Null } else { side }));
m.insert("takerOrMaker".to_string(), (if (takerOrMaker.as_str() == Some("unknown_liquidity_indicator")) { Value::Null } else { takerOrMaker }));
m.insert("price".to_string(), priceString);
m.insert("amount".to_string(), amountString);
m.insert("cost".to_string(), cost);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost);
m.insert("currency".to_string(), self.safe_currency_code(feeCurrencyId.map(Value::from).unwrap_or(Value::Null), &[]));
m
}));
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
}));
if matches!(self.safe_bool_k(self.options.clone(), "adjustForTimeDifference", &[Value::Bool(false)]), Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut method: Option<String> = self.safe_string_k(self.options.clone(), "fetchMarkets", &[Value::Str("fetchMarketsV3".into())]).as_str().map(str::to_owned);
if (method.as_deref() == Some("fetchMarketsV3")) {
return self.fetch_markets_v3(&[params.clone()]).await;
}
return self.fetch_markets_v2(&[params]).await;
Value::Null
}
pub async fn fetch_markets_v2(&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.fetch_currencies_from_cache(&[params]).await;
let mut currencies: Value = self.safe_dict_k(response.clone(), "currencies", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut exchangeRates: Value = self.safe_dict_k(response, "exchangeRates", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(currencies, "data", &[Value::from(vec![])]);
let mut dataById: Value = self.index_by(data.clone(), Value::Str("id".into()));
let mut rates: indexmap::IndexMap<String, Value> = self.safe_dict(self.safe_dict_k(exchangeRates, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), Value::Str("rates".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]).as_map().cloned().unwrap_or_default();
let mut baseIds: Vec<Value> = Value::Array(rates.keys().map(|__k| Value::Str(__k.clone().into())).collect()).as_array().cloned().unwrap_or_default();
let mut result: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_536: bool = true;
while { if !__for_first_536 { i += 1; } __for_first_536 = false; i < (baseIds.len() as i64) } {
let mut baseId: Value = baseIds.get(i as usize).cloned().unwrap_or(Value::Null);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
if (base == Value::Null) {
continue;
}
let mut type_var: String = "crypto".to_string();
if (matches!((&dataById, &baseId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
type_var = "fiat".to_string();
}
if ((type_var == "crypto")) {
{
let mut j: i64 = 0;
let mut __for_first_535: bool = true;
while { if !__for_first_535 { j += 1; } __for_first_535 = false; j < (data.len() as i64) } {
let mut quoteCurrency: Value = data.as_array().map(Vec::as_slice).unwrap_or_default().get(j as usize).cloned().unwrap_or(Value::Null);
let mut quoteId: Option<String> = self.safe_string_k_opt(quoteCurrency.clone(), "id", &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
if (quote == Value::Null) || (quoteId.is_none()) {
continue;
}
result.push(self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", baseId, Value::Str("-".into())).into()), quoteId.clone().map(Value::from).unwrap_or(Value::Null)).into()));
m.insert("symbol".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()));
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.map(Value::from).unwrap_or(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::Null);
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(), Value::Null);
m.insert("price".to_string(), Value::Null);
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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(quoteCurrency.clone(), "min_size", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("info".to_string(), quoteCurrency);
m
})]));
}
}
}
}
}
return Value::from(result);
Value::Null
}
pub async fn fetch_markets_v3(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let usePrivateparamsUsePrivateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchMarkets".into()), Value::Str("usePrivate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut usePrivate: Value = usePrivateparamsUsePrivateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUsePrivate: Value = usePrivateparamsUsePrivateVariable.get(1).cloned().unwrap_or(Value::Null);
let mut spotUnresolvedPromises: Vec<Value> = Vec::new();
if usePrivate.as_bool() == Some(true) {
spotUnresolvedPromises.push(self.v3_private_get_brokerage_products(&[paramsUsePrivate.clone()]).await);
} else {
spotUnresolvedPromises.push(self.v3_public_get_brokerage_market_products(&[paramsUsePrivate.clone()]).await);
}
if self.check_required_credentials(&[Value::Bool(false)]).as_bool() == Some(true) {
spotUnresolvedPromises.push(self.v3_private_get_brokerage_transaction_summary(&[paramsUsePrivate.clone()]).await);
}
let mut promises: Value = promise_all(&Value::from(spotUnresolvedPromises)).await;
let mut unresolvedContractPromises: Value = Value::from(vec![]);
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
let __ws_arg_10 = self.extend(paramsUsePrivate, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("product_type".to_string(), Value::Str("FUTURE".into()));
m
})]);
unresolvedContractPromises = Value::from(vec![self.v3_public_get_brokerage_market_products(&[__ws_arg_10]).await]);
#[allow(unreachable_code)] { Value::Null }})).await;
if _try_result.is_err() {
unresolvedContractPromises = Value::from(vec![]); }
let mut contractPromises: Value = Value::Null;
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
contractPromises = promise_all(&unresolvedContractPromises).await; #[allow(unreachable_code)] { Value::Null }})).await;
if _try_result.is_err() {
contractPromises = Value::from(vec![]);
}
let mut spot: Value = self.safe_dict(promises.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fees: Value = self.safe_dict(promises, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut expiringFutures: Value = self.safe_dict(contractPromises.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut perpetualFutures: Value = self.safe_dict(contractPromises, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut feeTier: Value = self.safe_dict_k(fees, "fee_tier", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Vec<Value> = self.safe_list_k(spot, "products", &[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_537: bool = true;
while { if !__for_first_537 { i += 1; } __for_first_537 = false; i < (data.len() as i64) } {
let mut spotMarket: Value = self.parse_spot_market(data.get(i as usize).cloned().unwrap_or(Value::Null), feeTier.clone());
if (spotMarket != Value::Null) {
result.push(spotMarket);
}
}
}
let mut futureData: Vec<Value> = self.safe_list_k(expiringFutures, "products", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
{
let mut i: i64 = 0;
let mut __for_first_538: bool = true;
while { if !__for_first_538 { i += 1; } __for_first_538 = false; i < (futureData.len() as i64) } {
let mut futureMarket: Value = self.parse_contract_market(futureData.get(i as usize).cloned().unwrap_or(Value::Null), &[]);
if (futureMarket != Value::Null) {
result.push(futureMarket);
}
}
}
let mut perpetualData: Vec<Value> = self.safe_list_k(perpetualFutures, "products", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
{
let mut i: i64 = 0;
let mut __for_first_539: bool = true;
while { if !__for_first_539 { i += 1; } __for_first_539 = false; i < (perpetualData.len() as i64) } {
let mut perpetualMarket: Value = self.parse_contract_market(perpetualData.get(i as usize).cloned().unwrap_or(Value::Null), &[]);
if (perpetualMarket != Value::Null) {
result.push(perpetualMarket);
}
}
}
let mut newMarkets: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_540: bool = true;
while { if !__for_first_540 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_540 = false; i.as_f64().unwrap_or(f64::NAN) < ((result.len() as i64) as f64) } {
let mut market: Value = result.get((i).as_i64().unwrap_or(-1) as usize).cloned().unwrap_or(Value::Null);
let mut info: Value = self.safe_dict_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut realMarketIds: Vec<Value> = self.safe_list_k(info, "alias_to", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut length: f64 = ((realMarketIds.len() as i64) as f64);
if length > ((0i64) as f64) {
newMarkets.push(self.extend(market.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("alias".to_string(), realMarketIds.get(0).cloned().unwrap_or(Value::Null));
m
})]));
} else {
newMarkets.push(self.extend(market, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("alias".to_string(), Value::Null);
m
})]));
}
}
}
return Value::from(newMarkets);
Value::Null
}
pub fn parse_spot_market(&self, mut market: Value, mut feeTier: Value) -> Value {
let __feeTier_empty = indexmap::IndexMap::new();
let feeTier = feeTier.as_map().unwrap_or(&__feeTier_empty);
let mut id: Option<String> = self.safe_string_k_opt(market.clone(), "product_id", &[]);
let mut baseId: Option<String> = self.safe_string_k_opt(market.clone(), "base_currency_id", &[]);
let mut quoteId: Option<String> = self.safe_string_k_opt(market.clone(), "quote_currency_id", &[]);
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().map(Value::from).unwrap_or(Value::Null), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut marketType: Option<String> = self.safe_string_lower_k_opt(market.clone(), "product_type", &[]);
let mut tradingDisabled: bool = self.safe_bool_k_opt(market.clone(), "trading_disabled", &[Value::Bool(false)]).unwrap_or(false);
let mut stablePairs: Value = self.safe_list_k(self.options.clone(), "stablePairs", &[Value::from(vec![])]);
let mut defaultTakerFee: Value = self.safe_number(self.fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null), Value::Str("taker".into()), &[]);
let mut defaultMakerFee: Value = self.safe_number(self.fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null), Value::Str("maker".into()), &[]);
let mut takerFee: Value = (if self.in_array(id.clone().map(Value::from).unwrap_or(Value::Null), stablePairs.clone()).as_bool() == Some(true) { Value::Float(0.00001) } else { (match feeTier.get("taker_fee_rate") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64),
Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => defaultTakerFee }, _ => defaultTakerFee }) });
let mut makerFee: Value = (if self.in_array(id.clone().map(Value::from).unwrap_or(Value::Null), stablePairs).as_bool() == Some(true) { Value::Int(0) } else { (match feeTier.get("maker_fee_rate") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64),
Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => defaultMakerFee }, _ => defaultMakerFee }) });
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()));
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId.map(Value::from).unwrap_or(Value::Null));
m.insert("quoteId".to_string(), quoteId.map(Value::from).unwrap_or(Value::Null));
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), marketType.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("spot".to_string(), (Value::Bool(marketType.as_deref() == Some("spot"))));
m.insert("margin".to_string(), Value::Null);
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(!tradingDisabled));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("taker".to_string(), takerFee);
m.insert("maker".to_string(), makerFee);
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.safe_number_k(market.clone(), "base_increment", &[]));
m.insert("price".to_string(), self.safe_number2(market.clone(), Value::Str("price_increment".into()), Value::Str("quote_increment".into()), &[]));
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(), "base_min_size", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "base_max_size", &[]));
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(), "quote_min_size", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "quote_max_size", &[]));
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
pub fn parse_contract_market(&self, mut market: Value, optional_args: &[Value]) -> Value {
let mut feeTier = get_arg(optional_args, 0, Value::Null);
let __feeTier_empty = indexmap::IndexMap::new();
let feeTier = feeTier.as_map().unwrap_or(&__feeTier_empty);
let mut id: Option<String> = self.safe_string_k_opt(market.clone(), "product_id", &[]);
let mut futureProductDetails: Value = self.safe_dict_k(market.clone(), "future_product_details", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractExpiryType: Option<String> = self.safe_string_k(futureProductDetails.clone(), "contract_expiry_type", &[]).as_str().map(str::to_owned);
let mut contractSize: Value = self.safe_number_k(futureProductDetails.clone(), "contract_size", &[]);
let mut contractExpire: Option<String> = self.safe_string_k_opt(futureProductDetails.clone(), "contract_expiry", &[]);
let mut expireTimestamp: Value = self.parse8601(contractExpire.map(Value::from).unwrap_or(Value::Null));
let mut expireDateTime: Value = self.iso8601(expireTimestamp.clone());
let mut fundingInterval: Option<String> = self.safe_string_k(futureProductDetails.clone(), "funding_interval", &[]).as_str().map(str::to_owned);
let mut displayName: Option<String> = self.safe_string_k_opt(market.clone(), "display_name", &[]);
let mut isPerpetualDisplayName: bool = (displayName.is_some()) && (displayName.as_deref().unwrap_or("").ends_with("PERP"));
let mut isSwap: Value = Value::Bool((contractExpiryType.as_deref() == Some("PERPETUAL")) || (fundingInterval.is_some()) || isPerpetualDisplayName);
let mut baseId: Option<String> = self.safe_string_k_opt(futureProductDetails, "contract_root_unit", &[]);
let mut quoteId: Option<String> = self.safe_string_k_opt(market.clone(), "quote_currency_id", &[]);
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().map(Value::from).unwrap_or(Value::Null), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut isDisabled: bool = self.safe_bool_k_opt(market.clone(), "is_disabled", &[Value::Bool(false)]).unwrap_or(false);
let mut tradingDisabled: bool = isDisabled || (self.safe_bool_k(market.clone(), "trading_disabled", &[]).as_bool() == Some(true));
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut type_var: Value = Value::Null;
if matches!(&isSwap, Value::Bool(true)) {
type_var = Value::Str("swap".into());
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), quote).into());
} else {
type_var = Value::Str("future".into());
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), quote).into()), Value::Str("-".into())).into()), self.yymmdd(expireTimestamp.clone(), &[])).into());
}
let mut takerFeeRate: Value = (match feeTier.get("taker_fee_rate") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64), Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => Value::Null }, _ => Value::Null });
let mut makerFeeRate: Value = (match feeTier.get("maker_fee_rate") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64), Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => Value::Null }, _ => Value::Null });
let mut taker: Value = (if ((takerFeeRate != Value::Null) && (takerFeeRate != Value::Null) && (takerFeeRate.as_f64() != Some(0.0))) { takerFeeRate } else { self.parse_number(Value::Str("0.0002".into()), &[]) });
let mut maker: Value = (if ((makerFeeRate != Value::Null) && (makerFeeRate != Value::Null) && (makerFeeRate.as_f64() != Some(0.0))) { makerFeeRate } else { self.parse_number(Value::Str("0.0002".into()), &[]) });
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.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.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("settleId".to_string(), quoteId.map(Value::from).unwrap_or(Value::Null));
m.insert("type".to_string(), type_var);
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), isSwap.clone());
m.insert("future".to_string(), Value::Bool(!(matches!(&isSwap, Value::Bool(true)))));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool(!tradingDisabled));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), Value::Bool(true));
m.insert("inverse".to_string(), Value::Bool(false));
m.insert("taker".to_string(), taker);
m.insert("maker".to_string(), maker);
m.insert("contractSize".to_string(), contractSize);
m.insert("expiry".to_string(), (if (isSwap).as_bool() == Some(true) { Value::Null } else { expireTimestamp }));
m.insert("expiryDatetime".to_string(), (if (isSwap).as_bool() == Some(true) { Value::Null } else { expireDateTime }));
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(), "base_increment", &[]));
m.insert("price".to_string(), self.safe_number2(market.clone(), Value::Str("price_increment".into()), Value::Str("quote_increment".into()), &[]));
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(), "base_min_size", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "base_max_size", &[]));
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(), "quote_min_size", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "quote_max_size", &[]));
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
pub async fn fetch_currencies_from_cache(&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 options: Value = self.safe_dict_k(self.options.clone(), "fetchCurrencies", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(options.clone(), "timestamp", &[]);
let mut expires: Value = self.safe_integer_k(options.clone(), "expires", &[Value::Int(1000)]);
let mut now: Value = self.milliseconds();
if (timestamp == Value::Null) || (((match (&(now), &(timestamp)) { (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 })).as_f64().unwrap_or(f64::NAN) > expires.as_f64().unwrap_or(f64::NAN)) {
let mut promises: Value = Value::from(vec![self.v2_public_get_currencies(&[params.clone()]).await, self.v2_public_get_currencies_crypto(&[params.clone()]).await]);
let mut promisesResult: Value = promise_all(&promises).await;
let mut fiatResponse: Value = self.safe_dict(promisesResult.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cryptoResponse: Value = self.safe_dict(promisesResult, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fiatData: Value = self.safe_list_k(fiatResponse, "data", &[Value::from(vec![])]);
let mut cryptoData: Value = self.safe_list_k(cryptoResponse, "data", &[Value::from(vec![])]);
let mut exchangeRates: Value = self.v2_public_get_exchange_rates(&[params]).await;
let __ws_arg_11 = self.array_concat(fiatData, cryptoData);
{ let __be_tmp = self.extend(options.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencies".to_string(), __ws_arg_11);
m.insert("exchangeRates".to_string(), exchangeRates);
m.insert("timestamp".to_string(), now);
m
})]); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("fetchCurrencies".into(), __be_tmp); } }
}
return self.safe_dict_k(self.options.clone(), "fetchCurrencies", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
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 promises: Value = Value::from(vec![self.v2_public_get_currencies(&[params.clone()]).await, self.v2_public_get_currencies_crypto(&[params.clone()]).await, self.v2_public_get_exchange_rates(&[params]).await]);
let mut promisesResult: Value = promise_all(&promises).await;
let mut fiatResponse: Value = self.safe_dict(promisesResult.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cryptoResponse: Value = self.safe_dict(promisesResult.clone(), Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ratesResponse: Value = self.safe_dict(promisesResult, Value::Int(2), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fiatData: Value = self.safe_list_k(fiatResponse, "data", &[Value::from(vec![])]);
let mut cryptoData: Value = self.safe_list_k(cryptoResponse, "data", &[Value::from(vec![])]);
let mut ratesData: Value = self.safe_dict_k(ratesResponse, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rates: indexmap::IndexMap<String, Value> = self.safe_dict_k(ratesData, "rates", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]).as_map().cloned().unwrap_or_default();
let mut ratesIds: Vec<Value> = Value::Array(rates.keys().map(|__k| Value::Str(__k.clone().into())).collect()).as_array().cloned().unwrap_or_default();
let mut currencies: Value = self.array_concat(fiatData, cryptoData);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut networks: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut networksById: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_541: bool = true;
while { if !__for_first_541 { i += 1; } __for_first_541 = false; i < (currencies.len() as i64) } {
let mut currency: Value = currencies.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut assetId: Option<String> = self.safe_string_k(currency.clone(), "asset_id", &[]).as_str().map(str::to_owned);
let mut id: Option<String> = self.safe_string2_opt(currency.clone(), Value::Str("id".into()), Value::Str("code".into()), &[]);
let mut code: Value = self.safe_currency_code(id.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut name: Option<String> = self.safe_string_k_opt(currency.clone(), "name", &[]);
if (code != Value::Null) {
if let Value::Dict(__rda) = &mut self.options { if let Value::Dict(__rdb) = std::sync::Arc::make_mut(__rda).entry("networks".to_string()).or_insert(Value::Null) { std::sync::Arc::make_mut(__rdb).insert(crate::runtime::stringify_param(&code), (if let Some(__s) = name.as_deref() { Value::Str(__s.to_lowercase().into()) } else { Value::Null })); } }
}
if (code != Value::Null) {
if let Value::Dict(__rda) = &mut self.options { if let Value::Dict(__rdb) = std::sync::Arc::make_mut(__rda).entry("networksById".to_string()).or_insert(Value::Null) { std::sync::Arc::make_mut(__rdb).insert(crate::runtime::stringify_param(&code), (if let Some(__s) = name.as_deref() { Value::Str(__s.to_lowercase().into()) } else { Value::Null })); } }
}
let mut type_var: String = "fiat".to_string();
if (assetId.is_some()) {
type_var = "crypto".to_string();
}
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), currency.clone());
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("code".to_string(), code.clone());
m.insert("type".to_string(), Value::from(type_var));
m.insert("name".to_string(), name.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("active".to_string(), Value::Bool(true));
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(currency, "min_size", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
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
}));
m
}))); }
}
if (assetId.is_some()) {
let mut lowerCaseName: Value = (if let Some(__s) = name.as_deref() { Value::Str(__s.to_lowercase().into()) } else { Value::Null });
if (code != Value::Null) {
networks.insert(crate::runtime::stringify_param(&code), lowerCaseName.clone());
}
networksById.insert(crate::runtime::stringify_param(&lowerCaseName), code.clone());
}
}
}
{
let mut i: i64 = 0;
let mut __for_first_542: bool = true;
while { if !__for_first_542 { i += 1; } __for_first_542 = false; i < (ratesIds.len() as i64) } {
let mut currencyId: Value = ratesIds.get(i as usize).cloned().unwrap_or(Value::Null);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
if (code == Value::Null) || !(matches!((&result, &code), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("id".to_string(), currencyId);
m.insert("code".to_string(), code.clone());
m.insert("type".to_string(), Value::Str("crypto".into()));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}))); }
}
}
}
}
let __ws_arg_12 = crate::value::get_value_k(&self.options, "networks");
{ let __be_tmp = self.extend(Value::Map(networks), &[__ws_arg_12]); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("networks".into(), __be_tmp); } }
let __ws_arg_13 = crate::value::get_value_k(&self.options, "networksById");
{ let __be_tmp = self.extend(Value::Map(networksById), &[__ws_arg_13]); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("networksById".into(), __be_tmp); } }
return result;
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
}));
let mut method: Option<String> = self.safe_string_k(self.options.clone(), "fetchTickers", &[Value::Str("fetchTickersV3".into())]).as_str().map(str::to_owned);
if (method.as_deref() == Some("fetchTickersV3")) {
return self.fetch_tickers_v3(&[symbols.clone(), params.clone()]).await;
}
return self.fetch_tickers_v2(&[symbols, params]).await;
Value::Null
}
pub async fn fetch_tickers_v2(&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
});
let __ws_arg_14 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v2_public_get_exchange_rates(&[__ws_arg_14]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rates: indexmap::IndexMap<String, Value> = self.safe_dict_k(data.clone(), "rates", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]).as_map().cloned().unwrap_or_default();
let quoteId: String = self.safe_string_k_opt(data, "currency", &[Value::Str("".into())]).unwrap_or_default();
let mut result: indexmap::IndexMap<String, Value> = {
let mut m = indexmap::IndexMap::new();
m
};
let mut baseIds: Vec<Value> = Value::Array(rates.keys().map(|__k| Value::Str(__k.clone().into())).collect()).as_array().cloned().unwrap_or_default();
let mut delimiter: String = "-".to_string();
{
let mut i: i64 = 0;
let mut __for_first_543: bool = true;
while { if !__for_first_543 { i += 1; } __for_first_543 = false; i < (baseIds.len() as i64) } {
let mut baseId: Value = baseIds.get(i as usize).cloned().unwrap_or(Value::Null);
let mut marketId: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", baseId, delimiter).into()), quoteId).into());
let mut market: Value = self.safe_market(&[marketId, Value::Null, Value::from(delimiter.clone())]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[Value::Str("".into())]);
result.insert(crate::runtime::stringify_param(&symbol), self.parse_ticker(rates.get(baseId.as_str().unwrap_or("")).cloned().unwrap_or(Value::Null), &[market]));
}
}
return self.filter_by_array_tickers(Value::Map(result), Value::Str("symbol".into()), &[symbolsNormalized]);
Value::Null
}
pub async fn fetch_tickers_v3(&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
});
if (symbolsNormalized != Value::Null) {
request.insert("product_ids".into(), self.market_ids(&[symbolsNormalized.clone()]));
}
let marketTypeparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchTickers".into()), &[self.get_market_from_symbols(&[symbolsNormalized.clone()]), params, Value::Str("default".into())]).as_array().cloned().unwrap_or_default();
let mut marketType: Value = marketTypeparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
if (marketType != Value::Null) && (marketType.as_str() != Some("default")) {
request.insert("product_type".into(), (if (marketType.as_str() == Some("swap")) { Value::Str("FUTURE".into()) } else { Value::Str("SPOT".into()) }));
}
let mut response: Value = Value::Null;
let usePrivateparamsUsePrivateVariable: Vec<Value> = self.handle_option_bool_and_params(paramsMarketType, Value::Str("fetchTickers".into()), Value::Str("usePrivate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut usePrivate: Value = usePrivateparamsUsePrivateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUsePrivate: Value = usePrivateparamsUsePrivateVariable.get(1).cloned().unwrap_or(Value::Null);
if usePrivate.as_bool() == Some(true) {
let __ws_arg_15 = self.extend(Value::Map(request.clone()), &[paramsUsePrivate.clone()]);
response = self.v3_private_get_brokerage_products(&[__ws_arg_15]).await;
} else {
let __ws_arg_16 = self.extend(Value::Map(request), &[paramsUsePrivate]);
response = self.v3_public_get_brokerage_market_products(&[__ws_arg_16]).await;
}
let mut data: Vec<Value> = self.safe_list_k(response, "products", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut result: indexmap::IndexMap<String, Value> = {
let mut m = indexmap::IndexMap::new();
m
};
{
let mut i: i64 = 0;
let mut __for_first_544: bool = true;
while { if !__for_first_544 { i += 1; } __for_first_544 = false; i < (data.len() as i64) } {
let mut entry: Value = data.get(i as usize).cloned().unwrap_or(Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(entry.clone(), "product_id", &[]);
let mut market: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), Value::Null, Value::Str("-".into())]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[Value::Str("".into())]);
result.insert(crate::runtime::stringify_param(&symbol), self.parse_ticker(entry, &[market]));
}
}
return self.filter_by_array_tickers(Value::Map(result), Value::Str("symbol".into()), &[symbolsNormalized]);
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
}));
let mut method: Option<String> = self.safe_string_k(self.options.clone(), "fetchTicker", &[Value::Str("fetchTickerV3".into())]).as_str().map(str::to_owned);
if (method.as_deref() == Some("fetchTickerV3")) {
return self.fetch_ticker_v3(symbol.clone(), &[params.clone()]).await;
}
return self.fetch_ticker_v2(symbol, &[params]).await;
Value::Null
}
pub async fn fetch_ticker_v2(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = self.extend(Value::Map({
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
}), &[params]);
let mut spot: Value = self.v2_public_get_prices_symbol_spot(&[request.clone()]).await;
let mut ask: Value = self.v2_public_get_prices_symbol_buy(&[request.clone()]).await;
let mut bid: Value = self.v2_public_get_prices_symbol_sell(&[request]).await;
let mut spotData: Value = self.safe_dict_k(spot, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut askData: Value = self.safe_dict_k(ask, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut bidData: Value = self.safe_dict_k(bid, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut bidAskLast: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("bid".to_string(), self.safe_number_k(bidData, "amount", &[]));
m.insert("ask".to_string(), self.safe_number_k(askData, "amount", &[]));
m.insert("price".to_string(), self.safe_number_k(spotData, "amount", &[]));
m
});
return self.parse_ticker(Value::Map(bidAskLast), &[market]);
Value::Null
}
pub async fn fetch_ticker_v3(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("limit".to_string(), Value::Int(1));
m
});
let usePrivateparamsUsePrivateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchTicker".into()), Value::Str("usePrivate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut usePrivate: Value = usePrivateparamsUsePrivateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUsePrivate: Value = usePrivateparamsUsePrivateVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if usePrivate.as_bool() == Some(true) {
let __ws_arg_17 = self.extend(Value::Map(request.clone()), &[paramsUsePrivate.clone()]);
response = self.v3_private_get_brokerage_products_product_id_ticker(&[__ws_arg_17]).await;
} else {
let __ws_arg_18 = self.extend(Value::Map(request), &[paramsUsePrivate]);
response = self.v3_public_get_brokerage_market_products_product_id_ticker(&[__ws_arg_18]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "trades", &[Value::from(vec![])]);
let mut first: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ticker: indexmap::IndexMap<String, Value> = self.parse_ticker(first, &[market]).as_map().cloned().unwrap_or_default();
ticker.insert("bid".into(), self.safe_number_k(response.clone(), "best_bid", &[]));
ticker.insert("ask".into(), self.safe_number_k(response, "best_ask", &[]));
return Value::Map(ticker);
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 bid: Value = self.safe_number_k(ticker.clone(), "bid", &[]);
let mut ask: Value = self.safe_number_k(ticker.clone(), "ask", &[]);
let mut bidVolume: Value = Value::Null;
let mut askVolume: Value = Value::Null;
if (matches!(&ticker, Value::Dict(__d) if __d.contains_key("bids"))) {
let mut bids: Value = self.safe_list_k(ticker.clone(), "bids", &[Value::from(vec![])]);
let mut asks: Value = self.safe_list_k(ticker.clone(), "asks", &[Value::from(vec![])]);
let mut firstBid: Value = self.safe_dict(bids, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut firstAsk: Value = self.safe_dict(asks, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
bid = self.safe_number_k(firstBid.clone(), "price", &[]);
bidVolume = self.safe_number_k(firstBid, "size", &[]);
ask = self.safe_number_k(firstAsk.clone(), "price", &[]);
askVolume = self.safe_number_k(firstAsk, "size", &[]);
}
let mut marketId: Option<String> = self.safe_string_k_opt(ticker.clone(), "product_id", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut last: Value = self.safe_number_k(ticker.clone(), "price", &[]);
let mut datetime: Option<String> = self.safe_string_k_opt(ticker.clone(), "time", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("timestamp".to_string(), self.parse8601(datetime.clone().map(Value::from).unwrap_or(Value::Null)));
m.insert("datetime".to_string(), datetime.map(Value::from).unwrap_or(Value::Null));
m.insert("bid".to_string(), bid);
m.insert("ask".to_string(), ask);
m.insert("last".to_string(), last.clone());
m.insert("high".to_string(), Value::Null);
m.insert("low".to_string(), Value::Null);
m.insert("bidVolume".to_string(), bidVolume);
m.insert("askVolume".to_string(), askVolume);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), self.safe_number_k(ticker.clone(), "price_percentage_change_24h", &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_number_k(ticker.clone(), "volume_24h", &[]));
m.insert("quoteVolume".to_string(), self.safe_number_k(ticker.clone(), "approximate_quote_24h_volume", &[]));
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_custom_balance(&self, mut response: Value, 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);
let mut summary: Value = self.safe_dict_k(response.clone(), "balance_summary", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut totalUsdBalanceData: Value = self.safe_dict_k(summary.clone(), "total_usd_balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut futuresBuyingPowerData: Value = self.safe_dict_k(summary, "futures_buying_power", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut totalUsdBalance: Value = self.safe_string_k(totalUsdBalanceData, "value", &[]);
let mut futuresBuyingPower: Value = self.safe_string_k(futuresBuyingPowerData, "value", &[]);
if (totalUsdBalance != Value::Null) || (futuresBuyingPower != Value::Null) {
let mut total: Value = (if (totalUsdBalance != Value::Null) { totalUsdBalance } else { futuresBuyingPower.clone() });
let mut free: Value = (if (futuresBuyingPower != Value::Null) { futuresBuyingPower } else { total.clone() });
let mut used: Value = crate::precise::Precise::stringSub(&total, &free);
let mut balanceResult: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
balanceResult.insert("USD".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), free.clone());
m.insert("used".to_string(), used.clone());
m.insert("total".to_string(), total.clone());
m
}));
return self.safe_balance(Value::Map(balanceResult));
}
let mut balances: Value = self.safe_list2(response.clone(), Value::Str("data".into()), Value::Str("accounts".into()), &[Value::from(vec![])]);
let mut accounts: Value = (match params.get("type") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => self.options.as_map().and_then(|__m| __m.get("accounts")).cloned().unwrap_or(Value::Null) });
let mut v3Accounts: Value = (match params.get("type") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => self.options.as_map().and_then(|__m| __m.get("v3Accounts")).cloned().unwrap_or(Value::Null) });
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
});
{
let mut b: i64 = 0;
let mut __for_first_545: bool = true;
while { if !__for_first_545 { b += 1; } __for_first_545 = false; b < (balances.len() as i64) } {
let mut balance: Value = self.safe_dict(balances.clone(), Value::Int(b), &[]);
let mut type_var: Option<String> = self.safe_string_k_opt(balance.clone(), "type", &[]);
if self.in_array(type_var.clone().map(Value::from).unwrap_or(Value::Null), accounts.clone()).as_bool() == Some(true) {
let mut value: Value = self.safe_dict_k(balance.clone(), "balance", &[]);
if (value != Value::Null) {
let mut currencyId: Option<String> = self.safe_string_k_opt(value.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[]);
let mut total: Option<String> = self.safe_string_k_opt(value, "amount", &[]);
let mut free: Value = total.clone().map(Value::from).unwrap_or(Value::Null);
let mut account: Value = self.safe_dict(Value::Map(result.clone()), code.clone(), &[]);
if (account == Value::Null) {
let __ws_arg_19 = self.account();
account = self.extend(__ws_arg_19, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), free.clone());
m.insert("total".to_string(), total.clone().map(Value::from).unwrap_or(Value::Null));
m
})]);
} else {
let __ws_arg_20 = self.safe_string_k(account.clone(), "free", &[]);
let __ws_arg_21 = self.safe_string_k(account.clone(), "total", &[]);
account = self.extend(account.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), crate::precise::Precise::stringAdd(&__ws_arg_20, &total.clone().map(Value::from).unwrap_or(Value::Null)));
m.insert("total".to_string(), crate::precise::Precise::stringAdd(&__ws_arg_21, &total.clone().map(Value::from).unwrap_or(Value::Null)));
m
})]);
}
if (code != Value::Null) {
result.insert(crate::runtime::stringify_param(&code), account.clone());
}
}
} else if self.in_array(type_var.map(Value::from).unwrap_or(Value::Null), v3Accounts.clone()).as_bool() == Some(true) {
let mut available: Value = self.safe_dict_k(balance.clone(), "available_balance", &[]);
let mut hold: Value = self.safe_dict_k(balance, "hold", &[]);
if (available != Value::Null) && (hold != Value::Null) {
let mut currencyId: Option<String> = self.safe_string_k_opt(available.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[]);
let mut used: Option<String> = self.safe_string_k_opt(hold, "value", &[]);
let mut free: Option<String> = self.safe_string_k_opt(available, "value", &[]);
let mut total: Value = crate::precise::Precise::stringAdd(&used.clone().map(Value::from).unwrap_or(Value::Null), &free.clone().map(Value::from).unwrap_or(Value::Null));
let mut account: Value = self.safe_dict(Value::Map(result.clone()), code.clone(), &[]);
if (account == Value::Null) {
let __ws_arg_22 = self.account();
account = self.extend(__ws_arg_22, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), free.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("used".to_string(), used.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("total".to_string(), total.clone());
m
})]);
} else {
let __ws_arg_23 = self.safe_string_k(account.clone(), "free", &[]);
let __ws_arg_24 = self.safe_string_k(account.clone(), "used", &[]);
let __ws_arg_25 = self.safe_string_k(account.clone(), "total", &[]);
account = self.extend(account.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), crate::precise::Precise::stringAdd(&__ws_arg_23, &free.clone().map(Value::from).unwrap_or(Value::Null)));
m.insert("used".to_string(), crate::precise::Precise::stringAdd(&__ws_arg_24, &used.clone().map(Value::from).unwrap_or(Value::Null)));
m.insert("total".to_string(), crate::precise::Precise::stringAdd(&__ws_arg_25, &total));
m
})]);
}
if (code != Value::Null) {
result.insert(crate::runtime::stringify_param(&code), account);
}
}
}
}
}
return self.safe_balance(Value::Map(result));
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
}));
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 response: Value = Value::Null;
let mut isV3: bool = self.safe_bool_k_opt(params.clone(), "v3", &[Value::Bool(false)]).unwrap_or(false);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("v3".into())]), &[]);
let marketTypeparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchBalance".into()), &[Value::Null, paramsOmitted]).as_array().cloned().unwrap_or_default();
let mut marketType: Value = marketTypeparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut method: Option<String> = self.safe_string_k(self.options.clone(), "fetchBalance", &[Value::Str("v3PrivateGetBrokerageAccounts".into())]).as_str().map(str::to_owned);
if (marketType.as_str() == Some("future")) || (marketType.as_str() == Some("swap")) {
let __ws_arg_26 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.v3_private_get_brokerage_cfm_balance_summary(&[__ws_arg_26]).await;
} else if isV3 || (method.as_deref() == Some("v3PrivateGetBrokerageAccounts")) {
request.insert("limit".into(), Value::Int(250));
let __ws_arg_27 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.v3_private_get_brokerage_accounts(&[__ws_arg_27]).await;
if (self.safe_string_k(paramsMarketType.clone(), "cursor", &[]) == Value::Null) {
let mut accounts: Value = self.safe_list_k(response.clone(), "accounts", &[Value::from(vec![])]);
let mut page: Value = response.clone();
let mut cursor: Value = self.safe_string_k(page.clone(), "cursor", &[]);
while matches!(self.safe_bool_k(page.clone(), "has_next", &[Value::Bool(false)]), Value::Bool(true)) && (cursor != Value::Null) && (cursor.as_str() != Some("")) {
request.insert("cursor".into(), cursor.clone());
let __ws_arg_28 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
page = self.v3_private_get_brokerage_accounts(&[__ws_arg_28]).await;
accounts = self.array_concat(accounts.clone(), self.safe_list_k(page.clone(), "accounts", &[Value::from(vec![])]));
let mut nextCursor: Option<String> = self.safe_string_k_opt(page.clone(), "cursor", &[]);
if (nextCursor.as_deref() == cursor.as_str()) {
break;
}
cursor = nextCursor.map(Value::from).unwrap_or(Value::Null);
}
let __ws_arg_29 = self.safe_bool_k(page.clone(), "has_next", &[Value::Bool(false)]);
let __ws_arg_30 = self.safe_string_k(page, "cursor", &[]);
response = self.extend(response.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accounts".to_string(), accounts);
m.insert("has_next".to_string(), __ws_arg_29);
m.insert("cursor".to_string(), __ws_arg_30);
m
})]);
}
} else {
request.insert("limit".into(), Value::Int(250));
let __ws_arg_31 = self.extend(Value::Map(request), &[paramsMarketType.clone()]);
response = self.v2_private_get_accounts(&[__ws_arg_31]).await;
}
let __ws_arg_32 = self.extend(paramsMarketType, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), marketType);
m
})]);
return self.parse_custom_balance(response, &[__ws_arg_32]);
Value::Null
}
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchLedger".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_cursor(Value::Str("fetchLedger".into()), &[code.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Str("next_starting_after".into()), Value::Str("starting_after".into()), Value::Null, Value::Int(100)]).await;
}
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code.clone());
}
let requestparamsValueVariable: Vec<Value> = self.prepare_account_request_with_currency_code(&[code, limit.clone(), paramsPaginate]).await.as_array().cloned().unwrap_or_default();
let mut request: Value = requestparamsValueVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsValue: Value = requestparamsValueVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_33 = self.extend(request, &[paramsValue]);
let mut response: Value = self.v2_private_get_accounts_account_id_transactions(&[__ws_arg_33]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut ledger: Value = self.parse_ledger(data, &[currency, since, limit]);
let mut length: Value = Value::Int(ledger.len() as i64);
if length.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
let mut lastIndex: Value = (match (&(length), &(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 });
let mut last: Value = self.safe_dict(ledger.clone(), lastIndex.clone(), &[]);
let mut pagination: Value = self.safe_dict_k(response, "pagination", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cursor: Option<String> = self.safe_string_k_opt(pagination, "next_starting_after", &[]);
if (cursor.is_some()) && (cursor.as_deref() != Some("")) {
add_element_to_object(get_value_mut(&mut last, &Value::Str("info".into())), &Value::Str("next_starting_after".into()), cursor.map(Value::from).unwrap_or(Value::Null));
add_element_to_object(&mut ledger, &lastIndex, last);
}
}
return self.to_array(ledger);
Value::Null
}
pub fn parse_ledger_entry_status(&self, mut status: Value) -> Option<String> {
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("completed".to_string(), Value::Str("ok".into()));
m
});
return self.safe_string(Value::Map(types), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Option<String> {
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("buy".to_string(), Value::Str("trade".into()));
m.insert("sell".to_string(), Value::Str("trade".into()));
m.insert("fiat_deposit".to_string(), Value::Str("transaction".into()));
m.insert("fiat_withdrawal".to_string(), Value::Str("transaction".into()));
m.insert("exchange_deposit".to_string(), Value::Str("transaction".into()));
m.insert("exchange_withdrawal".to_string(), Value::Str("transaction".into()));
m.insert("send".to_string(), Value::Str("transaction".into()));
m.insert("pro_deposit".to_string(), Value::Str("transaction".into()));
m.insert("pro_withdrawal".to_string(), Value::Str("transaction".into()));
m
});
return self.safe_string(Value::Map(types), type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut amountInfo: Value = self.safe_dict_k(item.clone(), "amount", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amount: Value = self.safe_string_k(amountInfo.clone(), "amount", &[]);
let mut direction: Value = Value::Null;
if crate::precise::Precise::stringLt(&amount, &Value::Str("0".into())).as_bool() == Some(true) {
direction = Value::Str("out".into());
amount = crate::precise::Precise::stringNeg(&amount);
} else {
direction = Value::Str("in".into());
}
let mut currencyId: Option<String> = self.safe_string_k_opt(amountInfo, "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone().map(Value::from).unwrap_or(Value::Null), &[currency.clone()]);
let mut currencyResolved: Value = self.safe_currency(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]);
let mut fee: Value = Value::Null;
let mut networkInfo: Value = self.safe_dict_k(item.clone(), "network", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut feeInfo: Value = self.safe_dict_k(networkInfo, "transaction_fee", &[]);
if (feeInfo != Value::Null) {
let mut feeCurrencyId: Option<String> = self.safe_string_k_opt(feeInfo.clone(), "currency", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId.map(Value::from).unwrap_or(Value::Null), &[currencyResolved.clone()]);
let mut feeAmount: Value = self.safe_number_k(feeInfo, "amount", &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeAmount);
m.insert("currency".to_string(), feeCurrencyCode);
m
});
}
let mut timestamp: Value = self.parse8601(self.safe_string_k(item.clone(), "created_at", &[]));
let mut id: Option<String> = self.safe_string_k_opt(item.clone(), "id", &[]);
let mut type_var: Value = self.parse_ledger_entry_type(self.safe_string_k(item.clone(), "type", &[])).map(Value::from).unwrap_or(Value::Null);
let mut status: Value = self.parse_ledger_entry_status(self.safe_string_k(item.clone(), "status", &[])).map(Value::from).unwrap_or(Value::Null);
let mut path: Option<String> = self.safe_string_k_opt(item.clone(), "resource_path", &[]);
let mut accountId: Value = Value::Null;
if (path.is_some()) {
let mut parts: Vec<Value> = Value::Array(if let Some(__s) = path.as_deref() { __s.split("/").map(Value::from).collect() } else { Vec::new() }).as_array().cloned().unwrap_or_default();
let mut numParts: f64 = ((parts.len() as i64) as f64);
if numParts > ((3i64) as f64) {
accountId = parts.get(3).cloned().unwrap_or(Value::Null);
}
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item);
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("direction".to_string(), direction);
m.insert("account".to_string(), accountId);
m.insert("referenceId".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code);
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), Value::Null);
m.insert("status".to_string(), status);
m.insert("fee".to_string(), fee);
m
}), &[currencyResolved]);
Value::Null
}
pub async fn find_account_id(&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;
}
self.load_accounts(&[Value::Bool(false), params]).await;
{
let mut i: i64 = 0;
let mut __for_first_546: bool = true;
while { if !__for_first_546 { i += 1; } __for_first_546 = false; i < (self.accounts.len() as i64) } {
let mut account: Value = self.accounts.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
if (self.safe_string_k(account.clone(), "code", &[]).as_str() == code.as_str()) {
return self.safe_string_k(account, "id", &[]);
}
}
}
return Value::Null;
Value::Null
}
pub fn prepare_account_request(&self, 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
}));
let mut accountId: Option<String> = self.safe_string2_opt(params, Value::Str("account_id".into()), Value::Str("accountId".into()), &[]);
if (accountId.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" prepareAccountRequest() method requires an account_id (or accountId) parameter".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("account_id".to_string(), accountId.map(Value::from).unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("limit".into(), limit);
}
return Value::Map(request);
Value::Null
}
pub async fn prepare_account_request_with_currency_code(&mut self, optional_args: &[Value]) -> Value {
let mut code = 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
}));
let mut accountId: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("account_id".into()), Value::Str("accountId".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("account_id".into()), Value::Str("accountId".into())]), &[]);
let mut request: indexmap::IndexMap<String, Value> = {
let mut m = indexmap::IndexMap::new();
m.insert("account_id".to_string(), accountId.clone().map(Value::from).unwrap_or(Value::Null));
m
};
if (limit != Value::Null) {
request.insert("limit".into(), limit);
}
if (accountId.is_none()) {
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" prepareAccountRequestWithCurrencyCode() method requires an account_id (or accountId) parameter OR a currency code argument".into()))));
}
let mut foundAccountId: Value = self.find_account_id(code.clone(), &[paramsOmitted.clone()]).await;
if (foundAccountId == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" prepareAccountRequestWithCurrencyCode() could not find account id for ".into())).into()), code).into()), Value::Str(". You might try to generate the deposit address in the website for that coin first.".into()))));
}
request.insert("account_id".into(), foundAccountId);
}
return Value::from(vec![Value::Map(request), paramsOmitted]);
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 id: String = self.safe_string_k_opt(self.options.clone(), "brokerId", &[Value::Str("ccxt".into())]).unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("client_order_id".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", id, Value::Str("-".into())).into()), self.uuid(&[])).into()));
m.insert("product_id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), (if let Some(__s) = side.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }));
m
});
let mut reduceOnly: bool = self.safe_bool_k_opt(params.clone(), "reduceOnly", &[Value::Bool(false)]).unwrap_or(false);
if reduceOnly {
let __ws_arg_34 = self.extend(self.omit(params.clone(), Value::Str("reduceOnly".into()), &[]), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m
})]);
return self.close_position(symbol.clone(), &[side.clone(), __ws_arg_34]).await;
}
let mut paramsMarketBuy: Value = Value::Null;
let mut triggerPrice: Value = self.safe_number_n(params.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("stop_price".into()), Value::Str("triggerPrice".into())]), &[]);
let mut stopLossPrice: Value = self.safe_number_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_number_k(params.clone(), "takeProfitPrice", &[]);
let mut isStop: bool = triggerPrice != Value::Null;
let mut isStopLoss: bool = stopLossPrice != Value::Null;
let mut isTakeProfit: bool = takeProfitPrice != Value::Null;
let mut timeInForce: Option<String> = self.safe_string_k(params.clone(), "timeInForce", &[]).as_str().map(str::to_owned);
let mut postOnly: Value = Value::Bool(false);
if (timeInForce.as_deref() == Some("PO")) {
postOnly = Value::Bool(true);
} else {
postOnly = self.safe_bool2(params.clone(), Value::Str("postOnly".into()), Value::Str("post_only".into()), &[Value::Bool(false)]);
}
let mut endTime: Option<String> = self.safe_string_k_opt(params.clone(), "end_time", &[]);
let mut stopDirection: Value = self.safe_string_k(params.clone(), "stop_direction", &[]);
if (type_var.as_str() == Some("limit")) {
if isStop {
if (stopDirection == Value::Null) {
stopDirection = (if (side.as_str() == Some("buy")) { Value::Str("STOP_DIRECTION_STOP_DOWN".into()) } else { Value::Str("STOP_DIRECTION_STOP_UP".into()) });
}
if (timeInForce.as_deref() == Some("GTD")) || (endTime.is_some()) {
if (endTime.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires an end_time parameter for a GTD order".into()))));
}
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stop_limit_stop_limit_gtd".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("limit_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m.insert("stop_price".to_string(), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
m.insert("stop_direction".to_string(), stopDirection.clone());
m.insert("end_time".to_string(), endTime.clone().map(Value::from).unwrap_or(Value::Null));
m
}));
m
}));
} else {
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stop_limit_stop_limit_gtc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("limit_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m.insert("stop_price".to_string(), self.price_to_precision(symbol.clone(), triggerPrice));
m.insert("stop_direction".to_string(), stopDirection.clone());
m
}));
m
}));
}
} else if isStopLoss || isTakeProfit {
let mut tpslPrice: Value = Value::Null;
if isStopLoss {
if (stopDirection == Value::Null) {
stopDirection = (if (side.as_str() == Some("buy")) { Value::Str("STOP_DIRECTION_STOP_UP".into()) } else { Value::Str("STOP_DIRECTION_STOP_DOWN".into()) });
}
tpslPrice = self.price_to_precision(symbol.clone(), stopLossPrice);
} else {
if (stopDirection == Value::Null) {
stopDirection = (if (side.as_str() == Some("buy")) { Value::Str("STOP_DIRECTION_STOP_DOWN".into()) } else { Value::Str("STOP_DIRECTION_STOP_UP".into()) });
}
tpslPrice = self.price_to_precision(symbol.clone(), takeProfitPrice);
}
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stop_limit_stop_limit_gtc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("limit_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m.insert("stop_price".to_string(), tpslPrice);
m.insert("stop_direction".to_string(), stopDirection);
m
}));
m
}));
} else {
if (timeInForce.as_deref() == Some("GTD")) || (endTime.is_some()) {
if (endTime.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires an end_time parameter for a GTD order".into()))));
}
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit_limit_gtd".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("limit_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m.insert("end_time".to_string(), endTime.map(Value::from).unwrap_or(Value::Null));
m.insert("post_only".to_string(), postOnly.clone());
m
}));
m
}));
} else if (timeInForce.as_deref() == Some("IOC")) {
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sor_limit_ioc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("limit_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m
}));
m
}));
} else if (timeInForce.as_deref() == Some("FOK")) {
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit_limit_fok".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("limit_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m
}));
m
}));
} else {
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit_limit_gtc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("limit_price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m.insert("post_only".to_string(), postOnly);
m
}));
m
}));
}
}
} else {
if isStop || isStopLoss || isTakeProfit {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() only stop limit orders are supported".into()))));
}
if matches!((self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)])), Value::Bool(true)) && (side.as_str() == Some("buy")) {
let mut total: Value = Value::Null;
let createMarketBuyOrderRequiresPriceparamsRequiresPriceVariable: Vec<Value> = self.handle_option_bool_and_params(params.clone(), Value::Str("createOrder".into()), Value::Str("createMarketBuyOrderRequiresPrice".into()), &[Value::Bool(true)]).as_array().cloned().unwrap_or_default();
let mut createMarketBuyOrderRequiresPrice: Value = createMarketBuyOrderRequiresPriceparamsRequiresPriceVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsRequiresPrice: Value = createMarketBuyOrderRequiresPriceparamsRequiresPriceVariable.get(1).cloned().unwrap_or(Value::Null);
let mut cost: Value = self.safe_number_k(paramsRequiresPrice.clone(), "cost", &[]);
paramsMarketBuy = self.omit(paramsRequiresPrice, Value::Str("cost".into()), &[]);
if (cost != Value::Null) {
total = 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 a price argument for market buy orders on spot markets to calculate the total amount 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);
total = self.cost_to_precision(symbol.clone(), costRequest);
}
} else {
total = self.cost_to_precision(symbol.clone(), amount.clone());
}
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_market_ioc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("quote_size".to_string(), total);
m
}));
m
}));
} else {
request.insert("order_configuration".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_market_ioc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("base_size".to_string(), self.amount_to_precision(symbol, amount));
m
}));
m
}));
}
}
let mut paramsBase: Value = (if (paramsMarketBuy == Value::Null) { params } else { paramsMarketBuy });
let mut marginMode: Option<String> = self.safe_string_k(paramsBase.clone(), "marginMode", &[]).as_str().map(str::to_owned);
if (marginMode.is_some()) {
if (marginMode.as_deref() == Some("isolated")) {
request.insert("margin_type".into(), Value::Str("ISOLATED".into()));
} else if (marginMode.as_deref() == Some("cross")) {
request.insert("margin_type".into(), Value::Str("CROSS".into()));
}
}
let mut paramsOmitted: Value = self.omit(paramsBase, Value::from(vec![Value::Str("timeInForce".into()), Value::Str("triggerPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("takeProfitPrice".into()), Value::Str("stopPrice".into()), Value::Str("stop_price".into()), Value::Str("stopDirection".into()), Value::Str("stop_direction".into()),
Value::Str("clientOrderId".into()), Value::Str("postOnly".into()), Value::Str("post_only".into()), Value::Str("end_time".into()), Value::Str("marginMode".into())]), &[]);
let mut preview: bool = self.safe_bool2_opt(paramsOmitted.clone(), Value::Str("preview".into()), Value::Str("test".into()), &[Value::Bool(false)]).unwrap_or(false);
let mut response: Value = Value::Null;
if preview {
request = self.omit(Value::Map(request.clone()), Value::Str("client_order_id".into()), &[]).as_map().cloned().unwrap_or_default();
let __ws_arg_35 = self.extend(Value::Map(request.clone()), &[self.omit(paramsOmitted.clone(), Value::from(vec![Value::Str("preview".into()), Value::Str("test".into())]), &[])]);
response = self.v3_private_post_brokerage_orders_preview(&[__ws_arg_35]).await;
} else {
let __ws_arg_36 = self.extend(Value::Map(request), &[paramsOmitted]);
response = self.v3_private_post_brokerage_orders(&[__ws_arg_36]).await;
}
let mut success: bool = self.safe_bool_k_opt(response.clone(), "success", &[Value::Bool(false)]).unwrap_or(false);
if !(success) {
let mut errorResponse: Value = self.safe_dict_k(response.clone(), "error_response", &[]);
let mut errorTitle: Option<String> = self.safe_string_k_opt(errorResponse.clone(), "error", &[]);
let mut errorMessage: Option<String> = self.safe_string_k_opt(errorResponse.clone(), "message", &[]);
if (errorResponse != Value::Null) {
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorTitle.clone().map(Value::from).unwrap_or(Value::Null), errorMessage.clone().map(Value::from).unwrap_or(Value::Null));
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), errorTitle.map(Value::from).unwrap_or(Value::Null), errorMessage.clone().map(Value::from).unwrap_or(Value::Null));
panic!("{}", crate::exchange_errors::exchange_error(errorMessage.map(Value::from).unwrap_or(Value::Null)));
}
}
let mut data: Value = self.safe_dict_k(response, "success_response", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[market]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(order.clone(), "product_id", &[]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market.clone(), Value::Str("-".into())]);
let mut marketResolved: Value = (if (symbol != Value::Null) { self.safe_market(&[symbol.clone(), market.clone()]) } else { market });
let mut orderConfiguration: Value = self.safe_dict_k(order.clone(), "order_configuration", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut limitGTC: Value = self.safe_dict_k(orderConfiguration.clone(), "limit_limit_gtc", &[]);
let mut limitGTD: Value = self.safe_dict_k(orderConfiguration.clone(), "limit_limit_gtd", &[]);
let mut limitIOC: Value = self.safe_dict_k(orderConfiguration.clone(), "sor_limit_ioc", &[]);
let mut stopLimitGTC: Value = self.safe_dict_k(orderConfiguration.clone(), "stop_limit_stop_limit_gtc", &[]);
let mut stopLimitGTD: Value = self.safe_dict_k(orderConfiguration.clone(), "stop_limit_stop_limit_gtd", &[]);
let mut marketIOC: Value = self.safe_dict_k(orderConfiguration, "market_market_ioc", &[]);
let mut isLimit: bool = (limitGTC != Value::Null) || (limitGTD != Value::Null) || (limitIOC != Value::Null);
let mut isStop: bool = (stopLimitGTC != Value::Null) || (stopLimitGTD != Value::Null);
let mut price: Value = Value::Null;
let mut amount: Value = Value::Null;
let mut postOnly: Value = Value::Null;
let mut triggerPrice: Value = Value::Null;
if isLimit {
let mut target: Value = Value::Null;
if (limitGTC != Value::Null) {
target = limitGTC;
} else if (limitGTD != Value::Null) {
target = limitGTD;
} else {
target = limitIOC;
}
price = self.safe_string_k(target.clone(), "limit_price", &[]);
amount = self.safe_string_k(target.clone(), "base_size", &[]);
postOnly = self.safe_bool_k(target, "post_only", &[]);
} else if isStop {
let mut stopTarget: Value = (if (stopLimitGTC != Value::Null) { stopLimitGTC } else { stopLimitGTD });
price = self.safe_string_k(stopTarget.clone(), "limit_price", &[]);
amount = self.safe_string_k(stopTarget.clone(), "base_size", &[]);
postOnly = self.safe_bool_k(stopTarget.clone(), "post_only", &[]);
triggerPrice = self.safe_string_k(stopTarget, "stop_price", &[]);
} else {
amount = self.safe_string_k(marketIOC, "base_size", &[]);
}
let mut datetime: Option<String> = self.safe_string_k_opt(order.clone(), "created_time", &[]);
let mut totalFees: Option<String> = self.safe_string_k(order.clone(), "total_fees", &[]).as_str().map(str::to_owned);
let mut currencyFee: Value = Value::Null;
if (totalFees.is_some()) && (marketResolved != Value::Null) {
currencyFee = self.safe_string_k(marketResolved.clone(), "quote", &[]);
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client_order_id", &[]));
m.insert("timestamp".to_string(), self.parse8601(datetime.clone().map(Value::from).unwrap_or(Value::Null)));
m.insert("datetime".to_string(), datetime.map(Value::from).unwrap_or(Value::Null));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), self.parse_order_type(self.safe_string_k(order.clone(), "order_type", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("timeInForce".to_string(), self.parse_time_in_force(self.safe_string_k(order.clone(), "time_in_force", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("postOnly".to_string(), postOnly);
m.insert("side".to_string(), self.safe_string_lower_k(order.clone(), "side", &[]));
m.insert("price".to_string(), price);
m.insert("triggerPrice".to_string(), triggerPrice);
m.insert("amount".to_string(), amount);
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "filled_size", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), self.safe_string_k(order.clone(), "average_filled_price", &[]));
m.insert("status".to_string(), self.parse_order_status(self.safe_string_k(order.clone(), "status", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.safe_string_k(order, "total_fees", &[]));
m.insert("currency".to_string(), currencyFee);
m
}));
m.insert("trades".to_string(), Value::Null);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("OPEN".to_string(), Value::Str("open".into()));
m.insert("FILLED".to_string(), Value::Str("closed".into()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".into()));
m.insert("EXPIRED".to_string(), Value::Str("canceled".into()));
m.insert("FAILED".to_string(), Value::Str("canceled".into()));
m.insert("UNKNOWN_ORDER_STATUS".to_string(), Value::Null);
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_order_type(&self, mut type_var: Value) -> Option<String> {
if (type_var.as_str() == Some("UNKNOWN_ORDER_TYPE")) {
return None;
}
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".into()));
m.insert("LIMIT".to_string(), Value::Str("limit".into()));
m.insert("STOP".to_string(), Value::Str("limit".into()));
m.insert("STOP_LIMIT".to_string(), Value::Str("limit".into()));
m
});
return self.safe_string(Value::Map(types), type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Option<String> {
let mut timeInForces: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("GOOD_UNTIL_CANCELLED".to_string(), Value::Str("GTC".into()));
m.insert("GOOD_UNTIL_DATE_TIME".to_string(), Value::Str("GTD".into()));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Str("IOC".into()));
m.insert("FILL_OR_KILL".to_string(), Value::Str("FOK".into()));
m.insert("UNKNOWN_TIME_IN_FORCE".to_string(), Value::Null);
m
});
return self.safe_string(Value::Map(timeInForces), timeInForce.clone(), &[timeInForce.clone()]).as_str().map(str::to_owned);
}
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut orders: Value = self.cancel_orders(Value::from(vec![id]), &[symbol, params]).await;
let mut order: Value = self.safe_dict(orders, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return order;
Value::Null
}
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("order_ids".to_string(), ids);
m
});
let __ws_arg_37 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_post_brokerage_orders_batch_cancel(&[__ws_arg_37]).await;
let mut orders: Value = self.safe_list_k(response, "results", &[Value::from(vec![])]);
{
let mut i: i64 = 0;
let mut __for_first_547: bool = true;
while { if !__for_first_547 { i += 1; } __for_first_547 = false; i < (orders.len() as i64) } {
let mut success: bool = self.safe_bool_k_opt(orders.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null), "success", &[Value::Bool(false)]).unwrap_or(false);
if !(success) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" cancelOrders() has failed, check your arguments and parameters".into()))));
}
}
}
return self.parse_orders(orders, &[market]);
Value::Null
}
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id);
m
});
if (amount != Value::Null) {
request.insert("size".into(), self.amount_to_precision(symbol.clone(), amount));
}
if (price != Value::Null) {
request.insert("price".into(), self.price_to_precision(symbol, price));
}
let mut preview: bool = self.safe_bool2_opt(params.clone(), Value::Str("preview".into()), Value::Str("test".into()), &[Value::Bool(false)]).unwrap_or(false);
let mut response: Value = Value::Null;
if preview {
let __ws_arg_38 = self.extend(Value::Map(request.clone()), &[self.omit(params.clone(), Value::from(vec![Value::Str("preview".into()), Value::Str("test".into())]), &[])]);
response = self.v3_private_post_brokerage_orders_edit_preview(&[__ws_arg_38]).await;
} else {
let __ws_arg_39 = self.extend(Value::Map(request), &[params]);
response = self.v3_private_post_brokerage_orders_edit(&[__ws_arg_39]).await;
}
return self.parse_order(response, &[market]);
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 market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id);
m
});
let __ws_arg_40 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_brokerage_orders_historical_order_id(&[__ws_arg_40]).await;
let mut order: Value = self.safe_dict_k(response, "order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[market]);
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::Int(100));
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 paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchOrders".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_cursor(Value::Str("fetchOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Str("cursor".into()), Value::Str("cursor".into()), Value::Null, Value::Int(1000)]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (market != Value::Null) {
request.insert("product_id".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
if (since != Value::Null) {
request.insert("start_date".into(), self.iso8601(since.clone()));
}
let mut until: Option<i64> = self.safe_integer_k(paramsPaginate.clone(), "until", &[]).as_i64();
if (until.is_some()) {
request.insert("end_date".into(), self.iso8601(Value::from(until)));
}
let mut paramsOmitted: Value = (if (until.is_some()) { self.omit(paramsPaginate.clone(), Value::from(vec![Value::Str("until".into())]), &[]) } else { paramsPaginate });
let __ws_arg_41 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v3_private_get_brokerage_orders_historical_batch(&[__ws_arg_41]).await;
let mut orders: Value = self.safe_list_k(response.clone(), "orders", &[Value::from(vec![])]);
let mut cursor: Option<String> = self.safe_string_k_opt(response, "cursor", &[]);
if (cursor.is_some()) && (cursor.as_deref() != Some("")) {
let __ws_arg_42 = self.safe_dict(orders.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_42, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cursor".to_string(), cursor.map(Value::from).unwrap_or(Value::Null));
m
})]); add_element_to_object(&mut orders, &Value::Int(0), __be_tmp); };
}
return self.parse_orders(orders, &[market, since, limit]);
Value::Null
}
pub async fn fetch_orders_by_status(&mut self, mut status: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("order_status".to_string(), status);
m
});
if (market != Value::Null) {
request.insert("product_id".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(100) } else { limit });
request.insert("limit".into(), limitResolved.clone());
if (since != Value::Null) {
request.insert("start_date".into(), self.iso8601(since.clone()));
}
let mut until: Option<i64> = self.safe_integer_k(params.clone(), "until", &[]).as_i64();
if (until.is_some()) {
request.insert("end_date".into(), self.iso8601(Value::from(until)));
}
let mut paramsOmitted: Value = (if (until.is_some()) { self.omit(params.clone(), Value::from(vec![Value::Str("until".into())]), &[]) } else { params });
let __ws_arg_43 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v3_private_get_brokerage_orders_historical_batch(&[__ws_arg_43]).await;
let mut orders: Value = self.safe_list_k(response.clone(), "orders", &[Value::from(vec![])]);
let mut cursor: Option<String> = self.safe_string_k_opt(response, "cursor", &[]);
if (cursor.is_some()) && (cursor.as_deref() != Some("")) {
let __ws_arg_44 = self.safe_dict(orders.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_44, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cursor".to_string(), cursor.map(Value::from).unwrap_or(Value::Null));
m
})]); add_element_to_object(&mut orders, &Value::Int(0), __be_tmp); };
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchOpenOrders".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_cursor(Value::Str("fetchOpenOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Str("cursor".into()), Value::Str("cursor".into()), Value::Null, Value::Int(100)]).await;
}
return self.fetch_orders_by_status(Value::Str("OPEN".into()), &[symbol, since, limit, paramsPaginate]).await;
Value::Null
}
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchClosedOrders".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_cursor(Value::Str("fetchClosedOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Str("cursor".into()), Value::Str("cursor".into()), Value::Null, Value::Int(1000)]).await;
}
return self.fetch_orders_by_status(Value::Str("FILLED".into()), &[symbol, since, limit, paramsPaginate]).await;
Value::Null
}
pub async fn fetch_canceled_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_orders_by_status(Value::Str("CANCELLED".into()), &[symbol, since, limit, params]).await;
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 maxLimit: i64 = 300;
let mut limitValue: Value = self.parse_to_int(Value::Int(maxLimit.clone()));
if (limit != Value::Null) && (limit.as_f64().unwrap_or(f64::NAN) < (maxLimit as f64)) {
limitValue = self.parse_to_int(limit.clone());
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit, timeframe.clone(), paramsPaginate.clone(), Value::Int(299)]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("granularity".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut until: Value = self.safe_integer2(paramsPaginate.clone(), Value::Str("until".into()), Value::Str("end".into()), &[]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut requestedDuration: Value = (match (&(limitValue), &(duration)) { (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 sinceString: Value = Value::Null;
if (since != Value::Null) {
sinceString = self.number_to_string(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 })));
} else {
let mut now: Value = Value::Str(format!("{}", self.seconds()).into());
sinceString = crate::precise::Precise::stringSub(&now, &Value::Str(format!("{}", requestedDuration).into()));
}
request.insert("start".into(), sinceString.clone());
let mut windowEnd: Value = crate::precise::Precise::stringAdd(&sinceString, &Value::Str(format!("{}", requestedDuration).into()));
if (until != Value::Null) {
let mut endString: Value = self.number_to_string(self.parse_to_int((match ((until).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) && crate::precise::Precise::stringLt(&windowEnd, &endString).as_bool() == Some(true) {
endString = windowEnd.clone();
}
request.insert("end".into(), endString);
} else {
request.insert("end".into(), windowEnd);
}
let mut response: Value = Value::Null;
let usePrivateparamsUsePrivateVariable: Vec<Value> = self.handle_option_bool_and_params(paramsOmitted, Value::Str("fetchOHLCV".into()), Value::Str("usePrivate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut usePrivate: Value = usePrivateparamsUsePrivateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUsePrivate: Value = usePrivateparamsUsePrivateVariable.get(1).cloned().unwrap_or(Value::Null);
if usePrivate.as_bool() == Some(true) {
let __ws_arg_45 = self.extend(Value::Map(request.clone()), &[paramsUsePrivate.clone()]);
response = self.v3_private_get_brokerage_products_product_id_candles(&[__ws_arg_45]).await;
} else {
let __ws_arg_46 = self.extend(Value::Map(request), &[paramsUsePrivate]);
response = self.v3_public_get_brokerage_market_products_product_id_candles(&[__ws_arg_46]).await;
}
let mut candles: Value = self.safe_list_k(response, "candles", &[Value::from(vec![])]);
return self.parse_ohlc_vs(candles, &[market, timeframe, since, limitValue]);
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_k(ohlcv.clone(), "start", &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv, "volume", &[])]);
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("product_id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
request.insert("start".into(), self.number_to_string(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 }))));
}
if (limit != Value::Null) {
request.insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(params, Value::Str("fetchTrades".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
request.insert("end".into(), self.number_to_string(self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))));
} else if (since != Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchTrades() requires a `until` parameter when you use `since` argument".into()))));
}
let mut response: Value = Value::Null;
let usePrivateparamsUsePrivateVariable: Vec<Value> = self.handle_option_bool_and_params(paramsUntil, Value::Str("fetchTrades".into()), Value::Str("usePrivate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut usePrivate: Value = usePrivateparamsUsePrivateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUsePrivate: Value = usePrivateparamsUsePrivateVariable.get(1).cloned().unwrap_or(Value::Null);
if usePrivate.as_bool() == Some(true) {
let __ws_arg_47 = self.extend(Value::Map(request.clone()), &[paramsUsePrivate.clone()]);
response = self.v3_private_get_brokerage_products_product_id_ticker(&[__ws_arg_47]).await;
} else {
let __ws_arg_48 = self.extend(Value::Map(request), &[paramsUsePrivate]);
response = self.v3_public_get_brokerage_market_products_product_id_ticker(&[__ws_arg_48]).await;
}
let mut trades: Value = self.safe_list_k(response, "trades", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market, since, limit]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchMyTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_cursor(Value::Str("fetchMyTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Str("cursor".into()), Value::Str("cursor".into()), Value::Null, Value::Int(250)]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (market != Value::Null) {
request.insert("product_id".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
if (since != Value::Null) {
request.insert("start_sequence_timestamp".into(), self.iso8601(since.clone()));
}
let mut until: Option<i64> = self.safe_integer_k(paramsPaginate.clone(), "until", &[]).as_i64();
if (until.is_some()) {
request.insert("end_sequence_timestamp".into(), self.iso8601(Value::from(until)));
}
let mut paramsOmitted: Value = (if (until.is_some()) { self.omit(paramsPaginate.clone(), Value::from(vec![Value::Str("until".into())]), &[]) } else { paramsPaginate });
let __ws_arg_49 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v3_private_get_brokerage_orders_historical_fills(&[__ws_arg_49]).await;
let mut trades: Value = self.safe_list_k(response.clone(), "fills", &[Value::from(vec![])]);
let mut cursor: Option<String> = self.safe_string_k_opt(response, "cursor", &[]);
if (cursor.is_some()) && (cursor.as_deref() != Some("")) {
let __ws_arg_50 = self.safe_dict(trades.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.extend(__ws_arg_50, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cursor".to_string(), cursor.map(Value::from).unwrap_or(Value::Null));
m
})]); add_element_to_object(&mut trades, &Value::Int(0), __be_tmp); };
}
return self.parse_trades(trades, &[market, since, limit]);
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: indexmap::IndexMap<String, Value> = self.market(symbol.clone()).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("limit".into(), limit);
}
let mut response: Value = Value::Null;
let usePrivateparamsUsePrivateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchOrderBook".into()), Value::Str("usePrivate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut usePrivate: Value = usePrivateparamsUsePrivateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUsePrivate: Value = usePrivateparamsUsePrivateVariable.get(1).cloned().unwrap_or(Value::Null);
if usePrivate.as_bool() == Some(true) {
let __ws_arg_51 = self.extend(Value::Map(request.clone()), &[paramsUsePrivate.clone()]);
response = self.v3_private_get_brokerage_product_book(&[__ws_arg_51]).await;
} else {
let __ws_arg_52 = self.extend(Value::Map(request), &[paramsUsePrivate]);
response = self.v3_public_get_brokerage_market_product_book(&[__ws_arg_52]).await;
}
let mut data: Value = self.safe_dict_k(response, "pricebook", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut time: Option<String> = self.safe_string_k_opt(data.clone(), "time", &[]);
let mut timestamp: Value = self.parse8601(time.map(Value::from).unwrap_or(Value::Null));
return self.parse_order_book(data, symbol, &[timestamp, Value::Str("bids".into()), Value::Str("asks".into()), Value::Str("price".into()), Value::Str("size".into())]);
Value::Null
}
pub async fn fetch_bids_asks(&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
});
if (symbolsNormalized != Value::Null) {
request.insert("product_ids".into(), self.market_ids(&[symbolsNormalized.clone()]));
}
let __ws_arg_53 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_brokerage_best_bid_ask(&[__ws_arg_53]).await;
let mut tickers: Value = self.safe_list_k(response, "pricebooks", &[Value::from(vec![])]);
return self.parse_tickers(tickers, &[symbolsNormalized]);
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 currency: Value = self.currency(code.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("send".into()));
m.insert("to".to_string(), address);
m.insert("amount".to_string(), self.number_to_string(amount));
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut accountId: Option<String> = self.safe_string2_opt(paramsWithdrawTag.clone(), Value::Str("account_id".into()), Value::Str("accountId".into()), &[]);
let mut paramsOmitted: Value = self.omit(paramsWithdrawTag, Value::from(vec![Value::Str("account_id".into()), Value::Str("accountId".into())]), &[]);
if (accountId.is_none()) {
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" withdraw() requires an account_id (or accountId) parameter OR a currency code argument".into()))));
}
let mut foundAccountId: Value = self.find_account_id(code.clone(), &[paramsOmitted.clone()]).await;
if (foundAccountId == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" withdraw() could not find account id for ".into())).into()), code)));
}
request.insert("account_id".into(), foundAccountId);
} else {
request.insert("account_id".into(), accountId.map(Value::from).unwrap_or(Value::Null));
}
if (tagWithdrawTag != Value::Null) {
request.insert("destination_tag".into(), tagWithdrawTag);
}
let __ws_arg_54 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v2_private_post_accounts_account_id_transactions(&[__ws_arg_54]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(data, &[currency]);
Value::Null
}
pub async fn fetch_deposit_addresses_by_network(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let requestparamsValueVariable: Vec<Value> = self.prepare_account_request_with_currency_code(&[self.safe_string_k(currency, "code", &[]), Value::Null, params]).await.as_array().cloned().unwrap_or_default();
let mut request: Value = requestparamsValueVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsValue: Value = requestparamsValueVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_55 = self.extend(request, &[paramsValue]);
let mut response: Value = self.v2_private_get_accounts_account_id_addresses(&[__ws_arg_55]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut addressStructures: Value = self.parse_deposit_addresses(data, &[Value::Null, Value::Bool(false)]);
return self.index_by(addressStructures, Value::Str("network".into()));
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut address: Option<String> = self.safe_string_k_opt(depositAddress.clone(), "address", &[]);
self.check_address(&[address.clone().map(Value::from).unwrap_or(Value::Null)]);
let mut networkId: Option<String> = self.safe_string_k_opt(depositAddress.clone(), "network", &[]);
let mut code: Value = self.safe_currency_code(Value::Null, &[currency.clone()]);
let mut addressLabel: Option<String> = self.safe_string_k_opt(depositAddress.clone(), "address_label", &[]);
let mut currencyId: Value = Value::Null;
if (addressLabel.is_some()) {
let mut splitAddressLabel: Value = Value::Array(if let Some(__s) = addressLabel.as_deref() { __s.split(" ").map(Value::from).collect() } else { Vec::new() });
currencyId = self.safe_string(splitAddressLabel, Value::Int(0), &[]);
} else {
currencyId = self.safe_string_k(depositAddress.clone(), "currency", &[]);
}
let mut addressInfo: Value = self.safe_dict_k(depositAddress.clone(), "address_info", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress);
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("network".to_string(), self.network_id_to_code(&[networkId.map(Value::from).unwrap_or(Value::Null), code]));
m.insert("address".to_string(), address.map(Value::from).unwrap_or(Value::Null));
m.insert("tag".to_string(), self.safe_string_k(addressInfo, "destination_tag", &[]));
m
});
Value::Null
}
pub async fn deposit(&mut self, mut code: Value, mut amount: Value, mut id: 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 accountId: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("account_id".into()), Value::Str("accountId".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("account_id".into()), Value::Str("accountId".into())]), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("account_id".to_string(), accountId.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), self.number_to_string(amount));
m.insert("currency".to_string(), (if let Some(__s) = code.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }));
m.insert("payment_method".to_string(), id.clone());
m.insert("commit".to_string(), Value::Bool(true));
m
});
if (accountId.is_none()) {
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" deposit() requires an account_id (or accountId) parameter OR a currency code argument".into()))));
}
let mut foundAccountId: Value = self.find_account_id(code.clone(), &[paramsOmitted.clone()]).await;
if (foundAccountId == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" deposit() could not find account id for ".into())).into()), code)));
}
request.insert("account_id".into(), foundAccountId);
}
let __ws_arg_56 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v2_private_post_accounts_account_id_deposits(&[__ws_arg_56]).await;
let mut data: Value = self.safe_dict2(response, Value::Str("data".into()), Value::Str("transfer".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(data, &[]);
Value::Null
}
pub async fn fetch_deposit(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut code = 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 accountId: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("account_id".into()), Value::Str("accountId".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("account_id".into()), Value::Str("accountId".into())]), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("account_id".to_string(), accountId.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("deposit_id".to_string(), id.clone());
m
});
if (accountId.is_none()) {
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchDeposit() requires an account_id (or accountId) parameter OR a currency code argument".into()))));
}
let mut foundAccountId: Value = self.find_account_id(code.clone(), &[paramsOmitted.clone()]).await;
if (foundAccountId == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchDeposit() could not find account id for ".into())).into()), code)));
}
request.insert("account_id".into(), foundAccountId);
}
let __ws_arg_57 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v2_private_get_accounts_account_id_deposits_deposit_id(&[__ws_arg_57]).await;
let mut data: Value = self.safe_dict2(response, Value::Str("data".into()), Value::Str("transfer".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(data, &[]);
Value::Null
}
pub async fn fetch_deposit_method_ids(&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.v3_private_get_brokerage_payment_methods(&[params]).await;
let mut result: Value = self.safe_list_k(response, "payment_methods", &[Value::from(vec![])]);
return self.parse_deposit_method_ids(result, &[]);
Value::Null
}
pub async fn fetch_deposit_method_id(&mut self, mut id: 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 request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("payment_method_id".to_string(), id);
m
});
let __ws_arg_58 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_brokerage_payment_methods_payment_method_id(&[__ws_arg_58]).await;
let mut result: Value = self.safe_dict_k(response, "payment_method", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_method_id(result);
Value::Null
}
pub fn parse_deposit_method_ids(&self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __ids_empty = Vec::new();
let ids = ids.as_array().unwrap_or(&__ids_empty);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_548: bool = true;
while { if !__for_first_548 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_548 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
let __ws_arg_59 = self.parse_deposit_method_id(ids.get((i).as_i64().unwrap_or(-1) as usize).cloned().unwrap_or(Value::Null));
let mut id: Value = self.extend(__ws_arg_59, &[params.clone()]);
result.push(id);
}
}
return Value::from(result);
Value::Null
}
pub fn parse_deposit_method_id(&self, mut depositId: Value) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositId.clone());
m.insert("id".to_string(), self.safe_string_k(depositId.clone(), "id", &[]));
m.insert("currency".to_string(), self.safe_string_k(depositId.clone(), "currency", &[]));
m.insert("verified".to_string(), self.safe_bool_k(depositId.clone(), "verified", &[]));
m.insert("tag".to_string(), self.safe_string_k(depositId, "name", &[]));
m
});
Value::Null
}
pub async fn fetch_convert_quote(&mut self, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> Value {
let mut amount = 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.insert("from_account".to_string(), fromCode);
m.insert("to_account".to_string(), toCode);
m.insert("amount".to_string(), self.number_to_string(amount));
m
});
let __ws_arg_60 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_post_brokerage_convert_quote(&[__ws_arg_60]).await;
let mut data: Value = self.safe_dict_k(response, "trade", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_conversion(data, &[]);
Value::Null
}
pub async fn create_convert_trade(&mut self, mut id: Value, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> Value {
let mut amount = 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.insert("trade_id".to_string(), id);
m.insert("from_account".to_string(), fromCode);
m.insert("to_account".to_string(), toCode);
m
});
let __ws_arg_61 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_post_brokerage_convert_trade_trade_id(&[__ws_arg_61]).await;
let mut data: Value = self.safe_dict_k(response, "trade", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_conversion(data, &[]);
Value::Null
}
pub async fn fetch_convert_trade(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut code = 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;
}
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertTrade() requires a code argument".into()))));
}
let mut toCode: Option<String> = self.safe_string_k_opt(params.clone(), "toCode", &[]);
if (toCode.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertTrade() requires a toCode parameter".into()))));
}
let mut paramsOmitted: Value = self.omit(params, Value::Str("toCode".into()), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("trade_id".to_string(), id);
m.insert("from_account".to_string(), code);
m.insert("to_account".to_string(), toCode.map(Value::from).unwrap_or(Value::Null));
m
});
let __ws_arg_62 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v3_private_get_brokerage_convert_trade_trade_id(&[__ws_arg_62]).await;
let mut data: Value = self.safe_dict_k(response, "trade", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_conversion(data, &[]);
Value::Null
}
pub fn parse_conversion(&self, mut conversion: Value, optional_args: &[Value]) -> Value {
let mut fromCurrency = get_arg(optional_args, 0, Value::Null);
let mut toCurrency = get_arg(optional_args, 1, Value::Null);
let mut fromCoin: Option<String> = self.safe_string_k_opt(conversion.clone(), "source_currency", &[]);
let mut fromCode: Value = self.safe_currency_code(fromCoin.map(Value::from).unwrap_or(Value::Null), &[fromCurrency]);
let mut to: Option<String> = self.safe_string_k_opt(conversion.clone(), "target_currency", &[]);
let mut toCode: Value = self.safe_currency_code(to.map(Value::from).unwrap_or(Value::Null), &[toCurrency]);
let mut fromAmountStructure: Value = self.safe_dict_k(conversion.clone(), "user_entered_amount", &[]);
let mut feeStructure: Value = self.safe_dict_k(conversion.clone(), "total_fee", &[]);
let mut feeAmountStructure: Value = self.safe_dict_k(feeStructure, "amount", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), conversion.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("id".to_string(), self.safe_string_k(conversion, "id", &[]));
m.insert("fromCurrency".to_string(), fromCode);
m.insert("fromAmount".to_string(), self.safe_number_k(fromAmountStructure, "value", &[]));
m.insert("toCurrency".to_string(), toCode);
m.insert("toAmount".to_string(), Value::Null);
m.insert("price".to_string(), Value::Null);
m.insert("fee".to_string(), self.safe_number_k(feeAmountStructure, "value", &[]));
m
});
Value::Null
}
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut currency: Value = self.currency(code.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("funds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("value".to_string(), self.currency_to_precision(code, amount.clone(), &[]));
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
}));
m.insert("source_portfolio_uuid".to_string(), fromAccount);
m.insert("target_portfolio_uuid".to_string(), toAccount);
m
});
let __ws_arg_63 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_post_brokerage_portfolios_move_funds(&[__ws_arg_63]).await;
let mut transfer: Value = self.parse_transfer(response, &[currency]);
if let Value::Dict(__d) = &mut transfer { std::sync::Arc::make_mut(__d).insert("amount".into(), amount); }
if let Value::Dict(__d) = &mut transfer { std::sync::Arc::make_mut(__d).insert("status".into(), Value::Str("ok".into())); }
return transfer;
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyCode: Value = self.safe_currency_code(Value::Null, &[currency]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("currency".to_string(), currencyCode);
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), self.safe_string_k(transfer.clone(), "source_portfolio_uuid", &[]));
m.insert("toAccount".to_string(), self.safe_string_k(transfer, "target_portfolio_uuid", &[]));
m.insert("status".to_string(), Value::Null);
m
});
Value::Null
}
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol).as_map().cloned().unwrap_or_default();
let mut clientOrderId: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("client_order_id".into()), Value::Str("clientOrderId".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("clientOrderId".into()), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m
});
if (clientOrderId.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" closePosition() requires a clientOrderId parameter".into()))));
}
request.insert("client_order_id".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
let __ws_arg_64 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v3_private_post_brokerage_orders_close_position(&[__ws_arg_64]).await;
let mut order: Value = self.safe_dict_k(response, "success_response", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[]);
Value::Null
}
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_intx_portfolio_param(Value::Str("fetchPositions".into()), params.clone());
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.v3_private_get_brokerage_cfm_positions(&[params]).await;
let mut positions: Value = self.safe_list_k(response, "positions", &[Value::from(vec![])]);
return self.parse_positions(positions, &[symbolsNormalized]);
Value::Null
}
pub async fn fetch_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_intx_portfolio_param(Value::Str("fetchPosition".into()), params.clone());
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("product_id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_65 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_brokerage_cfm_positions_product_id(&[__ws_arg_65]).await;
let mut position: Value = self.safe_dict_k(response, "position", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_position(position, &[market]);
Value::Null
}
pub fn check_intx_portfolio_param(&self, mut methodName: Value, mut params: Value) {
let __params_empty = indexmap::IndexMap::new();
let params = params.as_map().unwrap_or(&__params_empty);
let mut portfolio: Option<String> = (match params.get("portfolio") { 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 }).as_str().map(str::to_owned);
if (portfolio.is_some()) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() INTX perpetuals were removed from Coinbase Advanced Trade on 2026-10-01, use the coinbaseinternational exchange class for international perpetuals".into()))));
}
}
pub fn parse_position(&self, mut position: 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(position.clone(), "product_id", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone().map(Value::from).unwrap_or(Value::Null), market]);
let mut rawSide: Option<String> = self.safe_string_k(position.clone(), "side", &[]).as_str().map(str::to_owned);
let mut side: Value = Value::Null;
if (rawSide.as_deref() == Some("LONG")) {
side = Value::Str("long".into());
} else if (rawSide.as_deref() == Some("SHORT")) {
side = Value::Str("short".into());
}
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_k(position.clone(), "product_id", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[marketResolved.clone()]));
m.insert("notional".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), Value::Null);
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "avg_entry_price", &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealized_pnl", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "daily_realized_pnl", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "number_of_contracts", &[]));
m.insert("contractSize".to_string(), marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null));
m.insert("markPrice".to_string(), self.safe_number_k(position, "current_price", &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
pub 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 type_varparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchTradingFees".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 isSpot: bool = type_var.as_str() == Some("spot");
let mut productType: String = "FUTURE".to_string();
if isSpot {
productType = "SPOT".to_string();
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("product_type".to_string(), Value::from(productType.clone()));
m
});
let __ws_arg_66 = self.extend(Value::Map(request), &[paramsMarketType]);
let mut response: Value = self.v3_private_get_brokerage_transaction_summary(&[__ws_arg_66]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "fee_tier", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut taker_fee: Value = self.safe_number_k(data.clone(), "taker_fee_rate", &[]);
let mut maker_fee: Value = self.safe_number_k(data, "maker_fee_rate", &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_549: bool = true;
while { if !__for_first_549 { i += 1; } __for_first_549 = false; i < (self.symbols.len() as i64) } {
let mut symbol: Value = self.safe_string(self.symbols.clone(), Value::Int(i), &[Value::Str("".into())]);
let mut market: Value = self.market(symbol.clone());
if (isSpot && matches!((self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)])), Value::Bool(true))) || (!isSpot && (!matches!(self.safe_bool_k(market, "spot", &[Value::Bool(false)]), Value::Bool(true)))) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), maker_fee.clone());
m.insert("taker".to_string(), taker_fee.clone());
m.insert("percentage".to_string(), Value::Bool(true));
m
})); }
}
}
}
return result;
Value::Null
}
pub async fn fetch_portfolio_details(&mut self, mut portfolioUuid: 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 request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("portfolio_uuid".to_string(), portfolioUuid);
m
});
let __ws_arg_67 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_brokerage_portfolios_portfolio_uuid(&[__ws_arg_67]).await;
let mut result: Value = self.parse_portfolio_details(response);
return result;
Value::Null
}
pub fn parse_portfolio_details(&self, mut portfolioData: Value) -> Value {
let __portfolioData_empty = indexmap::IndexMap::new();
let portfolioData = portfolioData.as_map().unwrap_or(&__portfolioData_empty);
let mut breakdown: Value = (match portfolioData.get("breakdown") { Some(__v) if matches!(__v, Value::Dict(_)) => __v.clone(), _ => Value::Null });
let mut portfolioInfo: Value = self.safe_dict_k(breakdown.clone(), "portfolio", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut portfolioName: Value = self.safe_string_k(portfolioInfo.clone(), "name", &[Value::Str("Unknown".into())]);
let mut portfolioUuid: Value = self.safe_string_k(portfolioInfo, "uuid", &[Value::Str("".into())]);
let mut spotPositions: Vec<Value> = self.safe_list_k(breakdown, "spot_positions", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut parsedPositions: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_550: bool = true;
while { if !__for_first_550 { i += 1; } __for_first_550 = false; i < (spotPositions.len() as i64) } {
let mut position: Value = spotPositions.get(i as usize).cloned().unwrap_or(Value::Null);
let mut currencyCode: Value = self.safe_string_k(position.clone(), "asset", &[Value::Str("Unknown".into())]);
let mut availableBalanceStr: Value = self.safe_string_k(position.clone(), "available_to_trade_fiat", &[Value::Str("0".into())]);
let mut availableBalance: Value = self.parse_number(availableBalanceStr, &[]);
let mut totalBalanceFiatStr: Value = self.safe_string_k(position.clone(), "total_balance_fiat", &[Value::Str("0".into())]);
let mut totalBalanceFiat: Value = self.parse_number(totalBalanceFiatStr, &[]);
let mut holdAmount: Value = Value::Int(0);
if (totalBalanceFiat != Value::Null) && (availableBalance != Value::Null) && (totalBalanceFiat.as_f64().unwrap_or(f64::NAN) > availableBalance.as_f64().unwrap_or(f64::NAN)) {
holdAmount = (match (&(totalBalanceFiat), &(availableBalance)) { (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 costBasisDict: Value = self.safe_dict_k(position.clone(), "cost_basis", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut costBasisStr: Value = self.safe_string_k(costBasisDict.clone(), "value", &[Value::Str("0".into())]);
let mut averageEntryPriceDict: Value = self.safe_dict_k(position.clone(), "average_entry_price", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut averageEntryPriceStr: Value = self.safe_string_k(averageEntryPriceDict.clone(), "value", &[Value::Str("0".into())]);
let mut positionData: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currencyCode);
m.insert("available_balance".to_string(), availableBalance);
m.insert("hold_amount".to_string(), holdAmount);
m.insert("wallet_name".to_string(), portfolioName.clone());
m.insert("account_id".to_string(), portfolioUuid.clone());
m.insert("account_uuid".to_string(), self.safe_string_k(position.clone(), "account_uuid", &[Value::Str("".into())]));
m.insert("total_balance_fiat".to_string(), totalBalanceFiat);
m.insert("total_balance_crypto".to_string(), self.parse_number(self.safe_string_k(position.clone(), "total_balance_crypto", &[Value::Str("0".into())]), &[]));
m.insert("available_to_trade_fiat".to_string(), self.parse_number(self.safe_string_k(position.clone(), "available_to_trade_fiat", &[Value::Str("0".into())]), &[]));
m.insert("available_to_trade_crypto".to_string(), self.parse_number(self.safe_string_k(position.clone(), "available_to_trade_crypto", &[Value::Str("0".into())]), &[]));
m.insert("available_to_transfer_fiat".to_string(), self.parse_number(self.safe_string_k(position.clone(), "available_to_transfer_fiat", &[Value::Str("0".into())]), &[]));
m.insert("available_to_transfer_crypto".to_string(), self.parse_number(self.safe_string_k(position.clone(), "available_to_trade_crypto", &[Value::Str("0".into())]), &[]));
m.insert("allocation".to_string(), self.parse_number(self.safe_string_k(position.clone(), "allocation", &[Value::Str("0".into())]), &[]));
m.insert("cost_basis".to_string(), self.parse_number(costBasisStr, &[]));
m.insert("cost_basis_currency".to_string(), self.safe_string_k(costBasisDict, "currency", &[Value::Str("USD".into())]));
m.insert("is_cash".to_string(), self.safe_bool_k(position.clone(), "is_cash", &[Value::Bool(false)]));
m.insert("average_entry_price".to_string(), self.parse_number(averageEntryPriceStr, &[]));
m.insert("average_entry_price_currency".to_string(), self.safe_string_k(averageEntryPriceDict, "currency", &[Value::Str("USD".into())]));
m.insert("asset_uuid".to_string(), self.safe_string_k(position.clone(), "asset_uuid", &[Value::Str("".into())]));
m.insert("unrealized_pnl".to_string(), self.parse_number(self.safe_string_k(position.clone(), "unrealized_pnl", &[Value::Str("0".into())]), &[]));
m.insert("asset_color".to_string(), self.safe_string_k(position.clone(), "asset_color", &[Value::Str("".into())]));
m.insert("account_type".to_string(), self.safe_string_k(position, "account_type", &[Value::Str("".into())]));
m
});
parsedPositions.push(positionData);
}
}
return Value::from(parsedPositions);
Value::Null
}
pub fn is_eddsa_api_key(&self) -> Value {
return Value::Bool((Value::Int(self.secret.len() as i64).as_f64() == Some(88.0)) || self.safe_bool_k(self.options.clone(), "v2CloudAPiKey", &[Value::Bool(false)]).as_bool() == Some(true) || (self.secret.as_str().unwrap_or("").ends_with("=")));
Value::Null
}
pub fn create_auth_token(&self, mut seconds: Value, mut url: Value, optional_args: &[Value]) -> Value {
let mut method = get_arg(optional_args, 0, Value::Null);
let useEddsa: bool = get_arg(optional_args, 1, Value::Bool(false)).is_truthy();
let mut uri: Value = Value::Null;
if (url.as_str() != Some("")) {
uri = Value::Str(format!("{}{}", Value::Str(format!("{}{}", method, Value::Str(" ".into())).into()), url.as_str().map(|__s| Value::Str(__s.replace("https://", "").into())).unwrap_or_else(|| url.clone())).into());
let mut quesPos: Value = Value::Int(uri.as_str().and_then(|__s| __s.find("?")).map(|__i| __i as i64).unwrap_or(-1));
if quesPos.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
uri = (match (&(uri), 0i64, (match &(quesPos) { 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 });
}
}
let mut nonce: Value = self.random_bytes(Value::Int(16));
let mut aud: String = "retail_rest_api_proxy".to_string();
if useEddsa {
aud = "cdp_service".to_string();
}
let mut iss: String = "coinbase-cloud".to_string();
if useEddsa {
iss = "cdp".to_string();
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("aud".to_string(), Value::from(vec![Value::from(aud)]));
m.insert("iss".to_string(), Value::from(iss));
m.insert("nbf".to_string(), seconds.clone());
m.insert("exp".to_string(), (match (&(seconds), &(Value::Int(120))) { (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.insert("sub".to_string(), self.apiKey.clone());
m.insert("iat".to_string(), seconds);
m
});
if (uri != Value::Null) {
if !useEddsa {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("uri".into(), uri.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("uris".into(), Value::from(vec![uri])); }
}
}
if useEddsa {
let mut byteArray: Value = self.base64_to_binary(self.secret.clone(), &[]);
let mut seed: Value = self.array_slice(byteArray, Value::Int(0), &[Value::Int(32)]);
return jwt(request.clone(), seed, Value::Str("sha256".into()), Value::Bool(false), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("kid".to_string(), self.apiKey.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("alg".to_string(), Value::Str("EdDSA".into()));
m
}));
} else {
return jwt(request, self.encode(self.secret.clone()), Value::Str("sha256".into()), Value::Bool(false), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("kid".to_string(), self.apiKey.clone());
m.insert("nonce".to_string(), nonce);
m.insert("alg".to_string(), Value::Str("ES256".into()));
m
}));
}
Value::Null
}
pub fn nonce(&self) -> Value {
let mut timeDifference: Value = self.safe_integer_k(self.options.clone(), "timeDifference", &[]);
if (timeDifference == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" nonce() requires a numeric options[\"timeDifference\"]".into()))));
}
return (match (&(self.milliseconds()), &(timeDifference)) { (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::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![]));
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 requestBody: Value = Value::Null;
let mut requestHeaders: Value = Value::Null;
let mut version: Option<String> = api.get(0).and_then(Value::as_str).map(str::to_owned);
let mut signed: bool = api.get(1).cloned().unwrap_or(Value::Null).as_str() == Some("private");
let mut isV3: bool = version.as_deref() == Some("v3");
let mut pathPart: String = "v2".to_string();
if isV3 {
pathPart = "api/v3".to_string();
}
let mut fullPath: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("/".into()), pathPart).into()), Value::Str("/".into())).into()), self.implode_params(path.clone(), params.clone())).into());
let mut query: Value = self.omit(params, self.extract_params(path), &[]);
let mut savedPath: Value = fullPath.clone();
let mut queryLength: f64 = ((Value::Array(query.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).len() as i64) as f64);
if (method.as_str() == Some("GET")) {
if queryLength > ((0i64) as f64) {
fullPath = Value::Str(format!("{}{}", fullPath, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode_with_array_repeat(query.clone())).into())).into());
}
}
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!("{}{}", apiUrl.map(Value::from).unwrap_or(Value::Null), fullPath).into());
if signed {
let mut authorization: Option<String> = self.safe_string_k_opt(self.headers.clone(), "Authorization", &[]);
let mut authorizationString: Value = Value::Null;
if (authorization.is_some()) {
authorizationString = authorization.map(Value::from).unwrap_or(Value::Null);
} else if (self.token.as_str() != Some("")) && !(self.check_required_credentials(&[Value::Bool(false)]).as_bool() == Some(true)) {
authorizationString = Value::Str(format!("{}{}", Value::Str("Bearer ".into()), self.token.clone()).into());
} else {
self.check_required_credentials(&[]);
let mut seconds: Value = self.seconds();
let mut payload: Value = Value::Str("".into());
if (method.as_str() != Some("GET")) {
if queryLength > ((0i64) as f64) {
payload = json_stringify(&query);
requestBody = payload.clone();
}
} else {
if !isV3 {
if queryLength > ((0i64) as f64) {
payload = Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into());
}
}
}
let mut isCloudAPiKey: bool = (self.apiKey.as_str().unwrap_or("").contains("organizations/")) || (self.secret.as_str().unwrap_or("").starts_with("-----BEGIN"));
let mut isV2CloudAPiKey: Value = self.is_eddsa_api_key();
if isCloudAPiKey || isV2CloudAPiKey.as_bool() == Some(true) {
if isCloudAPiKey && (self.apiKey.as_str().unwrap_or("").starts_with("-----BEGIN")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" apiKey should contain the name (eg: organizations/3b910e93....) and not the public key".into()))));
}
let mut token: Value = self.create_auth_token(seconds, url.clone(), &[method.clone(), isV2CloudAPiKey]);
authorizationString = Value::Str(format!("{}{}", Value::Str("Bearer ".into()), token).into());
} else {
let mut nonce: Value = self.parse_to_int(self.nonce());
let mut timestamp: Value = self.parse_to_int((match ((nonce).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
let mut timestampString: Value = Value::Str(format!("{}", timestamp).into());
let mut auth: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", timestampString, method).into()), savedPath).into()), payload).into());
let mut signature: Value = self.hmac(self.encode(auth), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[]);
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CB-ACCESS-KEY".to_string(), self.apiKey.clone());
m.insert("CB-ACCESS-SIGN".to_string(), signature);
m.insert("CB-ACCESS-TIMESTAMP".to_string(), timestampString);
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
}
}
if (authorizationString != Value::Null) {
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Authorization".to_string(), authorizationString);
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
if (method.as_str() != Some("GET")) {
if queryLength > ((0i64) as f64) {
requestBody = json_stringify(&query);
}
}
}
}
let mut bodyResolved: Value = requestBody;
let mut headersResolved: Value = requestHeaders;
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(), bodyResolved);
m.insert("headers".to_string(), headersResolved);
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
let mut errorCode: Option<String> = self.safe_string_k_opt(response.clone(), "error", &[]);
if (errorCode.is_some()) {
let mut errorMessage: Option<String> = self.safe_string2_opt(response.clone(), Value::Str("error_description".into()), Value::Str("error".into()), &[]);
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode.clone().map(Value::from).unwrap_or(Value::Null), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), errorMessage.map(Value::from).unwrap_or(Value::Null), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut errorResponse: Value = self.safe_dict_k(response.clone(), "error_response", &[]);
if (errorResponse != Value::Null) {
let mut errorMessageInner: Option<String> = self.safe_string2_opt(errorResponse, Value::Str("preview_failure_reason".into()), Value::Str("preview_failure_reason".into()), &[]);
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorMessageInner.clone().map(Value::from).unwrap_or(Value::Null), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), errorMessageInner.map(Value::from).unwrap_or(Value::Null), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut errors: Value = self.safe_list_k(response.clone(), "errors", &[Value::from(vec![])]);
if (errors != Value::Null) {
let mut numErrors: f64 = ((errors.len() as i64) as f64);
if numErrors > ((0i64) as f64) {
errorCode = self.safe_string_opt(errors.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), Value::Str("id".into()), &[]);
let mut errorMessage: Option<String> = self.safe_string_opt(errors.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), Value::Str("message".into()), &[]);
if (errorCode.is_some()) {
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode.map(Value::from).unwrap_or(Value::Null), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), errorMessage.map(Value::from).unwrap_or(Value::Null), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
}
}
let mut advancedTrade: bool = self.safe_bool_k_opt(self.options.clone(), "advanced", &[Value::Bool(false)]).unwrap_or(false);
if !(in_op(&response, &Value::Str("data".into()))) && !(advancedTrade) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" failed due to a malformed response ".into())).into()), json_stringify(&response))));
}
return Value::Null;
Value::Null
}
pub async fn fetch_deposit_addresses(&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: Value = self.prepare_account_request(&[Value::Null, params.clone()]);
let __ws_arg_68 = self.extend(request, &[params]);
let mut response: Value = self.v2_private_get_accounts_account_id_addresses(&[__ws_arg_68]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_deposit_addresses(data, &[codes, Value::Bool(false), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
Value::Null
}
}