// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
// Generated from `ts/src/base/Exchange.ts` — methods below the
// "METHODS BELOW THIS LINE ARE TRANSPILED" marker. Everything
// above the marker is hand-written (src/exchange.rs / src/prediction_exchange.rs).
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::ExchangeError;
use crate::exchange::Exchange;
use crate::exchange::ExchangeRuntime;
use crate::exchange::CallDynamicChecked;
use crate::runtime::*;
pub trait ExchangeBase:
crate::exchange::DerivedExchange
+ std::ops::DerefMut<Target = Exchange>
+ Send
+ Sized
{
/// Dispatch a snake_case method name to this core's inherent async
/// methods, falling through to `call_dynamic_base` for base-only methods.
/// The single required method — every override reaches the core statically.
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>>;
/// Route `method(args)` to the derived override by name, with a per-method
/// re-entry guard (so a base method calling its own name falls through to
/// the base body instead of looping). Replaces `Exchange::dispatch_to_derived`
/// — no stored pointer; `call_dynamic` is a static trait call.
fn dispatch_to_derived<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = Option<crate::Value>> + Send + 'a>>
{
Box::pin(async move {
if !self.dispatch_guard_enter(method) { return None; }
let out = futures::FutureExt::catch_unwind(
std::panic::AssertUnwindSafe(self.call_dynamic(method, args))
).await;
self.dispatch_guard_exit();
match out {
Ok(v) => Some(v),
Err(p) => std::panic::resume_unwind(p),
}
})
}
/// `isDictionary(value)` — hand-provided base method. The ast-transpiler
/// drops `Exchange.ts`'s `typeof value === 'object'` body, so supply it here
/// as a trait default reachable by every Core (used across the base +
/// derived exchanges).
fn is_dictionary(&self, value: crate::Value) -> crate::Value {
crate::Value::Bool(
!crate::runtime::is_equal(&value, &crate::Value::Null)
&& crate::runtime::is_object(&value)
&& !crate::runtime::is_array(&value)
)
}
fn describe(&self) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.id.clone());
m.insert("name".to_string(), self.name.clone());
m.insert("countries".to_string(), self.countries.clone());
m.insert("enableRateLimit".to_string(), self.enableRateLimit.clone());
m.insert("rateLimit".to_string(), self.rateLimit.clone());
m.insert("rateLimiterAlgorithm".to_string(), self.rateLimiterAlgorithm.clone());
m.insert("timeout".to_string(), self.timeout.clone());
m.insert("certified".to_string(), self.certified.clone());
m.insert("pro".to_string(), self.pro.clone());
m.insert("alias".to_string(), self.alias.clone());
m.insert("dex".to_string(), Value::Bool(false));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("publicAPI".to_string(), Value::Bool(true));
m.insert("privateAPI".to_string(), Value::Bool(true));
m.insert("CORS".to_string(), Value::Null);
m.insert("sandbox".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Null);
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), Value::Null);
m.insert("future".to_string(), Value::Null);
m.insert("option".to_string(), Value::Null);
m.insert("index".to_string(), Value::Null);
m.insert("addMargin".to_string(), Value::Null);
m.insert("borrowCrossMargin".to_string(), Value::Null);
m.insert("borrowIsolatedMargin".to_string(), Value::Null);
m.insert("borrowMargin".to_string(), Value::Null);
m.insert("cancelAllOrders".to_string(), Value::Null);
m.insert("cancelAllOrdersWs".to_string(), Value::Null);
m.insert("cancelOrder".to_string(), Value::Null);
m.insert("cancelOrderWithClientOrderId".to_string(), Value::Null);
m.insert("cancelOrderWs".to_string(), Value::Null);
m.insert("cancelOrders".to_string(), Value::Null);
m.insert("cancelOrdersWithClientOrderId".to_string(), Value::Null);
m.insert("cancelOrdersWs".to_string(), Value::Null);
m.insert("closeAllPositions".to_string(), Value::Null);
m.insert("closePosition".to_string(), Value::Null);
m.insert("createDepositAddress".to_string(), Value::Null);
m.insert("createLimitBuyOrder".to_string(), Value::Null);
m.insert("createLimitBuyOrderWs".to_string(), Value::Null);
m.insert("createLimitOrder".to_string(), Value::Null);
m.insert("createLimitOrderWs".to_string(), Value::Null);
m.insert("createLimitSellOrder".to_string(), Value::Null);
m.insert("createLimitSellOrderWs".to_string(), Value::Null);
m.insert("createMarketBuyOrder".to_string(), Value::Null);
m.insert("createMarketBuyOrderWs".to_string(), Value::Null);
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Null);
m.insert("createMarketBuyOrderWithCostWs".to_string(), Value::Null);
m.insert("createMarketOrder".to_string(), Value::Null);
m.insert("createMarketOrderWs".to_string(), Value::Null);
m.insert("createMarketOrderWithCost".to_string(), Value::Null);
m.insert("createMarketOrderWithCostWs".to_string(), Value::Null);
m.insert("createMarketSellOrder".to_string(), Value::Null);
m.insert("createMarketSellOrderWs".to_string(), Value::Null);
m.insert("createMarketSellOrderWithCost".to_string(), Value::Null);
m.insert("createMarketSellOrderWithCostWs".to_string(), Value::Null);
m.insert("createOrder".to_string(), Value::Null);
m.insert("createOrderWs".to_string(), Value::Null);
m.insert("createOrders".to_string(), Value::Null);
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Null);
m.insert("createOrderWithTakeProfitAndStopLossWs".to_string(), Value::Null);
m.insert("createPostOnlyOrder".to_string(), Value::Null);
m.insert("createPostOnlyOrderWs".to_string(), Value::Null);
m.insert("createReduceOnlyOrder".to_string(), Value::Null);
m.insert("createReduceOnlyOrderWs".to_string(), Value::Null);
m.insert("createStopLimitOrder".to_string(), Value::Null);
m.insert("createStopLimitOrderWs".to_string(), Value::Null);
m.insert("createStopLossOrder".to_string(), Value::Null);
m.insert("createStopLossOrderWs".to_string(), Value::Null);
m.insert("createStopMarketOrder".to_string(), Value::Null);
m.insert("createStopMarketOrderWs".to_string(), Value::Null);
m.insert("createStopOrder".to_string(), Value::Null);
m.insert("createStopOrderWs".to_string(), Value::Null);
m.insert("createTakeProfitOrder".to_string(), Value::Null);
m.insert("createTakeProfitOrderWs".to_string(), Value::Null);
m.insert("createTrailingAmountOrder".to_string(), Value::Null);
m.insert("createTrailingAmountOrderWs".to_string(), Value::Null);
m.insert("createTrailingPercentOrder".to_string(), Value::Null);
m.insert("createTrailingPercentOrderWs".to_string(), Value::Null);
m.insert("createTriggerOrder".to_string(), Value::Null);
m.insert("createTriggerOrderWs".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("editOrder".to_string(), Value::Str("emulated".into()));
m.insert("editOrderWithClientOrderId".to_string(), Value::Null);
m.insert("editOrders".to_string(), Value::Null);
m.insert("editOrderWs".to_string(), Value::Null);
m.insert("fetchAccounts".to_string(), Value::Null);
m.insert("fetchADLRank".to_string(), Value::Null);
m.insert("fetchBalance".to_string(), Value::Null);
m.insert("fetchBalanceWs".to_string(), Value::Null);
m.insert("fetchBidsAsks".to_string(), Value::Null);
m.insert("fetchBorrowInterest".to_string(), Value::Null);
m.insert("fetchBorrowRate".to_string(), Value::Null);
m.insert("fetchBorrowRateHistories".to_string(), Value::Null);
m.insert("fetchBorrowRateHistory".to_string(), Value::Null);
m.insert("fetchBorrowRates".to_string(), Value::Null);
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Null);
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Null);
m.insert("fetchCanceledOrders".to_string(), Value::Null);
m.insert("fetchClosedOrder".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchClosedOrdersWs".to_string(), Value::Null);
m.insert("fetchConvertCurrencies".to_string(), Value::Null);
m.insert("fetchConvertQuote".to_string(), Value::Null);
m.insert("fetchConvertTrade".to_string(), Value::Null);
m.insert("fetchConvertTradeHistory".to_string(), Value::Null);
m.insert("fetchCrossBorrowRate".to_string(), Value::Null);
m.insert("fetchCrossBorrowRates".to_string(), Value::Null);
m.insert("fetchCurrencies".to_string(), Value::Str("emulated".into()));
m.insert("fetchCurrenciesWs".to_string(), Value::Str("emulated".into()));
m.insert("fetchDeposit".to_string(), Value::Null);
m.insert("fetchDepositAddress".to_string(), Value::Null);
m.insert("fetchDepositAddresses".to_string(), Value::Null);
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Null);
m.insert("fetchDeposits".to_string(), Value::Null);
m.insert("fetchDepositsWithdrawals".to_string(), Value::Null);
m.insert("fetchDepositsWs".to_string(), Value::Null);
m.insert("fetchDepositWithdrawFee".to_string(), Value::Null);
m.insert("fetchDepositWithdrawFees".to_string(), Value::Null);
m.insert("fetchFundingHistory".to_string(), Value::Null);
m.insert("fetchFundingRate".to_string(), Value::Null);
m.insert("fetchFundingRateHistory".to_string(), Value::Null);
m.insert("fetchFundingInterval".to_string(), Value::Null);
m.insert("fetchFundingIntervals".to_string(), Value::Null);
m.insert("fetchFundingRates".to_string(), Value::Null);
m.insert("fetchGreeks".to_string(), Value::Null);
m.insert("fetchIndexOHLCV".to_string(), Value::Null);
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Null);
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Null);
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Null);
m.insert("fetchIsolatedPositions".to_string(), Value::Null);
m.insert("fetchL2OrderBook".to_string(), Value::Null);
m.insert("fetchL3OrderBook".to_string(), Value::Null);
m.insert("fetchLastPrices".to_string(), Value::Null);
m.insert("fetchLedger".to_string(), Value::Null);
m.insert("fetchLedgerEntry".to_string(), Value::Null);
m.insert("fetchLeverage".to_string(), Value::Null);
m.insert("fetchLeverages".to_string(), Value::Null);
m.insert("fetchLeverageTiers".to_string(), Value::Null);
m.insert("fetchLiquidations".to_string(), Value::Null);
m.insert("fetchLongShortRatio".to_string(), Value::Null);
m.insert("fetchLongShortRatioHistory".to_string(), Value::Null);
m.insert("fetchMarginMode".to_string(), Value::Null);
m.insert("fetchMarginModes".to_string(), Value::Null);
m.insert("fetchMarketLeverageTiers".to_string(), Value::Null);
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarketsWs".to_string(), Value::Null);
m.insert("fetchMarkOHLCV".to_string(), Value::Null);
m.insert("fetchMyLiquidations".to_string(), Value::Null);
m.insert("fetchMySettlementHistory".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Null);
m.insert("fetchMyTradesWs".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Null);
m.insert("fetchOHLCVWs".to_string(), Value::Null);
m.insert("fetchOpenInterest".to_string(), Value::Null);
m.insert("fetchOpenInterests".to_string(), Value::Null);
m.insert("fetchOpenInterestHistory".to_string(), Value::Null);
m.insert("fetchOpenOrder".to_string(), Value::Null);
m.insert("fetchOpenOrders".to_string(), Value::Null);
m.insert("fetchOpenOrdersWs".to_string(), Value::Null);
m.insert("fetchOption".to_string(), Value::Null);
m.insert("fetchOptionChain".to_string(), Value::Null);
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOrderWithClientOrderId".to_string(), Value::Null);
m.insert("fetchOrderBook".to_string(), Value::Null);
m.insert("fetchOrderBooks".to_string(), Value::Null);
m.insert("fetchOrderBookWs".to_string(), Value::Null);
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchOrdersByStatus".to_string(), Value::Null);
m.insert("fetchOrdersWs".to_string(), Value::Null);
m.insert("fetchOrderTrades".to_string(), Value::Null);
m.insert("fetchOrderWs".to_string(), Value::Null);
m.insert("fetchPosition".to_string(), Value::Null);
m.insert("fetchPositionADLRank".to_string(), Value::Null);
m.insert("fetchPositionsADLRank".to_string(), Value::Null);
m.insert("fetchPositionHistory".to_string(), Value::Null);
m.insert("fetchPositionsHistory".to_string(), Value::Null);
m.insert("fetchPositionWs".to_string(), Value::Null);
m.insert("fetchPositionMode".to_string(), Value::Null);
m.insert("fetchPositions".to_string(), Value::Null);
m.insert("fetchPositionsWs".to_string(), Value::Null);
m.insert("fetchPositionsForSymbol".to_string(), Value::Null);
m.insert("fetchPositionsForSymbolWs".to_string(), Value::Null);
m.insert("fetchPositionsRisk".to_string(), Value::Null);
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Null);
m.insert("fetchSettlementHistory".to_string(), Value::Null);
m.insert("fetchStatus".to_string(), Value::Null);
m.insert("fetchTicker".to_string(), Value::Str("emulated".into()));
m.insert("fetchTickerWs".to_string(), Value::Null);
m.insert("fetchTickers".to_string(), Value::Null);
m.insert("fetchMarkPrices".to_string(), Value::Null);
m.insert("fetchTickersWs".to_string(), Value::Null);
m.insert("fetchTime".to_string(), Value::Null);
m.insert("fetchTrades".to_string(), Value::Null);
m.insert("fetchTradesWs".to_string(), Value::Null);
m.insert("fetchTradingFee".to_string(), Value::Null);
m.insert("fetchTradingFees".to_string(), Value::Null);
m.insert("fetchTradingFeesWs".to_string(), Value::Null);
m.insert("fetchTradingLimits".to_string(), Value::Null);
m.insert("fetchTransactionFee".to_string(), Value::Null);
m.insert("fetchTransactionFees".to_string(), Value::Null);
m.insert("fetchTransactions".to_string(), Value::Null);
m.insert("fetchTransfer".to_string(), Value::Null);
m.insert("fetchTransfers".to_string(), Value::Null);
m.insert("fetchUnderlyingAssets".to_string(), Value::Null);
m.insert("fetchVolatilityHistory".to_string(), Value::Null);
m.insert("fetchWithdrawAddresses".to_string(), Value::Null);
m.insert("fetchWithdrawal".to_string(), Value::Null);
m.insert("fetchWithdrawals".to_string(), Value::Null);
m.insert("fetchWithdrawalsWs".to_string(), Value::Null);
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Null);
m.insert("reduceMargin".to_string(), Value::Null);
m.insert("repayCrossMargin".to_string(), Value::Null);
m.insert("repayIsolatedMargin".to_string(), Value::Null);
m.insert("setLeverage".to_string(), Value::Null);
m.insert("setMargin".to_string(), Value::Null);
m.insert("setMarginMode".to_string(), Value::Null);
m.insert("setPositionMode".to_string(), Value::Null);
m.insert("signIn".to_string(), Value::Null);
m.insert("transfer".to_string(), Value::Null);
m.insert("watchBalance".to_string(), Value::Null);
m.insert("watchMyTrades".to_string(), Value::Null);
m.insert("watchOHLCV".to_string(), Value::Null);
m.insert("watchOHLCVForSymbols".to_string(), Value::Null);
m.insert("watchOrderBook".to_string(), Value::Null);
m.insert("watchBidsAsks".to_string(), Value::Null);
m.insert("watchOrderBookForSymbols".to_string(), Value::Null);
m.insert("watchOrders".to_string(), Value::Null);
m.insert("watchOrdersForSymbols".to_string(), Value::Null);
m.insert("watchPosition".to_string(), Value::Null);
m.insert("watchPositions".to_string(), Value::Null);
m.insert("watchStatus".to_string(), Value::Null);
m.insert("watchTicker".to_string(), Value::Null);
m.insert("watchTickers".to_string(), Value::Null);
m.insert("watchTrades".to_string(), Value::Null);
m.insert("watchTradesForSymbols".to_string(), Value::Null);
m.insert("watchLiquidations".to_string(), Value::Null);
m.insert("watchLiquidationsForSymbols".to_string(), Value::Null);
m.insert("watchMyLiquidations".to_string(), Value::Null);
m.insert("unWatchOrders".to_string(), Value::Null);
m.insert("unWatchTrades".to_string(), Value::Null);
m.insert("unWatchTradesForSymbols".to_string(), Value::Null);
m.insert("unWatchOHLCVForSymbols".to_string(), Value::Null);
m.insert("unWatchOrderBookForSymbols".to_string(), Value::Null);
m.insert("unWatchPositions".to_string(), Value::Null);
m.insert("unWatchOrderBook".to_string(), Value::Null);
m.insert("unWatchTickers".to_string(), Value::Null);
m.insert("unWatchMyTrades".to_string(), Value::Null);
m.insert("unWatchTicker".to_string(), Value::Null);
m.insert("unWatchOHLCV".to_string(), Value::Null);
m.insert("watchMyLiquidationsForSymbols".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("ws".to_string(), Value::Null);
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Null);
m.insert("api".to_string(), Value::Null);
m.insert("test".to_string(), Value::Null);
m.insert("www".to_string(), Value::Null);
m.insert("doc".to_string(), Value::Null);
m.insert("api_management".to_string(), Value::Null);
m.insert("fees".to_string(), Value::Null);
m.insert("referral".to_string(), Value::Null);
m
}));
m.insert("api".to_string(), Value::Null);
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.insert("uid".to_string(), Value::Bool(false));
m.insert("accountId".to_string(), Value::Bool(false));
m.insert("login".to_string(), Value::Bool(false));
m.insert("password".to_string(), Value::Bool(false));
m.insert("twofa".to_string(), Value::Bool(false));
m.insert("privateKey".to_string(), Value::Bool(false));
m.insert("walletAddress".to_string(), Value::Bool(false));
m.insert("token".to_string(), Value::Bool(false));
m
}));
m.insert("markets".to_string(), Value::Null);
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("timeframes".to_string(), Value::Null);
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("taker".to_string(), Value::Null);
m.insert("maker".to_string(), Value::Null);
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m.insert("status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("ok".into()));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), Value::Null);
m
}));
m.insert("exceptions".to_string(), Value::Null);
m.insert("httpExceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("422".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("418".to_string(), Value::Str("DDoSProtection".into()).clone());
m.insert("429".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("404".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("409".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("410".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("451".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("500".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("501".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("502".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("520".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("521".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("522".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("525".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("526".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("400".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("403".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("405".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("503".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("530".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("408".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("504".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("401".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("407".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("511".to_string(), Value::Str("AuthenticationError".into()).clone());
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("XBT".to_string(), Value::Str("BTC".into()));
m.insert("BCHSV".to_string(), Value::Str("BSV".into()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("paddingMode".to_string(), Value::Int(crate::runtime::NO_PADDING));
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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("rollingWindowSize".to_string(), Value::Int(60000));
m
});
Value::Null
}
fn clean_rest_data(&mut self) {
self.ids = Value::Null;
self.markets = Value::Null;
self.markets_by_id = Value::Null;
self.symbols = Value::from(vec![]);
self.codes = Value::Null;
{ let __t = self.create_safe_dictionary(&[]); self.currencies = __t; }
self.currencies_by_id = Value::Null;
self.baseCurrencies = Value::Null;
self.quoteCurrencies = Value::Null;
self.last_http_response = Value::Null;
// this.last_json_response = undefined; // not unified prop
self.last_response_headers = Value::Null;
self.last_request_headers = Value::Null;
}
fn clean_ws_data(&mut self) {
{ let __t = self.create_safe_dictionary(&[Value::Bool(true)]); self.balance = __t; }
{ let __t = self.create_safe_dictionary(&[Value::Bool(true)]); self.orderbooks = __t; }
{ let __t = self.create_safe_dictionary(&[Value::Bool(true)]); self.tickers = __t; }
self.liquidations = Value::Null;
self.myLiquidations = Value::Null;
self.orders = Value::Null;
{ let __t = self.create_safe_dictionary(&[Value::Bool(true)]); self.trades = __t; }
{ let __t = self.create_safe_dictionary(&[]); self.transactions = __t; }
{ let __t = self.create_safe_dictionary(&[Value::Bool(true)]); self.ohlcvs = __t; }
self.myTrades = Value::Null;
self.positions = Value::Null;
}
fn safe_bool_n(&self, mut dictionaryOrList: Value, mut keys: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract boolean value from dictionary or list
* @returns {bool | undefined}
*/
let mut value: Value = self.safe_value_n(dictionaryOrList, keys, &[defaultValue.clone()]);
if matches!(&value, Value::Bool(_)) {
return value;
}
return defaultValue;
Value::Null
}
fn safe_bool2(&self, mut dictionaryOrList: Value, mut key1: Value, mut key2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract boolean value from dictionary or list
* @returns {bool | undefined}
*/
let mut value: Value = self.safe_value(dictionaryOrList.clone(), key1, &[]);
if matches!(&value, Value::Bool(_)) {
return value;
}
let mut value2: Value = self.safe_value(dictionaryOrList, key2, &[]);
if matches!(&value2, Value::Bool(_)) {
return value2;
}
return defaultValue;
Value::Null
}
fn safe_bool(&self, mut dictionaryOrList: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract boolean value from dictionary or list
* @returns {bool | undefined}
*/
let mut value: Value = self.safe_value(dictionaryOrList, key, &[defaultValue.clone()]);
if matches!(&value, Value::Bool(_)) {
return value;
}
return defaultValue;
Value::Null
}
fn safe_dict_n(&self, mut dictionaryOrList: Value, mut keys: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract a dictionary from dictionary or list
* @returns {object | undefined}
*/
let mut value: Value = self.safe_value_n(dictionaryOrList, keys, &[defaultValue.clone()]);
if (value == Value::Null) {
return defaultValue;
}
if self.is_dictionary(value.clone()).as_bool() == Some(true) {
return value;
}
return defaultValue;
Value::Null
}
fn safe_dict(&self, mut dictionaryOrList: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract a dictionary from dictionary or list
* @returns {object | undefined}
*/
let mut value: Value = self.safe_value(dictionaryOrList, key, &[defaultValue.clone()]);
if (value == Value::Null) {
return defaultValue;
}
if self.is_dictionary(value.clone()).as_bool() == Some(true) {
return value;
}
return defaultValue;
Value::Null
}
fn safe_dict2(&self, mut dictionaryOrList: Value, mut key1: Value, mut key2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract a dictionary from dictionary or list
* @returns {object | undefined}
*/
let mut value: Value = self.safe_value(dictionaryOrList.clone(), key1, &[]);
if self.is_dictionary(value.clone()).as_bool() == Some(true) {
return value;
}
let mut value2: Value = self.safe_value(dictionaryOrList, key2, &[]);
if self.is_dictionary(value2.clone()).as_bool() == Some(true) {
return value2;
}
return defaultValue;
Value::Null
}
fn safe_list_n(&self, mut dictionaryOrList: Value, mut keys: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract an Array from dictionary or list
* @returns {Array | undefined}
*/
let mut value: Value = self.safe_value_n(dictionaryOrList, keys, &[defaultValue.clone()]);
if (value == Value::Null) {
return defaultValue;
}
if (matches!(&value, Value::Arr(_))) {
return value;
}
return defaultValue;
Value::Null
}
fn safe_list2(&self, mut dictionaryOrList: Value, mut key1: Value, mut key2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract an Array from dictionary or list
* @returns {Array | undefined}
*/
let mut value: Value = self.safe_value(dictionaryOrList.clone(), key1, &[]);
if (value != Value::Null) && (matches!(&value, Value::Arr(_))) {
return value;
}
let mut value2: Value = self.safe_value(dictionaryOrList, key2, &[]);
if (value2 != Value::Null) && (matches!(&value2, Value::Arr(_))) {
return value2;
}
return defaultValue;
Value::Null
}
fn safe_list(&self, mut dictionaryOrList: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @description safely extract an Array from dictionary or list
* @returns {Array | undefined}
*/
let mut value: Value = self.safe_value(dictionaryOrList, key, &[defaultValue.clone()]);
if (value == Value::Null) {
return defaultValue;
}
if (matches!(&value, Value::Arr(_))) {
return value;
}
return defaultValue;
Value::Null
}
fn store_by_key(&self, mut dict: Value, mut key: Value, mut value: Value) {
/*
* @ignore
* @method
* @description store value under key if key is defined (no-op on undefined)
*/
let mut k: Value = key.clone();
if (k != Value::Null) {
add_element_to_object(&mut dict, &k, value);
}
}
fn handle_deltas(&self, mut bookside: Value, mut deltas: Value) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_71: bool = true;
while { if !__for_first_71 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_71 = false; i.as_f64().unwrap_or(f64::NAN) < ((deltas.len() as i64) as f64) } {
self.handle_delta(bookside.clone(), deltas.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
}
}
}
fn handle_delta(&self, mut bookside: Value, mut delta: Value) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" handleDelta not supported yet".into()))));
}
fn handle_book_deltas(&self, mut orderbook: Value, mut deltas: Value) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_72: bool = true;
while { if !__for_first_72 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_72 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&deltas).as_f64().unwrap_or(f64::NAN) } {
self.handle_book_delta(orderbook.clone(), get_value(&deltas, &i));
}
}
}
fn handle_book_delta(&self, mut orderbook: Value, mut delta: Value) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" handleBookDelta not supported yet".into()))));
}
fn handle_deltas_with_keys(&self, mut bookSide: Value, mut deltas: Value, optional_args: &[Value]) {
let mut priceKey = get_arg(optional_args, 0, Value::Int(0));
let mut amountKey = get_arg(optional_args, 1, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 2, Value::Int(2));
{
let mut i: Value = Value::Int(0);
let mut __for_first_73: bool = true;
while { if !__for_first_73 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_73 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&deltas).as_f64().unwrap_or(f64::NAN) } {
let mut bidAsk: Value = self.parse_order_book_bid_ask(get_value(&deltas, &i), &[priceKey.clone(), amountKey.clone(), countOrIdKey.clone()]);
bookSide.store_array(bidAsk);
}
}
}
fn get_cache_index(&self, mut orderbook: Value, mut deltas: Value) -> Value {
return Value::Int(-1);
Value::Null
}
fn arrays_concat(&self, mut arraysOfArrays: Value) -> Value {
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_74: bool = true;
while { if !__for_first_74 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_74 = false; i.as_f64().unwrap_or(f64::NAN) < ((arraysOfArrays.len() as i64) as f64) } {
result = self.array_concat(result.clone(), arraysOfArrays.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
}
}
return result;
Value::Null
}
fn find_timeframe(&self, mut timeframe: Value, optional_args: &[Value]) -> Value {
let mut timeframes = get_arg(optional_args, 0, Value::Null);
let mut timeframesResolved: Value = (if (timeframes == Value::Null) { self.timeframes.clone() } else { timeframes });
let mut keys: Value = object_keys(&timeframesResolved);
{
let mut i: Value = Value::Int(0);
let mut __for_first_75: bool = true;
while { if !__for_first_75 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_75 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if is_equal(&timeframesResolved.as_map().and_then(|__m| key.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), &timeframe) {
return key;
}
}
}
return Value::Null;
Value::Null
}
fn check_proxy_url_settings(&self, optional_args: &[Value]) -> Value {
let mut url = get_arg(optional_args, 0, Value::Null);
let mut method = get_arg(optional_args, 1, Value::Null);
let mut headers = get_arg(optional_args, 2, Value::Null);
let mut body = get_arg(optional_args, 3, Value::Null);
let mut usedProxies: Vec<Value> = Vec::new();
let mut proxyUrl: Value = Value::Null;
if (self.proxyUrl.clone() != Value::Null) {
usedProxies.push(Value::Str("proxyUrl".into()));
proxyUrl = self.proxyUrl.clone();
}
if (self.proxy_url.clone() != Value::Null) {
usedProxies.push(Value::Str("proxy_url".into()));
proxyUrl = self.proxy_url.clone();
}
if (self.proxyUrlCallback.clone() != Value::Null) {
usedProxies.push(Value::Str("proxyUrlCallback".into()));
proxyUrl = self.proxy_url_callback_fn(url.clone(), method.clone(), headers.clone(), body.clone());
}
if (self.proxy_url_callback.clone() != Value::Null) {
usedProxies.push(Value::Str("proxy_url_callback".into()));
proxyUrl = self.proxy_url_callback_fn(url.clone(), method.clone(), headers.clone(), body.clone());
}
// backwards-compatibility
if (self.proxy.clone() != Value::Null) {
usedProxies.push(Value::Str("proxy".into()));
if is_function(&self.proxy) {
proxyUrl = self.proxy_fn(url, method, headers, body);
} else {
proxyUrl = self.proxy.clone();
}
}
let mut length: f64 = ((usedProxies.len() as i64) as f64);
if length > ((1i64) as f64) {
let mut joinedProxyNames: Value = Value::Str(usedProxies.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",").into());
panic!("{}", crate::exchange_errors::invalid_proxy_settings(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" you have multiple conflicting proxy settings (".into())).into()), joinedProxyNames).into()), Value::Str("), please use only one from : proxyUrl, proxy_url, proxyUrlCallback, proxy_url_callback".into()))));
}
return proxyUrl;
Value::Null
}
fn url_encoder_for_proxy_url(&self, mut targetUrl: Value) -> Value {
// to be overriden
let mut includesQuery: bool = Value::Int(targetUrl.as_str().and_then(|__s| __s.find("?")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64);
let mut finalUrl: Value = (if includesQuery { self.encode_uri_component(targetUrl.clone()) } else { targetUrl });
return finalUrl;
Value::Null
}
fn check_proxy_settings(&self, optional_args: &[Value]) -> Value {
let mut url = get_arg(optional_args, 0, Value::Null);
let mut method = get_arg(optional_args, 1, Value::Null);
let mut headers = get_arg(optional_args, 2, Value::Null);
let mut body = get_arg(optional_args, 3, Value::Null);
let mut usedProxies: Vec<Value> = Vec::new();
let mut httpProxy: Value = Value::Null;
let mut httpsProxy: Value = Value::Null;
let mut socksProxy: Value = Value::Null;
// httpProxy
let mut isHttpProxyDefined: Value = self.value_is_defined(self.httpProxy.clone());
let mut isHttp_proxy_defined: Value = self.value_is_defined(self.http_proxy.clone());
if isHttpProxyDefined.as_bool() == Some(true) || isHttp_proxy_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("httpProxy".into()));
httpProxy = (if isHttpProxyDefined.as_bool() == Some(true) { self.httpProxy.clone() } else { self.http_proxy.clone() });
}
let mut ishttpProxyCallbackDefined: Value = self.value_is_defined(self.httpProxyCallback.clone());
let mut ishttp_proxy_callback_defined: Value = self.value_is_defined(self.http_proxy_callback.clone());
if ishttpProxyCallbackDefined.as_bool() == Some(true) || ishttp_proxy_callback_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("httpProxyCallback".into()));
httpProxy = (if ishttpProxyCallbackDefined.as_bool() == Some(true) { self.http_proxy_callback_fn(url.clone(), method.clone(), headers.clone(), body.clone()) } else { self.http_proxy_callback_fn(url.clone(), method.clone(), headers.clone(), body.clone()) });
}
// httpsProxy
let mut isHttpsProxyDefined: Value = self.value_is_defined(self.httpsProxy.clone());
let mut isHttps_proxy_defined: Value = self.value_is_defined(self.https_proxy.clone());
if isHttpsProxyDefined.as_bool() == Some(true) || isHttps_proxy_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("httpsProxy".into()));
httpsProxy = (if isHttpsProxyDefined.as_bool() == Some(true) { self.httpsProxy.clone() } else { self.https_proxy.clone() });
}
let mut ishttpsProxyCallbackDefined: Value = self.value_is_defined(self.httpsProxyCallback.clone());
let mut ishttps_proxy_callback_defined: Value = self.value_is_defined(self.https_proxy_callback.clone());
if ishttpsProxyCallbackDefined.as_bool() == Some(true) || ishttps_proxy_callback_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("httpsProxyCallback".into()));
httpsProxy = (if ishttpsProxyCallbackDefined.as_bool() == Some(true) { self.https_proxy_callback_fn(url.clone(), method.clone(), headers.clone(), body.clone()) } else { self.https_proxy_callback_fn(url.clone(), method.clone(), headers.clone(), body.clone()) });
}
// socksProxy
let mut isSocksProxyDefined: Value = self.value_is_defined(self.socksProxy.clone());
let mut isSocks_proxy_defined: Value = self.value_is_defined(self.socks_proxy.clone());
if isSocksProxyDefined.as_bool() == Some(true) || isSocks_proxy_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("socksProxy".into()));
socksProxy = (if isSocksProxyDefined.as_bool() == Some(true) { self.socksProxy.clone() } else { self.socks_proxy.clone() });
}
let mut issocksProxyCallbackDefined: Value = self.value_is_defined(self.socksProxyCallback.clone());
let mut issocks_proxy_callback_defined: Value = self.value_is_defined(self.socks_proxy_callback.clone());
if issocksProxyCallbackDefined.as_bool() == Some(true) || issocks_proxy_callback_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("socksProxyCallback".into()));
socksProxy = (if issocksProxyCallbackDefined.as_bool() == Some(true) { self.socks_proxy_callback_fn(url.clone(), method.clone(), headers.clone(), body.clone()) } else { self.socks_proxy_callback_fn(url, method, headers, body) });
}
// check
let mut length: f64 = ((usedProxies.len() as i64) as f64);
if length > ((1i64) as f64) {
let mut joinedProxyNames: Value = Value::Str(usedProxies.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",").into());
panic!("{}", crate::exchange_errors::invalid_proxy_settings(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" you have multiple conflicting proxy settings (".into())).into()), joinedProxyNames).into()), Value::Str("), please use only one from: httpProxy, httpsProxy, httpProxyCallback, httpsProxyCallback, socksProxy, socksProxyCallback".into()))));
}
return Value::from(vec![httpProxy, httpsProxy, socksProxy]);
Value::Null
}
fn check_ws_proxy_settings(&self) -> Value {
let mut usedProxies: Vec<Value> = Vec::new();
let mut wsProxy: Value = Value::Null;
let mut wssProxy: Value = Value::Null;
let mut wsSocksProxy: Value = Value::Null;
// ws proxy
let mut isWsProxyDefined: Value = self.value_is_defined(self.wsProxy.clone());
let mut is_ws_proxy_defined: Value = self.value_is_defined(self.ws_proxy.clone());
if isWsProxyDefined.as_bool() == Some(true) || is_ws_proxy_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("wsProxy".into()));
wsProxy = (if isWsProxyDefined.as_bool() == Some(true) { self.wsProxy.clone() } else { self.ws_proxy.clone() });
}
// wss proxy
let mut isWssProxyDefined: Value = self.value_is_defined(self.wssProxy.clone());
let mut is_wss_proxy_defined: Value = self.value_is_defined(self.wss_proxy.clone());
if isWssProxyDefined.as_bool() == Some(true) || is_wss_proxy_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("wssProxy".into()));
wssProxy = (if isWssProxyDefined.as_bool() == Some(true) { self.wssProxy.clone() } else { self.wss_proxy.clone() });
}
// ws socks proxy
let mut isWsSocksProxyDefined: Value = self.value_is_defined(self.wsSocksProxy.clone());
let mut is_ws_socks_proxy_defined: Value = self.value_is_defined(self.ws_socks_proxy.clone());
if isWsSocksProxyDefined.as_bool() == Some(true) || is_ws_socks_proxy_defined.as_bool() == Some(true) {
usedProxies.push(Value::Str("wsSocksProxy".into()));
wsSocksProxy = (if isWsSocksProxyDefined.as_bool() == Some(true) { self.wsSocksProxy.clone() } else { self.ws_socks_proxy.clone() });
}
// check
let mut length: f64 = ((usedProxies.len() as i64) as f64);
if length > ((1i64) as f64) {
let mut joinedProxyNames: Value = Value::Str(usedProxies.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",").into());
panic!("{}", crate::exchange_errors::invalid_proxy_settings(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" you have multiple conflicting proxy settings (".into())).into()), joinedProxyNames).into()), Value::Str("), please use only one from: wsProxy, wssProxy, wsSocksProxy".into()))));
}
return Value::from(vec![wsProxy, wssProxy, wsSocksProxy]);
Value::Null
}
fn check_conflicting_proxies(&self, mut proxyAgentSet: Value, mut proxyUrlSet: Value) {
let mut proxyAgentIsSet: bool = (proxyAgentSet != Value::Null) && (proxyAgentSet != Value::Null) && (proxyAgentSet.as_str() != Some(""));
let mut proxyUrlIsSet: bool = (proxyUrlSet != Value::Null) && (proxyUrlSet != Value::Null) && (proxyUrlSet.as_str() != Some(""));
if proxyAgentIsSet && proxyUrlIsSet {
panic!("{}", crate::exchange_errors::invalid_proxy_settings(format!("{}{}", self.id.clone(), Value::Str(" you have multiple conflicting proxy settings, please use only one from : proxyUrl, httpProxy, httpsProxy, socksProxy".into()))));
}
}
fn check_address(&self, optional_args: &[Value]) -> Value {
let mut address = get_arg(optional_args, 0, Value::Null);
let mut code = get_arg(optional_args, 1, Value::Null);
let mut tag = get_arg(optional_args, 2, Value::Null);
if (address == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_address(format!("{}{}", self.id.clone(), Value::Str(" address is undefined".into()))));
}
// check the address is not the same letter like 'aaaaa' nor too short nor has a space
let mut uniqChars: Value = (self.unique(self.string_to_chars_array(address.clone())));
let mut length: f64 = ((uniqChars.len() as i64) as f64); // py transpiler trick
if (length == 1.0) || ((address.len() as i64) as f64) < self.minFundingAddressLength.as_f64().unwrap_or(f64::NAN) || Value::Int(address.as_str().and_then(|__s| __s.find(" ")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) > ((-1i64) as f64) {
panic!("{}", crate::exchange_errors::invalid_address(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" address is invalid or has less than ".into())).into()), Value::Str(format!("{}", self.minFundingAddressLength.clone()).into())).into()), Value::Str(" characters: \"".into())).into()), Value::Str(format!("{}", address).into())).into()), Value::Str("\"".into()))));
}
if (code != Value::Null) {
let mut tagRequiredCurrencies: Value = self.safe_list_k(self.options.clone(), "withdrawTagRequiredCurrencies", &[Value::from(vec![])]);
if self.in_array(code.clone(), tagRequiredCurrencies).as_bool() == Some(true) {
if (tag == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" withdraw() requires params[\"tag\"] for ".into())).into()), code)));
}
}
}
return address;
Value::Null
}
fn find_message_hashes(&self, mut client: Value, mut element: Value) -> Value {
let mut result: Vec<Value> = Vec::new();
let mut messageHashes: Value = object_keys(&get_value(&client, &Value::Str("futures".into())));
{
let mut i: Value = Value::Int(0);
let mut __for_first_76: bool = true;
while { if !__for_first_76 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_76 = false; i.as_f64().unwrap_or(f64::NAN) < ((messageHashes.len() as i64) as f64) } {
let mut messageHash: Value = messageHashes.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if Value::Int(messageHash.as_str().zip(element.as_str()).and_then(|(__s, __n)| __s.find(__n)).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
result.push(messageHash);
}
}
}
return Value::from(result);
Value::Null
}
fn filter_by_limit(&self, mut array: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut key = get_arg(optional_args, 1, Value::Str("timestamp".into()));
let mut fromStart = get_arg(optional_args, 2, Value::Bool(false));
if self.value_is_defined(limit.clone()).as_bool() == Some(true) {
let mut arrayLength: Value = Value::Int(array.len() as i64);
if arrayLength.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
let mut ascending: bool = true;
if (in_op(&array.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), &key)) {
let mut first: Value = self.safe_float(array.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), key.clone(), &[]);
let mut last: Value = self.safe_float(array.as_array().and_then(|__arr| match &((match (&(arrayLength), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null })) { Value::Int(__n) if *__n >= 0 => __arr.get(*__n as usize), _ => None }).cloned().unwrap_or(Value::Null), key.clone(), &[]);
if (first != Value::Null) && (last != Value::Null) {
ascending = last.as_f64().unwrap_or(f64::NAN) >= first.as_f64().unwrap_or(f64::NAN); // true if array is sorted in ascending order based on 'timestamp'
}
}
if is_true(&fromStart) {
let mut limitResolved: Value = (if (limit.as_f64().unwrap_or(f64::NAN) > arrayLength.as_f64().unwrap_or(f64::NAN)) { arrayLength } else { limit.clone() });
if ascending {
return self.array_slice(array.clone(), Value::Int(0), &[limitResolved.clone()]);
}
return self.array_slice(array.clone(), (match &(limitResolved) { Value::Int(x) => Value::Int(-x), Value::Float(x) => Value::Float(-x), _ => Value::Null }), &[]);
}
if ascending {
return self.array_slice(array.clone(), (match &(limit) { Value::Int(x) => Value::Int(-x), Value::Float(x) => Value::Float(-x), _ => Value::Null }), &[]);
}
return self.array_slice(array.clone(), Value::Int(0), &[limit]);
}
}
return array;
Value::Null
}
fn filter_by_since_limit(&self, mut array: 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 key = get_arg(optional_args, 2, Value::Str("timestamp".into()));
let mut tail = get_arg(optional_args, 3, Value::Bool(false));
if (array == Value::Null) {
return Value::from(vec![]);
}
let mut sinceIsDefined: Value = self.value_is_defined(since.clone());
let mut parsedArray: Value = self.to_array(array);
let mut result: Value = parsedArray.clone();
if sinceIsDefined.as_bool() == Some(true) {
result = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_77: bool = true;
while { if !__for_first_77 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_77 = false; i.as_f64().unwrap_or(f64::NAN) < ((parsedArray.len() as i64) as f64) } {
let mut entry: Value = get_value(&parsedArray, &i);
let mut entry: Value = get_value(&parsedArray, &i);
let mut value: Value = self.safe_integer(entry.clone(), key.clone(), &[]);
if (value != Value::Null) && (value.as_f64() != Some(0.0)) && (value.as_f64().unwrap_or(f64::NAN) >= since.as_f64().unwrap_or(f64::NAN)) {
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(entry); }
}
}
}
}
if is_true(&tail) && (limit != Value::Null) {
return self.array_slice(result.clone(), (match &(limit) { Value::Int(x) => Value::Int(-x), Value::Float(x) => Value::Float(-x), _ => Value::Null }), &[]);
}
// if the user provided a 'since' argument
// we want to limit the result starting from the 'since'
let mut shouldFilterFromStart: Value = Value::Bool(!is_true(&tail) && sinceIsDefined.as_bool() == Some(true));
return self.filter_by_limit(result, &[limit, key, shouldFilterFromStart]);
Value::Null
}
fn filter_by_value_since_limit(&self, mut array: Value, mut field: Value, optional_args: &[Value]) -> Value {
let mut value = 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 key = get_arg(optional_args, 3, Value::Str("timestamp".into()));
let mut tail = get_arg(optional_args, 4, Value::Bool(false));
let mut valueIsDefined: Value = self.value_is_defined(value.clone());
let mut sinceIsDefined: Value = self.value_is_defined(since.clone());
let mut parsedArray: Value = self.to_array(array);
let mut result: Value = parsedArray.clone();
// single-pass filter for both symbol and since
if valueIsDefined.as_bool() == Some(true) || sinceIsDefined.as_bool() == Some(true) {
result = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_78: bool = true;
while { if !__for_first_78 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_78 = false; i.as_f64().unwrap_or(f64::NAN) < ((parsedArray.len() as i64) as f64) } {
let mut entry: Value = get_value(&parsedArray, &i);
let mut entry: Value = get_value(&parsedArray, &i);
// safeValue (not entry[field]) so a missing field is a non-match, not a
// KeyError in python/php — prediction structures key on outcome, not symbol
let mut entryFiledEqualValue: Value = Value::Bool(is_equal(&self.safe_value(entry.clone(), field.clone(), &[]), &value));
let mut firstCondition: Value = (if valueIsDefined.as_bool() == Some(true) { entryFiledEqualValue } else { Value::Bool(true) });
let mut entryKeyValue: Value = self.safe_integer(entry.clone(), key.clone(), &[]);
let mut entryKeyGESince: Value = Value::Bool((entryKeyValue != Value::Null) && (entryKeyValue.as_f64() != Some(0.0)) && (since != Value::Null) && (entryKeyValue.as_f64().unwrap_or(f64::NAN) >= since.as_f64().unwrap_or(f64::NAN)));
let mut secondCondition: Value = (if sinceIsDefined.as_bool() == Some(true) { entryKeyGESince } else { Value::Bool(true) });
if is_true(&firstCondition) && is_true(&secondCondition) {
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(entry); }
}
}
}
}
if tail.as_bool() == Some(true) && (limit != Value::Null) {
return self.array_slice(result.clone(), (match &(limit) { Value::Int(x) => Value::Int(-x), Value::Float(x) => Value::Float(-x), _ => Value::Null }), &[]);
}
return self.filter_by_limit(result, &[limit, key, sinceIsDefined]);
Value::Null
}
/*
* @method
* @name Exchange#setSandboxMode
* @description set the sandbox mode for the exchange
* @param {boolean} enabled true to enable sandbox mode, false to disable it
*/
fn set_sandbox_mode(&mut self, mut enabled: Value) {
if is_true(&enabled) {
if (matches!(&self.urls, Value::Dict(__d) if __d.contains_key("test"))) {
if matches!(&self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), Value::Str(_)) {
{ let __be_tmp = crate::value::get_value_k(&self.urls, "api"); add_element_to_object(&mut self.urls, &Value::Str("apiBackup".into()), __be_tmp); };
{ let __be_tmp = crate::value::get_value_k(&self.urls, "test"); add_element_to_object(&mut self.urls, &Value::Str("api".into()), __be_tmp); };
} else {
{ let __be_tmp = self.clone_value(crate::value::get_value_k(&self.urls, "api")); add_element_to_object(&mut self.urls, &Value::Str("apiBackup".into()), __be_tmp); };
{ let __be_tmp = self.clone_value(crate::value::get_value_k(&self.urls, "test")); add_element_to_object(&mut self.urls, &Value::Str("api".into()), __be_tmp); };
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" does not have a sandbox URL".into()))));
}
// set flag
self.isSandboxModeEnabled = Value::Bool(true);
} else if (matches!(&self.urls, Value::Dict(__d) if __d.contains_key("apiBackup"))) {
if matches!(&self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), Value::Str(_)) {
{ let __be_tmp = crate::value::get_value_k(&self.urls, "apiBackup"); add_element_to_object(&mut self.urls, &Value::Str("api".into()), __be_tmp); };
} else {
{ let __be_tmp = self.clone_value(crate::value::get_value_k(&self.urls, "apiBackup")); add_element_to_object(&mut self.urls, &Value::Str("api".into()), __be_tmp); };
}
let mut newUrls: Value = self.omit(self.urls.clone(), Value::Str("apiBackup".into()), &[]);
self.urls = newUrls;
// set flag
self.isSandboxModeEnabled = Value::Bool(false);
}
}
/*
* @method
* @name Exchange#enableDemoTrading
* @description enables or disables demo trading mode
* @param {boolean} [enable] true if demo trading should be enabled, false otherwise
*/
fn enable_demo_trading(&mut self, mut enable: Value) {
if self.isSandboxModeEnabled.as_bool() == Some(true) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" demo trading does not support in sandbox environment. Please check https://www.binance.com/en/support/faq/detail/9be58f73e5e14338809e3b705b9687dd to see the differences".into()))));
}
if is_true(&enable) {
{ let __be_tmp = crate::value::get_value_k(&self.urls, "api"); add_element_to_object(&mut self.urls, &Value::Str("apiBackupDemoTrading".into()), __be_tmp); };
{ let __be_tmp = crate::value::get_value_k(&self.urls, "demo"); add_element_to_object(&mut self.urls, &Value::Str("api".into()), __be_tmp); };
} else if (matches!(&self.urls, Value::Dict(__d) if __d.contains_key("apiBackupDemoTrading"))) {
{ let __be_tmp = crate::value::get_value_k(&self.urls, "apiBackupDemoTrading"); add_element_to_object(&mut self.urls, &Value::Str("api".into()), __be_tmp); };
let mut newUrls: Value = self.omit(self.urls.clone(), Value::Str("apiBackupDemoTrading".into()), &[]);
self.urls = newUrls;
}
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("enableDemoTrading".into(), enable); }
}
fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::sign(self, ...))
{ let __v = crate::exchange::DerivedExchange::sign(self, path, crate::runtime::get_arg(optional_args, 0, crate::Value::Null), crate::runtime::get_arg(optional_args, 1, crate::Value::Null), crate::runtime::get_arg(optional_args, 2, crate::Value::Null), crate::runtime::get_arg(optional_args, 3, crate::Value::Null), crate::runtime::get_arg(optional_args, 4, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Null);
m.insert("method".to_string(), Value::Null);
m.insert("headers".to_string(), Value::Null);
m.insert("body".to_string(), Value::Null);
m
});
Value::Null
}
fn fetch_accounts(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchAccounts() is not supported yet".into()))));
Value::Null
} }
fn watch_liquidations(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("watchLiquidationsForSymbols")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("watchLiquidationsForSymbols")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.watch_liquidations_for_symbols(Value::from(vec![symbol]), &[since, limit, params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchLiquidations() is not supported yet".into()))));
Value::Null
} }
fn watch_liquidations_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchLiquidationsForSymbols() is not supported yet".into()))));
Value::Null
} }
fn watch_my_liquidations(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("watchMyLiquidationsForSymbols")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("watchMyLiquidationsForSymbols")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.watch_my_liquidations_for_symbols(Value::from(vec![symbol]), &[since, limit, params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchMyLiquidations() is not supported yet".into()))));
Value::Null
} }
fn watch_my_liquidations_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchMyLiquidationsForSymbols() is not supported yet".into()))));
Value::Null
} }
fn un_watch_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchOrders() is not supported yet".into()))));
Value::Null
} }
fn un_watch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchTrades() is not supported yet".into()))));
Value::Null
} }
fn un_watch_trades_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchTradesForSymbols() is not supported yet".into()))));
Value::Null
} }
fn watch_ohlcv_for_symbols(&mut self, mut symbolsAndTimeframes: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchOHLCVForSymbols() is not supported yet".into()))));
Value::Null
} }
fn un_watch_ohlcv_for_symbols(&mut self, mut symbolsAndTimeframes: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchOHLCVForSymbols() is not supported yet".into()))));
Value::Null
} }
fn un_watch_order_book_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchOrderBookForSymbols() is not supported yet".into()))));
Value::Null
} }
fn un_watch_positions(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchPositions() is not supported yet".into()))));
Value::Null
} }
fn un_watch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchTicker() is not supported yet".into()))));
Value::Null
} }
fn un_watch_mark_price(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchMarkPrice() is not supported yet".into()))));
Value::Null
} }
fn un_watch_mark_prices(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchMarkPrices() is not supported yet".into()))));
Value::Null
} }
fn fetch_deposit_addresses(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_deposit_addresses", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddresses() is not supported yet".into()))));
Value::Null
} }
fn fetch_margin_mode(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_margin_mode", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchMarginModes")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchMarginModes")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut marginModes: Value = self.fetch_margin_modes(&[Value::from(vec![symbol.clone()]), params]).await;
let mut marginMode: Value = self.safe_dict(marginModes, symbol, &[]);
return marginMode;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMarginMode() is not supported yet".into()))));
}
Value::Null
} }
fn fetch_margin_modes(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_margin_modes", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMarginModes () is not supported yet".into()))));
Value::Null
} }
fn un_watch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchOrderBook() is not supported yet".into()))));
Value::Null
} }
fn fetch_time(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_time", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTime() is not supported yet".into()))));
Value::Null
} }
fn fetch_trading_limits(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTradingLimits() is not supported yet".into()))));
Value::Null
} }
fn parse_currency(&self, mut rawCurrency: Value) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_currency(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_currency(self, rawCurrency); if !matches!(__v, crate::Value::Null) { return __v; } }
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseCurrency() is not supported yet".into()))));
Value::Null
}
fn parse_currencies(&self, mut rawCurrencies: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut arr: Value = self.to_array(rawCurrencies);
{
let mut i: Value = Value::Int(0);
let mut __for_first_79: bool = true;
while { if !__for_first_79 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_79 = false; i.as_f64().unwrap_or(f64::NAN) < ((arr.len() as i64) as f64) } {
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_currency(self, arr.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
if (parsed == Value::Null) {
continue;
}
let mut code: Value = parsed.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), parsed); }
}
}
return result;
Value::Null
}
fn parse_market(&self, mut market: Value) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_market(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_market(self, market); if !matches!(__v, crate::Value::Null) { return __v; } }
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseMarket() is not supported yet".into()))));
Value::Null
}
fn parse_markets(&self, mut markets: Value) -> Value {
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_80: bool = true;
while { if !__for_first_80 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_80 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&markets).as_f64().unwrap_or(f64::NAN) } {
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_market(self, get_value(&markets, &i));
// parseMarket returns undefined for a market it cannot build (e.g. unknown base or quote)
if (market != Value::Null) {
result.push(market);
}
}
}
return Value::from(result);
Value::Null
}
fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_ticker(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_ticker(self, ticker, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseTicker() is not supported yet".into()))));
Value::Null
}
fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_deposit_address(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_deposit_address(self, depositAddress, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut currency = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseDepositAddress() is not supported yet".into()))));
Value::Null
}
fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_trade(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_trade(self, trade, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseTrade() is not supported yet".into()))));
Value::Null
}
fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_transaction(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_transaction(self, transaction, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut currency = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseTransaction() is not supported yet".into()))));
Value::Null
}
fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_transfer(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_transfer(self, transfer.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut currency = get_arg(optional_args, 0, Value::Null);
if (transfer == Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseTransfer() is not supported yet".into()))));
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseTransfer() is not supported yet".into()))));
Value::Null
}
fn parse_account(&self, mut account: Value) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_account(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_account(self, account); if !matches!(__v, crate::Value::Null) { return __v; } }
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseAccount() is not supported yet".into()))));
Value::Null
}
fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_ledger_entry(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_ledger_entry(self, item, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut currency = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseLedgerEntry() is not supported yet".into()))));
Value::Null
}
fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_order(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_order(self, order, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseOrder() is not supported yet".into()))));
Value::Null
}
fn fetch_cross_borrow_rates(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchCrossBorrowRates() is not supported yet".into()))));
Value::Null
} }
fn fetch_isolated_borrow_rates(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchIsolatedBorrowRates() is not supported yet".into()))));
Value::Null
} }
fn parse_market_leverage_tiers(&self, mut info: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_market_leverage_tiers(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_market_leverage_tiers(self, info, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseMarketLeverageTiers() is not supported yet".into()))));
Value::Null
}
fn fetch_leverage_tiers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_leverage_tiers", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLeverageTiers() is not supported yet".into()))));
Value::Null
} }
fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_position(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_position(self, position, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parsePosition() is not supported yet".into()))));
Value::Null
}
fn parse_funding_rate_history(&self, mut info: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_funding_rate_history(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_funding_rate_history(self, info, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseFundingRateHistory() is not supported yet".into()))));
Value::Null
}
fn parse_borrow_interest(&self, mut info: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_borrow_interest(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_borrow_interest(self, info, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseBorrowInterest() is not supported yet".into()))));
Value::Null
}
fn parse_isolated_borrow_rate(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseIsolatedBorrowRate() is not supported yet".into()))));
Value::Null
}
fn parse_ws_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseWsTrade() is not supported yet".into()))));
Value::Null
}
fn parse_ws_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseWsOrder() is not supported yet".into()))));
Value::Null
}
fn parse_ws_order_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseWsOrderTrade() is not supported yet".into()))));
Value::Null
}
fn parse_ws_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return <Self as crate::exchange_generated::ExchangeBase>::parse_ohlcv(self, ohlcv, &[market]);
Value::Null
}
fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_funding_rates", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRates() is not supported yet".into()))));
Value::Null
} }
fn fetch_funding_intervals(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_funding_intervals", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingIntervals() is not supported yet".into()))));
Value::Null
} }
fn watch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchFundingRate() is not supported yet".into()))));
Value::Null
} }
fn watch_funding_rates(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchFundingRates() is not supported yet".into()))));
Value::Null
} }
fn un_watch_funding_rates(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchFundingRates() is not supported yet".into()))));
Value::Null
} }
fn watch_funding_rates_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.watch_funding_rates(&[symbols, params]).await;
Value::Null
} }
fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("transfer", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(code); __args.push(amount); __args.push(fromAccount); __args.push(toAccount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" transfer() is not supported yet".into()))));
Value::Null
} }
fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("withdraw", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(code); __args.push(amount); __args.push(address); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" withdraw() is not supported yet".into()))));
Value::Null
} }
fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createDepositAddress() is not supported yet".into()))));
Value::Null
} }
fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("set_leverage", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(leverage); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() is not supported yet".into()))));
Value::Null
} }
fn fetch_leverage(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_leverage", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchLeverages")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchLeverages")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut leverages: Value = self.fetch_leverages(&[Value::from(vec![symbol.clone()]), params]).await;
let mut leverage: Value = self.safe_dict(leverages, symbol, &[]);
return leverage;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLeverage() is not supported yet".into()))));
}
Value::Null
} }
fn fetch_leverages(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_leverages", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLeverages() is not supported yet".into()))));
Value::Null
} }
fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("set_position_mode", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(hedged); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setPositionMode() is not supported yet".into()))));
Value::Null
} }
fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("add_margin", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.push(amount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" addMargin() is not supported yet".into()))));
Value::Null
} }
fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("reduce_margin", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.push(amount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" reduceMargin() is not supported yet".into()))));
Value::Null
} }
fn set_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setMargin() is not supported yet".into()))));
Value::Null
} }
fn fetch_long_short_ratio(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut timeframe = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLongShortRatio() is not supported yet".into()))));
Value::Null
} }
fn fetch_long_short_ratio_history(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut timeframe = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLongShortRatioHistory() is not supported yet".into()))));
Value::Null
} }
fn fetch_margin_adjustment_history(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut type_var = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMarginAdjustmentHistory() is not supported yet".into()))));
Value::Null
} }
fn set_margin_mode(&mut self, mut marginMode: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("set_margin_mode", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(marginMode); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() is not supported yet".into()))));
Value::Null
} }
fn fetch_deposit_addresses_by_network(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_deposit_addresses_by_network", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(code); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddressesByNetwork() is not supported yet".into()))));
Value::Null
} }
fn fetch_open_interest_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1h".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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenInterestHistory() is not supported yet".into()))));
Value::Null
} }
fn fetch_open_interests(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_open_interests", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenInterests() is not supported yet".into()))));
Value::Null
} }
fn sign_in(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("sign_in", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" signIn() is not supported yet".into()))));
Value::Null
} }
fn fetch_payment_methods(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPaymentMethods() is not supported yet".into()))));
Value::Null
} }
fn parse_to_int(&self, mut number: Value) -> Value {
// Solve Common parseInt misuse ex: parseInt ((since / 1000).toString ())
// using a number as parameter which is not valid in ts
// numberToString is typed as nullable under strictNullChecks; cast to string
// the cast is erased at transpile-time, so output matches every target language, rather than
// branching to a bare `NaN` literal, which has no symbol in Go/Java/C#
let mut stringifiedNumber: Value = self.number_to_string(number);
let mut convertedNumber: Value = (match &stringifiedNumber { Value::Str(__parse_s) => __parse_s.trim().parse::<f64>().map(Value::Float).unwrap_or(Value::Null), Value::Float(__parse_f) => Value::Float(*__parse_f), Value::Int(__parse_n) => Value::Float(*__parse_n as f64), _ => Value::Null });
return crate::runtime::parse_int(&convertedNumber);
Value::Null
}
fn parse_to_numeric(&self, mut number: Value) -> Value {
let mut stringVersion: Value = self.number_to_string(number); // this will convert 1.0 and 1 to "1" and 1.1 to "1.1"
// keep this in mind:
// in JS: 1 === 1.0 is true
// in Python: 1 == 1.0 is true
// in PHP: 1 == 1.0 is true, but 1 === 1.0 is false.
if Value::Int(stringVersion.as_str().and_then(|__s| __s.find(".")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return (match &stringVersion { Value::Str(__parse_s) => __parse_s.trim().parse::<f64>().map(Value::Float).unwrap_or(Value::Null), Value::Float(__parse_f) => Value::Float(*__parse_f), Value::Int(__parse_n) => Value::Float(*__parse_n as f64), _ => Value::Null });
}
return (match &stringVersion { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null });
Value::Null
}
fn is_round_number(&self, mut value: Value) -> Value {
// this method is similar to isInteger, but this is more loyal and does not check for types.
// i.e. isRoundNumber(1.000) returns true, while isInteger(1.000) returns false
let mut res: Value = self.parse_to_numeric(((match (&(value), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) if *y != 0 => Value::Int(x % y), (Value::Int(x), Value::Float(y)) if *y != 0.0 => Value::Float(*x as f64 % *y), (Value::Float(x), Value::Int(y)) if *y != 0 => Value::Float(*x % *y as f64), (Value::Float(x), Value::Float(y)) if *y != 0.0 => Value::Float(x % y), _ => Value::Null })));
return Value::Bool(res.as_f64() == Some(0.0));
Value::Null
}
fn is_empty_string(&self, mut value: Value) -> Value {
return Value::Bool(!(self.value_is_defined(value.clone()).as_bool() == Some(true)) || (value.as_str() == Some("")));
Value::Null
}
fn safe_number_omit_zero(&self, mut obj: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_string(obj, key, &[]);
let mut final_val: Value = self.parse_number(self.omit_zero(value), &[]);
return (if (final_val == Value::Null) { defaultValue } else { final_val });
Value::Null
}
fn safe_integer_omit_zero(&self, mut obj: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.safe_integer(obj, key, &[defaultValue]);
if (timestamp == Value::Null) || (timestamp.as_f64() == Some(0.0)) {
return Value::Null;
}
return timestamp;
Value::Null
}
fn after_construct(&mut self, optional_args: &[Value]) {
let mut userConfig = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __userConfig_empty = indexmap::IndexMap::new();
let userConfig = userConfig.as_map().unwrap_or(&__userConfig_empty);
// networksById: inverse of options.networks, explicit options.networksById entries win
let mut networkIdsToCodesGenerated: Value = self.invert_flat_string_dictionary(self.safe_value_k(self.options.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]));
{ let __be_tmp = self.extend(networkIdsToCodesGenerated, &[self.safe_value_k(self.options.clone(), "networksById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})])]); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("networksById".into(), __be_tmp); } }
self.features_generator();
self.has_autocorrect();
// init predefined markets if any
if (self.markets.clone() != Value::Null) {
self.set_markets(self.markets.clone(), &[]);
}
// init the request rate limiter
self.init_rest_rate_limiter();
// sanbox mode
let mut isSandbox: Value = self.safe_bool2(self.options.clone(), Value::Str("sandbox".into()), Value::Str("testnet".into()), &[Value::Bool(false)]);
if isSandbox.as_bool() == Some(true) {
self.set_sandbox_mode(isSandbox);
}
// compatibility for sandbox/testnet options in userConfig
if matches!(((match userConfig.get("sandbox") { Some(Value::Bool(__b)) => Value::Bool(*__b), _ => Value::Bool(false) })), Value::Bool(true)) || matches!(((match userConfig.get("testnet") { Some(Value::Bool(__b)) => Value::Bool(*__b), _ => Value::Bool(false) })), Value::Bool(true)) {
self.set_sandbox_mode(Value::Bool(true));
}
}
fn has_autocorrect(&self) {
let mut fallbacks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fetchL2OrderBook".to_string(), Value::Str("fetchOrderBook".into()));
m.insert("createLimitOrder".to_string(), Value::Str("createOrder".into()));
m.insert("createMarketOrder".to_string(), Value::Str("createOrder".into()));
m.insert("createLimitOrderWs".to_string(), Value::Str("createOrderWs".into()));
m.insert("createMarketOrderWs".to_string(), Value::Str("createOrderWs".into()));
m
});
let mut targets: Value = Value::Array(fallbacks.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
{
let mut i: Value = Value::Int(0);
let mut __for_first_81: bool = true;
while { if !__for_first_81 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_81 = false; i.as_f64().unwrap_or(f64::NAN) < ((targets.len() as i64) as f64) } {
let mut target: Value = targets.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut source: Value = fallbacks.as_map().and_then(|__m| target.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
let mut sourceDefined: bool = (matches!((&self.has, &source), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) && (get_value(&self.has, &source) != Value::Null);
let mut targetDefined: bool = (matches!((&self.has, &target), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) && (self.has.as_map().and_then(|__m| target.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null) != Value::Null);
if sourceDefined && !targetDefined {
{ let __be_tmp = get_value(&self.has, &source); if let Value::Dict(__d) = &mut self.has.clone() { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&target), __be_tmp); } }
}
}
}
}
fn init_rest_rate_limiter(&mut self) {
if (self.rateLimit.clone() == Value::Null) || ((self.id.clone() != Value::Null) && (self.rateLimit.as_f64() == Value::Int(-1).as_f64())) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(".rateLimit property is not configured".into()))));
}
let mut refillRate: Value = self.MAX_VALUE.clone();
if self.rateLimit.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
refillRate = (match ((Value::Int(1)).as_f64(), (self.rateLimit.clone()).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null });
}
let mut useLeaky: bool = (self.rollingWindowSize.as_f64() == Some(0.0)) || (self.rateLimiterAlgorithm.as_str() == Some("leakyBucket"));
let mut algorithm: Value = (if useLeaky { Value::Str("leakyBucket".into()) } else { Value::Str("rollingWindow".into()) });
let mut defaultBucket: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("delay".to_string(), Value::Float(0.001));
m.insert("capacity".to_string(), Value::Int(1));
m.insert("cost".to_string(), Value::Int(1));
m.insert("refillRate".to_string(), refillRate);
m.insert("algorithm".to_string(), algorithm);
m.insert("windowSize".to_string(), self.rollingWindowSize.clone());
m.insert("rateLimit".to_string(), self.rateLimit.clone());
m
});
let mut existingBucket: Value = (if (self.tokenBucket.clone() == Value::Null) { Value::Map({
let mut m = indexmap::IndexMap::new();
m
}) } else { self.tokenBucket.clone() });
{ let __t = self.extend(defaultBucket, &[existingBucket]); self.tokenBucket = __t; }
self.init_throttler();
}
fn features_generator(&mut self) {
//
// in the exchange-specific features can be something like this, where we support 'string' aliases too:
//
// {
// 'my' : {
// 'createOrder' : {...},
// },
// 'swap': {
// 'linear': {
// 'extends': my',
// },
// },
// }
//
if (self.features.clone() == Value::Null) {
return;
}
// reconstruct
let mut initialFeatures: Value = self.features.clone();
self.features = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut unifiedMarketTypes: Value = Value::from(vec![Value::Str("spot".into()), Value::Str("swap".into()), Value::Str("future".into()), Value::Str("option".into())]);
let mut subTypes: Value = Value::from(vec![Value::Str("linear".into()), Value::Str("inverse".into())]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_83: bool = true;
while { if !__for_first_83 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_83 = false; i.as_f64().unwrap_or(f64::NAN) < ((unifiedMarketTypes.len() as i64) as f64) } {
let mut marketType: Value = unifiedMarketTypes.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
// if marketType is not filled for this exchange, don't add that in `features`
if !(matches!((&initialFeatures, &marketType), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let Value::Dict(__d) = &mut self.features { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&marketType), Value::Null); }
} else {
if (marketType.as_str() == Some("spot")) {
{ let __be_tmp = self.features_mapper(initialFeatures.clone(), marketType.clone(), &[]); if let Value::Dict(__d) = &mut self.features { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&marketType), __be_tmp); } }
} else {
if let Value::Dict(__d) = &mut self.features { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&marketType), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})); }
{
let mut j: Value = Value::Int(0);
let mut __for_first_82: bool = true;
while { if !__for_first_82 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_82 = false; j.as_f64().unwrap_or(f64::NAN) < ((subTypes.len() as i64) as f64) } {
let mut subType: Value = subTypes.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
{ let __be_tmp = self.features_mapper(initialFeatures.clone(), marketType.clone(), &[subType.clone()]); add_element_to_object(get_value_mut(&mut self.features, &marketType), &subType, __be_tmp); };
}
}
}
}
}
}
}
fn features_mapper(&mut self, mut initialFeatures: Value, mut marketType: Value, optional_args: &[Value]) -> Value {
let mut subType = get_arg(optional_args, 0, Value::Null);
let mut featuresObj: Value = (if (subType != Value::Null) { get_value(&initialFeatures.as_map().and_then(|__m| marketType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), &subType) } else { initialFeatures.as_map().and_then(|__m| marketType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null) });
// if exchange does not have that market-type (eg. future>inverse)
if (featuresObj == Value::Null) {
return Value::Null;
}
let mut extendsStr: Value = self.safe_string_k(featuresObj.clone(), "extends", &[]);
if (extendsStr != Value::Null) {
featuresObj = self.omit(featuresObj.clone(), Value::Str("extends".into()), &[]);
let mut extendObj: Value = self.features_mapper(initialFeatures, extendsStr, &[]);
featuresObj = self.deep_extend(extendObj, &[featuresObj.clone()]);
}
//
// ### corrections ###
//
// createOrder
if (in_op(&featuresObj, &Value::Str("createOrder".into()))) {
let mut value: Value = self.safe_dict_k(crate::value::get_value_k(&featuresObj, "createOrder"), "attachedStopLossTakeProfit", &[]);
add_element_to_object(get_value_mut(&mut featuresObj, &Value::Str("createOrder".into())), &Value::Str("stopLoss".into()), value.clone());
add_element_to_object(get_value_mut(&mut featuresObj, &Value::Str("createOrder".into())), &Value::Str("takeProfit".into()), value.clone());
if (marketType.as_str() == Some("spot")) {
// default 'hedged': false
add_element_to_object(get_value_mut(&mut featuresObj, &Value::Str("createOrder".into())), &Value::Str("hedged".into()), Value::Bool(false));
// default 'leverage': false
if !(in_op(&crate::value::get_value_k(&featuresObj, "createOrder"), &Value::Str("leverage".into()))) {
add_element_to_object(get_value_mut(&mut featuresObj, &Value::Str("createOrder".into())), &Value::Str("leverage".into()), Value::Bool(false));
}
}
// default 'GTC' to true
if (self.safe_bool(crate::value::get_value_k(&crate::value::get_value_k(&featuresObj, "createOrder"), "timeInForce"), Value::Str("GTC".into()), &[]) == Value::Null) {
add_element_to_object(get_value_mut(get_value_mut(&mut featuresObj, &Value::Str("createOrder".into())), &Value::Str("timeInForce".into())), &Value::Str("GTC".into()), Value::Bool(true));
}
}
// other methods
let mut keys: Value = object_keys(&featuresObj);
{
let mut i: Value = Value::Int(0);
let mut __for_first_84: bool = true;
while { if !__for_first_84 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_84 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut featureBlock: Value = get_value(&featuresObj, &key);
let mut featureBlock: Value = get_value(&featuresObj, &key);
if !(self.in_array(key.clone(), Value::from(vec![Value::Str("sandbox".into())])).as_bool() == Some(true)) && (featureBlock != Value::Null) {
// default "symbolRequired" to false to all methods (except `createOrder`)
if !(in_op(&featureBlock, &Value::Str("symbolRequired".into()))) {
add_element_to_object(&mut featureBlock, &Value::Str("symbolRequired".into()), self.in_array(key, Value::from(vec![Value::Str("createOrder".into()), Value::Str("createOrders".into()), Value::Str("fetchOHLCV".into())])));
}
}
}
}
return featuresObj;
Value::Null
}
fn feature_value(&self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut methodName = get_arg(optional_args, 0, Value::Null);
let mut paramName = get_arg(optional_args, 1, Value::Null);
let mut defaultValue = get_arg(optional_args, 2, Value::Null);
/*
* @method
* @name exchange#featureValue
* @description this method is a very deterministic to help users to know what feature is supported by the exchange
* @param {string} [symbol] unified symbol
* @param {string} [methodName] view currently supported methods: https://docs.ccxt.com/README?id=features
* @param {string} [paramName] unified param value, like: `triggerPrice`, `stopLoss.triggerPrice` (check docs for supported param names)
* @param {object} [defaultValue] return default value if no result found
* @returns {object} returns feature value
*/
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol.clone());
return self.feature_value_by_type(market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null), market.as_map().and_then(|__m| __m.get("subType")).cloned().unwrap_or(Value::Null), &[methodName, paramName, defaultValue]);
Value::Null
}
fn feature_value_by_type(&self, mut marketType: Value, mut subType: Value, optional_args: &[Value]) -> Value {
let mut methodName = get_arg(optional_args, 0, Value::Null);
let mut paramName = get_arg(optional_args, 1, Value::Null);
let mut defaultValue = get_arg(optional_args, 2, Value::Null);
/*
* @method
* @name exchange#featureValueByType
* @description this method is a very deterministic to help users to know what feature is supported by the exchange
* @param {string} [marketType] supported only: "spot", "swap", "future"
* @param {string} [subType] supported only: "linear", "inverse"
* @param {string} [methodName] view currently supported methods: https://docs.ccxt.com/README?id=features
* @param {string} [paramName] unified param value (check docs for supported param names)
* @param {object} [defaultValue] return default value if no result found
* @returns {object} returns feature value
*/
// if exchange does not yet have features manually implemented
if (self.features.clone() == Value::Null) {
return defaultValue;
}
if (marketType == Value::Null) {
return defaultValue;
}
// if marketType (e.g. 'option') does not exist in features
if !(matches!((&self.features, &marketType), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return defaultValue;
}
// if marketType dict undefined
if (self.features.as_map().and_then(|__m| marketType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null) == Value::Null) {
return defaultValue;
}
let mut methodsContainer: Value = self.features.as_map().and_then(|__m| marketType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
if (subType == Value::Null) {
if (marketType.as_str() != Some("spot")) {
return defaultValue;
}
} else {
if !(in_op(&self.features.as_map().and_then(|__m| marketType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), &subType)) {
return defaultValue;
}
// if subType dict undefined
if (self.features.as_map().and_then(|__m| marketType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| subType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null) == Value::Null) {
return defaultValue;
}
methodsContainer = self.features.as_map().and_then(|__m| marketType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| subType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
}
// if user wanted only marketType and didn't provide methodName, eg: featureIsSupported('spot')
if (methodName == Value::Null) {
return (if (defaultValue != Value::Null) { defaultValue.clone() } else { methodsContainer.clone() });
}
if !(matches!((&methodsContainer, &methodName), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return defaultValue;
}
let mut methodDict: Value = get_value(&methodsContainer, &methodName);
let mut methodDict: Value = get_value(&methodsContainer, &methodName);
if (methodDict == Value::Null) {
return defaultValue;
}
// if user wanted only method and didn't provide `paramName`, eg: featureIsSupported('swap', 'linear', 'createOrder')
if (paramName == Value::Null) {
return (if (defaultValue != Value::Null) { defaultValue.clone() } else { methodDict.clone() });
}
let mut splited: Value = Value::Array(paramName.as_str().map(|__s| __s.split(".").map(|__p| Value::Str(__p.to_string().into())).collect()).unwrap_or_default()); // can be only parent key (`stopLoss`) or with child (`stopLoss.triggerPrice`)
let mut parentKey: Value = splited.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut subKey: Value = self.safe_string(splited, Value::Int(1), &[]);
if !(in_op(&methodDict, &parentKey)) {
return defaultValue;
}
let mut dictionary: Value = self.safe_dict(methodDict.clone(), parentKey.clone(), &[]);
if (dictionary == Value::Null) {
return get_value(&methodDict, &parentKey);
} else {
// return as is, when calling without subKey eg: featureValueByType('spot', undefined, 'createOrder', 'stopLoss')
if (subKey == Value::Null) {
return get_value(&methodDict, &parentKey);
}
// throw an exception for unsupported subKey
if !(in_op(&get_value(&methodDict, &parentKey), &subKey)) {
return defaultValue;
}
return get_value(&get_value(&methodDict, &parentKey), &subKey);
}
Value::Null
}
fn orderbook_checksum_message(&self, mut symbol: Value) -> Value {
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" orderbookChecksumMessage() requires a symbol argument".into()))));
}
return Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(" : ".into())).into()), Value::Str("orderbook data checksum validation failed. You can reconnect by calling watchOrderBook again or you can mute the error by setting exchange.options[\"watchOrderBook\"][\"checksum\"] = false".into())).into());
Value::Null
}
fn get_default_options(&self) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdrawTagRequiredCurrencies".to_string(), Value::from(vec![Value::Str("XRP".into()), Value::Str("XLM".into()), Value::Str("EOS".into()), Value::Str("ATOM".into()), Value::Str("HBAR".into()), Value::Str("TON".into()), Value::Str("KAVA".into()), Value::Str("STX".into()), Value::Str("XEM".into()), Value::Str("IOST".into()), Value::Str("OSMO".into()), Value::Str("WAXP".into())]));
m
});
Value::Null
}
fn safe_ledger_entry(&self, mut entry: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyResolved: Value = self.safe_currency(Value::Null, &[currency]);
let mut direction: Value = self.safe_string_k(entry.clone(), "direction", &[]);
let mut before: Value = self.safe_string_k(entry.clone(), "before", &[]);
let mut after: Value = self.safe_string_k(entry.clone(), "after", &[]);
let mut amount: Value = self.safe_string_k(entry.clone(), "amount", &[]);
if (amount != Value::Null) {
if (before == Value::Null) && (after != Value::Null) {
before = crate::precise::Precise::stringSub(&after, &amount);
} else if (before != Value::Null) && (after == Value::Null) {
after = crate::precise::Precise::stringAdd(&before, &amount);
}
}
if (before != Value::Null) && (after != Value::Null) {
if (direction == Value::Null) {
if crate::precise::Precise::stringGt(&before, &after).as_bool() == Some(true) {
direction = Value::Str("out".into());
}
if crate::precise::Precise::stringGt(&after, &before).as_bool() == Some(true) {
direction = Value::Str("in".into());
}
}
}
let mut fee: Value = self.safe_value_k(entry.clone(), "fee", &[]);
if (fee != Value::Null) {
{ let __be_tmp = self.safe_number_k(fee.clone(), "cost", &[]); add_element_to_object(&mut fee, &Value::Str("cost".into()), __be_tmp); };
}
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "timestamp", &[]);
let mut info: Value = self.safe_dict_k(entry.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(entry.clone(), "id", &[]));
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(), self.safe_string_k(entry.clone(), "account", &[]));
m.insert("referenceId".to_string(), self.safe_string_k(entry.clone(), "referenceId", &[]));
m.insert("referenceAccount".to_string(), self.safe_string_k(entry.clone(), "referenceAccount", &[]));
m.insert("type".to_string(), self.safe_string_k(entry.clone(), "type", &[]));
m.insert("currency".to_string(), currencyResolved.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("before".to_string(), self.parse_number(before, &[]));
m.insert("after".to_string(), self.parse_number(after, &[]));
m.insert("status".to_string(), self.safe_string_k(entry, "status", &[]));
m.insert("fee".to_string(), fee);
m.insert("info".to_string(), info);
m
});
Value::Null
}
fn safe_currency_structure(&self, mut currency: Value) -> Value {
// derive data from networks: deposit, withdraw, active, fee, limits, precision
let mut networks: Value = self.safe_dict_k(currency.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut keys: Value = Value::Array(networks.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
let mut length: f64 = ((keys.len() as i64) as f64);
if (length != 0.0) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_85: bool = true;
while { if !__for_first_85 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_85 = false; i.as_f64().unwrap_or(f64::NAN) < length } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut network: Value = networks.as_map().and_then(|__m| key.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
let mut deposit: Value = self.safe_bool_k(network.clone(), "deposit", &[]);
let mut currencyDeposit: Value = self.safe_bool_k(currency.clone(), "deposit", &[]);
if (currencyDeposit == Value::Null) || (deposit.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut currency { std::sync::Arc::make_mut(__d).insert("deposit".into(), deposit); }
}
let mut withdraw: Value = self.safe_bool_k(network.clone(), "withdraw", &[]);
let mut currencyWithdraw: Value = self.safe_bool_k(currency.clone(), "withdraw", &[]);
if (currencyWithdraw == Value::Null) || (withdraw.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut currency { std::sync::Arc::make_mut(__d).insert("withdraw".into(), withdraw); }
}
// find lowest fee (which is more desired)
let mut fee: Value = self.safe_string_k(network.clone(), "fee", &[]);
let mut feeMain: Value = self.safe_string_k(currency.clone(), "fee", &[]);
if (feeMain == Value::Null) || crate::precise::Precise::stringLt(&fee, &feeMain).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut currency { std::sync::Arc::make_mut(__d).insert("fee".into(), self.parse_number(fee.clone(), &[])); }
}
// find lowest precision (which is more desired)
let mut precision: Value = self.safe_string_k(network.clone(), "precision", &[]);
let mut precisionMain: Value = self.safe_string_k(currency.clone(), "precision", &[]);
if (precisionMain == Value::Null) || crate::precise::Precise::stringGt(&precision, &precisionMain).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut currency { std::sync::Arc::make_mut(__d).insert("precision".into(), self.parse_number(precision.clone(), &[])); }
}
// limits
let mut limits: Value = self.safe_dict_k(network, "limits", &[]);
let mut limitsMain: Value = self.safe_dict_k(currency.clone(), "limits", &[]);
if (limitsMain == Value::Null) {
if let Value::Dict(__d) = &mut currency { std::sync::Arc::make_mut(__d).insert("limits".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})); }
}
// deposits
let mut limitsDeposit: Value = self.safe_dict_k(limits.clone(), "deposit", &[]);
let mut limitsDepositMain: Value = self.safe_dict_k(limitsMain.clone(), "deposit", &[]);
if (limitsDepositMain == Value::Null) {
add_element_to_object(get_value_mut(&mut currency, &Value::Str("limits".into())), &Value::Str("deposit".into()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
let mut limitsDepositMin: Value = self.safe_string_k(limitsDeposit.clone(), "min", &[]);
let mut limitsDepositMax: Value = self.safe_string_k(limitsDeposit, "max", &[]);
let mut limitsDepositMinMain: Value = self.safe_string_k(limitsDepositMain.clone(), "min", &[]);
let mut limitsDepositMaxMain: Value = self.safe_string_k(limitsDepositMain, "max", &[]);
// find min
if (limitsDepositMinMain == Value::Null) || crate::precise::Precise::stringLt(&limitsDepositMin, &limitsDepositMinMain).as_bool() == Some(true) {
add_element_to_object(get_value_mut(get_value_mut(&mut currency, &Value::Str("limits".into())), &Value::Str("deposit".into())), &Value::Str("min".into()), self.parse_number(limitsDepositMin, &[]));
}
// find max
if (limitsDepositMaxMain == Value::Null) || crate::precise::Precise::stringGt(&limitsDepositMax, &limitsDepositMaxMain).as_bool() == Some(true) {
add_element_to_object(get_value_mut(get_value_mut(&mut currency, &Value::Str("limits".into())), &Value::Str("deposit".into())), &Value::Str("max".into()), self.parse_number(limitsDepositMax, &[]));
}
// withdrawals
let mut limitsWithdraw: Value = self.safe_dict_k(limits, "withdraw", &[]);
let mut limitsWithdrawMain: Value = self.safe_dict_k(limitsMain, "withdraw", &[]);
if (limitsWithdrawMain == Value::Null) {
add_element_to_object(get_value_mut(&mut currency, &Value::Str("limits".into())), &Value::Str("withdraw".into()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
let mut limitsWithdrawMin: Value = self.safe_string_k(limitsWithdraw.clone(), "min", &[]);
let mut limitsWithdrawMax: Value = self.safe_string_k(limitsWithdraw, "max", &[]);
let mut limitsWithdrawMinMain: Value = self.safe_string_k(limitsWithdrawMain.clone(), "min", &[]);
let mut limitsWithdrawMaxMain: Value = self.safe_string_k(limitsWithdrawMain, "max", &[]);
// find min
if (limitsWithdrawMinMain == Value::Null) || crate::precise::Precise::stringLt(&limitsWithdrawMin, &limitsWithdrawMinMain).as_bool() == Some(true) {
add_element_to_object(get_value_mut(get_value_mut(&mut currency, &Value::Str("limits".into())), &Value::Str("withdraw".into())), &Value::Str("min".into()), self.parse_number(limitsWithdrawMin, &[]));
}
// find max
if (limitsWithdrawMaxMain == Value::Null) || crate::precise::Precise::stringGt(&limitsWithdrawMax, &limitsWithdrawMaxMain).as_bool() == Some(true) {
add_element_to_object(get_value_mut(get_value_mut(&mut currency, &Value::Str("limits".into())), &Value::Str("withdraw".into())), &Value::Str("max".into()), self.parse_number(limitsWithdrawMax, &[]));
}
}
}
}
return self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), Value::Null);
m.insert("id".to_string(), Value::Null);
m.insert("numericId".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("name".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.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
}), &[currency]);
Value::Null
}
fn safe_market_structure(&self, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut cleanStructure: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Null);
m.insert("lowercaseId".to_string(), Value::Null);
m.insert("symbol".to_string(), Value::Null);
m.insert("base".to_string(), Value::Null);
m.insert("quote".to_string(), Value::Null);
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), Value::Null);
m.insert("quoteId".to_string(), Value::Null);
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Null);
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), Value::Null);
m.insert("future".to_string(), Value::Null);
m.insert("option".to_string(), Value::Null);
m.insert("index".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("contract".to_string(), Value::Null);
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("subType".to_string(), Value::Null);
m.insert("taker".to_string(), Value::Null);
m.insert("maker".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.insert("cost".to_string(), Value::Null);
m.insert("base".to_string(), Value::Null);
m.insert("quote".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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("marginModes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cross".to_string(), Value::Null);
m.insert("isolated".to_string(), Value::Null);
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), Value::Null);
m
});
if (market != Value::Null) {
let mut result: Value = self.extend(cleanStructure.clone(), &[market]);
// set undefined swap/future/etc
if (match &(result.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null)) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) }) {
if (result.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null) == Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("contract".into(), Value::Bool(false)); }
}
if (result.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null) == Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("swap".into(), Value::Bool(false)); }
}
if (result.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null) == Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("future".into(), Value::Bool(false)); }
}
if (result.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null) == Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("option".into(), Value::Bool(false)); }
}
if (result.as_map().and_then(|__m| __m.get("index")).cloned().unwrap_or(Value::Null) == Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("index".into(), Value::Bool(false)); }
}
}
return result;
}
return self.extend(cleanStructure, &[]);
Value::Null
}
fn set_markets(&mut self, mut markets: Value, optional_args: &[Value]) -> Value {
let mut currencies = get_arg(optional_args, 0, Value::Null);
let mut values: Vec<Value> = Vec::new();
// build the id index locally and publish it in one swap, so ws handlers never see a half-built table
let mut marketsById: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
// handle marketId conflicts
// we insert spot markets first
let mut marketValues: Value = self.sort_by(self.to_array(markets.clone()), Value::Str("spot".into()), &[Value::Bool(true), Value::Bool(true)]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_87: bool = true;
while { if !__for_first_87 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_87 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketValues.len() as i64) as f64) } {
let mut value: Value = marketValues.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (in_op(&marketsById, &crate::value::get_value_k(&value, "id"))) {
let mut marketsByIdArray: Value = get_value(&marketsById, &crate::value::get_value_k(&value, "id"));
append_to_array(&mut marketsByIdArray, value.clone());
add_element_to_object(&mut marketsById, &crate::value::get_value_k(&value, "id"), marketsByIdArray);
} else {
add_element_to_object(&mut marketsById, &crate::value::get_value_k(&value, "id"), Value::from(vec![value.clone()]));
}
// strip undefined-valued keys from the parsed market before deepExtend,
// otherwise an explicit `taker: undefined` (from safeMarketStructure)
// would clobber the fee defaults from this.fees['trading'] in the merge
let mut valueDefined: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut valueKeys: Value = object_keys(&value);
{
let mut j: Value = Value::Int(0);
let mut __for_first_86: bool = true;
while { if !__for_first_86 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_86 = false; j.as_f64().unwrap_or(f64::NAN) < ((valueKeys.len() as i64) as f64) } {
let mut valueKey: Value = valueKeys.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (get_value(&value, &valueKey) != Value::Null) {
if let Value::Dict(__d) = &mut valueDefined { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&valueKey), get_value(&value, &valueKey)); }
}
}
}
let mut market: Value = self.deep_extend(self.safe_market_structure(&[]), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("precision".to_string(), self.precision.clone());
m.insert("limits".to_string(), self.limits.clone());
m
}), self.fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null), valueDefined]);
if (match &(market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null)) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) }) {
add_element_to_object(&mut market, &Value::Str("subType".into()), Value::Str("linear".into()));
} else if (match &(market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null)) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) }) {
add_element_to_object(&mut market, &Value::Str("subType".into()), Value::Str("inverse".into()));
} else {
add_element_to_object(&mut market, &Value::Str("subType".into()), Value::Null);
}
values.push(market.clone());
}
}
{ let __t = self.map_to_safe_map(self.index_by(Value::from(values.clone()), Value::Str("symbol".into()))); self.markets = __t; }
{ let __t = self.map_to_safe_map(marketsById); self.markets_by_id = __t; }
let mut marketsSortedBySymbol: Value = self.keysort(self.markets.clone(), &[]);
let mut marketsSortedById: Value = self.keysort(self.markets_by_id.clone(), &[]);
self.symbols = object_keys(&marketsSortedBySymbol);
self.ids = object_keys(&marketsSortedById);
let mut numCurrencies: Value = Value::Int(0);
if (currencies != Value::Null) {
let mut keys: Value = object_keys(¤cies);
numCurrencies = Value::Int(keys.len() as i64);
}
if numCurrencies.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
// currencies is always undefined when called in constructor but not when called from loadMarkets
{ let __t = self.map_to_safe_map(self.deep_extend(self.currencies.clone(), &[currencies.clone()])); self.currencies = __t; }
} else {
let mut baseCurrencies: Value = Value::from(vec![]);
let mut quoteCurrencies: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_88: bool = true;
while { if !__for_first_88 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_88 = false; i.as_f64().unwrap_or(f64::NAN) < ((values.len() as i64) as f64) } {
let mut market: Value = values.get((i).as_i64().map_or(usize::MAX, |__n| __n as usize)).cloned().unwrap_or(Value::Null);
let mut defaultCurrencyPrecision: Value = (if (self.precisionMode.as_f64() == Value::Int(crate::runtime::DECIMAL_PLACES).as_f64()) { Value::Int(8) } else { self.parse_number(Value::Str("1e-8".into()), &[]) });
let mut marketPrecision: Value = self.safe_dict_k(market.clone(), "precision", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (matches!(&market, Value::Dict(__d) if __d.contains_key("base"))) {
let mut currency: Value = self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string2(market.clone(), Value::Str("baseId".into()), Value::Str("base".into()), &[]));
m.insert("numericId".to_string(), self.safe_integer_k(market.clone(), "baseNumericId", &[]));
m.insert("code".to_string(), self.safe_string_k(market.clone(), "base", &[]));
m.insert("precision".to_string(), self.safe_value2(marketPrecision.clone(), Value::Str("base".into()), Value::Str("amount".into()), &[defaultCurrencyPrecision.clone()]));
m
}));
if let Value::Arr(__a) = &mut baseCurrencies { std::sync::Arc::make_mut(__a).push(currency.clone()); }
}
if (matches!(&market, Value::Dict(__d) if __d.contains_key("quote"))) {
let mut currency: Value = self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string2(market.clone(), Value::Str("quoteId".into()), Value::Str("quote".into()), &[]));
m.insert("numericId".to_string(), self.safe_integer_k(market.clone(), "quoteNumericId", &[]));
m.insert("code".to_string(), self.safe_string_k(market.clone(), "quote", &[]));
m.insert("precision".to_string(), self.safe_value2(marketPrecision, Value::Str("quote".into()), Value::Str("price".into()), &[defaultCurrencyPrecision]));
m
}));
if let Value::Arr(__a) = &mut quoteCurrencies { std::sync::Arc::make_mut(__a).push(currency); }
}
}
}
baseCurrencies = self.sort_by(baseCurrencies.clone(), Value::Str("code".into()), &[Value::Bool(false), Value::Str("".into())]);
quoteCurrencies = self.sort_by(quoteCurrencies.clone(), Value::Str("code".into()), &[Value::Bool(false), Value::Str("".into())]);
{ let __t = self.map_to_safe_map(self.index_by(baseCurrencies.clone(), Value::Str("code".into()))); self.baseCurrencies = __t; }
{ let __t = self.map_to_safe_map(self.index_by(quoteCurrencies.clone(), Value::Str("code".into()))); self.quoteCurrencies = __t; }
let mut allCurrencies: Value = self.array_concat(baseCurrencies, quoteCurrencies);
let mut groupedCurrencies: Value = self.group_by(allCurrencies, Value::Str("code".into()), &[]);
let mut codes: Value = object_keys(&groupedCurrencies);
let mut resultingCurrencies: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_90: bool = true;
while { if !__for_first_90 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_90 = false; i.as_f64().unwrap_or(f64::NAN) < ((codes.len() as i64) as f64) } {
let mut code: Value = codes.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut groupedCurrenciesCode: Value = self.safe_list(groupedCurrencies.clone(), code, &[Value::from(vec![])]);
let mut highestPrecisionCurrency: Value = self.safe_value(groupedCurrenciesCode.clone(), Value::Int(0), &[]);
{
let mut j: Value = Value::Int(1);
let mut __for_first_89: bool = true;
while { if !__for_first_89 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_89 = false; j.as_f64().unwrap_or(f64::NAN) < ((groupedCurrenciesCode.len() as i64) as f64) } {
let mut currentCurrency: Value = get_value(&groupedCurrenciesCode, &j);
let mut currentCurrency: Value = get_value(&groupedCurrenciesCode, &j);
let mut currentPrecision: Value = self.safe_number_k(currentCurrency.clone(), "precision", &[]);
let mut highestPrecision: Value = self.safe_number_k(highestPrecisionCurrency.clone(), "precision", &[]);
if (currentPrecision == Value::Null) || (highestPrecision == Value::Null) {
continue;
}
if (self.precisionMode.as_f64() == Value::Int(crate::runtime::TICK_SIZE).as_f64()) {
if highestPrecision.as_f64().unwrap_or(f64::NAN) > currentPrecision.as_f64().unwrap_or(f64::NAN) {
highestPrecisionCurrency = currentCurrency.clone();
}
} else if currentPrecision.as_f64().unwrap_or(f64::NAN) > highestPrecision.as_f64().unwrap_or(f64::NAN) {
highestPrecisionCurrency = currentCurrency;
}
}
}
resultingCurrencies.push(highestPrecisionCurrency);
}
}
let mut sortedCurrencies: Value = self.sort_by(Value::from(resultingCurrencies), Value::Str("code".into()), &[]);
{ let __t = self.map_to_safe_map(self.deep_extend(self.currencies.clone(), &[self.index_by(sortedCurrencies, Value::Str("code".into()))])); self.currencies = __t; }
}
{ let __t = self.index_by_safe(self.currencies.clone(), Value::Str("id".into())); self.currencies_by_id = __t; }
let mut currenciesSortedByCode: Value = self.keysort(self.currencies.clone(), &[]);
self.codes = object_keys(¤ciesSortedByCode);
if (self.markets.clone() == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" setMarkets() markets not set".into()))));
}
return self.markets.clone();
Value::Null
}
fn set_markets_from_exchange(&mut self, mut sourceExchange: Value) -> Value {
// Validate that both exchanges are of the same type
if !is_equal(&self.id, &get_value(&sourceExchange, &Value::Str("id".into()))) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" shareMarkets() can only share markets with exchanges of the same type (got ".into())).into()), crate::value::get_value_k(&sourceExchange, "id")).into()), Value::Str(")".into()))));
}
// Validate that source exchange has loaded markets
if (get_value(&sourceExchange, &Value::Str("markets".into())) == Value::Null) || (get_value(&sourceExchange, &Value::Str("markets".into())) == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error("setMarketsFromExchange() source exchange must have loaded markets first. Can call by using loadMarkets function"));
}
// Set all market-related data
self.markets = get_value(&sourceExchange, &Value::Str("markets".into()));
self.markets_by_id = get_value(&sourceExchange, &Value::Str("markets_by_id".into()));
self.symbols = get_value(&sourceExchange, &Value::Str("symbols".into()));
self.ids = get_value(&sourceExchange, &Value::Str("ids".into()));
self.currencies = get_value(&sourceExchange, &Value::Str("currencies".into()));
self.currencies_by_id = get_value(&sourceExchange, &Value::Str("currencies_by_id".into()));
self.baseCurrencies = get_value(&sourceExchange, &Value::Str("baseCurrencies".into()));
self.quoteCurrencies = get_value(&sourceExchange, &Value::Str("quoteCurrencies".into()));
self.codes = get_value(&sourceExchange, &Value::Str("codes".into()));
// check marketHelperProps
let mut sourceExchangeHelpers: Value = self.safe_list(get_value(&sourceExchange, &Value::Str("options".into())), Value::Str("marketHelperProps".into()), &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_91: bool = true;
while { if !__for_first_91 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_91 = false; i.as_f64().unwrap_or(f64::NAN) < ((sourceExchangeHelpers.len() as i64) as f64) } {
let mut helper: Value = get_value(&sourceExchangeHelpers, &i);
let mut helper: Value = get_value(&sourceExchangeHelpers, &i);
if (get_value(&get_value(&sourceExchange, &Value::Str("options".into())), &helper) != Value::Null) {
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&helper), get_value(&get_value(&sourceExchange, &Value::Str("options".into())), &helper)); }
}
}
}
return Value::Null;
Value::Null
}
fn get_describe_for_extended_ws_exchange(&self, mut currentRestInstance: Value, mut parentRestInstance: Value, mut wsBaseDescribe: Value) -> Value {
let mut extendedRestDescribe: Value = self.deep_extend(parentRestInstance.describe(), &[currentRestInstance.describe()]);
let mut superWithRestDescribe: Value = self.deep_extend(extendedRestDescribe, &[wsBaseDescribe]);
return superWithRestDescribe;
Value::Null
}
fn safe_balance(&self, mut balance: Value) -> Value {
let mut balances: Value = self.omit(balance.clone(), Value::from(vec![Value::Str("info".into()), Value::Str("timestamp".into()), Value::Str("datetime".into()), Value::Str("free".into()), Value::Str("used".into()), Value::Str("total".into())]), &[]);
let mut codes: Value = object_keys(&balances);
if let Value::Dict(__d) = &mut balance { std::sync::Arc::make_mut(__d).insert("free".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})); }
if let Value::Dict(__d) = &mut balance { std::sync::Arc::make_mut(__d).insert("used".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})); }
if let Value::Dict(__d) = &mut balance { std::sync::Arc::make_mut(__d).insert("total".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})); }
let mut debtBalance: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_92: bool = true;
while { if !__for_first_92 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_92 = false; i.as_f64().unwrap_or(f64::NAN) < ((codes.len() as i64) as f64) } {
let mut code: Value = codes.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut total: Value = self.safe_string(balance.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), Value::Str("total".into()), &[]);
let mut free: Value = self.safe_string(balance.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), Value::Str("free".into()), &[]);
let mut used: Value = self.safe_string(balance.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), Value::Str("used".into()), &[]);
let mut debt: Value = self.safe_string(balance.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), Value::Str("debt".into()), &[]);
if (total == Value::Null) && (free != Value::Null) && (used != Value::Null) {
total = crate::precise::Precise::stringAdd(&free, &used);
}
if (free == Value::Null) && (total != Value::Null) && (used != Value::Null) {
free = crate::precise::Precise::stringSub(&total, &used);
}
if (used == Value::Null) && (total != Value::Null) && (free != Value::Null) {
used = crate::precise::Precise::stringSub(&total, &free);
}
add_element_to_object(get_value_mut(&mut balance, &code), &Value::Str("free".into()), self.parse_number(free, &[]));
add_element_to_object(get_value_mut(&mut balance, &code), &Value::Str("used".into()), self.parse_number(used, &[]));
add_element_to_object(get_value_mut(&mut balance, &code), &Value::Str("total".into()), self.parse_number(total, &[]));
{ let __be_tmp = crate::value::get_value_k(&get_value(&balance, &code), "free"); add_element_to_object(get_value_mut(&mut balance, &Value::Str("free".into())), &code, __be_tmp); };
{ let __be_tmp = crate::value::get_value_k(&get_value(&balance, &code), "used"); add_element_to_object(get_value_mut(&mut balance, &Value::Str("used".into())), &code, __be_tmp); };
{ let __be_tmp = crate::value::get_value_k(&get_value(&balance, &code), "total"); add_element_to_object(get_value_mut(&mut balance, &Value::Str("total".into())), &code, __be_tmp); };
if (debt != Value::Null) {
add_element_to_object(get_value_mut(&mut balance, &code), &Value::Str("debt".into()), self.parse_number(debt, &[]));
if let Value::Dict(__d) = &mut debtBalance { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), crate::value::get_value_k(&balance.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), "debt")); }
}
}
}
let mut debtBalanceArray: Value = Value::Array(debtBalance.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
let mut length: Value = Value::Int(debtBalanceArray.len() as i64);
if (length != Value::Null) && (length.as_f64() != Some(0.0)) {
if let Value::Dict(__d) = &mut balance { std::sync::Arc::make_mut(__d).insert("debt".into(), debtBalance); }
}
return balance;
Value::Null
}
fn safe_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
// parses numbers as strings
// * it is important pass the trades as unparsed rawTrades
let mut orderDict: Value = order.clone();
if (order == Value::Null) {
orderDict = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut amount: Value = self.omit_zero(self.safe_string_k(orderDict.clone(), "amount", &[]));
let mut remaining: Value = self.safe_string_k(orderDict.clone(), "remaining", &[]);
let mut filled: Value = self.safe_string_k(orderDict.clone(), "filled", &[]);
let mut cost: Value = self.safe_string_k(orderDict.clone(), "cost", &[]);
let mut average: Value = self.omit_zero(self.safe_string_k(orderDict.clone(), "average", &[]));
let mut price: Value = self.omit_zero(self.safe_string_k(orderDict.clone(), "price", &[]));
let mut lastTradeTimeTimestamp: Value = self.safe_integer_k(orderDict.clone(), "lastTradeTimestamp", &[]);
let mut symbol: Value = self.safe_string_k(orderDict.clone(), "symbol", &[]);
let mut side: Value = self.safe_string_k(orderDict.clone(), "side", &[]);
let mut status: Value = self.safe_string_k(orderDict.clone(), "status", &[]);
let mut parseFilled: bool = filled == Value::Null;
let mut parseCost: bool = cost == Value::Null;
let mut parseLastTradeTimeTimestamp: bool = lastTradeTimeTimestamp == Value::Null;
let mut fee: Value = self.safe_value_k(orderDict.clone(), "fee", &[]);
let mut parseFee: bool = fee == Value::Null;
let mut parseFees: bool = self.safe_value_k(orderDict.clone(), "fees", &[]) == Value::Null;
let mut parseSymbol: bool = symbol == Value::Null;
let mut parseSide: bool = side == Value::Null;
let mut shouldParseFees: bool = parseFee || parseFees;
let mut fees: Value = self.safe_list_k(orderDict.clone(), "fees", &[Value::from(vec![])]);
let mut trades: Value = Value::from(vec![]);
let mut isTriggerOrSLTpOrder: bool = ((self.safe_string_k(orderDict.clone(), "triggerPrice", &[]) != Value::Null) || (self.safe_string_k(orderDict.clone(), "stopLossPrice", &[]) != Value::Null)) || (self.safe_string_k(orderDict.clone(), "takeProfitPrice", &[]) != Value::Null);
if parseFilled || parseCost || shouldParseFees {
let mut rawTrades: Value = self.safe_value_k(orderDict.clone(), "trades", &[trades.clone()]);
// const oldNumber = this.number;
// we parse trades as strings here!
// i don't think this is needed anymore
// (this as any).number = String;
let mut firstTrade: Value = self.safe_value(rawTrades.clone(), Value::Int(0), &[]);
// parse trades if they haven't already been parsed
let mut tradesAreParsed: bool = (firstTrade != Value::Null) && (in_op(&firstTrade, &Value::Str("info".into()))) && (in_op(&firstTrade, &Value::Str("id".into())));
if !tradesAreParsed {
trades = self.parse_trades(rawTrades.clone(), &[market.clone()]);
} else {
trades = rawTrades;
}
// this.number = oldNumber; why parse trades as strings if you read the value using `safeString` ?
let mut tradesLength: Value = Value::Int(0);
let mut isArray: bool = matches!(&trades, Value::Arr(_));
if isArray {
tradesLength = Value::Int(trades.len() as i64);
}
if isArray && (tradesLength.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64)) {
// move properties that are defined in trades up into the order
if (orderDict.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) == Value::Null) {
add_element_to_object(&mut orderDict, &Value::Str("symbol".into()), crate::value::get_value_k(&trades.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), "symbol"));
}
if (orderDict.as_map().and_then(|__m| __m.get("side")).cloned().unwrap_or(Value::Null) == Value::Null) {
add_element_to_object(&mut orderDict, &Value::Str("side".into()), crate::value::get_value_k(&trades.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), "side"));
}
if (orderDict.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null) == Value::Null) {
add_element_to_object(&mut orderDict, &Value::Str("type".into()), crate::value::get_value_k(&trades.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), "type"));
}
if (orderDict.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null) == Value::Null) {
add_element_to_object(&mut orderDict, &Value::Str("id".into()), crate::value::get_value_k(&trades.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), "order"));
}
if parseFilled {
filled = Value::Str("0".into());
}
if parseCost {
cost = Value::Str("0".into());
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_94: bool = true;
while { if !__for_first_94 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_94 = false; i.as_f64().unwrap_or(f64::NAN) < ((trades.len() as i64) as f64) } {
let mut trade: Value = trades.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut tradeAmount: Value = self.safe_string_k(trade.clone(), "amount", &[]);
if parseFilled && (tradeAmount != Value::Null) {
filled = crate::precise::Precise::stringAdd(&filled, &tradeAmount);
}
let mut tradeCost: Value = self.safe_string_k(trade.clone(), "cost", &[]);
if parseCost && (tradeCost != Value::Null) {
cost = crate::precise::Precise::stringAdd(&cost, &tradeCost);
}
if parseSymbol {
symbol = self.safe_string_k(trade.clone(), "symbol", &[]);
}
if parseSide {
side = self.safe_string_k(trade.clone(), "side", &[]);
}
let mut tradeTimestamp: Value = self.safe_value_k(trade.clone(), "timestamp", &[]);
if parseLastTradeTimeTimestamp && (tradeTimestamp != Value::Null) {
if (lastTradeTimeTimestamp == Value::Null) {
lastTradeTimeTimestamp = tradeTimestamp.clone();
} else {
lastTradeTimeTimestamp = crate::runtime::Math::max(&lastTradeTimeTimestamp, &tradeTimestamp);
}
}
if shouldParseFees {
let mut tradeFees: Value = self.safe_value_k(trade.clone(), "fees", &[]);
if (tradeFees != Value::Null) {
{
let mut j: Value = Value::Int(0);
let mut __for_first_93: bool = true;
while { if !__for_first_93 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_93 = false; j.as_f64().unwrap_or(f64::NAN) < get_array_length(&tradeFees).as_f64().unwrap_or(f64::NAN) } {
let mut tradeFee: Value = get_value(&tradeFees, &j);
let mut tradeFee: Value = get_value(&tradeFees, &j);
if let Value::Arr(__a) = &mut fees { std::sync::Arc::make_mut(__a).push(self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[tradeFee.clone()])); }
}
}
} else {
let mut tradeFee: Value = self.safe_value_k(trade, "fee", &[]);
if (tradeFee != Value::Null) {
if let Value::Arr(__a) = &mut fees { std::sync::Arc::make_mut(__a).push(self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[tradeFee.clone()])); }
}
}
}
}
}
}
}
if shouldParseFees {
let mut reducedFees: Value = fees.clone();
if self.reduceFees.as_bool() == Some(true) {
reducedFees = self.reduce_fees_by_currency(fees);
}
if (reducedFees == Value::Null) {
reducedFees = Value::from(vec![]);
}
let mut reducedLength: f64 = ((reducedFees.len() as i64) as f64);
{
let mut i: Value = Value::Int(0);
let mut __for_first_95: bool = true;
while { if !__for_first_95 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_95 = false; i.as_f64().unwrap_or(f64::NAN) < reducedLength } {
{ let __be_tmp = self.safe_number_k(get_value(&reducedFees, &i), "cost", &[]); add_element_to_object(get_value_mut(&mut reducedFees, &i), &Value::Str("cost".into()), __be_tmp); };
if (in_op(&reducedFees.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &Value::Str("rate".into()))) {
{ let __be_tmp = self.safe_number_k(get_value(&reducedFees, &i), "rate", &[]); add_element_to_object(get_value_mut(&mut reducedFees, &i), &Value::Str("rate".into()), __be_tmp); };
}
}
}
if !parseFee && (reducedLength == 0.0) {
// copy fee to avoid modification by reference
let mut feeCopy: Value = self.deep_extend(fee, &[]);
{ let __be_tmp = self.safe_number_k(feeCopy.clone(), "cost", &[]); add_element_to_object(&mut feeCopy, &Value::Str("cost".into()), __be_tmp); };
if (in_op(&feeCopy, &Value::Str("rate".into()))) {
{ let __be_tmp = self.safe_number_k(feeCopy.clone(), "rate", &[]); add_element_to_object(&mut feeCopy, &Value::Str("rate".into()), __be_tmp); };
}
append_to_array(&mut reducedFees, feeCopy);
}
add_element_to_object(&mut orderDict, &Value::Str("fees".into()), reducedFees.clone());
if parseFee && (reducedLength == 1.0) {
add_element_to_object(&mut orderDict, &Value::Str("fee".into()), reducedFees.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
}
}
if (amount == Value::Null) {
// ensure amount = filled + remaining
if (filled != Value::Null) && (remaining != Value::Null) {
amount = crate::precise::Precise::stringAdd(&filled, &remaining);
} else if (status.as_str() == Some("closed")) {
amount = filled.clone();
}
}
if (filled == Value::Null) {
if (amount != Value::Null) && (remaining != Value::Null) {
filled = crate::precise::Precise::stringSub(&amount, &remaining);
} else if (status.as_str() == Some("closed")) && (amount != Value::Null) {
filled = amount.clone();
}
}
if (remaining == Value::Null) {
if (amount != Value::Null) && (filled != Value::Null) {
remaining = crate::precise::Precise::stringSub(&amount, &filled);
} else if (status.as_str() == Some("closed")) {
remaining = Value::Str("0".into());
}
}
// ensure that the average field is calculated correctly
let mut inverse: Value = self.safe_bool_k(market.clone(), "inverse", &[Value::Bool(false)]);
let mut contractSize: Value = self.number_to_string(self.safe_value_k(market, "contractSize", &[Value::Int(1)]));
// inverse
// price = filled * contract size / cost
//
// linear
// price = cost / (filled * contract size)
if (average == Value::Null) {
if (filled != Value::Null) && (cost != Value::Null) && crate::precise::Precise::stringGt(&filled, &Value::Str("0".into())).as_bool() == Some(true) {
let mut filledTimesContractSize: Value = crate::precise::Precise::stringMul(&filled, &contractSize);
if inverse.as_bool() == Some(true) {
average = crate::precise::Precise::stringDiv(&filledTimesContractSize, &cost);
} else {
average = crate::precise::Precise::stringDiv(&cost, &filledTimesContractSize);
}
}
}
// similarly
// inverse
// cost = filled * contract size / price
//
// linear
// cost = filled * contract size * price
let mut costPriceExists: bool = (average != Value::Null) || (price != Value::Null);
if parseCost && (filled != Value::Null) && costPriceExists {
let mut multiplyPrice: Value = Value::Null;
if (average == Value::Null) {
multiplyPrice = price.clone();
} else {
multiplyPrice = average.clone();
}
// contract trading
let mut filledTimesContractSize: Value = crate::precise::Precise::stringMul(&filled, &contractSize);
if inverse.as_bool() == Some(true) {
cost = crate::precise::Precise::stringDiv(&filledTimesContractSize, &multiplyPrice);
} else {
cost = crate::precise::Precise::stringMul(&filledTimesContractSize, &multiplyPrice);
}
}
// support for market orders
let mut orderType: Value = self.safe_value_k(orderDict.clone(), "type", &[]);
let mut emptyPrice: bool = (price == Value::Null) || crate::precise::Precise::stringEquals(&price, &Value::Str("0".into())).as_bool() == Some(true);
if emptyPrice && (orderType.as_str() == Some("market")) {
price = average.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_97: bool = true;
while { if !__for_first_97 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_97 = false; i.as_f64().unwrap_or(f64::NAN) < ((trades.len() as i64) as f64) } {
let mut entry: Value = get_value(&trades, &i);
let mut entry: Value = get_value(&trades, &i);
{ let __be_tmp = self.safe_number_k(entry.clone(), "amount", &[]); add_element_to_object(&mut entry, &Value::Str("amount".into()), __be_tmp); };
{ let __be_tmp = self.safe_number_k(entry.clone(), "price", &[]); add_element_to_object(&mut entry, &Value::Str("price".into()), __be_tmp); };
{ let __be_tmp = self.safe_number_k(entry.clone(), "cost", &[]); add_element_to_object(&mut entry, &Value::Str("cost".into()), __be_tmp); };
let mut tradeFee: Value = self.safe_dict_k(entry.clone(), "fee", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = self.safe_number_k(tradeFee.clone(), "cost", &[]); if let Value::Dict(__d) = &mut tradeFee { std::sync::Arc::make_mut(__d).insert("cost".into(), __be_tmp); } }
if (matches!(&tradeFee, Value::Dict(__d) if __d.contains_key("rate"))) {
{ let __be_tmp = self.safe_number_k(tradeFee.clone(), "rate", &[]); if let Value::Dict(__d) = &mut tradeFee { std::sync::Arc::make_mut(__d).insert("rate".into(), __be_tmp); } }
}
let mut entryFees: Value = self.safe_list_k(entry.clone(), "fees", &[Value::from(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_96: bool = true;
while { if !__for_first_96 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_96 = false; j.as_f64().unwrap_or(f64::NAN) < ((entryFees.len() as i64) as f64) } {
{ let __be_tmp = self.safe_number_k(get_value(&entryFees, &j), "cost", &[]); add_element_to_object(get_value_mut(&mut entryFees, &j), &Value::Str("cost".into()), __be_tmp); };
}
}
add_element_to_object(&mut entry, &Value::Str("fees".into()), entryFees);
add_element_to_object(&mut entry, &Value::Str("fee".into()), tradeFee);
}
}
let mut timeInForce: Value = self.safe_string_k(orderDict.clone(), "timeInForce", &[]);
let mut postOnly: Value = self.safe_value_k(orderDict.clone(), "postOnly", &[]);
// timeInForceHandling
if (timeInForce == Value::Null) {
if !isTriggerOrSLTpOrder && (self.safe_string_k(orderDict.clone(), "type", &[]).as_str() == Some("market")) {
timeInForce = Value::Str("IOC".into());
}
// allow postOnly override
if (match &(postOnly) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) }) {
timeInForce = Value::Str("PO".into());
}
} else if (postOnly == Value::Null) {
// timeInForce is not undefined here
postOnly = Value::Bool(timeInForce.as_str() == Some("PO"));
}
let mut timestamp: Value = self.safe_integer_k(orderDict.clone(), "timestamp", &[]);
let mut lastUpdateTimestamp: Value = self.safe_integer_k(orderDict.clone(), "lastUpdateTimestamp", &[]);
let mut datetime: Value = self.safe_string_k(orderDict.clone(), "datetime", &[]);
if (datetime == Value::Null) {
datetime = self.iso8601(timestamp.clone());
}
let mut triggerPrice: Value = self.parse_number(self.safe_string2(orderDict.clone(), Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), &[]), &[]);
let mut takeProfitPrice: Value = self.parse_number(self.safe_string_k(orderDict.clone(), "takeProfitPrice", &[]), &[]);
let mut stopLossPrice: Value = self.parse_number(self.safe_string_k(orderDict.clone(), "stopLossPrice", &[]), &[]);
return self.extend(orderDict.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(orderDict.clone(), "id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(orderDict.clone(), "clientOrderId", &[]));
m.insert("timestamp".to_string(), timestamp);
m.insert("datetime".to_string(), datetime);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), self.safe_string_k(orderDict.clone(), "type", &[]));
m.insert("side".to_string(), side);
m.insert("lastTradeTimestamp".to_string(), lastTradeTimeTimestamp);
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp);
m.insert("price".to_string(), self.parse_number(price, &[]));
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("cost".to_string(), self.parse_number(cost, &[]));
m.insert("average".to_string(), self.parse_number(average, &[]));
m.insert("filled".to_string(), self.parse_number(filled, &[]));
m.insert("remaining".to_string(), self.parse_number(remaining, &[]));
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), postOnly);
m.insert("trades".to_string(), trades);
m.insert("reduceOnly".to_string(), self.safe_value_k(orderDict.clone(), "reduceOnly", &[]));
m.insert("stopPrice".to_string(), triggerPrice.clone());
m.insert("triggerPrice".to_string(), triggerPrice);
m.insert("takeProfitPrice".to_string(), takeProfitPrice);
m.insert("stopLossPrice".to_string(), stopLossPrice);
m.insert("status".to_string(), status);
m.insert("fee".to_string(), self.safe_value_k(orderDict, "fee", &[]));
m
})]);
Value::Null
}
fn parse_orders(&self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut market = 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
}));
//
// the value of orders is either a dict or a list
//
// dict
//
// {
// 'id1': { ... },
// 'id2': { ... },
// 'id3': { ... },
// ...
// }
//
// list
//
// [
// { 'id': 'id1', ... },
// { 'id': 'id2', ... },
// { 'id': 'id3', ... },
// ...
// ]
//
if (orders == Value::Null) {
return Value::from(vec![]);
}
let mut results: Value = Value::from(vec![]);
if (matches!(&orders, Value::Arr(_))) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_98: bool = true;
while { if !__for_first_98 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_98 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_order(self, get_value(&orders, &i), &[market.clone()]); // don't inline this call
let mut order: Value = self.extend(parsed, &[params.clone()]);
if let Value::Arr(__a) = &mut results { std::sync::Arc::make_mut(__a).push(order.clone()); }
}
}
} else {
let mut ids: Value = object_keys(&orders);
{
let mut i: Value = Value::Int(0);
let mut __for_first_99: bool = true;
while { if !__for_first_99 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_99 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
let mut id: Value = ids.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut idExtended: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
}), &[get_value(&orders, &id)]);
let mut parsedOrder: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_order(self, idExtended, &[market.clone()]); // don't inline these calls
let mut order: Value = self.extend(parsedOrder, &[params.clone()]);
if let Value::Arr(__a) = &mut results { std::sync::Arc::make_mut(__a).push(order); }
}
}
}
results = self.sort_by(results.clone(), Value::Str("timestamp".into()), &[]);
let mut symbol: Value = self.safe_string_k(market, "symbol", &[]);
return self.filter_by_symbol_since_limit(results, &[symbol, since, limit]);
Value::Null
}
fn calculate_fee_with_rate(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> Value {
let mut takerOrMaker = get_arg(optional_args, 0, Value::Str("taker".into()));
let mut feeRate = 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 (type_var.as_str() == Some("market")) && (takerOrMaker.as_str() == Some("maker")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" calculateFee() - you have provided incompatible arguments - \"market\" type order can not be \"maker\". Change either the \"type\" or the \"takerOrMaker\" argument to calculate the fee.".into()))));
}
let mut markets: Value = self.markets.clone();
if (markets == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" markets not loaded".into()))));
}
let mut market: Value = get_value(&markets, &symbol);
let mut market: Value = get_value(&markets, &symbol);
let mut feeSide: Option<String> = self.safe_string_k(market.clone(), "feeSide", &[Value::Str("quote".into())]).as_str().map(str::to_owned);
let mut useQuote: Value = Value::Null;
if (feeSide.as_deref() == Some("get")) {
// the fee is always in the currency you get
useQuote = Value::Bool(side.as_str() == Some("sell"));
} else if (feeSide.as_deref() == Some("give")) {
// the fee is always in the currency you give
useQuote = Value::Bool(side.as_str() == Some("buy"));
} else {
// the fee is always in feeSide currency
useQuote = Value::Bool(feeSide.as_deref() == Some("quote"));
}
let mut cost: Value = self.number_to_string(amount);
let mut key: Value = Value::Null;
if useQuote.as_bool() == Some(true) {
let mut priceString: Value = self.number_to_string(price);
cost = crate::precise::Precise::stringMul(&cost, &priceString);
key = Value::Str("quote".into());
} else {
key = Value::Str("base".into());
}
// for derivatives, the fee is in 'settle' currency
if !(match &(crate::value::get_value_k(&market, "spot")) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) }) {
key = Value::Str("settle".into());
}
// even if `takerOrMaker` argument was set to 'maker', for 'market' orders we should forcefully override it to 'taker'
let mut takerOrMakerResolved: Value = (if (type_var.as_str() == Some("market")) { Value::Str("taker".into()) } else { takerOrMaker });
let mut rate: Value = (if (feeRate != Value::Null) { self.number_to_string(feeRate) } else { self.safe_string(market.clone(), takerOrMakerResolved.clone(), &[]) });
cost = crate::precise::Precise::stringMul(&cost, &rate);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), takerOrMakerResolved);
m.insert("currency".to_string(), get_value(&market, &key));
m.insert("rate".to_string(), self.parse_number(rate, &[]));
m.insert("cost".to_string(), self.parse_number(cost, &[]));
m
});
Value::Null
}
fn calculate_fee(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> Value {
let mut takerOrMaker = get_arg(optional_args, 0, Value::Str("taker".into()));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.calculate_fee_with_rate(symbol, type_var, side, amount, price, &[takerOrMaker, Value::Null, params]);
Value::Null
}
fn safe_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let __market_empty = indexmap::IndexMap::new();
let market = market.as_map().unwrap_or(&__market_empty);
let mut contracts: Value = self.safe_string_k(liquidation.clone(), "contracts", &[]);
let mut contractSize: Value = (match market.get("contractSize") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut price: Value = self.safe_string_k(liquidation.clone(), "price", &[]);
let mut baseValue: Value = self.safe_string_k(liquidation.clone(), "baseValue", &[]);
let mut quoteValue: Value = self.safe_string_k(liquidation.clone(), "quoteValue", &[]);
if (baseValue == Value::Null) && (contracts != Value::Null) && (contractSize != Value::Null) && (price != Value::Null) {
baseValue = crate::precise::Precise::stringMul(&contracts, &contractSize);
}
if (quoteValue == Value::Null) && (baseValue != Value::Null) && (price != Value::Null) {
quoteValue = crate::precise::Precise::stringMul(&baseValue, &price);
}
if let Value::Dict(__d) = &mut liquidation { std::sync::Arc::make_mut(__d).insert("contracts".into(), self.parse_number(contracts, &[])); }
if let Value::Dict(__d) = &mut liquidation { std::sync::Arc::make_mut(__d).insert("contractSize".into(), self.parse_number(contractSize, &[])); }
if let Value::Dict(__d) = &mut liquidation { std::sync::Arc::make_mut(__d).insert("price".into(), self.parse_number(price, &[])); }
if let Value::Dict(__d) = &mut liquidation { std::sync::Arc::make_mut(__d).insert("baseValue".into(), self.parse_number(baseValue, &[])); }
if let Value::Dict(__d) = &mut liquidation { std::sync::Arc::make_mut(__d).insert("quoteValue".into(), self.parse_number(quoteValue, &[])); }
return liquidation;
Value::Null
}
fn safe_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let __market_empty = indexmap::IndexMap::new();
let market = market.as_map().unwrap_or(&__market_empty);
let mut amount: Value = self.safe_string_k(trade.clone(), "amount", &[]);
let mut price: Value = self.safe_string_k(trade.clone(), "price", &[]);
let mut cost: Value = self.safe_string_k(trade.clone(), "cost", &[]);
if (cost == Value::Null) {
// contract trading
let mut contractSize: Value = (match market.get("contractSize") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut multiplyPrice: Value = price.clone();
if (contractSize != Value::Null) {
let mut inverse: Value = (match market.get("inverse") { Some(Value::Bool(__b)) => Value::Bool(*__b), _ => Value::Bool(false) });
if inverse.as_bool() == Some(true) {
multiplyPrice = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &price);
}
multiplyPrice = crate::precise::Precise::stringMul(&multiplyPrice, &contractSize);
}
cost = crate::precise::Precise::stringMul(&multiplyPrice, &amount);
}
let mut resultFeeresultFeesVariable = self.parsed_fee_and_fees(trade.clone());
let mut resultFee: Value = resultFeeresultFeesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut resultFees: Value = resultFeeresultFeesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut trade { std::sync::Arc::make_mut(__d).insert("fee".into(), resultFee); }
if let Value::Dict(__d) = &mut trade { std::sync::Arc::make_mut(__d).insert("fees".into(), resultFees); }
if let Value::Dict(__d) = &mut trade { std::sync::Arc::make_mut(__d).insert("amount".into(), self.parse_number(amount, &[])); }
if let Value::Dict(__d) = &mut trade { std::sync::Arc::make_mut(__d).insert("price".into(), self.parse_number(price, &[])); }
if let Value::Dict(__d) = &mut trade { std::sync::Arc::make_mut(__d).insert("cost".into(), self.parse_number(cost, &[])); }
return trade;
Value::Null
}
fn create_ccxt_trade_id(&self, optional_args: &[Value]) -> Value {
let mut timestamp = get_arg(optional_args, 0, Value::Null);
let mut side = get_arg(optional_args, 1, Value::Null);
let mut amount = get_arg(optional_args, 2, Value::Null);
let mut price = get_arg(optional_args, 3, Value::Null);
let mut takerOrMaker = get_arg(optional_args, 4, Value::Null);
// this approach is being used by multiple exchanges (mexc, woo, coinsbit, dydx, ...)
let mut id: Value = Value::Null;
if (timestamp != Value::Null) {
id = self.number_to_string(timestamp);
if (side != Value::Null) {
id = Value::Str(format!("{}{}", id, Value::Str(format!("{}{}", Value::Str("-".into()), side).into())).into());
}
if (amount != Value::Null) {
id = Value::Str(format!("{}{}", id, Value::Str(format!("{}{}", Value::Str("-".into()), self.number_to_string(amount)).into())).into());
}
if (price != Value::Null) {
id = Value::Str(format!("{}{}", id, Value::Str(format!("{}{}", Value::Str("-".into()), self.number_to_string(price)).into())).into());
}
if (takerOrMaker != Value::Null) {
id = Value::Str(format!("{}{}", id, Value::Str(format!("{}{}", Value::Str("-".into()), takerOrMaker).into())).into());
}
}
return id;
Value::Null
}
fn parsed_fee_and_fees(&self, mut container: Value) -> Value {
let mut fee: Value = self.safe_dict_k(container.clone(), "fee", &[]);
let mut fees: Value = self.safe_list_k(container, "fees", &[]);
let mut feeDefined: bool = fee != Value::Null;
let mut feesDefined: bool = fees != Value::Null;
// parsing only if at least one of them is defined
let mut shouldParseFees: bool = feeDefined || feesDefined;
if shouldParseFees {
if feeDefined {
fee = self.parse_fee_numeric(fee.clone());
}
if !feesDefined {
// just set it directly, no further processing needed.
fees = Value::from(vec![fee.clone()]);
}
// 'fees' were set, so reparse them
let mut reducedFees: Value = fees.clone();
if self.reduceFees.as_bool() == Some(true) {
reducedFees = self.reduce_fees_by_currency(fees.clone());
}
if (reducedFees == Value::Null) {
reducedFees = Value::from(vec![]);
}
let mut reducedLength: f64 = ((reducedFees.len() as i64) as f64);
{
let mut i: Value = Value::Int(0);
let mut __for_first_100: bool = true;
while { if !__for_first_100 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_100 = false; i.as_f64().unwrap_or(f64::NAN) < reducedLength } {
{ let __be_tmp = self.parse_fee_numeric(get_value(&reducedFees, &i)); add_element_to_object(&mut reducedFees, &i, __be_tmp); };
}
}
fees = reducedFees.clone();
if (reducedLength == 1.0) {
fee = reducedFees.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
} else if (reducedLength == 0.0) {
fee = Value::Null;
}
}
// in case `fee & fees` are undefined, set `fees` as empty array
if (fee == Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Null);
m.insert("currency".to_string(), Value::Null);
m
});
}
if (fees == Value::Null) {
fees = Value::from(vec![]);
}
return Value::from(vec![fee, fees]);
Value::Null
}
fn parse_fee_numeric(&self, mut fee: Value) -> Value {
{ let __be_tmp = self.safe_number_k(fee.clone(), "cost", &[]); add_element_to_object(&mut fee, &Value::Str("cost".into()), __be_tmp); }; // ensure numeric
if (in_op(&fee, &Value::Str("rate".into()))) {
{ let __be_tmp = self.safe_number_k(fee.clone(), "rate", &[]); add_element_to_object(&mut fee, &Value::Str("rate".into()), __be_tmp); };
}
return fee;
Value::Null
}
fn find_nearest_ceiling(&self, mut arr: Value, mut providedValue: Value) -> Value {
// i.e. findNearestCeiling ([ 10, 30, 50], 23) returns 30
let mut length: Value = Value::Int(arr.len() as i64);
{
let mut i: Value = Value::Int(0);
let mut __for_first_101: bool = true;
while { if !__for_first_101 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_101 = false; i.as_f64().unwrap_or(f64::NAN) < length.as_f64().unwrap_or(f64::NAN) } {
let mut current: Value = arr.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if providedValue.as_f64().unwrap_or(f64::NAN) <= current.as_f64().unwrap_or(f64::NAN) {
return current;
}
}
}
return arr.as_array().and_then(|__arr| match &((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 })) { Value::Int(__n) if *__n >= 0 => __arr.get(*__n as usize), _ => None }).cloned().unwrap_or(Value::Null);
Value::Null
}
fn add_key_in_array_items(&self, mut obj: Value, mut keyName: Value) -> Value {
let mut result: Vec<Value> = Vec::new();
let mut keys: Value = object_keys(&obj);
{
let mut i: Value = Value::Int(0);
let mut __for_first_102: bool = true;
while { if !__for_first_102 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_102 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut item: Value = get_value(&obj, &key);
let mut item: Value = get_value(&obj, &key);
if (item == Value::Null) {
continue;
}
let mut itemWithKey: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[item]);
if let Value::Dict(__d) = &mut itemWithKey { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&keyName), key); }
result.push(itemWithKey);
}
}
return Value::from(result);
Value::Null
}
fn invert_flat_string_dictionary(&self, mut dict: Value) -> Value {
let mut reversed: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut keys: Value = object_keys(&dict);
{
let mut i: Value = Value::Int(0);
let mut __for_first_103: bool = true;
while { if !__for_first_103 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_103 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut value: Value = get_value(&dict, &key);
let mut value: Value = get_value(&dict, &key);
if matches!(&value, Value::Str(_)) {
if let Value::Dict(__d) = &mut reversed { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&value), key); }
}
}
}
return reversed;
Value::Null
}
fn string_to_base16(&self, mut str_val: Value) -> Value {
return Value::Str(format!("{}{}", Value::Str("0x".into()), self.binary_to_base16(self.base64_to_binary(self.string_to_base64(str_val, &[]), &[]), &[])).into());
Value::Null
}
fn reduce_fees_by_currency(&self, mut fees: Value) -> Value {
//
// this function takes a list of fee structures having the following format
//
// string = true
//
// [
// { 'currency': 'BTC', 'cost': '0.1' },
// { 'currency': 'BTC', 'cost': '0.2' },
// { 'currency': 'BTC', 'cost': '0.2', 'rate': '0.00123' },
// { 'currency': 'BTC', 'cost': '0.4', 'rate': '0.00123' },
// { 'currency': 'BTC', 'cost': '0.5', 'rate': '0.00456' },
// { 'currency': 'USDT', 'cost': '12.3456' },
// ]
//
// string = false
//
// [
// { 'currency': 'BTC', 'cost': 0.1 },
// { 'currency': 'BTC', 'cost': 0.2 },
// { 'currency': 'BTC', 'cost': 0.2, 'rate': 0.00123 },
// { 'currency': 'BTC', 'cost': 0.4, 'rate': 0.00123 },
// { 'currency': 'BTC', 'cost': 0.5, 'rate': 0.00456 },
// { 'currency': 'USDT', 'cost': 12.3456 },
// ]
//
// and returns a reduced fee list, where fees are summed per currency and rate (if any)
//
// string = true
//
// [
// { 'currency': 'BTC', 'cost': '0.4' },
// { 'currency': 'BTC', 'cost': '0.6', 'rate': '0.00123' },
// { 'currency': 'BTC', 'cost': '0.5', 'rate': '0.00456' },
// { 'currency': 'USDT', 'cost': '12.3456' },
// ]
//
// string = false
//
// [
// { 'currency': 'BTC', 'cost': 0.3 },
// { 'currency': 'BTC', 'cost': 0.6, 'rate': 0.00123 },
// { 'currency': 'BTC', 'cost': 0.5, 'rate': 0.00456 },
// { 'currency': 'USDT', 'cost': 12.3456 },
// ]
//
let mut reduced: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_104: bool = true;
while { if !__for_first_104 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_104 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&fees).as_f64().unwrap_or(f64::NAN) } {
let mut fee: Value = get_value(&fees, &i);
let mut fee: Value = get_value(&fees, &i);
let mut code: Value = self.safe_string_k(fee.clone(), "currency", &[]);
let mut feeCurrencyCode: Value = (if (code != Value::Null) { code.clone() } else { Value::Str(format!("{}", i).into()) });
if (feeCurrencyCode != Value::Null) {
let mut rate: Value = self.safe_string_k(fee.clone(), "rate", &[]);
let mut cost: Value = self.safe_string_k(fee, "cost", &[]);
if (cost == Value::Null) {
continue;
}
if !(matches!((&reduced, &feeCurrencyCode), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let Value::Dict(__d) = &mut reduced { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&feeCurrencyCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})); }
}
let mut rateKey: Value = (if (rate == Value::Null) { Value::Str("".into()) } else { rate.clone() });
if (in_op(&reduced.as_map().and_then(|__m| feeCurrencyCode.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), &rateKey)) {
{ let __be_tmp = crate::precise::Precise::stringAdd(&crate::value::get_value_k(&get_value(&get_value(&reduced, &feeCurrencyCode), &rateKey), "cost"), &cost); add_element_to_object(get_value_mut(get_value_mut(&mut reduced, &feeCurrencyCode), &rateKey), &Value::Str("cost".into()), __be_tmp); };
} else {
add_element_to_object(get_value_mut(&mut reduced, &feeCurrencyCode), &rateKey, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("cost".to_string(), cost);
m
}));
if (rate != Value::Null) {
add_element_to_object(get_value_mut(get_value_mut(&mut reduced, &feeCurrencyCode), &rateKey), &Value::Str("rate".into()), rate);
}
}
}
}
}
let mut result: Value = Value::from(vec![]);
let mut feeValues: Value = Value::Array(reduced.as_map().map(|__m| __m.values().cloned().collect()).unwrap_or_default());
{
let mut i: Value = Value::Int(0);
let mut __for_first_105: bool = true;
while { if !__for_first_105 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_105 = false; i.as_f64().unwrap_or(f64::NAN) < ((feeValues.len() as i64) as f64) } {
let mut reducedFeeValues: Value = object_values(&feeValues.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
result = self.array_concat(result.clone(), reducedFeeValues);
}
}
return result;
Value::Null
}
fn safe_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut open: Value = self.omit_zero(self.safe_string_k(ticker.clone(), "open", &[]));
let mut close: Value = self.omit_zero(self.safe_string2(ticker.clone(), Value::Str("close".into()), Value::Str("last".into()), &[]));
let mut change: Value = self.safe_string_k(ticker.clone(), "change", &[]); // change can be a legitimate zero on a flat day, do not omitZero it, see https://github.com/ccxt/ccxt/issues/25971
let mut percentage: Value = self.omit_zero(self.safe_string_k(ticker.clone(), "percentage", &[]));
let mut average: Value = self.omit_zero(self.safe_string_k(ticker.clone(), "average", &[]));
let mut vwap: Value = self.safe_string_k(ticker.clone(), "vwap", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "baseVolume", &[]);
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "quoteVolume", &[]);
if (vwap == Value::Null) {
vwap = crate::precise::Precise::stringDiv(&self.omit_zero(quoteVolume.clone()), &baseVolume);
}
// calculate open
if (change != Value::Null) {
if (close == Value::Null) && (average != Value::Null) {
close = crate::precise::Precise::stringAdd(&average, &crate::precise::Precise::stringDiv(&change, &Value::Str("2".into())));
}
if (open == Value::Null) && (close != Value::Null) {
open = crate::precise::Precise::stringSub(&close, &change);
}
} else if (percentage != Value::Null) {
if (close == Value::Null) && (average != Value::Null) {
let mut openAddClose: Value = crate::precise::Precise::stringMul(&average, &Value::Str("2".into()));
// openAddClose = open * (1 + (100 + percentage)/100)
let mut denominator: Value = crate::precise::Precise::stringAdd(&Value::Str("2".into()), &crate::precise::Precise::stringDiv(&percentage, &Value::Str("100".into())));
let mut calcOpen: Value = (if (open != Value::Null) { open.clone() } else { crate::precise::Precise::stringDiv(&openAddClose, &denominator) });
close = crate::precise::Precise::stringMul(&calcOpen, &crate::precise::Precise::stringAdd(&Value::Str("1".into()), &crate::precise::Precise::stringDiv(&percentage, &Value::Str("100".into()))));
}
if (open == Value::Null) && (close != Value::Null) {
open = crate::precise::Precise::stringDiv(&close, &crate::precise::Precise::stringAdd(&Value::Str("1".into()), &crate::precise::Precise::stringDiv(&percentage, &Value::Str("100".into()))));
}
}
// change
if (change == Value::Null) {
if (close != Value::Null) && (open != Value::Null) {
change = crate::precise::Precise::stringSub(&close, &open);
} else if (close != Value::Null) && (percentage != Value::Null) {
change = crate::precise::Precise::stringMul(&crate::precise::Precise::stringDiv(&percentage, &Value::Str("100".into())), &crate::precise::Precise::stringDiv(&close, &Value::Str("100".into())));
} else if (open != Value::Null) && (percentage != Value::Null) {
change = crate::precise::Precise::stringMul(&open, &crate::precise::Precise::stringDiv(&percentage, &Value::Str("100".into())));
}
}
// calculate things according to "open" (similar can be done with "close")
if (open != Value::Null) {
// percentage (using change)
if (percentage == Value::Null) && (change != Value::Null) {
percentage = crate::precise::Precise::stringMul(&crate::precise::Precise::stringDiv(&change, &open), &Value::Str("100".into()));
}
// close (using change)
if (close == Value::Null) && (change != Value::Null) {
close = crate::precise::Precise::stringAdd(&open, &change);
}
// close (using average)
if (close == Value::Null) && (average != Value::Null) {
// average is the midpoint of open and close, so twice it is their sum
close = crate::precise::Precise::stringSub(&crate::precise::Precise::stringMul(&average, &Value::Str("2".into())), &open);
}
// average
if (average == Value::Null) && (close != Value::Null) {
let mut precision: Value = Value::Int(18);
if (market != Value::Null) && self.is_tick_precision().as_bool() == Some(true) {
let mut marketPrecision: Value = self.safe_dict_k(market, "precision", &[]);
let mut precisionPrice: Value = self.safe_string_k(marketPrecision, "price", &[]);
if (precisionPrice != Value::Null) {
precision = self.precision_from_string(precisionPrice);
}
}
average = crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringAdd(&open, &close), &Value::Str("2".into()), &precision);
}
}
// timestamp and symbol operations don't belong in safeTicker
// they should be done in the derived classes
let mut closeParsed: Value = self.parse_number(self.omit_zero(close), &[]);
return self.extend(ticker.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bid".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(ticker.clone(), "bid", &[])), &[]));
m.insert("bidVolume".to_string(), self.safe_number_k(ticker.clone(), "bidVolume", &[]));
m.insert("ask".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(ticker.clone(), "ask", &[])), &[]));
m.insert("askVolume".to_string(), self.safe_number_k(ticker.clone(), "askVolume", &[]));
m.insert("high".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(ticker.clone(), "high", &[])), &[]));
m.insert("low".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(ticker.clone(), "low", &[])), &[]));
m.insert("open".to_string(), self.parse_number(self.omit_zero(open), &[]));
m.insert("close".to_string(), closeParsed.clone());
m.insert("last".to_string(), closeParsed);
m.insert("change".to_string(), self.parse_number(change, &[]));
m.insert("percentage".to_string(), self.parse_number(percentage, &[]));
m.insert("average".to_string(), self.parse_number(average, &[]));
m.insert("vwap".to_string(), self.parse_number(vwap, &[]));
m.insert("baseVolume".to_string(), self.parse_number(baseVolume, &[]));
m.insert("quoteVolume".to_string(), self.parse_number(quoteVolume, &[]));
m.insert("previousClose".to_string(), self.safe_number_k(ticker.clone(), "previousClose", &[]));
m.insert("indexPrice".to_string(), self.safe_number_k(ticker.clone(), "indexPrice", &[]));
m.insert("markPrice".to_string(), self.safe_number_k(ticker, "markPrice", &[]));
m
})]);
Value::Null
}
fn fetch_borrow_rate(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchBorrowRate is deprecated, please use fetchCrossBorrowRate or fetchIsolatedBorrowRate instead".into()))));
Value::Null
} }
fn repay_cross_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("repay_cross_margin", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(code); __args.push(amount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" repayCrossMargin is not support yet".into()))));
Value::Null
} }
fn repay_isolated_margin(&mut self, mut symbol: Value, mut code: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("repay_isolated_margin", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.push(code); __args.push(amount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" repayIsolatedMargin is not support yet".into()))));
Value::Null
} }
fn borrow_cross_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("borrow_cross_margin", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(code); __args.push(amount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" borrowCrossMargin is not support yet".into()))));
Value::Null
} }
fn borrow_isolated_margin(&mut self, mut symbol: Value, mut code: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("borrow_isolated_margin", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.push(code); __args.push(amount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" borrowIsolatedMargin is not support yet".into()))));
Value::Null
} }
fn borrow_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" borrowMargin is deprecated, please use borrowCrossMargin or borrowIsolatedMargin instead".into()))));
Value::Null
} }
fn repay_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" repayMargin is deprecated, please use repayCrossMargin or repayIsolatedMargin instead".into()))));
Value::Null
} }
fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_ohlcv", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
let mut message: Value = Value::Str("".into());
if (self.has.as_map().and_then(|__m| __m.get("fetchTrades")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchTrades")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
message = Value::Str(". If you want to build OHLCV candles from trade executions data, visit https://github.com/ccxt/ccxt/tree/master/examples/ and see \"build-ohlcv-bars\" file".into());
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchOHLCV() is not supported yet".into())).into()), message)));
Value::Null
} }
fn fetch_spot_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchSpotOHLCV() is not supported yet".into()))));
Value::Null
} }
fn fetch_contract_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchContractOHLCV() is not supported yet".into()))));
Value::Null
} }
fn fetch_ohlcv_ws(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
let mut message: Value = Value::Str("".into());
if (self.has.as_map().and_then(|__m| __m.get("fetchTradesWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchTradesWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
message = Value::Str(". If you want to build OHLCV candles from trade executions data, visit https://github.com/ccxt/ccxt/tree/master/examples/ and see \"build-ohlcv-bars\" file".into());
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchOHLCVWs() is not supported yet. Try using fetchOHLCV instead.".into())).into()), message)));
Value::Null
} }
fn watch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchOHLCV() is not supported yet".into()))));
Value::Null
} }
fn convert_trading_view_to_ohlcv(&self, mut ohlcvs: Value, optional_args: &[Value]) -> Value {
let mut timestamp = get_arg(optional_args, 0, Value::Str("t".into()));
let mut open = get_arg(optional_args, 1, Value::Str("o".into()));
let mut high = get_arg(optional_args, 2, Value::Str("h".into()));
let mut low = get_arg(optional_args, 3, Value::Str("l".into()));
let mut close = get_arg(optional_args, 4, Value::Str("c".into()));
let mut volume = get_arg(optional_args, 5, Value::Str("v".into()));
let mut ms = get_arg(optional_args, 6, Value::Bool(false));
let mut result: Vec<Value> = Vec::new();
let mut timestamps: Value = self.safe_list(ohlcvs.clone(), timestamp, &[Value::from(vec![])]);
let mut opens: Value = self.safe_list(ohlcvs.clone(), open, &[Value::from(vec![])]);
let mut highs: Value = self.safe_list(ohlcvs.clone(), high, &[Value::from(vec![])]);
let mut lows: Value = self.safe_list(ohlcvs.clone(), low, &[Value::from(vec![])]);
let mut closes: Value = self.safe_list(ohlcvs.clone(), close, &[Value::from(vec![])]);
let mut volumes: Value = self.safe_list(ohlcvs, volume, &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_106: bool = true;
while { if !__for_first_106 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_106 = false; i.as_f64().unwrap_or(f64::NAN) < ((timestamps.len() as i64) as f64) } {
result.push(Value::from(vec![(if is_true(&ms) { self.safe_integer(timestamps.clone(), i.clone(), &[]) } else { self.safe_timestamp(timestamps.clone(), i.clone(), &[]) }), self.safe_value(opens.clone(), i.clone(), &[]), self.safe_value(highs.clone(), i.clone(), &[]), self.safe_value(lows.clone(), i.clone(), &[]), self.safe_value(closes.clone(), i.clone(), &[]), self.safe_value(volumes.clone(), i.clone(), &[])]));
}
}
return Value::from(result);
Value::Null
}
fn convert_ohlcv_to_trading_view(&self, mut ohlcvs: Value, optional_args: &[Value]) -> Value {
let mut timestamp = get_arg(optional_args, 0, Value::Str("t".into()));
let mut open = get_arg(optional_args, 1, Value::Str("o".into()));
let mut high = get_arg(optional_args, 2, Value::Str("h".into()));
let mut low = get_arg(optional_args, 3, Value::Str("l".into()));
let mut close = get_arg(optional_args, 4, Value::Str("c".into()));
let mut volume = get_arg(optional_args, 5, Value::Str("v".into()));
let mut ms = get_arg(optional_args, 6, Value::Bool(false));
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(×tamp), Value::from(vec![])); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&open), Value::from(vec![])); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&high), Value::from(vec![])); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&low), Value::from(vec![])); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&close), Value::from(vec![])); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&volume), Value::from(vec![])); }
{
let mut i: Value = Value::Int(0);
let mut __for_first_107: bool = true;
while { if !__for_first_107 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_107 = false; i.as_f64().unwrap_or(f64::NAN) < ((ohlcvs.len() as i64) as f64) } {
let mut ts: Value = (if is_true(&ms) { ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null) } else { self.parse_to_int((match ((ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null)).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })) });
let mut resultTimestamp: Value = get_value(&result, ×tamp);
append_to_array(&mut resultTimestamp, ts);
crate::set_value(&mut result, ×tamp, resultTimestamp);
let mut resultOpen: Value = get_value(&result, &open);
append_to_array(&mut resultOpen, ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null));
crate::set_value(&mut result, &open, resultOpen);
let mut resultHigh: Value = get_value(&result, &high);
append_to_array(&mut resultHigh, ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_array().and_then(|__arr| __arr.get(2)).cloned().unwrap_or(Value::Null));
crate::set_value(&mut result, &high, resultHigh);
let mut resultLow: Value = get_value(&result, &low);
append_to_array(&mut resultLow, ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_array().and_then(|__arr| __arr.get(3)).cloned().unwrap_or(Value::Null));
crate::set_value(&mut result, &low, resultLow);
let mut resultClose: Value = get_value(&result, &close);
append_to_array(&mut resultClose, ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_array().and_then(|__arr| __arr.get(4)).cloned().unwrap_or(Value::Null));
crate::set_value(&mut result, &close, resultClose);
let mut resultVolume: Value = get_value(&result, &volume);
append_to_array(&mut resultVolume, ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_array().and_then(|__arr| __arr.get(5)).cloned().unwrap_or(Value::Null));
crate::set_value(&mut result, &volume, resultVolume);
}
}
return result;
Value::Null
}
fn fetch_web_endpoint(&mut self, mut method: Value, mut endpointMethod: Value, mut returnAsJson: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut startRegex = get_arg(optional_args, 0, Value::Null);
let mut endRegex = get_arg(optional_args, 1, Value::Null);
let mut errorMessage: Value = Value::Str("".into());
let mut options: Value = self.safe_value(self.options.clone(), method, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut muteOnFailure: Value = self.safe_bool_k(options.clone(), "webApiMuteFailure", &[Value::Bool(true)]);
{
// if it was not explicitly disabled, then don't fetch
if !matches!(self.safe_bool_k(options.clone(), "webApiEnable", &[Value::Bool(true)]), Value::Bool(true)) {
return Value::Null;
}
let mut maxRetries: Value = self.safe_integer_k(options, "webApiRetries", &[Value::Int(10)]);
let mut response: Value = Value::Null;
let mut retry: f64 = ((0i64) as f64);
let mut shouldBreak: bool = false;
while retry < maxRetries.as_f64().unwrap_or(f64::NAN) {
{
response = self.call_dynamic_checked(endpointMethod.clone(), vec![(Value::Map({
let mut m = indexmap::IndexMap::new();
m
})).clone()]).await;
shouldBreak = true;
break;
}
if shouldBreak {
break;
}
}
let mut content: Value = response;
if (content == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" fetchWebEndpoint() returned empty content".into()))));
}
if (startRegex != Value::Null) {
let mut splitted_by_start: Value = split(&content, &startRegex);
content = get_value(&splitted_by_start, &Value::Int(1)); // we need second part after start
}
if (content == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" fetchWebEndpoint() returned empty content".into()))));
}
if (endRegex != Value::Null) {
let mut splitted_by_end: Value = split(&content, &endRegex);
content = get_value(&splitted_by_end, &Value::Int(0)); // we need first part after start
}
if ((match &(returnAsJson) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) })) && (matches!(&content, Value::Str(_))) {
let mut jsoned: Value = self.parse_json_value(content.as_str().map(|__s| Value::Str(__s.trim().to_string().into())).unwrap_or(Value::Null)); // content should be trimmed before json parsing
if (jsoned != Value::Null) && (jsoned != Value::Null) {
return jsoned;
} else {
panic!("{}", crate::exchange_errors::bad_response("could not parse the response into json"));
}
} else {
return content;
}
}
if muteOnFailure.as_bool() == Some(true) {
return Value::Null;
} else {
panic!("{}", crate::exchange_errors::bad_response(errorMessage));
}
} }
fn market_ids(&self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
/*
* @param {string[]|undefined} symbols list of unified symbols
* @returns {string[]|undefined} list of exchange-specific market ids
* Overloads: non-null `string[]` input yields `string[]`; optional input yields `Strings`.
*/
if (symbols == Value::Null) {
return symbols;
}
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_108: bool = true;
while { if !__for_first_108 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_108 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbols.len() as i64) as f64) } {
let mut id: Value = self.market_id(symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
if (id != Value::Null) {
result.push(id);
}
}
}
return Value::from(result);
Value::Null
}
fn currency_ids(&self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
if (codes == Value::Null) {
return codes;
}
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_109: bool = true;
while { if !__for_first_109 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_109 = false; i.as_f64().unwrap_or(f64::NAN) < ((codes.len() as i64) as f64) } {
let mut id: Value = self.currency_id(codes.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
if (id != Value::Null) {
result.push(id);
}
}
}
return Value::from(result);
Value::Null
}
fn markets_for_symbols(&self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
if (symbols == Value::Null) {
return Value::Null;
}
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_110: bool = true;
while { if !__for_first_110 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_110 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbols.len() as i64) as f64) } {
result.push(<Self as crate::exchange_generated::ExchangeBase>::market(self, symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)));
}
}
return Value::from(result);
Value::Null
}
// allowEmpty: false always returns string[] (throws on empty/undefined at runtime)
fn market_symbols(&self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut type_var = get_arg(optional_args, 1, Value::Null);
let mut allowEmpty = get_arg(optional_args, 2, Value::Bool(true));
let mut sameTypeOnly = get_arg(optional_args, 3, Value::Bool(false));
let mut sameSubTypeOnly = get_arg(optional_args, 4, Value::Bool(false));
/*
* @param {string[]|undefined} symbols list of unified symbols
* @param {string|undefined} type filter by market type
* @param {boolean} allowEmpty whether empty/undefined symbols is allowed
* @param {boolean} sameTypeOnly require all markets to share type
* @param {boolean} sameSubTypeOnly require all markets to share linear/inverse subType
* @returns {string[]|undefined} validated unified symbols
* Overloads: `allowEmpty: false` or non-null `string[]` input yields `string[]`; permissive form yields `Strings`.
*/
if (symbols == Value::Null) {
if !(allowEmpty.as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" empty list of symbols is not supported".into()))));
}
return symbols;
}
let mut symbolsLength: f64 = ((symbols.len() as i64) as f64);
if (symbolsLength == 0.0) {
if !(allowEmpty.as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" empty list of symbols is not supported".into()))));
}
return symbols;
}
let mut result: Vec<Value> = Vec::new();
let mut marketType: Value = Value::Null;
let mut isLinearSubType: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_111: bool = true;
while { if !__for_first_111 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_111 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbols.len() as i64) as f64) } {
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
if sameTypeOnly.as_bool() == Some(true) && (marketType != Value::Null) {
if (market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null).as_str() != marketType.as_str()) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" symbols must be of the same type, either ".into())).into()), marketType).into()), Value::Str(" or ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(".".into()))));
}
}
if sameSubTypeOnly.as_bool() == Some(true) && (isLinearSubType != Value::Null) {
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() != isLinearSubType.as_bool()) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" symbols must be of the same subType, either linear or inverse.".into()))));
}
}
if (type_var != Value::Null) && (market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null).as_str() != type_var.as_str()) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" symbols must be of the same type ".into())).into()), type_var).into()), Value::Str(". If the type is incorrect you can change it in options or the params of the request".into()))));
}
marketType = self.safe_string_k(market.clone(), "type", &[]);
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
isLinearSubType = self.safe_bool_k(market.clone(), "linear", &[]);
}
let mut symbol: Value = self.safe_string_k(market, "symbol", &[symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)]);
result.push(symbol);
}
}
return Value::from(result);
Value::Null
}
fn market_codes(&self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
if (codes == Value::Null) {
return codes;
}
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_112: bool = true;
while { if !__for_first_112 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_112 = false; i.as_f64().unwrap_or(f64::NAN) < ((codes.len() as i64) as f64) } {
result.push(self.common_currency_code(codes.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)));
}
}
return Value::from(result);
Value::Null
}
fn parse_order_book_bids_asks(&self, mut bidasks: Value, optional_args: &[Value]) -> Value {
let mut priceKey = get_arg(optional_args, 0, Value::Int(0));
let mut amountKey = get_arg(optional_args, 1, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 2, Value::Int(2));
let mut bidasksValue: Value = self.to_array(bidasks);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_113: bool = true;
while { if !__for_first_113 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_113 = false; i.as_f64().unwrap_or(f64::NAN) < ((bidasksValue.len() as i64) as f64) } {
result.push(self.parse_order_book_bid_ask(get_value(&bidasksValue, &i), &[priceKey.clone(), amountKey.clone(), countOrIdKey.clone()]));
}
}
return Value::from(result);
Value::Null
}
fn parse_order_book_bids_asks_l3(&self, mut bidasks: Value, optional_args: &[Value]) -> Value {
let mut priceKey = get_arg(optional_args, 0, Value::Int(0));
let mut amountKey = get_arg(optional_args, 1, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 2, Value::Int(2));
let mut bidasksValue: Value = self.to_array(bidasks);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_114: bool = true;
while { if !__for_first_114 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_114 = false; i.as_f64().unwrap_or(f64::NAN) < ((bidasksValue.len() as i64) as f64) } {
result.push(self.parse_order_book_bid_ask_l3(get_value(&bidasksValue, &i), &[priceKey.clone(), amountKey.clone(), countOrIdKey.clone()]));
}
}
return Value::from(result);
Value::Null
}
fn filter_by_key(&self, mut objects: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut value = get_arg(optional_args, 0, Value::Null);
if (value == Value::Null) {
return objects;
}
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_115: bool = true;
while { if !__for_first_115 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_115 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&objects).as_f64().unwrap_or(f64::NAN) } {
let mut objectValue: Value = self.safe_string(get_value(&objects, &i), key.clone(), &[]);
if (objectValue.as_str() == value.as_str()) {
result.push(get_value(&objects, &i));
}
}
}
return Value::from(result);
Value::Null
}
fn filter_by_symbol(&self, mut objects: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
return self.filter_by_key(objects, Value::Str("symbol".into()), &[symbol]);
Value::Null
}
fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_ohlcv(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_ohlcv(self, ohlcv.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
if (matches!(&ohlcv, Value::Arr(_))) {
return Value::from(vec![self.safe_integer(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
}
return ohlcv;
Value::Null
}
fn safe_network(&self, mut network: Value) -> Value {
let mut withdrawEnabled: Value = self.safe_bool_k(network.clone(), "withdraw", &[]);
let mut depositEnabled: Value = self.safe_bool_k(network.clone(), "deposit", &[]);
let mut limits: Value = self.safe_dict_k(network.clone(), "limits", &[]);
let mut withdraw: Value = self.safe_dict_k(limits.clone(), "withdraw", &[]);
let mut deposit: Value = self.safe_dict_k(limits, "deposit", &[]);
let mut isEnabled: Value = withdrawEnabled.clone();
if (withdrawEnabled.as_bool() == Some(true)) {
isEnabled = depositEnabled.clone();
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), crate::value::get_value_k(&network, "info"));
m.insert("id".to_string(), self.safe_string_k(network.clone(), "id", &[]));
m.insert("name".to_string(), self.safe_string_k(network.clone(), "name", &[]));
m.insert("network".to_string(), self.safe_string_k(network.clone(), "network", &[]));
m.insert("active".to_string(), self.safe_bool_k(network.clone(), "active", &[isEnabled]));
m.insert("deposit".to_string(), depositEnabled);
m.insert("withdraw".to_string(), withdrawEnabled);
m.insert("fee".to_string(), self.safe_number_k(network.clone(), "fee", &[]));
m.insert("precision".to_string(), self.safe_number_k(network, "precision", &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(withdraw.clone(), "min", &[]));
m.insert("max".to_string(), self.safe_number_k(withdraw, "max", &[]));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(deposit.clone(), "min", &[]));
m.insert("max".to_string(), self.safe_number_k(deposit, "max", &[]));
m
}));
m
}));
m
});
Value::Null
}
fn network_code_to_id(&self, mut networkCode: Value, optional_args: &[Value]) -> Value {
let mut currencyCode = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @name exchange#networkCodeToId
* @description tries to convert the provided networkCode (a unified network code or one of its aliases) to a network id. In order to achieve this, derived class needs to have 'options->networks' defined.
* @param {string} networkCode unified network code
* @param {string} currencyCode unified currency code, but this argument is not required by default, unless there is an exchange (like huobi) that needs an override of the method to be able to pass currencyCode argument additionally
* @returns {string|undefined} exchange-specific network id
*/
if (networkCode == Value::Null) {
return Value::Null;
}
let mut unifiedCode: Value = self.safe_string(self.networkAliases.clone(), networkCode.clone(), &[networkCode.clone()]);
let mut networkIdsByCodes: Value = self.safe_dict_k(self.options.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networkId: Value = self.safe_string(networkIdsByCodes.clone(), unifiedCode.clone(), &[]);
if (networkId != Value::Null) {
return networkId;
}
// options.networks may still be keyed by an alias of the unified code
let mut aliases: Value = self.networkAliases.clone();
let mut aliasKeys: Value = object_keys(&aliases);
{
let mut i: Value = Value::Int(0);
let mut __for_first_116: bool = true;
while { if !__for_first_116 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_116 = false; i.as_f64().unwrap_or(f64::NAN) < ((aliasKeys.len() as i64) as f64) } {
let mut alias: Value = aliasKeys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (aliases.as_map().and_then(|__m| alias.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null).as_str() == unifiedCode.as_str()) && (matches!((&networkIdsByCodes, &alias), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return networkIdsByCodes.as_map().and_then(|__m| alias.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
}
}
}
// fall back to scanning loaded currencies
let mut currenciesToCheck: Value = Value::from(vec![]);
if (currencyCode == Value::Null) {
currenciesToCheck = Value::Array(self.currencies.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
} else {
currenciesToCheck = Value::from(vec![self.safe_dict(self.currencies.clone(), currencyCode, &[])]);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_117: bool = true;
while { if !__for_first_117 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_117 = false; i.as_f64().unwrap_or(f64::NAN) < ((currenciesToCheck.len() as i64) as f64) } {
let mut networks: Value = self.safe_dict(currenciesToCheck.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), Value::Str("networks".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (matches!((&networks, &unifiedCode), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return self.safe_string(networks.as_map().and_then(|__m| unifiedCode.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), Value::Str("id".into()), &[]);
}
}
}
return networkCode;
Value::Null
}
fn network_id_to_code(&self, optional_args: &[Value]) -> Value {
let mut networkId = get_arg(optional_args, 0, Value::Null);
let mut currencyCode = get_arg(optional_args, 1, Value::Null);
/*
* @ignore
* @method
* @name exchange#networkIdToCode
* @description tries to convert the provided exchange-specific networkId to an unified network Code. In order to achieve this, derived class needs to have "options['networksById']" defined.
* @param {string} networkId exchange specific network id/title, like: TRON, Trc-20, usdt-erc20, etc
* @param {string|undefined} currencyCode unified currency code, but this argument is not required by default, unless there is an exchange (like huobi) that needs an override of the method to be able to pass currencyCode argument additionally
* @returns {string|undefined} unified network code
*/
if (networkId == Value::Null) {
return Value::Null;
}
let mut networkCodesByIds: Value = self.safe_dict_k(self.options.clone(), "networksById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut mappedCode: Value = self.safe_string(networkCodesByIds, networkId.clone(), &[]);
let mut networkCode: Value = (if (mappedCode == Value::Null) { networkId } else { mappedCode });
return self.safe_string(self.networkAliases.clone(), networkCode.clone(), &[networkCode.clone()]);
Value::Null
}
fn handle_network_code_and_params(&self, mut params: Value) -> Value {
let mut networkCodeInParams: Value = self.safe_string2(params.clone(), Value::Str("networkCode".into()), Value::Str("network".into()), &[]);
let mut paramsOmitted: Value = (if (networkCodeInParams != Value::Null) { self.omit(params.clone(), Value::from(vec![Value::Str("networkCode".into()), Value::Str("network".into())]), &[]) } else { params });
return Value::from(vec![networkCodeInParams, paramsOmitted]);
Value::Null
}
fn select_network_key_from_networks(&self, mut currencyCode: Value, mut networkCode: Value, mut indexedNetworkEntries: Value, optional_args: &[Value]) -> Value {
let mut isIndexedByUnifiedNetworkCode = get_arg(optional_args, 0, Value::Bool(false));
// this method is used against raw & unparse network entries, which are just indexed by network id
let mut chosenNetworkId: Value = Value::Null;
let mut availableNetworkIds: Value = object_keys(&indexedNetworkEntries);
let mut responseNetworksLength: f64 = ((availableNetworkIds.len() as i64) as f64);
if (networkCode != Value::Null) {
if (responseNetworksLength == 0.0) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" - ".into())).into()), networkCode).into()), Value::Str(" network did not return any result for ".into())).into()), currencyCode)));
} else {
// if networkCode was provided by user, we should check it after response, as the referenced exchange doesn't support network-code during request
let mut networkIdOrCode: Value = (if isIndexedByUnifiedNetworkCode.as_bool() == Some(true) { networkCode.clone() } else { self.network_code_to_id(networkCode.clone(), &[currencyCode.clone()]) });
if (networkIdOrCode == Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" - ".into())).into()), networkCode).into()), Value::Str(" network was not found for ".into())).into()), currencyCode)));
}
if (in_op(&indexedNetworkEntries, &networkIdOrCode)) {
chosenNetworkId = networkIdOrCode.clone();
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" - ".into())).into()), networkIdOrCode).into()), Value::Str(" network was not found for ".into())).into()), currencyCode).into()), Value::Str(", use one of ".into())).into()), Value::Str(availableNetworkIds.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(", ")).unwrap_or_default().into()))));
}
}
} else {
if (responseNetworksLength == 0.0) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" - no networks were returned for ".into())).into()), currencyCode)));
} else {
// if networkCode was not provided by user, then we try to use the default network (if it was defined in "defaultNetworks"), otherwise, we just return the first network entry
let mut defaultNetworkCode: Value = self.safe_string(self.safe_dict_k(self.options.clone(), "defaultNetworks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), currencyCode.clone(), &[self.safe_string_k(self.options.clone(), "defaultNetwork", &[])]);
let mut defaultNetworkId: Value = (if isIndexedByUnifiedNetworkCode.as_bool() == Some(true) { defaultNetworkCode.clone() } else { self.network_code_to_id(defaultNetworkCode, &[currencyCode]) });
if (defaultNetworkId == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" selectNetworkKeyFromNetworks() missing defaultNetworkId".into()))));
}
if (in_op(&indexedNetworkEntries, &defaultNetworkId)) {
return defaultNetworkId;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" - can not determine the default network, please pass param[\"network\"] one from : ".into())).into()), Value::Str(availableNetworkIds.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(", ")).unwrap_or_default().into()))));
}
}
return chosenNetworkId;
Value::Null
}
fn safe_number2(&self, mut dictionary: Value, mut key1: Value, mut key2: Value, optional_args: &[Value]) -> Value {
let mut d = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_string2(dictionary, key1, key2, &[]);
return self.parse_number(value, &[d]);
Value::Null
}
fn parse_order_book(&self, mut orderbook: Value, mut symbol: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_order_book(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_order_book(self, orderbook.clone(), symbol.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null), crate::runtime::get_arg(optional_args, 1, crate::Value::Null), crate::runtime::get_arg(optional_args, 2, crate::Value::Null), crate::runtime::get_arg(optional_args, 3, crate::Value::Null), crate::runtime::get_arg(optional_args, 4, crate::Value::Null), crate::runtime::get_arg(optional_args, 5, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut timestamp = get_arg(optional_args, 0, Value::Null);
let mut bidsKey = get_arg(optional_args, 1, Value::Str("bids".into()));
let mut asksKey = get_arg(optional_args, 2, Value::Str("asks".into()));
let mut priceKey = get_arg(optional_args, 3, Value::Int(0));
let mut amountKey = get_arg(optional_args, 4, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 5, Value::Int(2));
let mut bids: Value = self.parse_order_book_bids_asks(self.safe_value(orderbook.clone(), bidsKey, &[Value::from(vec![])]), &[priceKey.clone(), amountKey.clone(), countOrIdKey.clone()]);
let mut asks: Value = self.parse_order_book_bids_asks(self.safe_value(orderbook, asksKey, &[Value::from(vec![])]), &[priceKey, amountKey, countOrIdKey]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("bids".to_string(), self.sort_by(bids, Value::Int(0), &[Value::Bool(true)]));
m.insert("asks".to_string(), self.sort_by(asks, Value::Int(0), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("nonce".to_string(), Value::Null);
m
});
Value::Null
}
fn parse_order_book_l3(&self, mut orderbook: Value, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timestamp = get_arg(optional_args, 0, Value::Null);
let mut bidsKey = get_arg(optional_args, 1, Value::Str("bids".into()));
let mut asksKey = get_arg(optional_args, 2, Value::Str("asks".into()));
let mut priceKey = get_arg(optional_args, 3, Value::Int(0));
let mut amountKey = get_arg(optional_args, 4, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 5, Value::Int(2));
let mut bids: Value = self.parse_order_book_bids_asks_l3(self.safe_value(orderbook.clone(), bidsKey, &[Value::from(vec![])]), &[priceKey.clone(), amountKey.clone(), countOrIdKey.clone()]);
let mut asks: Value = self.parse_order_book_bids_asks_l3(self.safe_value(orderbook, asksKey, &[Value::from(vec![])]), &[priceKey, amountKey, countOrIdKey]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("bids".to_string(), self.sort_by(bids, Value::Int(0), &[Value::Bool(true)]));
m.insert("asks".to_string(), self.sort_by(asks, Value::Int(0), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("nonce".to_string(), Value::Null);
m
});
Value::Null
}
fn parse_ohlc_vs(&self, mut ohlcvs: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timeframe = get_arg(optional_args, 1, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut tail = get_arg(optional_args, 4, Value::Bool(false));
if (ohlcvs == Value::Null) {
return Value::from(vec![]);
}
let mut results: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_118: bool = true;
while { if !__for_first_118 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_118 = false; i.as_f64().unwrap_or(f64::NAN) < ((ohlcvs.len() as i64) as f64) } {
results.push(<Self as crate::exchange_generated::ExchangeBase>::parse_ohlcv(self, ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[market.clone()]));
}
}
let mut sorted: Value = self.sort_by(Value::from(results), Value::Int(0), &[]);
return self.filter_by_since_limit(sorted, &[since, limit, Value::Int(0), tail]);
Value::Null
}
fn parse_leverage_tiers(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut marketIdKey = get_arg(optional_args, 1, Value::Null);
// marketIdKey should only be undefined when response is a dictionary.
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut tiers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut symbolsLength: Value = Value::Int(0);
if (symbolsNormalized != Value::Null) {
symbolsLength = Value::Int(symbolsNormalized.len() as i64);
}
let mut noSymbols: bool = (symbolsNormalized == Value::Null) || (symbolsLength.as_f64() == Some(0.0));
if (matches!(&response, Value::Arr(_))) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_119: bool = true;
while { if !__for_first_119 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_119 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut item: Value = response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut id: Value = (if (marketIdKey == Value::Null) { Value::Null } else { self.safe_string(item.clone(), marketIdKey.clone(), &[]) });
let mut market: Value = self.safe_market(&[id, Value::Null, Value::Null, Value::Str("swap".into())]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut contract: Value = self.safe_bool_k(market.clone(), "contract", &[Value::Bool(false)]);
if contract.as_bool() == Some(true) && (noSymbols || ((symbolsNormalized != Value::Null) && self.in_array(symbol.clone(), symbolsNormalized.clone()).as_bool() == Some(true))) {
if let Value::Dict(__d) = &mut tiers { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), <Self as crate::exchange_generated::ExchangeBase>::parse_market_leverage_tiers(self, item.clone(), &[market.clone()])); }
}
}
}
} else {
let mut keys: Value = object_keys(&response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_120: bool = true;
while { if !__for_first_120 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_120 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut marketId: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut item: Value = get_value(&response, &marketId);
let mut item: Value = get_value(&response, &marketId);
let mut market: Value = self.safe_market(&[marketId, Value::Null, Value::Null, Value::Str("swap".into())]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut contract: Value = self.safe_bool_k(market.clone(), "contract", &[Value::Bool(false)]);
if contract.as_bool() == Some(true) && (noSymbols || ((symbolsNormalized != Value::Null) && self.in_array(symbol.clone(), symbolsNormalized.clone()).as_bool() == Some(true))) {
if let Value::Dict(__d) = &mut tiers { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), <Self as crate::exchange_generated::ExchangeBase>::parse_market_leverage_tiers(self, item, &[market])); }
}
}
}
}
return tiers;
Value::Null
}
fn load_trading_limits(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut reload = get_arg(optional_args, 1, Value::Bool(false));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchTradingLimits")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchTradingLimits")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
if reload.as_bool() == Some(true) || !(matches!(&self.options, Value::Dict(__d) if __d.contains_key("limitsLoaded"))) {
let mut response: Value = self.fetch_trading_limits(&[symbols.clone()]).await;
let mut symbolsArray: Value = self.require_value(symbols, &[Value::Str("loadTradingLimits() requires a symbols argument".into())]);
let mut markets: Value = self.markets.clone();
if (markets == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" markets not loaded".into()))));
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_121: bool = true;
while { if !__for_first_121 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_121 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&symbolsArray).as_f64().unwrap_or(f64::NAN) } {
let mut symbol: Value = get_value(&symbolsArray, &i);
let mut symbol: Value = get_value(&symbolsArray, &i);
{ let __be_tmp = self.deep_extend(get_value(&markets, &symbol), &[get_value(&response, &symbol)]); add_element_to_object(&mut markets, &symbol, __be_tmp); };
}
}
{ let __be_tmp = self.milliseconds(); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("limitsLoaded".into(), __be_tmp); } }
}
}
return self.markets.clone();
Value::Null
} }
fn safe_position(&self, mut position: Value) -> Value {
// simplified version of: /pull/12765/
// if contractSize is undefined get from market
let mut contractSize: Value = self.safe_number_k(position.clone(), "contractSize", &[]);
let mut symbol: Value = self.safe_string_k(position.clone(), "symbol", &[]);
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.safe_value(self.markets.clone(), symbol, &[]);
}
if (contractSize == Value::Null) && (market != Value::Null) {
contractSize = self.safe_number_k(market.clone(), "contractSize", &[]);
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("contractSize".into(), contractSize); }
}
let mut isInverse: bool = (market != Value::Null) && self.safe_bool_k(market, "inverse", &[Value::Bool(false)]).as_bool() == Some(true);
let mut side: Option<String> = self.safe_string_k(position.clone(), "side", &[]).as_str().map(str::to_owned);
let mut marginMode: Option<String> = self.safe_string_k(position.clone(), "marginMode", &[]).as_str().map(str::to_owned);
let mut unrealizedPnlString: Value = self.safe_string_k(position.clone(), "unrealizedPnl", &[]);
let mut initialMarginString: Value = self.safe_string_k(position.clone(), "initialMargin", &[]);
let mut maintenanceMarginString: Value = self.safe_string_k(position.clone(), "maintenanceMargin", &[]);
let mut collateralString: Value = self.safe_string_k(position.clone(), "collateral", &[]);
let mut entryPriceString: Value = self.safe_string_k(position.clone(), "entryPrice", &[]);
let mut liquidationPriceString: Value = self.safe_string_k(position.clone(), "liquidationPrice", &[]);
let mut contractsString: Value = self.safe_string_k(position.clone(), "contracts", &[]);
let mut contractSizeString: Value = self.safe_string_k(position.clone(), "contractSize", &[]);
// margin is the amount held in the position (excludes unrealized pnl), collateral = margin + unrealizedPnl
let mut marginString: Value = self.safe_string_k(position.clone(), "positionMargin", &[]);
if (marginString == Value::Null) && (marginMode.as_deref() == Some("isolated")) && (collateralString != Value::Null) {
let mut derivedMargin: Value = collateralString.clone();
if (unrealizedPnlString != Value::Null) && !(crate::precise::Precise::stringEq(&collateralString, &initialMarginString).as_bool() == Some(true)) {
derivedMargin = crate::precise::Precise::stringSub(&collateralString, &unrealizedPnlString);
}
if crate::precise::Precise::stringGt(&derivedMargin, &Value::Str("0".into())).as_bool() == Some(true) {
marginString = derivedMargin.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("positionMargin".into(), self.parse_number(derivedMargin, &[])); }
}
}
if (marginString == Value::Null) {
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("positionMargin".into(), Value::Null); }; // keep the unified key present across all exchanges
}
if (collateralString == Value::Null) && (marginString != Value::Null) && (unrealizedPnlString != Value::Null) {
collateralString = crate::precise::Precise::stringAdd(&marginString, &unrealizedPnlString);
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("collateral".into(), self.parse_number(collateralString.clone(), &[])); }
}
if (marginMode.as_deref() == Some("isolated")) {
let mut entryMarginString: Value = marginString.clone();
if (entryMarginString == Value::Null) && (collateralString == Value::Null) {
entryMarginString = initialMarginString.clone();
}
let mut hasEntryMargin: bool = (entryMarginString != Value::Null) && crate::precise::Precise::stringGt(&entryMarginString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasEntryPrice: bool = (entryPriceString != Value::Null) && crate::precise::Precise::stringGt(&entryPriceString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasLiqPrice: bool = (liquidationPriceString != Value::Null) && crate::precise::Precise::stringGt(&liquidationPriceString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasContracts: bool = (contractsString != Value::Null) && crate::precise::Precise::stringGt(&contractsString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasContractSize: bool = (contractSizeString != Value::Null) && crate::precise::Precise::stringGt(&contractSizeString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasMm: bool = (maintenanceMarginString != Value::Null) && crate::precise::Precise::stringGt(&maintenanceMarginString, &Value::Str("0".into())).as_bool() == Some(true);
let mut priceDiff: Value = Value::Null;
if hasEntryPrice && hasLiqPrice {
if isInverse {
let mut invEntry: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &entryPriceString);
let mut invLiq: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &liquidationPriceString);
if (side.as_deref() == Some("long")) {
priceDiff = crate::precise::Precise::stringSub(&invLiq, &invEntry);
} else if (side.as_deref() == Some("short")) {
priceDiff = crate::precise::Precise::stringSub(&invEntry, &invLiq);
} else {
priceDiff = crate::precise::Precise::stringAbs(&crate::precise::Precise::stringSub(&invEntry, &invLiq));
}
} else {
if (side.as_deref() == Some("long")) {
priceDiff = crate::precise::Precise::stringSub(&entryPriceString, &liquidationPriceString);
} else if (side.as_deref() == Some("short")) {
priceDiff = crate::precise::Precise::stringSub(&liquidationPriceString, &entryPriceString);
} else {
priceDiff = crate::precise::Precise::stringAbs(&crate::precise::Precise::stringSub(&entryPriceString, &liquidationPriceString));
}
}
}
let mut hasPriceDiff: bool = (priceDiff != Value::Null) && crate::precise::Precise::stringGt(&priceDiff, &Value::Str("0".into())).as_bool() == Some(true);
if (maintenanceMarginString == Value::Null) && hasEntryMargin && hasPriceDiff && hasContracts && hasContractSize {
let mut lossFromEntry: Value = crate::precise::Precise::stringMul(&priceDiff, &crate::precise::Precise::stringMul(&contractsString, &contractSizeString));
let mut derivedMm: Value = crate::precise::Precise::stringSub(&entryMarginString, &lossFromEntry);
if crate::precise::Precise::stringGt(&derivedMm, &Value::Str("0".into())).as_bool() == Some(true) {
maintenanceMarginString = derivedMm.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("maintenanceMargin".into(), self.parse_number(derivedMm.clone(), &[])); }
}
} else if (collateralString == Value::Null) && (initialMarginString == Value::Null) && hasMm && hasPriceDiff && hasContracts && hasContractSize {
let mut lossFromEntry: Value = crate::precise::Precise::stringMul(&priceDiff, &crate::precise::Precise::stringMul(&contractsString, &contractSizeString));
let mut derivedEntryMargin: Value = crate::precise::Precise::stringAdd(&maintenanceMarginString, &lossFromEntry);
if crate::precise::Precise::stringGt(&derivedEntryMargin, &Value::Str("0".into())).as_bool() == Some(true) {
initialMarginString = derivedEntryMargin.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("initialMargin".into(), self.parse_number(derivedEntryMargin.clone(), &[])); }
marginString = derivedEntryMargin.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("positionMargin".into(), self.parse_number(derivedEntryMargin.clone(), &[])); }
let mut derivedCollateral: Value = derivedEntryMargin.clone();
if (unrealizedPnlString != Value::Null) {
derivedCollateral = crate::precise::Precise::stringAdd(&derivedEntryMargin, &unrealizedPnlString);
}
if crate::precise::Precise::stringGt(&derivedCollateral, &Value::Str("0".into())).as_bool() == Some(true) {
collateralString = derivedCollateral.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("collateral".into(), self.parse_number(derivedCollateral, &[])); }
}
}
} else if (liquidationPriceString == Value::Null) && hasEntryMargin && hasMm && hasEntryPrice && hasContracts && hasContractSize && ((side.as_deref() == Some("long")) || (side.as_deref() == Some("short"))) {
let mut marginBuffer: Value = crate::precise::Precise::stringSub(&entryMarginString, &maintenanceMarginString);
let mut totalSize: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
if crate::precise::Precise::stringGt(&marginBuffer, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&totalSize, &Value::Str("0".into())).as_bool() == Some(true) {
let mut bufferPerUnit: Value = crate::precise::Precise::stringDiv(&marginBuffer, &totalSize);
let mut derivedLp: Value = crate::precise::Precise::stringAdd(&entryPriceString, &bufferPerUnit);
if (side.as_deref() == Some("long")) {
derivedLp = crate::precise::Precise::stringSub(&entryPriceString, &bufferPerUnit);
}
if isInverse {
let mut invEntry: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &entryPriceString);
let mut invDerivedLp: Value = crate::precise::Precise::stringSub(&invEntry, &bufferPerUnit);
if (side.as_deref() == Some("long")) {
invDerivedLp = crate::precise::Precise::stringAdd(&invEntry, &bufferPerUnit);
}
// 1 / invDerivedLp keeps its sign (undefined at 0), so the > 0 guard below
// rejects exactly the values a separate invDerivedLp > 0 check would
derivedLp = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &invDerivedLp);
}
if (derivedLp != Value::Null) && crate::precise::Precise::stringGt(&derivedLp, &Value::Str("0".into())).as_bool() == Some(true) {
liquidationPriceString = derivedLp.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("liquidationPrice".into(), self.parse_number(derivedLp, &[])); }
}
}
} else if (entryPriceString == Value::Null) && hasEntryMargin && hasMm && hasLiqPrice && hasContracts && hasContractSize && ((side.as_deref() == Some("long")) || (side.as_deref() == Some("short"))) {
let mut marginBuffer: Value = crate::precise::Precise::stringSub(&entryMarginString, &maintenanceMarginString);
let mut totalSize: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
if crate::precise::Precise::stringGt(&marginBuffer, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&totalSize, &Value::Str("0".into())).as_bool() == Some(true) {
let mut bufferPerUnit: Value = crate::precise::Precise::stringDiv(&marginBuffer, &totalSize);
let mut derivedEp: Value = crate::precise::Precise::stringSub(&liquidationPriceString, &bufferPerUnit);
if (side.as_deref() == Some("long")) {
derivedEp = crate::precise::Precise::stringAdd(&liquidationPriceString, &bufferPerUnit);
}
if isInverse {
let mut invLp: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &liquidationPriceString);
let mut invEp: Value = crate::precise::Precise::stringAdd(&invLp, &bufferPerUnit);
if (side.as_deref() == Some("long")) {
invEp = crate::precise::Precise::stringSub(&invLp, &bufferPerUnit);
}
// 1 / invEp keeps its sign (undefined at 0), so the > 0 guard below
// rejects exactly the values a separate invEp > 0 check would
derivedEp = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &invEp);
}
if (derivedEp != Value::Null) && crate::precise::Precise::stringGt(&derivedEp, &Value::Str("0".into())).as_bool() == Some(true) {
entryPriceString = derivedEp.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("entryPrice".into(), self.parse_number(derivedEp, &[])); }
}
}
} else if (contractsString == Value::Null) && hasEntryMargin && hasMm && hasPriceDiff && hasContractSize {
let mut marginBuffer: Value = crate::precise::Precise::stringSub(&entryMarginString, &maintenanceMarginString);
let mut denom: Value = crate::precise::Precise::stringMul(&priceDiff, &contractSizeString);
if crate::precise::Precise::stringGt(&marginBuffer, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&denom, &Value::Str("0".into())).as_bool() == Some(true) {
let mut derivedContracts: Value = crate::precise::Precise::stringDiv(&marginBuffer, &denom);
if crate::precise::Precise::stringGt(&derivedContracts, &Value::Str("0".into())).as_bool() == Some(true) {
contractsString = derivedContracts.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("contracts".into(), self.parse_number(derivedContracts, &[])); }
}
}
} else if (contractSizeString == Value::Null) && hasEntryMargin && hasMm && hasPriceDiff && hasContracts {
let mut marginBuffer: Value = crate::precise::Precise::stringSub(&entryMarginString, &maintenanceMarginString);
let mut denom: Value = crate::precise::Precise::stringMul(&priceDiff, &contractsString);
if crate::precise::Precise::stringGt(&marginBuffer, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&denom, &Value::Str("0".into())).as_bool() == Some(true) {
let mut derivedContractSize: Value = crate::precise::Precise::stringDiv(&marginBuffer, &denom);
if crate::precise::Precise::stringGt(&derivedContractSize, &Value::Str("0".into())).as_bool() == Some(true) {
contractSizeString = derivedContractSize.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("contractSize".into(), self.parse_number(derivedContractSize, &[])); }
}
}
}
}
//
// POSITION-LOCAL DERIVATIONS (CROSS & ISOLATED)
//
let mut isZeroPosition: bool = (contractsString != Value::Null) && crate::precise::Precise::stringEq(&contractsString, &Value::Str("0".into())).as_bool() == Some(true);
if !isZeroPosition {
let mut notionalString: Value = self.safe_string_k(position.clone(), "notional", &[]);
let mut markPriceString: Value = self.safe_string_k(position.clone(), "markPrice", &[]);
let mut lastPriceString: Option<String> = self.safe_string_k(position.clone(), "lastPrice", &[]).as_str().map(str::to_owned);
let mut hasContracts: bool = (contractsString != Value::Null) && crate::precise::Precise::stringGt(&contractsString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasContractSize: bool = (contractSizeString != Value::Null) && crate::precise::Precise::stringGt(&contractSizeString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasMarkPrice: bool = (markPriceString != Value::Null) && crate::precise::Precise::stringGt(&markPriceString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasNotional: bool = (notionalString != Value::Null) && crate::precise::Precise::stringGt(¬ionalString, &Value::Str("0".into())).as_bool() == Some(true);
// 1. notional <-> markPrice / contracts / contractSize
if (notionalString == Value::Null) && hasMarkPrice && hasContracts && hasContractSize {
let mut totalSize: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
let mut derivedNotional: Value = crate::precise::Precise::stringMul(&totalSize, &markPriceString);
if isInverse {
derivedNotional = crate::precise::Precise::stringDiv(&totalSize, &markPriceString);
}
if crate::precise::Precise::stringGt(&derivedNotional, &Value::Str("0".into())).as_bool() == Some(true) {
notionalString = derivedNotional.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("notional".into(), self.parse_number(derivedNotional, &[])); }
}
} else if (markPriceString == Value::Null) && (entryPriceString == Value::Null) && (lastPriceString.is_none()) && hasNotional && hasContracts && hasContractSize {
let mut totalSize: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
let mut derivedMark: Value = crate::precise::Precise::stringDiv(¬ionalString, &totalSize);
if isInverse {
derivedMark = crate::precise::Precise::stringDiv(&totalSize, ¬ionalString);
}
if crate::precise::Precise::stringGt(&derivedMark, &Value::Str("0".into())).as_bool() == Some(true) {
markPriceString = derivedMark.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("markPrice".into(), self.parse_number(derivedMark, &[])); }
}
} else if (contractsString == Value::Null) && hasNotional && hasMarkPrice && hasContractSize {
let mut notionalContracts: Value = crate::precise::Precise::stringDiv(¬ionalString, &crate::precise::Precise::stringMul(&markPriceString, &contractSizeString));
if isInverse {
notionalContracts = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(¬ionalString, &markPriceString), &contractSizeString);
}
if crate::precise::Precise::stringGt(¬ionalContracts, &Value::Str("0".into())).as_bool() == Some(true) {
contractsString = notionalContracts.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("contracts".into(), self.parse_number(notionalContracts, &[])); }
}
} else if (contractSizeString == Value::Null) && hasNotional && hasMarkPrice && hasContracts {
let mut notionalContractSize: Value = crate::precise::Precise::stringDiv(¬ionalString, &crate::precise::Precise::stringMul(&markPriceString, &contractsString));
if isInverse {
notionalContractSize = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(¬ionalString, &markPriceString), &contractsString);
}
if crate::precise::Precise::stringGt(¬ionalContractSize, &Value::Str("0".into())).as_bool() == Some(true) {
contractSizeString = notionalContractSize.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("contractSize".into(), self.parse_number(notionalContractSize, &[])); }
}
}
// 2. unrealizedPnl from entryPrice, markPrice, contracts, contractSize, side
if (unrealizedPnlString == Value::Null) && (entryPriceString != Value::Null) && (markPriceString != Value::Null) && (contractsString != Value::Null) && (contractSizeString != Value::Null) {
if crate::precise::Precise::stringGt(&entryPriceString, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&markPriceString, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&contractsString, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&contractSizeString, &Value::Str("0".into())).as_bool() == Some(true) {
let mut totalSize: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
let mut pnlDiff: Value = Value::Null;
if isInverse {
let mut invEntry: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &entryPriceString);
let mut invMark: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &markPriceString);
if (side.as_deref() == Some("long")) {
pnlDiff = crate::precise::Precise::stringSub(&invEntry, &invMark);
} else if (side.as_deref() == Some("short")) {
pnlDiff = crate::precise::Precise::stringSub(&invMark, &invEntry);
}
} else {
if (side.as_deref() == Some("long")) {
pnlDiff = crate::precise::Precise::stringSub(&markPriceString, &entryPriceString);
} else if (side.as_deref() == Some("short")) {
pnlDiff = crate::precise::Precise::stringSub(&entryPriceString, &markPriceString);
}
}
if (pnlDiff != Value::Null) {
let mut candidateUpnl: Value = crate::precise::Precise::stringMul(&pnlDiff, &totalSize);
if crate::precise::Precise::stringEq(&candidateUpnl, &Value::Str("0".into())).as_bool() == Some(true) || crate::precise::Precise::stringGe(&crate::precise::Precise::stringAbs(&candidateUpnl), &Value::Str("0.000001".into())).as_bool() == Some(true) {
unrealizedPnlString = candidateUpnl.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("unrealizedPnl".into(), self.parse_number(unrealizedPnlString.clone(), &[])); }
}
}
}
}
// 3. initialMargin <-> initialMarginPercentage <-> leverage / notional
let mut hasValidNotional: bool = (notionalString != Value::Null) && crate::precise::Precise::stringGt(¬ionalString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasNegativeCollateral: bool = (collateralString != Value::Null) && crate::precise::Precise::stringLt(&collateralString, &Value::Str("0".into())).as_bool() == Some(true);
let mut initialMarginPercentageString: Value = self.safe_string_k(position.clone(), "initialMarginPercentage", &[]);
let mut leverageString: Value = self.safe_string_k(position.clone(), "leverage", &[]);
let mut hasLeverage: bool = (leverageString != Value::Null) && crate::precise::Precise::stringGt(&leverageString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasInitialMargin: bool = (initialMarginString != Value::Null) && crate::precise::Precise::stringGt(&initialMarginString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hadInitialMargin: bool = initialMarginString != Value::Null;
if (initialMarginPercentageString == Value::Null) && !hasNegativeCollateral && (hasInitialMargin || !hadInitialMargin) {
if hasInitialMargin && hasValidNotional {
initialMarginPercentageString = crate::precise::Precise::stringDiv(&initialMarginString, ¬ionalString);
} else if hasLeverage {
initialMarginPercentageString = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &leverageString);
}
if (initialMarginPercentageString != Value::Null) && crate::precise::Precise::stringGt(&initialMarginPercentageString, &Value::Str("0".into())).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("initialMarginPercentage".into(), self.parse_number(initialMarginPercentageString.clone(), &[])); }
}
}
let mut hasImp: bool = (initialMarginPercentageString != Value::Null) && crate::precise::Precise::stringGt(&initialMarginPercentageString, &Value::Str("0".into())).as_bool() == Some(true);
if (initialMarginString == Value::Null) && !hasNegativeCollateral && hasValidNotional {
if hasLeverage {
initialMarginString = crate::precise::Precise::stringDiv(¬ionalString, &leverageString);
} else if hasImp {
initialMarginString = crate::precise::Precise::stringMul(¬ionalString, &initialMarginPercentageString);
}
if (initialMarginString != Value::Null) && crate::precise::Precise::stringGt(&initialMarginString, &Value::Str("0".into())).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("initialMargin".into(), self.parse_number(initialMarginString.clone(), &[])); }
}
}
if (leverageString == Value::Null) && !hadInitialMargin && hasImp {
let mut derivedLeverage: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &initialMarginPercentageString);
if crate::precise::Precise::stringGt(&derivedLeverage, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringLe(&derivedLeverage, &Value::Str("200".into())).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("leverage".into(), self.parse_number(derivedLeverage, &[])); }
}
}
// 4. maintenanceMargin <-> maintenanceMarginPercentage / notional
let mut maintenanceMarginPercentageString: Value = self.safe_string_k(position.clone(), "maintenanceMarginPercentage", &[]);
let mut hasValidMm: bool = (maintenanceMarginString != Value::Null) && crate::precise::Precise::stringGt(&maintenanceMarginString, &Value::Str("0".into())).as_bool() == Some(true);
let mut hasValidMmp: bool = (maintenanceMarginPercentageString != Value::Null) && crate::precise::Precise::stringGt(&maintenanceMarginPercentageString, &Value::Str("0".into())).as_bool() == Some(true);
if (maintenanceMarginString == Value::Null) && hasValidNotional && hasValidMmp {
let mut derivedMm: Value = crate::precise::Precise::stringMul(¬ionalString, &maintenanceMarginPercentageString);
if crate::precise::Precise::stringGt(&derivedMm, &Value::Str("0".into())).as_bool() == Some(true) {
maintenanceMarginString = derivedMm.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("maintenanceMargin".into(), self.parse_number(derivedMm, &[])); }
}
} else if (maintenanceMarginPercentageString == Value::Null) && hasValidNotional && hasValidMm {
let mut derivedMmp: Value = crate::precise::Precise::stringDiv(&maintenanceMarginString, ¬ionalString);
if crate::precise::Precise::stringGt(&derivedMmp, &Value::Str("0".into())).as_bool() == Some(true) {
maintenanceMarginPercentageString = derivedMmp.clone();
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("maintenanceMarginPercentage".into(), self.parse_number(derivedMmp, &[])); }
}
}
// 5. marginRatio = maintenanceMargin / collateral
let mut marginRatio: Value = self.safe_value_k(position.clone(), "marginRatio", &[]);
if (marginRatio == Value::Null) && (maintenanceMarginString != Value::Null) && (collateralString != Value::Null) {
if crate::precise::Precise::stringGt(&maintenanceMarginString, &Value::Str("0".into())).as_bool() == Some(true) && crate::precise::Precise::stringGt(&collateralString, &Value::Str("0".into())).as_bool() == Some(true) {
let mut derivedMarginRatio: Value = crate::precise::Precise::stringDivPrec(&maintenanceMarginString, &collateralString, &Value::Int(4));
if (derivedMarginRatio != Value::Null) && crate::precise::Precise::stringGt(&derivedMarginRatio, &Value::Str("0".into())).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("marginRatio".into(), self.parse_number(derivedMarginRatio, &[])); }
}
}
}
}
//
// PERCENTAGE
//
let mut percentage: Value = self.safe_value_k(position.clone(), "percentage", &[]);
if (percentage == Value::Null) && (unrealizedPnlString != Value::Null) && (initialMarginString != Value::Null) {
// as it was done in all implementations ( aax, btcex, bybit, deribit, gate, kucoinfutures, phemex )
let mut percentageString: Value = crate::precise::Precise::stringMul(&crate::precise::Precise::stringDivPrec(&unrealizedPnlString, &initialMarginString, &Value::Int(4)), &Value::Str("100".into()));
if let Value::Dict(__d) = &mut position { std::sync::Arc::make_mut(__d).insert("percentage".into(), self.parse_number(percentageString, &[])); }
}
return position;
Value::Null
}
fn parse_positions(&self, mut positions: Value, 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 symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut positionsArray: Value = self.to_array(positions);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_122: bool = true;
while { if !__for_first_122 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_122 = false; i.as_f64().unwrap_or(f64::NAN) < ((positionsArray.len() as i64) as f64) } {
let mut position: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_position(self, positionsArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]), &[params.clone()]);
result.push(position);
}
}
return self.filter_by_array_positions(Value::from(result), Value::Str("symbol".into()), &[symbolsNormalized]);
Value::Null
}
fn parse_adl_rank(&self, mut info: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_adl_rank(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_adl_rank(self, info.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
if (info == Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseADLRank() is not supported yet".into()))));
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseADLRank() is not supported yet".into()))));
Value::Null
}
fn parse_adl_ranks(&self, mut ranks: Value, 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 symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut ranksArray: Value = self.to_array(ranks);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_123: bool = true;
while { if !__for_first_123 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_123 = false; i.as_f64().unwrap_or(f64::NAN) < ((ranksArray.len() as i64) as f64) } {
let mut rank: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_adl_rank(self, ranksArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]), &[params.clone()]);
result.push(rank);
}
}
return self.filter_by_array_positions(Value::from(result), Value::Str("symbol".into()), &[symbolsNormalized]);
Value::Null
}
fn parse_accounts(&self, mut accounts: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut accountsArray: Value = self.to_array(accounts);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_124: bool = true;
while { if !__for_first_124 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_124 = false; i.as_f64().unwrap_or(f64::NAN) < ((accountsArray.len() as i64) as f64) } {
let mut account: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_account(self, accountsArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)), &[params.clone()]);
result.push(account);
}
}
return Value::from(result);
Value::Null
}
fn parse_trades_helper(&self, mut isWs: Value, mut trades: Value, optional_args: &[Value]) -> Value {
let mut market = 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 tradesArray: Value = self.to_array(trades);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_125: bool = true;
while { if !__for_first_125 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_125 = false; i.as_f64().unwrap_or(f64::NAN) < ((tradesArray.len() as i64) as f64) } {
let mut parsed: Value = Value::Null;
if isWs.as_bool() == Some(true) {
parsed = self.parse_ws_trade(tradesArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[market.clone()]);
} else {
parsed = <Self as crate::exchange_generated::ExchangeBase>::parse_trade(self, tradesArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[market.clone()]);
}
let mut trade: Value = self.extend(parsed, &[params.clone()]);
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(trade); }
}
}
result = self.sort_by2(result.clone(), Value::Str("timestamp".into()), Value::Str("id".into()), &[]);
let mut symbol: Value = self.safe_string_k(market, "symbol", &[]);
return self.filter_by_symbol_since_limit(result, &[symbol, since, limit]);
Value::Null
}
fn parse_trades(&self, mut trades: Value, optional_args: &[Value]) -> Value {
let mut market = 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.parse_trades_helper(Value::Bool(false), trades, &[market, since, limit, params]);
Value::Null
}
fn parse_ws_trades(&self, mut trades: Value, optional_args: &[Value]) -> Value {
let mut market = 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.parse_trades_helper(Value::Bool(true), trades, &[market, since, limit, params]);
Value::Null
}
fn parse_transactions(&self, mut transactions: Value, optional_args: &[Value]) -> Value {
let mut currency = 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 transactionsArray: Value = self.to_array(transactions);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_126: bool = true;
while { if !__for_first_126 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_126 = false; i.as_f64().unwrap_or(f64::NAN) < ((transactionsArray.len() as i64) as f64) } {
let mut transaction: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_transaction(self, transactionsArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[currency.clone()]), &[params.clone()]);
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(transaction); }
}
}
result = self.sort_by(result.clone(), Value::Str("timestamp".into()), &[]);
let mut code: Value = (if (currency != Value::Null) { currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null) } else { Value::Null });
return self.filter_by_currency_since_limit(result, &[code, since, limit]);
Value::Null
}
fn parse_transfers(&self, mut transfers: Value, optional_args: &[Value]) -> Value {
let mut currency = 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 transfersArray: Value = self.to_array(transfers);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_127: bool = true;
while { if !__for_first_127 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_127 = false; i.as_f64().unwrap_or(f64::NAN) < ((transfersArray.len() as i64) as f64) } {
let mut transfer: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_transfer(self, transfersArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[currency.clone()]), &[params.clone()]);
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(transfer); }
}
}
result = self.sort_by(result.clone(), Value::Str("timestamp".into()), &[]);
let mut code: Value = (if (currency != Value::Null) { currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null) } else { Value::Null });
return self.filter_by_currency_since_limit(result, &[code, since, limit]);
Value::Null
}
fn parse_ledger(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut currency = 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 result: Value = Value::from(vec![]);
let mut arrayData: Value = self.to_array(data);
{
let mut i: Value = Value::Int(0);
let mut __for_first_129: bool = true;
while { if !__for_first_129 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_129 = false; i.as_f64().unwrap_or(f64::NAN) < ((arrayData.len() as i64) as f64) } {
let mut itemOrItems: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_ledger_entry(self, arrayData.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[currency.clone()]);
if (matches!(&itemOrItems, Value::Arr(_))) {
{
let mut j: Value = Value::Int(0);
let mut __for_first_128: bool = true;
while { if !__for_first_128 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_128 = false; j.as_f64().unwrap_or(f64::NAN) < get_array_length(&itemOrItems).as_f64().unwrap_or(f64::NAN) } {
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(self.extend(get_value(&itemOrItems, &j), &[params.clone()])); }
}
}
} else {
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(self.extend(itemOrItems, &[params.clone()])); }
}
}
}
result = self.sort_by(result.clone(), Value::Str("timestamp".into()), &[]);
let mut code: Value = (if (currency != Value::Null) { currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null) } else { Value::Null });
return self.filter_by_currency_since_limit(result, &[code, since, limit]);
Value::Null
}
fn nonce(&self) -> Value {
// virtual-dispatch (static: DerivedExchange::nonce(self, ...))
{ let __v = crate::exchange::DerivedExchange::nonce(self, ); if !matches!(__v, crate::Value::Null) { return __v; } }
return self.seconds();
Value::Null
}
/*
* @method
* @ignore
* @name Exchange#incrementingNonce
* @description returns a strictly-increasing nonce for venues that reject duplicate nonces per signer;
* the unit is whatever nonce () returns — the base default is seconds, so a venue that does not override
* nonce () gets a second-resolution counter that drifts ahead of wall clock under load, while venues
* needing milliseconds override nonce () as hyperliquid does. The counter is per exchange instance,
* so it narrows the duplicate-nonce race but does not remove it across instances or processes.
* @returns {int} a strictly-increasing nonce in the unit returned by nonce ()
*/
fn incrementing_nonce(&mut self) -> Value {
let mut currentNonce: Value = <Self as crate::exchange_generated::ExchangeBase>::nonce(self, );
self.lock_last_nonce(&[]);
let mut lastNonce: Value = self.safe_integer_k(self.options.clone(), "lastNonce", &[Value::Int(0)]);
let mut result: Value = (if (currentNonce.as_f64().unwrap_or(f64::NAN) > lastNonce.as_f64().unwrap_or(f64::NAN)) { currentNonce } else { (match (&(lastNonce), &(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 let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("lastNonce".into(), result.clone()); }
self.unlock_last_nonce(&[]);
return result;
Value::Null
}
fn set_headers(&self, mut headers: Value) -> Value {
return headers;
Value::Null
}
fn currency_id(&self, mut code: Value) -> Value {
if (code == Value::Null) {
return code;
}
let mut currency: Value = self.safe_dict(self.currencies.clone(), code.clone(), &[]);
if (currency == Value::Null) {
currency = self.safe_currency(code.clone(), &[]);
}
if (currency != Value::Null) {
return currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
}
return code;
Value::Null
}
fn market_id(&self, mut symbol: Value) -> Value {
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol.clone());
if (market != Value::Null) {
return market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
}
return symbol;
Value::Null
}
fn symbol(&self, mut symbol: Value) -> Value {
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" symbol() requires a symbol argument".into()))));
}
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol.clone());
return self.safe_string_k(market, "symbol", &[symbol]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_param_string(&self, mut params: Value, mut paramName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_string(params.clone(), paramName.clone(), &[defaultValue]);
let mut paramsOmitted: Value = (if (value != Value::Null) { self.omit(params.clone(), paramName, &[]) } else { params });
return Value::from(vec![value, paramsOmitted]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_param_string2(&self, mut params: Value, mut paramName1: Value, mut paramName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_string2(params.clone(), paramName1.clone(), paramName2.clone(), &[defaultValue]);
let mut paramsOmitted: Value = (if (value != Value::Null) { self.omit(params.clone(), Value::from(vec![paramName1, paramName2]), &[]) } else { params });
return Value::from(vec![value, paramsOmitted]);
Value::Null
}
fn handle_param_integer(&self, mut params: Value, mut paramName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_integer(params.clone(), paramName.clone(), &[defaultValue]);
let mut paramsOmitted: Value = (if (value != Value::Null) { self.omit(params.clone(), paramName, &[]) } else { params });
return Value::from(vec![value, paramsOmitted]);
Value::Null
}
fn handle_param_integer2(&self, mut params: Value, mut paramName1: Value, mut paramName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_integer2(params.clone(), paramName1.clone(), paramName2.clone(), &[defaultValue]);
let mut paramsOmitted: Value = (if (value != Value::Null) { self.omit(params.clone(), Value::from(vec![paramName1, paramName2]), &[]) } else { params });
return Value::from(vec![value, paramsOmitted]);
Value::Null
}
fn handle_param_bool(&self, mut params: Value, mut paramName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_bool(params.clone(), paramName.clone(), &[defaultValue]);
let mut paramsOmitted: Value = (if (value != Value::Null) { self.omit(params.clone(), paramName, &[]) } else { params });
return Value::from(vec![value, paramsOmitted]);
Value::Null
}
fn handle_param_bool2(&self, mut params: Value, mut paramName1: Value, mut paramName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_bool2(params.clone(), paramName1.clone(), paramName2.clone(), &[defaultValue]);
let mut paramsOmitted: Value = (if (value != Value::Null) { self.omit(params.clone(), Value::from(vec![paramName1, paramName2]), &[]) } else { params });
return Value::from(vec![value, paramsOmitted]);
Value::Null
}
fn resolve_path(&self, mut path: Value, mut params: Value) -> Value {
return Value::from(vec![self.implode_params(path.clone(), params.clone()), self.omit(params, self.extract_params(path), &[])]);
Value::Null
}
fn get_list_from_object_values(&self, mut objects: Value, mut key: Value) -> Value {
let mut newArray: Value = objects.clone();
if !(matches!(&objects, Value::Arr(_))) {
newArray = self.to_array(objects.clone());
}
let mut results: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_130: bool = true;
while { if !__for_first_130 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_130 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&newArray).as_f64().unwrap_or(f64::NAN) } {
results.push(get_value(&get_value(&newArray, &i), &key));
}
}
return Value::from(results);
Value::Null
}
fn get_symbols_for_market_type(&self, optional_args: &[Value]) -> Value {
let mut marketType = get_arg(optional_args, 0, Value::Null);
let mut subType = get_arg(optional_args, 1, Value::Null);
let mut symbolWithActiveStatus = get_arg(optional_args, 2, Value::Bool(true));
let mut symbolWithUnknownStatus = get_arg(optional_args, 3, Value::Bool(true));
let mut filteredMarkets: Value = self.markets.clone();
if (marketType != Value::Null) {
filteredMarkets = self.filter_by(filteredMarkets.clone(), Value::Str("type".into()), marketType, &[]);
}
if (subType != Value::Null) {
self.check_required_argument(Value::Str("getSymbolsForMarketType".into()), subType.clone(), Value::Str("subType".into()), &[Value::from(vec![Value::Str("linear".into()), Value::Str("inverse".into()), Value::Str("quanto".into())])]);
filteredMarkets = self.filter_by(filteredMarkets.clone(), Value::Str("subType".into()), subType, &[]);
}
let mut activeStatuses: Vec<Value> = Vec::new();
if symbolWithActiveStatus.as_bool() == Some(true) {
activeStatuses.push(Value::Bool(true));
}
if symbolWithUnknownStatus.as_bool() == Some(true) {
activeStatuses.push(Value::Null);
}
filteredMarkets = self.filter_by_array(filteredMarkets.clone(), Value::Str("active".into()), &[Value::from(activeStatuses), Value::Bool(false)]);
return self.get_list_from_object_values(filteredMarkets, Value::Str("symbol".into()));
Value::Null
}
fn filter_by_array(&self, mut objects: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut values = get_arg(optional_args, 0, Value::Null);
let mut indexed = get_arg(optional_args, 1, Value::Bool(true));
let mut objectsValue: Value = self.to_array(objects);
// return all of them if no values were passed
if (values == Value::Null) || (values == Value::Null) || ((match &(values) { Value::Bool(__x) => *__x == false, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 0.0) })) || ((match &(values) { Value::Int(__x) => *__x == 0, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 0.0) })) || (values.as_str() == Some("")) {
// return indexed ? this.indexBy (objects, key) : objects;
if indexed.as_bool() == Some(true) {
return self.index_by(objectsValue.clone(), key.clone());
} else {
return objectsValue;
}
}
let mut results: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_131: bool = true;
while { if !__for_first_131 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_131 = false; i.as_f64().unwrap_or(f64::NAN) < ((objectsValue.len() as i64) as f64) } {
if self.in_array(get_value(&get_value(&objectsValue, &i), &key), values.clone()).as_bool() == Some(true) {
results.push(get_value(&objectsValue, &i));
}
}
}
// return indexed ? this.indexBy (results, key) : results;
if indexed.as_bool() == Some(true) {
return self.index_by(Value::from(results), key);
}
return Value::from(results);
Value::Null
}
fn filter_out_by_array(&self, mut objects: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut values = get_arg(optional_args, 0, Value::Null);
let mut indexed = get_arg(optional_args, 1, Value::Bool(true));
let mut objectsValue: Value = self.to_array(objects);
// return all of them if no values were passed
if (values == Value::Null) || (values == Value::Null) || ((match &(values) { Value::Bool(__x) => *__x == false, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 0.0) })) || ((match &(values) { Value::Int(__x) => *__x == 0, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 0.0) })) || (values.as_str() == Some("")) {
// return indexed ? this.indexBy (objects, key) : objects;
if indexed.as_bool() == Some(true) {
return self.index_by(objectsValue.clone(), key.clone());
} else {
return objectsValue;
}
}
let mut results: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_132: bool = true;
while { if !__for_first_132 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_132 = false; i.as_f64().unwrap_or(f64::NAN) < ((objectsValue.len() as i64) as f64) } {
if !(self.in_array(get_value(&get_value(&objectsValue, &i), &key), values.clone()).as_bool() == Some(true)) {
results.push(get_value(&objectsValue, &i));
}
}
}
// return indexed ? this.indexBy (results, key) : results;
if indexed.as_bool() == Some(true) {
return self.index_by(Value::from(results), key);
}
return Value::from(results);
Value::Null
}
fn fetch2(&mut self, mut path: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut config = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_true(&self.enableRateLimit) {
let mut cost: Value = self.calculate_rate_limiter_cost(api.clone(), method.clone(), path.clone(), params.clone(), &[config]);
self.throttle(&[cost]).await;
}
let mut retries: Value = Value::Int(0);
// implicit endpoints may pass a list body as params: keep it an untyped box
let mut requestParams: Value = params;
let mut retriesMaxRetriesOnFailureparamsMaxRetriesOnFailureVariable = self.handle_option_integer_and_params(requestParams, path.clone(), Value::Str("maxRetriesOnFailure".into()), &[retries]);
let mut retriesMaxRetriesOnFailure: Value = retriesMaxRetriesOnFailureparamsMaxRetriesOnFailureVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxRetriesOnFailure: Value = retriesMaxRetriesOnFailureparamsMaxRetriesOnFailureVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut retryDelay: Value = Value::Int(0);
let mut retryDelayMaxRetriesOnFailureDelayparamsMaxRetriesOnFailureDelayVariable = self.handle_option_integer_and_params(paramsMaxRetriesOnFailure, path.clone(), Value::Str("maxRetriesOnFailureDelay".into()), &[retryDelay]);
let mut retryDelayMaxRetriesOnFailureDelay: Value = retryDelayMaxRetriesOnFailureDelayparamsMaxRetriesOnFailureDelayVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxRetriesOnFailureDelay: Value = retryDelayMaxRetriesOnFailureDelayparamsMaxRetriesOnFailureDelayVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut fetchDataCacheEnabled: bool = self.fetchHistoryCacheSize.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64);
{
let mut i: Value = Value::Int(0);
let mut __for_first_133: bool = true;
while { if !__for_first_133 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_133 = false; i.as_f64().unwrap_or(f64::NAN) < (match (&(retriesMaxRetriesOnFailure), &(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 }).as_f64().unwrap_or(f64::NAN) } {
let mut fetchData: Value = Value::Null;
if fetchDataCacheEnabled {
fetchData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("request".to_string(), Value::Null);
m.insert("response".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("body".to_string(), Value::Null);
m
}));
m.insert("error".to_string(), Value::Null);
m
});
}
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
self.set_last_rest_request_timestamp();
let mut request: Value = <Self as crate::exchange_generated::ExchangeBase>::sign(self, path.clone(), &[api.clone(), method.clone(), paramsMaxRetriesOnFailureDelay.clone()]);
if (fetchData != Value::Null) {
if let Value::Dict(__d) = &mut fetchData { std::sync::Arc::make_mut(__d).insert("request".into(), request.clone()); }
}
self.set_last_request(request.clone());
let mut response: Value = self.fetch(request.as_map().and_then(|__m| __m.get("url")).cloned().unwrap_or(Value::Null), &[request.as_map().and_then(|__m| __m.get("method")).cloned().unwrap_or(Value::Null), request.as_map().and_then(|__m| __m.get("headers")).cloned().unwrap_or(Value::Null), request.as_map().and_then(|__m| __m.get("body")).cloned().unwrap_or(Value::Null)]).await;
if (fetchData != Value::Null) {
add_element_to_object(get_value_mut(&mut fetchData, &Value::Str("response".into())), &Value::Str("body".into()), response.clone());
self.add_fetch_cache(fetchData.clone());
}
return response;
#[allow(unreachable_code)] { Value::Null }})).await;
match _try_result { Ok(__try_ok) => { if !matches!(__try_ok, Value::Null) { return __try_ok; } return Value::Null; } Err(_try_err) => { let e: Value = panic_to_value(_try_err);
if (fetchData != Value::Null) {
if let Value::Dict(__d) = &mut fetchData { std::sync::Arc::make_mut(__d).insert("error".into(), e.clone()); }
self.add_fetch_cache(fetchData);
}
if is_instance(&e, &Value::Str("OperationFailed".into())) {
if i.as_f64().unwrap_or(f64::NAN) < retriesMaxRetriesOnFailure.as_f64().unwrap_or(f64::NAN) {
if is_true(&self.verbose) {
let mut index: Value = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null });
self.log(Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Request failed with the error: ".into()), to_string_val(&e)).into()), Value::Str(", retrying ".into())).into()), Value::Str(format!("{}", index).into())).into()), Value::Str(" of ".into())).into()), Value::Str(format!("{}", retriesMaxRetriesOnFailure).into())).into()), Value::Str("...".into())).into()));
}
if (retryDelayMaxRetriesOnFailureDelay != Value::Null) && (retryDelayMaxRetriesOnFailureDelay.as_f64() != Some(0.0)) {
self.sleep(retryDelayMaxRetriesOnFailureDelay.clone()).await;
}
} else {
panic!("{}", e);
}
} else {
panic!("{}", e);
}
} }
}
}
return Value::Null;
Value::Null
} }
fn request(&mut self, mut path: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut config = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch2(path, &[api, method, params, config]).await;
Value::Null
} }
fn load_accounts(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut reload = get_arg(optional_args, 0, Value::Bool(false));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if reload.as_bool() == Some(true) {
{ let __t = self.fetch_accounts(&[params.clone()]).await; self.accounts = __t; }
} else {
if (self.accounts.clone() != Value::Null) {
return self.accounts.clone();
} else {
{ let __t = self.fetch_accounts(&[params]).await; self.accounts = __t; }
}
}
{ let __t = self.index_by(self.accounts.clone(), Value::Str("id".into())); self.accountsById = __t; }
return self.accounts.clone();
Value::Null
} }
fn build_ohlcvc(&self, mut trades: 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::Int(0));
let mut limit = get_arg(optional_args, 2, Value::Int(2147483647));
// given a sorted arrays of trades (recent last) and a timeframe builds an array of OHLCV candles
// note, default limit value (2147483647) is max int32 value
let mut ms: Value = (match (&(self.parse_timeframe(timeframe)), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
let mut ohlcvs: Value = Value::from(vec![]);
let mut i_timestamp: Value = Value::Int(0);
// const open = 1;
let mut i_high: Value = Value::Int(2);
let mut i_low: Value = Value::Int(3);
let mut i_close: Value = Value::Int(4);
let mut i_volume: Value = Value::Int(5);
let mut i_count: Value = Value::Int(6);
let mut tradesLength: Value = Value::Int(trades.len() as i64);
let mut oldest: Value = crate::runtime::Math::min(&tradesLength, &limit);
let mut options: Value = self.safe_dict_k(self.options.clone(), "buildOHLCVC", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut skipZeroPrices: Value = self.safe_bool_k(options, "skipZeroPrices", &[Value::Bool(true)]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_134: bool = true;
while { if !__for_first_134 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_134 = false; i.as_f64().unwrap_or(f64::NAN) < oldest.as_f64().unwrap_or(f64::NAN) } {
let mut trade: Value = trades.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut ts: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
let mut price: Value = trade.as_map().and_then(|__m| __m.get("price")).cloned().unwrap_or(Value::Null);
if (ts == Value::Null) || (price == Value::Null) {
continue;
}
if ts.as_f64().unwrap_or(f64::NAN) < since.as_f64().unwrap_or(f64::NAN) {
continue;
}
if (ts == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" buildOHLCVC() missing ts".into()))));
}
let mut openingTime: Value = (match (&(((match ((ts).as_f64(), (ms).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })).as_f64().map(|__x| Value::Float(__x.floor())).unwrap_or(Value::Null)), &(ms)) { (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 }); // shift to the edge of m/h/d (but not M)
if openingTime.as_f64().unwrap_or(f64::NAN) < since.as_f64().unwrap_or(f64::NAN) {
continue;
}
let mut ohlcv_length: Value = Value::Int(ohlcvs.len() as i64);
let mut candle: Value = (match (&(ohlcv_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 (price == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" buildOHLCVC() requires a price argument".into()))));
}
if skipZeroPrices.as_bool() == Some(true) && !(price.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64)) && !(price.as_f64().unwrap_or(f64::NAN) < ((0i64) as f64)) {
continue;
}
let mut isNewCandle: bool = candle.as_f64() == Value::Int(-1).as_f64();
if !isNewCandle {
let mut candleTimestamp: Value = get_value(&ohlcvs, &candle).as_array().and_then(|__arr| match &i_timestamp { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (candleTimestamp == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" buildOHLCVC() missing candle timestamp".into()))));
}
isNewCandle = (match (&(openingTime), &(self.sum(&[candleTimestamp, ms.clone()]))) { (__a, __b) => (match ((match __a { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), (match __b { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None })) { (Some(__x), Some(__y)) => __x > __y, _ => matches!((__a, __b), (Value::Str(__x), Value::Str(__y)) if __x > __y) }) || (match (__a, __b) { (Value::Null, Value::Null) => true, (Value::Bool(__x), Value::Bool(__y)) => __x == __y, (Value::Str(__x), Value::Str(__y)) => __x == __y, (Value::Int(__x), Value::Int(__y)) => __x == __y, (Value::Float(__x), Value::Float(__y)) => __x == __y, _ => matches!(((match __a { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), (match __b { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None })), (Some(__x), Some(__y)) if __x == __y) }) });
}
if isNewCandle {
// moved to a new timeframe -> create a new candle from opening trade
if let Value::Arr(__a) = &mut ohlcvs { std::sync::Arc::make_mut(__a).push(Value::from(vec![openingTime, price.clone(), price.clone(), price.clone(), price.clone(), trade.as_map().and_then(|__m| __m.get("amount")).cloned().unwrap_or(Value::Null), Value::Int(1)])); }
} else {
// still processing the same timeframe -> update opening trade
let mut prevHigh: Value = get_value(&ohlcvs, &candle).as_array().and_then(|__arr| match &i_high { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut prevLow: Value = get_value(&ohlcvs, &candle).as_array().and_then(|__arr| match &i_low { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut prevHighValue: Value = (if (prevHigh == Value::Null) { price.clone() } else { prevHigh });
let mut prevLowValue: Value = (if (prevLow == Value::Null) { price.clone() } else { prevLow });
add_element_to_object(get_value_mut(&mut ohlcvs, &candle), &i_high, crate::runtime::Math::max(&prevHighValue, &price));
add_element_to_object(get_value_mut(&mut ohlcvs, &candle), &i_low, crate::runtime::Math::min(&prevLowValue, &price));
add_element_to_object(get_value_mut(&mut ohlcvs, &candle), &i_close, price);
{ let __be_tmp = self.sum(&[get_value(&get_value(&ohlcvs, &candle), &i_volume), trade.as_map().and_then(|__m| __m.get("amount")).cloned().unwrap_or(Value::Null)]); add_element_to_object(get_value_mut(&mut ohlcvs, &candle), &i_volume, __be_tmp); };
{ let __be_tmp = self.sum(&[get_value(&get_value(&ohlcvs, &candle), &i_count), Value::Int(1)]); add_element_to_object(get_value_mut(&mut ohlcvs, &candle), &i_count, __be_tmp); };
}
}
}
return ohlcvs;
Value::Null
}
fn parse_trading_view_ohlcv(&self, mut ohlcvs: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timeframe = get_arg(optional_args, 1, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut result: Value = self.convert_trading_view_to_ohlcv(ohlcvs, &[]);
return self.parse_ohlc_vs(result, &[market, timeframe, since, limit]);
Value::Null
}
fn fetch_borrow_interest(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut symbol = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchBorrowInterest() is not supported yet".into()))));
Value::Null
} }
fn fetch_ledger(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_ledger", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLedger() is not supported yet".into()))));
Value::Null
} }
fn fetch_ledger_entry(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLedgerEntry() is not supported yet".into()))));
Value::Null
} }
fn parse_order_book_bid_ask(&self, mut bidask: Value, optional_args: &[Value]) -> Value {
let mut priceKey = get_arg(optional_args, 0, Value::Int(0));
let mut amountKey = get_arg(optional_args, 1, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 2, Value::Int(2));
let mut price: Value = self.safe_float(bidask.clone(), priceKey, &[]);
let mut amount: Value = self.safe_float(bidask.clone(), amountKey, &[]);
let mut countOrId: Value = self.safe_integer(bidask, countOrIdKey, &[]);
let mut bidAsk: Value = Value::from(vec![price, amount]);
if (countOrId != Value::Null) {
if let Value::Arr(__a) = &mut bidAsk { std::sync::Arc::make_mut(__a).push(countOrId); }
}
return bidAsk;
Value::Null
}
fn parse_order_book_bid_ask_l3(&self, mut bidask: Value, optional_args: &[Value]) -> Value {
let mut priceKey = get_arg(optional_args, 0, Value::Int(0));
let mut amountKey = get_arg(optional_args, 1, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 2, Value::Int(2));
let mut price: Value = self.safe_float(bidask.clone(), priceKey, &[]);
let mut amount: Value = self.safe_float(bidask.clone(), amountKey, &[]);
let mut countOrId: Value = self.safe_string(bidask, countOrIdKey, &[]);
let mut bidAsk: Value = Value::from(vec![price, amount]);
if (countOrId != Value::Null) {
if let Value::Arr(__a) = &mut bidAsk { std::sync::Arc::make_mut(__a).push(countOrId); }
}
return bidAsk;
Value::Null
}
fn safe_currency(&self, mut currencyId: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
if (currencyId == Value::Null) && (currency != Value::Null) {
return currency;
}
if (currencyId != Value::Null) && (self.currencies_by_id.clone() != Value::Null) && (matches!((&self.currencies_by_id, ¤cyId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) && (self.currencies_by_id.as_map().and_then(|__m| currencyId.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null) != Value::Null) {
return self.currencies_by_id.as_map().and_then(|__m| currencyId.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
}
let mut code: Value = currencyId.clone();
if (currencyId != Value::Null) {
code = self.common_currency_code(currencyId.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null));
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId);
m.insert("code".to_string(), code);
m.insert("precision".to_string(), Value::Null);
m
}));
Value::Null
}
fn safe_market(&self, optional_args: &[Value]) -> Value {
let mut marketId = get_arg(optional_args, 0, Value::Null);
let mut market = get_arg(optional_args, 1, Value::Null);
let mut delimiter = get_arg(optional_args, 2, Value::Null);
let mut marketType = get_arg(optional_args, 3, Value::Null);
if (marketId != Value::Null) {
if (self.markets_by_id.clone() != Value::Null) && (matches!((&self.markets_by_id, &marketId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
let mut markets: Value = self.markets_by_id.as_map().and_then(|__m| marketId.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
let mut numMarkets: Value = get_array_length(&markets);
if (numMarkets.as_f64() == Some(1.0)) {
return get_value(&markets, &Value::Int(0));
} else {
if (marketType == Value::Null) && (market == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" safeMarket() requires a fourth argument for ".into())).into()), marketId).into()), Value::Str(" to disambiguate between different markets with the same market id".into()))));
}
let mut marketTypeResolved: Value = (if (marketType == Value::Null) { self.safe_string_k(market.clone(), "type", &[Value::Str("".into())]) } else { marketType });
{
let mut i: Value = Value::Int(0);
let mut __for_first_135: bool = true;
while { if !__for_first_135 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_135 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&markets).as_f64().unwrap_or(f64::NAN) } {
let mut currentMarket: Value = get_value(&markets, &i);
let mut currentMarket: Value = get_value(&markets, &i);
if (match &(get_value(¤tMarket, &marketTypeResolved)) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) }) {
return currentMarket;
}
}
}
}
} else if (delimiter != Value::Null) && (delimiter.as_str() != Some("")) {
let mut parts: Value = Value::Array(marketId.as_str().zip(delimiter.as_str()).map(|(__s, __d)| __s.split(__d).map(|__p| Value::Str(__p.to_string().into())).collect()).unwrap_or_default());
let mut partsLength: f64 = ((parts.len() as i64) as f64);
let mut result: Value = self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketId.clone());
m.insert("marketId".to_string(), marketId.clone());
m
})]);
if (result == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" safeMarket() failed to build market structure".into()))));
}
if (partsLength == 2.0) {
let mut baseId: Value = self.safe_string(parts.clone(), Value::Int(0), &[]);
let mut quoteId: Value = self.safe_string(parts, Value::Int(1), &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("baseId".into(), baseId); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("quoteId".into(), quoteId); }
if (base != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("base".into(), base.clone()); }
}
if (quote != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("quote".into(), quote.clone()); }
}
if (base != Value::Null) && (quote != Value::Null) {
add_element_to_object(&mut result, &Value::Str("symbol".into()), Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()));
}
}
return result;
}
}
if (market != Value::Null) {
return market;
}
let mut emptyMarket: Value = self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketId.clone());
m.insert("marketId".to_string(), marketId);
m
})]);
if (emptyMarket == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" safeMarket() failed to build market structure".into()))));
}
return emptyMarket;
Value::Null
}
fn market_or_null(&self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
if (symbol == Value::Null) {
return Value::Null;
}
return <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
Value::Null
}
fn check_required_credentials(&self, optional_args: &[Value]) -> Value {
let mut error = get_arg(optional_args, 0, Value::Bool(true));
/*
* @ignore
* @method
* @param {boolean} error throw an error that a credential is required if true
* @returns {boolean} true if all required credentials have been set, otherwise false or an error is thrown is param error=true
*/
let mut keys: Value = Value::Array(self.requiredCredentials.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
{
let mut i: Value = Value::Int(0);
let mut __for_first_136: bool = true;
while { if !__for_first_136 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_136 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut credentialValue: Value = self.prop(&key);
let mut credentialMissing: bool = (credentialValue == Value::Null) || (credentialValue == Value::Null) || ((match &(credentialValue) { Value::Bool(__x) => *__x == false, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 0.0) })) || (credentialValue.as_str() == Some(""));
if (self.requiredCredentials.as_map().and_then(|__m| key.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) && credentialMissing {
if is_true(&error) {
panic!("{}", crate::exchange_errors::authentication_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" requires \"".into())).into()), key).into()), Value::Str("\" credential".into()))));
} else {
return Value::Bool(false);
}
}
}
}
return Value::Bool(true);
Value::Null
}
fn oath(&self) -> Value {
if (self.twofa.clone() != Value::Null) {
return totp(self.twofa.clone());
} else {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" exchange.twofa has not been set for 2FA Two-Factor Authentication".into()))));
}
Value::Null
}
fn fetch_balance(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_balance", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchBalance() is not supported yet".into()))));
Value::Null
} }
fn fetch_balance_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchBalanceWs() is not supported yet".into()))));
Value::Null
} }
fn parse_balance(&self, mut response: Value) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_balance(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_balance(self, response); if !matches!(__v, crate::Value::Null) { return __v; } }
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseBalance() is not supported yet".into()))));
Value::Null
}
fn watch_balance(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchBalance() is not supported yet".into()))));
Value::Null
} }
fn fetch_partial_balance(&mut self, mut part: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut balance: Value = self.fetch_balance(&[params]).await;
return get_value(&balance, &part);
Value::Null
} }
fn fetch_free_balance(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_partial_balance(Value::Str("free".into()), &[params]).await;
Value::Null
} }
fn fetch_used_balance(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_partial_balance(Value::Str("used".into()), &[params]).await;
Value::Null
} }
fn fetch_total_balance(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_partial_balance(Value::Str("total".into()), &[params]).await;
Value::Null
} }
fn fetch_status(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_status", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchStatus() is not supported yet".into()))));
Value::Null
} }
fn fetch_transaction_fee(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchTransactionFees")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("fetchTransactionFees")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTransactionFee() is not supported yet".into()))));
}
return self.fetch_transaction_fees(&[Value::from(vec![code]), params]).await;
Value::Null
} }
fn fetch_transaction_fees(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTransactionFees() is not supported yet".into()))));
Value::Null
} }
fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_deposit_withdraw_fees", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositWithdrawFees() is not supported yet".into()))));
Value::Null
} }
fn fetch_deposit_withdraw_fee(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_deposit_withdraw_fee", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(code.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchDepositWithdrawFees")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("fetchDepositWithdrawFees")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositWithdrawFee() is not supported yet".into()))));
}
let mut fees: Value = self.fetch_deposit_withdraw_fees(&[Value::from(vec![code.clone()]), params]).await;
return self.safe_dict(fees, code, &[]);
Value::Null
} }
fn get_supported_mapping(&self, mut key: Value, optional_args: &[Value]) -> Value {
let mut mapping = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (key == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" getSupportedMapping() requires a key argument".into()))));
}
if (matches!((&mapping, &key), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return mapping.as_map().and_then(|__m| key.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
} else {
let mut keys: Value = object_keys(&mapping);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), key).into()), Value::Str(" does not have a value in mapping".into())).into()), Value::Str(", must be one of ".into())).into()), Value::Str(keys.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(", ")).unwrap_or_default().into()))));
}
Value::Null
}
fn fetch_cross_borrow_rate(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
if (self.has.as_map().and_then(|__m| __m.get("fetchBorrowRates")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("fetchBorrowRates")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchCrossBorrowRate() is not supported yet".into()))));
}
let mut borrowRates: Value = self.fetch_cross_borrow_rates(&[params]).await;
let mut rate: Value = self.safe_dict(borrowRates, code.clone(), &[]);
if (rate == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchCrossBorrowRate() could not find the borrow rate for currency code ".into())).into()), code)));
}
return rate;
Value::Null
} }
fn fetch_isolated_borrow_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
if (self.has.as_map().and_then(|__m| __m.get("fetchBorrowRates")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("fetchBorrowRates")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchIsolatedBorrowRate() is not supported yet".into()))));
}
let mut borrowRates: Value = self.fetch_isolated_borrow_rates(&[params]).await;
let mut rate: Value = self.safe_dict(borrowRates, symbol.clone(), &[]);
if (rate == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchIsolatedBorrowRate() could not find the borrow rate for market symbol ".into())).into()), symbol)));
}
return rate;
Value::Null
} }
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn require_value(&self, mut value: Value, optional_args: &[Value]) -> Value {
let mut message = get_arg(optional_args, 0, Value::Null);
if (value == Value::Null) {
let mut errorMessage: Value = (if (message != Value::Null) { message } else { Value::Str("value is required".into()) });
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), errorMessage)));
}
return value;
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_and_params(&self, mut params: Value, mut methodName: Value, mut optionName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
// This method can be used to obtain method specific properties, i.e: this.handleOptionAndParams (params, 'fetchPosition', 'marginMode', 'isolated')
let mut defaultOptionName: Value = Value::Str(format!("{}{}", Value::Str("default".into()), self.capitalize(optionName.clone())).into()); // we also need to check the 'defaultXyzWhatever'
// check if params contain the key
let mut value: Value = self.safe_value2(params.clone(), optionName.clone(), defaultOptionName.clone(), &[]);
if (value != Value::Null) {
let mut paramsOmitted: Value = self.omit(params.clone(), Value::from(vec![optionName.clone(), defaultOptionName.clone()]), &[]);
return Value::from(vec![value.clone(), paramsOmitted]);
} else {
// handle routed methods like "watchTrades > watchTradesForSymbols" (or "watchTicker > watchTickers")
let mut callerMethodNameparamsCallerMethodNameVariable = self.handle_param_string(params, Value::Str("callerMethodName".into()), &[methodName]);
let mut callerMethodName: Value = callerMethodNameparamsCallerMethodNameVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsCallerMethodName: Value = callerMethodNameparamsCallerMethodNameVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
// check if exchange has properties for this method
let mut exchangeWideMethodOptions: Value = self.safe_value(self.options.clone(), callerMethodName, &[]);
if (exchangeWideMethodOptions != Value::Null) {
// check if the option is defined inside this method's props
value = self.safe_value2(exchangeWideMethodOptions, optionName.clone(), defaultOptionName.clone(), &[]);
}
if (value == Value::Null) {
// if it's still undefined, check if global exchange-wide option exists
value = self.safe_value2(self.options.clone(), optionName, defaultOptionName, &[]);
}
// if it's still undefined, use the default value
value = (if (value != Value::Null) { value.clone() } else { defaultValue });
return Value::from(vec![value, paramsCallerMethodName]);
}
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_and_params2(&self, mut params: Value, mut methodName1: Value, mut optionName1: Value, mut optionName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut valueparamsOption1Variable = self.handle_option_and_params(params, methodName1.clone(), optionName1, &[]);
let mut value: Value = valueparamsOption1Variable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsOption1: Value = valueparamsOption1Variable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (value != Value::Null) {
// omit optionName2 too from params
let mut paramsOmitted: Value = self.omit(paramsOption1.clone(), optionName2.clone(), &[]);
return Value::from(vec![value, paramsOmitted]);
}
return self.handle_option_and_params(paramsOption1, methodName1, optionName2, &[defaultValue]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_string_and_params(&self, mut params: Value, mut methodName: Value, mut optionName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
// handleOptionAndParams read as a string; the statically typed ports throw on another type
let mut valuenewParamsVariable = self.handle_option_and_params(params, methodName.clone(), optionName.clone(), &[defaultValue]);
let mut value: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut newParams: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return Value::from(vec![self.check_option_string(methodName, optionName, value), newParams]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_string_and_params2(&self, mut params: Value, mut methodName: Value, mut optionName1: Value, mut optionName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut valuenewParamsVariable = self.handle_option_and_params2(params, methodName.clone(), optionName1.clone(), optionName2, &[defaultValue]);
let mut value: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut newParams: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return Value::from(vec![self.check_option_string(methodName, optionName1, value), newParams]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_bool_and_params(&self, mut params: Value, mut methodName: Value, mut optionName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
// handleOptionAndParams read as a boolean (see checkOptionBool)
let mut valuenewParamsVariable = self.handle_option_and_params(params, methodName.clone(), optionName.clone(), &[defaultValue]);
let mut value: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut newParams: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return Value::from(vec![self.check_option_bool(methodName, optionName, value), newParams]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_bool_and_params2(&self, mut params: Value, mut methodName: Value, mut optionName1: Value, mut optionName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut valuenewParamsVariable = self.handle_option_and_params2(params, methodName.clone(), optionName1.clone(), optionName2, &[defaultValue]);
let mut value: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut newParams: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return Value::from(vec![self.check_option_bool(methodName, optionName1, value), newParams]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_integer_and_params(&self, mut params: Value, mut methodName: Value, mut optionName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
// handleOptionAndParams read as an integer; the statically typed ports throw on another type
let mut valuenewParamsVariable = self.handle_option_and_params(params, methodName.clone(), optionName.clone(), &[defaultValue]);
let mut value: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut newParams: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return Value::from(vec![self.check_option_integer(methodName, optionName, value), newParams]);
Value::Null
}
/* eslint-disable no-unused-vars */
/* eslint-enable no-unused-vars */
fn handle_option_integer_and_params2(&self, mut params: Value, mut methodName: Value, mut optionName1: Value, mut optionName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut valuenewParamsVariable = self.handle_option_and_params2(params, methodName.clone(), optionName1.clone(), optionName2, &[defaultValue]);
let mut value: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut newParams: Value = valuenewParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return Value::from(vec![self.check_option_integer(methodName, optionName1, value), newParams]);
Value::Null
}
fn handle_option(&self, mut methodName: Value, mut optionName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut res: Value = self.handle_option_and_params(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), methodName, optionName, &[defaultValue]);
return self.safe_value(res, Value::Int(0), &[]);
Value::Null
}
fn handle_market_type_and_params(&self, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut market = 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 defaultValue = get_arg(optional_args, 2, Value::Null);
/*
* @ignore
* @method
* @name exchange#handleMarketTypeAndParams
* @param methodName the method calling handleMarketTypeAndParams
* @param {Market} market
* @param {object} params
* @param {string} [params.type] type assigned by user
* @param {string} [params.defaultType] same as params.type
* @param {string} [defaultValue] assigned programatically in the method calling handleMarketTypeAndParams
* @returns {[string, object]} the market type and params with type and defaultType omitted
*/
// type from param
let mut type_var: Value = self.safe_string2(params.clone(), Value::Str("defaultType".into()), Value::Str("type".into()), &[]);
if (type_var != Value::Null) {
let mut paramsOmitted: Value = self.omit(params.clone(), Value::from(vec![Value::Str("defaultType".into()), Value::Str("type".into())]), &[]);
return Value::from(vec![type_var, paramsOmitted]);
}
// type from market
if (market != Value::Null) {
return Value::from(vec![market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null), params.clone()]);
}
// type from default-argument
if (defaultValue != Value::Null) {
return Value::from(vec![defaultValue, params.clone()]);
}
let mut methodOptions: Value = self.safe_dict(self.options.clone(), methodName, &[]);
if (methodOptions != Value::Null) {
if matches!(&methodOptions, Value::Str(_)) {
return Value::from(vec![methodOptions.clone(), params.clone()]);
} else {
let mut typeFromMethod: Value = self.safe_string2(methodOptions, Value::Str("defaultType".into()), Value::Str("type".into()), &[]);
if (typeFromMethod != Value::Null) {
return Value::from(vec![typeFromMethod, params.clone()]);
}
}
}
let mut defaultType: Value = self.safe_string2(self.options.clone(), Value::Str("defaultType".into()), Value::Str("type".into()), &[Value::Str("spot".into())]);
return Value::from(vec![defaultType, params]);
Value::Null
}
fn handle_sub_type_and_params(&self, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut market = 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 defaultValue = get_arg(optional_args, 2, Value::Null);
let mut subType: Value = Value::Null;
// if set in params, it takes precedence
let mut subTypeInParams: Value = self.safe_string2(params.clone(), Value::Str("subType".into()), Value::Str("defaultSubType".into()), &[]);
// avoid omitting if it's not present
if (subTypeInParams != Value::Null) {
if (subTypeInParams.as_str() == Some("linear")) || (subTypeInParams.as_str() == Some("inverse")) {
subType = subTypeInParams;
}
let mut paramsOmitted: Value = self.omit(params.clone(), Value::from(vec![Value::Str("subType".into()), Value::Str("defaultSubType".into())]), &[]);
return Value::from(vec![subType.clone(), paramsOmitted]);
} else {
// at first, check from market object
if (market != Value::Null) {
if (market.as_map().and_then(|__m| __m.get("linear")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
subType = Value::Str("linear".into());
} else if (market.as_map().and_then(|__m| __m.get("inverse")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
subType = Value::Str("inverse".into());
}
}
// if it was not defined in market object
if (subType == Value::Null) {
let mut values: Value = self.handle_option_and_params(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), methodName, Value::Str("subType".into()), &[defaultValue]); // no need to re-test params here
subType = values.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
}
}
return Value::from(vec![subType, params]);
Value::Null
}
fn handle_margin_mode_and_params(&self, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut defaultValue = get_arg(optional_args, 1, Value::Null);
return self.handle_option_string_and_params(params, methodName, Value::Str("marginMode".into()), &[defaultValue]);
Value::Null
}
fn throw_exactly_matched_exception(&self, mut exact: Value, mut string: Value, mut message: Value) {
if (string == Value::Null) {
return;
}
if (in_op(&exact, &string)) {
panic!("{}", crate::exchange_errors::create_error(&crate::runtime::stringify_param(&(get_value(&exact, &string))), &crate::runtime::stringify_param(&(message))));
}
}
fn throw_broadly_matched_exception(&self, mut broad: Value, mut string: Value, mut message: Value) {
let mut broadKey: Value = self.find_broadly_matched_key(broad.clone(), string);
if (broadKey != Value::Null) {
panic!("{}", crate::exchange_errors::create_error(&crate::runtime::stringify_param(&(get_value(&broad, &broadKey))), &crate::runtime::stringify_param(&(message))));
}
}
fn find_broadly_matched_key(&self, mut broad: Value, mut string: Value) -> Value {
// a helper for matching error strings exactly vs broadly
let mut keys: Value = object_keys(&broad);
{
let mut i: Value = Value::Int(0);
let mut __for_first_137: bool = true;
while { if !__for_first_137 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_137 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (string != Value::Null) {
if Value::Int(string.as_str().zip(key.as_str()).and_then(|(__s, __n)| __s.find(__n)).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return key;
}
}
}
}
return Value::Null;
Value::Null
}
fn handle_errors(&self, mut statusCode: Value, mut statusText: Value, mut url: Value, mut method: Value, mut responseHeaders: Value, mut responseBody: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
// virtual-dispatch (static: DerivedExchange::handle_errors(self, ...))
{ let __v = crate::exchange::DerivedExchange::handle_errors(self, statusCode, statusText, url, method, responseHeaders, responseBody, response, requestHeaders, requestBody); if !matches!(__v, crate::Value::Null) { return __v; } }
return Value::Null;
Value::Null
}
fn calculate_rate_limiter_cost(&self, mut api: Value, mut method: Value, mut path: Value, mut params: Value, optional_args: &[Value]) -> Value {
let mut config = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __config_empty = indexmap::IndexMap::new();
let config = config.as_map().unwrap_or(&__config_empty);
return (match config.get("cost") { Some(__v) if !matches!(__v, Value::Null) && !matches!(__v, Value::Str(__s) if __s.is_empty()) => __v.clone(), _ => Value::Int(1) });
Value::Null
}
fn fetch_spot_tickers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchSpotTickers() is not supported yet".into()))));
Value::Null
} }
fn fetch_contract_tickers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchContractTickers() is not supported yet".into()))));
Value::Null
} }
fn fetch_order_books(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut symbols = 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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderBooks() is not supported yet".into()))));
Value::Null
} }
fn un_watch_tickers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchTickers() is not supported yet".into()))));
Value::Null
} }
fn un_watch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchFundingRate() is not supported yet".into()))));
Value::Null
} }
fn create_twap_order(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, mut duration: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTwapOrder() is not supported yet".into()))));
Value::Null
} }
fn create_convert_trade(&mut self, mut id: Value, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() is not supported yet".into()))));
Value::Null
} }
fn fetch_convert_trade(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertTrade() is not supported yet".into()))));
Value::Null
} }
fn fetch_convert_trade_history(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertTradeHistory() is not supported yet".into()))));
Value::Null
} }
fn fetch_position_mode(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_position_mode", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionMode() is not supported yet".into()))));
Value::Null
} }
fn fetch_adl_rank(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchADLRank() is not supported yet".into()))));
Value::Null
} }
fn fetch_positions_adl_rank(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_positions_adl_rank", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsADLRank() is not supported yet".into()))));
Value::Null
} }
fn fetch_position_adl_rank(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_position_adl_rank", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchPositionsADLRank")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchPositionsADLRank")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
self.load_markets(&[]).await;
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut symbolResolved: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut ranks: Value = self.fetch_positions_adl_rank(&[Value::from(vec![symbolResolved.clone()]), params]).await;
let mut rank: Value = self.safe_dict(ranks, Value::Int(0), &[]);
if (rank == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsADLRank() could not find a rank for ".into())).into()), symbolResolved)));
} else {
return rank;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsADLRank() is not supported yet".into()))));
}
Value::Null
} }
fn set_take_profit_and_stop_loss_params(&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 takeProfit = get_arg(optional_args, 1, Value::Null);
let mut stopLoss = 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 (takeProfit == Value::Null) && (stopLoss == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrderWithTakeProfitAndStopLoss() requires either a takeProfit or stopLoss argument".into()))));
}
if (takeProfit != Value::Null) {
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("takeProfit".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPrice".to_string(), takeProfit);
m
})); }
}
if (stopLoss != Value::Null) {
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("stopLoss".into(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPrice".to_string(), stopLoss);
m
})); }
}
let mut takeProfitType: Value = self.safe_string_k(params.clone(), "takeProfitType", &[]);
let mut takeProfitPriceType: Value = self.safe_string_k(params.clone(), "takeProfitPriceType", &[]);
let mut takeProfitLimitPrice: Value = self.safe_string_k(params.clone(), "takeProfitLimitPrice", &[]);
let mut takeProfitAmount: Value = self.safe_string_k(params.clone(), "takeProfitAmount", &[]);
let mut stopLossType: Value = self.safe_string_k(params.clone(), "stopLossType", &[]);
let mut stopLossPriceType: Value = self.safe_string_k(params.clone(), "stopLossPriceType", &[]);
let mut stopLossLimitPrice: Value = self.safe_string_k(params.clone(), "stopLossLimitPrice", &[]);
let mut stopLossAmount: Value = self.safe_string_k(params.clone(), "stopLossAmount", &[]);
if (takeProfitType != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("takeProfit".into())), &Value::Str("type".into()), takeProfitType);
}
if (takeProfitPriceType != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("takeProfit".into())), &Value::Str("priceType".into()), takeProfitPriceType);
}
if (takeProfitLimitPrice != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("takeProfit".into())), &Value::Str("price".into()), self.parse_to_numeric(takeProfitLimitPrice));
}
if (takeProfitAmount != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("takeProfit".into())), &Value::Str("amount".into()), self.parse_to_numeric(takeProfitAmount));
}
if (stopLossType != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("stopLoss".into())), &Value::Str("type".into()), stopLossType);
}
if (stopLossPriceType != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("stopLoss".into())), &Value::Str("priceType".into()), stopLossPriceType);
}
if (stopLossLimitPrice != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("stopLoss".into())), &Value::Str("price".into()), self.parse_to_numeric(stopLossLimitPrice));
}
if (stopLossAmount != Value::Null) {
add_element_to_object(get_value_mut(&mut params, &Value::Str("stopLoss".into())), &Value::Str("amount".into()), self.parse_to_numeric(stopLossAmount));
}
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("takeProfitType".into()), Value::Str("takeProfitPriceType".into()), Value::Str("takeProfitLimitPrice".into()), Value::Str("takeProfitAmount".into()), Value::Str("stopLossType".into()), Value::Str("stopLossPriceType".into()), Value::Str("stopLossLimitPrice".into()), Value::Str("stopLossAmount".into())]), &[]);
return paramsOmitted;
Value::Null
}
fn create_spot_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createSpotOrders() is not supported yet".into()))));
Value::Null
} }
fn create_contract_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createContractOrders() is not supported yet".into()))));
Value::Null
} }
fn cancel_spot_order(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelSpotOrder() is not supported yet".into()))));
Value::Null
} }
fn cancel_contract_order(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelContractOrder() is not supported yet".into()))));
Value::Null
} }
fn cancel_all_spot_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllSpotOrders() is not supported yet".into()))));
Value::Null
} }
fn cancel_all_contract_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllContractOrders() is not supported yet".into()))));
Value::Null
} }
fn cancel_all_orders_after(&mut self, mut timeout: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrdersAfter() is not supported yet".into()))));
Value::Null
} }
fn cancel_orders_for_symbols(&mut self, mut orders: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrdersForSymbols() is not supported yet".into()))));
Value::Null
} }
fn fetch_my_liquidations(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMyLiquidations() is not supported yet".into()))));
Value::Null
} }
fn fetch_liquidations(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLiquidations() is not supported yet".into()))));
Value::Null
} }
fn fetch_greeks(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchGreeks() is not supported yet".into()))));
Value::Null
} }
fn fetch_all_greeks(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchAllGreeks() is not supported yet".into()))));
Value::Null
} }
fn fetch_option_chain(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOptionChain() is not supported yet".into()))));
Value::Null
} }
fn fetch_option(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOption() is not supported yet".into()))));
Value::Null
} }
fn fetch_convert_quote(&mut self, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() is not supported yet".into()))));
Value::Null
} }
fn fetch_deposits_withdrawals(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_deposits_withdrawals", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositsWithdrawals() is not supported yet".into()))));
Value::Null
} }
fn fetch_deposits(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_deposits", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDeposits() is not supported yet".into()))));
Value::Null
} }
fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_withdrawals", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchWithdrawals() is not supported yet".into()))));
Value::Null
} }
fn fetch_deposits_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositsWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_withdrawals_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchWithdrawalsWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_funding_rate_history", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() is not supported yet".into()))));
Value::Null
} }
fn fetch_funding_history(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingHistory() is not supported yet".into()))));
Value::Null
} }
fn parse_last_price(&self, mut price: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_last_price(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_last_price(self, price, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseLastPrice() is not supported yet".into()))));
Value::Null
}
fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_deposit_address", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(code.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchDepositAddresses")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchDepositAddresses")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut depositAddressesList: Value = self.fetch_deposit_addresses(&[Value::from(vec![code.clone()]), params.clone()]).await;
let mut depositAddresses: Value = self.index_by(depositAddressesList, Value::Str("currency".into()));
if (self.safe_dict(depositAddresses.clone(), code.clone(), &[]) == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_address(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddress() could not find a deposit address for ".into())).into()), code).into()), Value::Str(", make sure you have created a corresponding deposit address in your wallet on the exchange website".into()))));
}
return self.safe_dict(depositAddresses, code.clone(), &[]);
} else if (self.has.as_map().and_then(|__m| __m.get("fetchDepositAddressesByNetwork")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchDepositAddressesByNetwork")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut network: Value = self.safe_string_k(params.clone(), "network", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("network".into()), &[]);
let mut addressStructures: Value = self.fetch_deposit_addresses_by_network(code, &[paramsOmitted]).await;
if (network != Value::Null) {
return self.safe_dict(addressStructures.clone(), network, &[]);
} else {
let mut keys: Value = object_keys(&addressStructures);
let mut key: Value = keys.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
return self.safe_dict(addressStructures, key, &[]);
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddress() is not supported yet".into()))));
}
Value::Null
} }
fn fetch_contract_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchContractDepositAddress() is not supported yet".into()))));
Value::Null
} }
fn account(&self) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), Value::Null);
m.insert("used".to_string(), Value::Null);
m.insert("total".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @ignore
* @method
* @description merges a per-market (isolated margin) account into a flat code-keyed balance dict, summing string fields when the code recurs across markets
* @param {object} result the code-keyed balance dict being built
* @param {string} code unified currency code
* @param {object} account a balance account with string free/used/total/debt
* @returns {object} result — callers MUST reassign (`result = this.mergeBalanceAccount (result, ...)`): PHP arrays are passed by value, so the mutation is not visible through the argument
*/
fn merge_balance_account(&self, mut result: Value, mut code: Value, mut account: Value) -> Value {
if !(matches!((&result, &code), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account.clone()); }
return result;
}
let mut fields: Value = Value::from(vec![Value::Str("free".into()), Value::Str("used".into()), Value::Str("total".into()), Value::Str("debt".into())]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_138: bool = true;
while { if !__for_first_138 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_138 = false; i.as_f64().unwrap_or(f64::NAN) < ((fields.len() as i64) as f64) } {
let mut field: Value = fields.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut current: Value = self.safe_string(result.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), field.clone(), &[]);
let mut incoming: Value = self.safe_string(account.clone(), field.clone(), &[]);
if (current == Value::Null) {
add_element_to_object(get_value_mut(&mut result, &code), &field, incoming.clone());
} else if (incoming != Value::Null) {
add_element_to_object(get_value_mut(&mut result, &code), &field, crate::precise::Precise::stringAdd(¤t, &incoming));
}
}
}
return result;
Value::Null
}
fn common_currency_code(&self, mut code: Value) -> Value {
if !(self.substituteCommonCurrencyCodes.as_bool() == Some(true)) {
return code;
}
return self.safe_string(self.commonCurrencies.clone(), code.clone(), &[code.clone()]);
Value::Null
}
fn currency(&self, mut code: Value) -> Value {
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" currency() requires a code argument".into()))));
}
let mut keys: Value = Value::Array(self.currencies.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
let mut numCurrencies: f64 = ((keys.len() as i64) as f64);
if (numCurrencies == 0.0) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" currencies not loaded".into()))));
}
if matches!(&code, Value::Str(_)) {
let mut currencies: Value = self.currencies.clone();
let mut currenciesById: Value = self.currencies_by_id.clone();
if (matches!((¤cies, &code), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return currencies.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
} else if (currenciesById != Value::Null) && (matches!((¤ciesById, &code), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return currenciesById.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
}
}
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" does not have currency code ".into())).into()), code)));
Value::Null
}
fn market(&self, mut symbol: Value) -> Value {
// virtual-dispatch (static: DerivedExchange::market(self, ...))
{ let __v = crate::exchange::DerivedExchange::market(self, symbol.clone()); if !matches!(__v, crate::Value::Null) { return __v; } }
self.market_non_virtual(symbol)
}
fn market_non_virtual(&self, mut symbol: Value) -> Value {
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" market() requires a symbol argument".into()))));
}
let mut markets: Value = self.markets.clone();
if (markets == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" markets not loaded".into()))));
}
let mut marketsById: Value = self.markets_by_id.clone();
if (matches!((&markets, &symbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return get_value(&markets, &symbol);
} else if (marketsById != Value::Null) && (matches!((&marketsById, &symbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
let mut marketsList: Value = get_value(&marketsById, &symbol);
let mut marketsList: Value = get_value(&marketsById, &symbol);
let mut defaultType: Value = self.safe_string2(self.options.clone(), Value::Str("defaultType".into()), Value::Str("defaultSubType".into()), &[Value::Str("spot".into())]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_139: bool = true;
while { if !__for_first_139 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_139 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&marketsList).as_f64().unwrap_or(f64::NAN) } {
let mut market: Value = get_value(&marketsList, &i);
let mut market: Value = get_value(&marketsList, &i);
if (match &(get_value(&market, &defaultType)) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) }) {
return market;
}
}
}
return get_value(&marketsList, &Value::Int(0));
} else if (symbol.as_str().is_some_and(|__s| __s.ends_with("-C"))) || (symbol.as_str().is_some_and(|__s| __s.ends_with("-P"))) || (symbol.as_str().is_some_and(|__s| __s.starts_with("C-"))) || (symbol.as_str().is_some_and(|__s| __s.starts_with("P-"))) {
return <Self as crate::exchange_generated::ExchangeBase>::create_expired_option_market(self, symbol.clone());
}
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" does not have market symbol ".into())).into()), symbol)));
Value::Null
}
fn create_expired_option_market(&self, mut symbol: Value) -> Value {
// virtual-dispatch (static: DerivedExchange::create_expired_option_market(self, ...))
{ let __v = crate::exchange::DerivedExchange::create_expired_option_market(self, symbol); if !matches!(__v, crate::Value::Null) { return __v; } }
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createExpiredOptionMarket () is not supported yet".into()))));
Value::Null
}
fn is_leveraged_currency(&self, mut currencyCode: Value, optional_args: &[Value]) -> Value {
let mut checkBaseCoin = get_arg(optional_args, 0, Value::Bool(false));
let mut existingCurrencies = get_arg(optional_args, 1, Value::Null);
let mut leverageSuffixes: Value = Value::from(vec![Value::Str("2L".into()), Value::Str("2S".into()), Value::Str("3L".into()), Value::Str("3S".into()), Value::Str("4L".into()), Value::Str("4S".into()), Value::Str("5L".into()), Value::Str("5S".into()), Value::Str("UP".into()), Value::Str("DOWN".into()), Value::Str("BULL".into()), Value::Str("BEAR".into())]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_140: bool = true;
while { if !__for_first_140 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_140 = false; i.as_f64().unwrap_or(f64::NAN) < ((leverageSuffixes.len() as i64) as f64) } {
let mut leverageSuffix: Value = leverageSuffixes.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut endsWithSuffix: bool = ends_with(¤cyCode, &leverageSuffix);
if endsWithSuffix {
if !(checkBaseCoin.as_bool() == Some(true)) {
return Value::Bool(true);
} else {
// check if base currency is inside dict
let mut baseCurrencyCode: Value = replace_str(¤cyCode, &leverageSuffix, &Value::Str("".into()));
if (existingCurrencies != Value::Null) && (matches!((&existingCurrencies, &baseCurrencyCode), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return Value::Bool(true);
}
}
}
}
}
return Value::Bool(false);
Value::Null
}
fn cost_to_precision(&self, mut symbol: Value, mut cost: Value) -> Value {
if (cost == Value::Null) {
return Value::Null;
}
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
return self.decimal_to_precision(cost, Value::Int(crate::runtime::TRUNCATE), self.safe_string2(market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null), Value::Str("cost".into()), Value::Str("price".into()), &[]), &[self.precisionMode.clone(), self.paddingMode.clone()]);
Value::Null
}
fn price_to_precision(&self, mut symbol: Value, mut price: Value) -> Value {
if (price == Value::Null) {
return Value::Null;
}
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut result: Value = self.decimal_to_precision(price, Value::Int(crate::runtime::ROUND), market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("price")).cloned().unwrap_or(Value::Null), &[self.precisionMode.clone(), self.paddingMode.clone()]);
if (result.as_str() == Some("0")) {
let mut pricePrecision: Value = self.number_to_string(market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("price")).cloned().unwrap_or(Value::Null));
if (pricePrecision == Value::Null) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" priceToPrecision() market ".into())).into()), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" has no price precision".into()))));
}
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" price of ".into())).into()), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" must be greater than minimum price precision of ".into())).into()), pricePrecision)));
}
return result;
Value::Null
}
fn amount_to_precision(&self, mut symbol: Value, mut amount: Value) -> Value {
if (amount == Value::Null) {
return Value::Null;
}
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut result: Value = self.decimal_to_precision(amount, Value::Int(crate::runtime::TRUNCATE), market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("amount")).cloned().unwrap_or(Value::Null), &[self.precisionMode.clone(), self.paddingMode.clone()]);
if (result.as_str() == Some("0")) {
let mut amountPrecision: Value = self.number_to_string(market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("amount")).cloned().unwrap_or(Value::Null));
if (amountPrecision == Value::Null) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" amountToPrecision() market ".into())).into()), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" has no amount precision".into()))));
}
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" amount of ".into())).into()), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" must be greater than minimum amount precision of ".into())).into()), amountPrecision)));
}
return result;
Value::Null
}
fn fee_to_precision(&self, mut symbol: Value, mut fee: Value) -> Value {
if (fee == Value::Null) {
return Value::Null;
}
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
return self.decimal_to_precision(fee, Value::Int(crate::runtime::ROUND), market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("price")).cloned().unwrap_or(Value::Null), &[self.precisionMode.clone(), self.paddingMode.clone()]);
Value::Null
}
fn currency_to_precision(&self, mut code: Value, mut fee: Value, optional_args: &[Value]) -> Value {
let mut networkCode = get_arg(optional_args, 0, Value::Null);
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" currencyToPrecision() requires a code argument".into()))));
}
let mut currency: Value = self.currencies.as_map().and_then(|__m| code.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
let mut precision: Value = self.safe_value_k(currency.clone(), "precision", &[]);
if (networkCode != Value::Null) {
let mut networks: Value = self.safe_dict_k(currency, "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networkItem: Value = self.safe_dict(networks, networkCode, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
precision = self.safe_value_k(networkItem, "precision", &[precision.clone()]);
}
if (precision == Value::Null) {
return self.force_string(fee.clone());
} else {
let mut roundingMode: Value = self.safe_integer_k(self.options.clone(), "currencyToPrecisionRoundingMode", &[Value::Int(crate::runtime::ROUND)]);
return self.decimal_to_precision(fee, roundingMode, precision, &[self.precisionMode.clone(), self.paddingMode.clone()]);
}
Value::Null
}
fn force_string(&self, mut value: Value) -> Value {
if !matches!(&value, Value::Str(_)) {
return self.number_to_string(value.clone());
}
return value;
Value::Null
}
fn is_tick_precision(&self) -> Value {
return Value::Bool(self.precisionMode.as_f64() == Value::Int(crate::runtime::TICK_SIZE).as_f64());
Value::Null
}
fn is_significant_precision(&self) -> Value {
return Value::Bool(self.precisionMode.as_f64() == Value::Int(crate::runtime::SIGNIFICANT_DIGITS).as_f64());
Value::Null
}
fn safe_number(&self, mut obj: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut defaultNumber = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_string(obj, key, &[]);
return self.parse_number(value, &[defaultNumber]);
Value::Null
}
fn safe_number_n(&self, mut obj: Value, mut arr: Value, optional_args: &[Value]) -> Value {
let mut defaultNumber = get_arg(optional_args, 0, Value::Null);
let mut value: Value = self.safe_string_n(obj, arr, &[]);
return self.parse_number(value, &[defaultNumber]);
Value::Null
}
fn parse_precision(&self, optional_args: &[Value]) -> Value {
let mut precision = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @param {string} precision The number of digits to the right of the decimal
* @returns {string} a string number equal to 1e-precision
*/
if (precision == Value::Null) {
return Value::Null;
}
let mut precisionNumber: Value = (match &precision { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null });
if (precisionNumber.as_f64() == Some(0.0)) {
return Value::Str("1".into());
}
if precisionNumber.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
let mut parsedPrecision: Value = Value::Str("0.".into());
{
let mut i: Value = Value::Int(0);
let mut __for_first_141: bool = true;
while { if !__for_first_141 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_141 = false; i.as_f64().unwrap_or(f64::NAN) < (match (&(precisionNumber), &(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 }).as_f64().unwrap_or(f64::NAN) } {
parsedPrecision = Value::Str(format!("{}{}", parsedPrecision, Value::Str("0".into())).into());
}
}
return Value::Str(format!("{}{}", parsedPrecision, Value::Str("1".into())).into());
} else {
let mut parsedPrecision: Value = Value::Str("1".into());
{
let mut i: Value = Value::Int(0);
let mut __for_first_142: bool = true;
while { if !__for_first_142 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_142 = false; i.as_f64().unwrap_or(f64::NAN) < (match (&(Value::Int(-1)), &(precisionNumber)) { (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) } {
parsedPrecision = Value::Str(format!("{}{}", parsedPrecision, Value::Str("0".into())).into());
}
}
return Value::Str(format!("{}{}", parsedPrecision, Value::Str("0".into())).into());
}
Value::Null
}
fn integer_precision_to_amount(&self, mut precision: Value) -> Value {
/*
* @ignore
* @method
* @description handles positive & negative numbers too. parsePrecision() does not handle negative numbers, but this method handles
* @param {string} precision The number of digits to the right of the decimal
* @returns {string} a string number equal to 1e-precision
*/
if (precision == Value::Null) {
return Value::Null;
}
if crate::precise::Precise::stringGe(&precision, &Value::Str("0".into())).as_bool() == Some(true) {
return self.parse_precision(&[precision.clone()]);
} else {
let mut positivePrecisionString: Value = crate::precise::Precise::stringAbs(&precision);
if (positivePrecisionString == Value::Null) {
return Value::Null;
}
let mut positivePrecision: Value = (match &positivePrecisionString { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null });
let mut parsedPrecision: Value = Value::Str("1".into());
{
let mut i: Value = Value::Int(0);
let mut __for_first_143: bool = true;
while { if !__for_first_143 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_143 = false; i.as_f64().unwrap_or(f64::NAN) < (match (&(positivePrecision), &(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 }).as_f64().unwrap_or(f64::NAN) } {
parsedPrecision = Value::Str(format!("{}{}", parsedPrecision, Value::Str("0".into())).into());
}
}
return Value::Str(format!("{}{}", parsedPrecision, Value::Str("0".into())).into());
}
}
fn load_time_difference(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut serverTime: Value = self.fetch_time(&[params]).await;
let mut after: Value = self.milliseconds();
if (serverTime == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" loadTimeDifference() missing serverTime".into()))));
}
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("timeDifference".into(), (match (&(after), &(serverTime)) { (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 })); }
return self.parse_to_int(self.options.as_map().and_then(|__m| __m.get("timeDifference")).cloned().unwrap_or(Value::Null));
Value::Null
} }
fn implode_hostname(&self, mut url: Value) -> Value {
return self.implode_params(url, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("hostname".to_string(), self.hostname.clone());
m
}));
Value::Null
}
fn fetch_market_leverage_tiers(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_market_leverage_tiers", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchLeverageTiers")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchLeverageTiers")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol.clone());
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchMarketLeverageTiers() supports contract markets only".into()))));
}
let mut tiers: Value = self.fetch_leverage_tiers(&[Value::from(vec![symbol.clone()])]).await;
let mut marketTiers: Value = self.safe_list(tiers, symbol, &[]);
return marketTiers;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMarketLeverageTiers() is not supported yet".into()))));
}
Value::Null
} }
fn create_sub_account(&mut self, mut name: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createSubAccount() is not supported yet".into()))));
Value::Null
} }
fn safe_currency_code(&self, mut currencyId: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyResolved: Value = self.safe_currency(currencyId, &[currency]);
return currencyResolved.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null);
Value::Null
}
fn filter_by_symbol_since_limit(&self, mut array: 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 tail = get_arg(optional_args, 3, Value::Bool(false));
return self.filter_by_value_since_limit(array, Value::Str("symbol".into()), &[symbol, since, limit, Value::Str("timestamp".into()), tail]);
Value::Null
}
fn filter_by_currency_since_limit(&self, mut array: 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 tail = get_arg(optional_args, 3, Value::Bool(false));
return self.filter_by_value_since_limit(array, Value::Str("currency".into()), &[code, since, limit, Value::Str("timestamp".into()), tail]);
Value::Null
}
fn filter_by_symbols_since_limit(&self, mut array: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut tail = get_arg(optional_args, 3, Value::Bool(false));
let mut result: Value = self.filter_by_array(array, Value::Str("symbol".into()), &[symbols, Value::Bool(false)]);
return self.filter_by_since_limit(result, &[since, limit, Value::Str("timestamp".into()), tail]);
Value::Null
}
fn parse_last_prices(&self, mut pricesData: Value, 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
}));
//
// the value of tickers is either a dict or a list
//
// dict
//
// {
// 'marketId1': { ... },
// 'marketId2': { ... },
// ...
// }
//
// list
//
// [
// { 'market': 'marketId1', ... },
// { 'market': 'marketId2', ... },
// ...
// ]
//
let mut results: Vec<Value> = Vec::new();
if (matches!(&pricesData, Value::Arr(_))) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_144: bool = true;
while { if !__for_first_144 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_144 = false; i.as_f64().unwrap_or(f64::NAN) < ((pricesData.len() as i64) as f64) } {
let mut priceData: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_last_price(self, pricesData.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]), &[params.clone()]);
results.push(priceData.clone());
}
}
} else {
let mut marketIds: Value = object_keys(&pricesData);
{
let mut i: Value = Value::Int(0);
let mut __for_first_145: bool = true;
while { if !__for_first_145 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_145 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketIds.len() as i64) as f64) } {
let mut marketId: Value = marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut priceData: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_last_price(self, get_value(&pricesData, &marketId), &[market]), &[params.clone()]);
results.push(priceData);
}
}
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
return self.index_by(self.filter_by_array(Value::from(results), Value::Str("symbol".into()), &[symbolsNormalized, Value::Bool(false)]), Value::Str("symbol".into()));
Value::Null
}
fn parse_tickers(&self, mut tickers: Value, 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
}));
//
// the value of tickers is either a dict or a list
//
//
// dict
//
// {
// 'marketId1': { ... },
// 'marketId2': { ... },
// 'marketId3': { ... },
// ...
// }
//
// list
//
// [
// { 'market': 'marketId1', ... },
// { 'market': 'marketId2', ... },
// { 'market': 'marketId3', ... },
// ...
// ]
//
let mut results: Vec<Value> = Vec::new();
if (matches!(&tickers, Value::Arr(_))) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_146: bool = true;
while { if !__for_first_146 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_146 = false; i.as_f64().unwrap_or(f64::NAN) < ((tickers.len() as i64) as f64) } {
let mut parsedTicker: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_ticker(self, tickers.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]);
let mut ticker: Value = self.extend(parsedTicker, &[params.clone()]);
results.push(ticker.clone());
}
}
} else {
let mut marketIds: Value = object_keys(&tickers);
{
let mut i: Value = Value::Int(0);
let mut __for_first_147: bool = true;
while { if !__for_first_147 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_147 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketIds.len() as i64) as f64) } {
let mut marketId: Value = marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_ticker(self, get_value(&tickers, &marketId), &[market]);
let mut ticker: Value = self.extend(parsed, &[params.clone()]);
results.push(ticker);
}
}
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
return self.filter_by_array_tickers(Value::from(results), Value::Str("symbol".into()), &[symbolsNormalized]);
Value::Null
}
fn parse_deposit_addresses(&self, mut addresses: Value, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut indexed = get_arg(optional_args, 1, Value::Bool(true));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_148: bool = true;
while { if !__for_first_148 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_148 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&addresses).as_f64().unwrap_or(f64::NAN) } {
let mut address: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_deposit_address(self, get_value(&addresses, &i), &[]), &[params.clone()]);
if let Value::Arr(__a) = &mut result { std::sync::Arc::make_mut(__a).push(address); }
}
}
if (codes != Value::Null) {
result = self.to_array(self.filter_by_array(result.clone(), Value::Str("currency".into()), &[codes, Value::Bool(false)]));
}
if indexed.as_bool() == Some(true) {
result = self.to_array(self.filter_by_array(result.clone(), Value::Str("currency".into()), &[Value::Null, indexed]));
}
return result;
Value::Null
}
fn parse_borrow_interests(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut interests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_149: bool = true;
while { if !__for_first_149 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_149 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut row: Value = get_value(&response, &i);
let mut row: Value = get_value(&response, &i);
if let Value::Arr(__a) = &mut interests { std::sync::Arc::make_mut(__a).push(<Self as crate::exchange_generated::ExchangeBase>::parse_borrow_interest(self, row, &[market.clone()])); }
}
}
return interests;
Value::Null
}
fn parse_borrow_rate(&self, mut info: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_borrow_rate(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_borrow_rate(self, info, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut currency = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseBorrowRate() is not supported yet".into()))));
Value::Null
}
fn parse_borrow_rate_history(&self, mut response: Value, mut code: Value, mut since: Value, mut limit: Value) -> Value {
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_150: bool = true;
while { if !__for_first_150 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_150 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut item: Value = get_value(&response, &i);
let mut item: Value = get_value(&response, &i);
let mut borrowRate: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_borrow_rate(self, item, &[]);
result.push(borrowRate);
}
}
let mut sorted: Value = self.sort_by(Value::from(result), Value::Str("timestamp".into()), &[]);
return self.filter_by_currency_since_limit(sorted, &[code, since, limit]);
Value::Null
}
fn parse_isolated_borrow_rates(&self, mut info: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_151: bool = true;
while { if !__for_first_151 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_151 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&info).as_f64().unwrap_or(f64::NAN) } {
let mut item: Value = get_value(&info, &i);
let mut item: Value = get_value(&info, &i);
let mut borrowRate: Value = self.parse_isolated_borrow_rate(item, &[]);
let mut symbol: Value = self.safe_string_k(borrowRate.clone(), "symbol", &[]);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), borrowRate); }
}
}
return result;
Value::Null
}
fn parse_funding_rate_histories(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut market = 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 rates: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_152: bool = true;
while { if !__for_first_152 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_152 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
rates.push(<Self as crate::exchange_generated::ExchangeBase>::parse_funding_rate_history(self, entry, &[market.clone()]));
}
}
let mut sorted: Value = self.sort_by(Value::from(rates), Value::Str("timestamp".into()), &[]);
let mut symbol: Value = (if (market == Value::Null) { Value::Null } else { market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) });
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
fn safe_symbol(&self, mut marketId: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut delimiter = get_arg(optional_args, 1, Value::Null);
let mut marketType = get_arg(optional_args, 2, Value::Null);
let mut marketResolved: Value = self.safe_market(&[marketId, market, delimiter, marketType]);
return marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
Value::Null
}
fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_funding_rate(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_funding_rate(self, contract, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseFundingRate() is not supported yet".into()))));
Value::Null
}
fn parse_funding_rates(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut fundingRates: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_153: bool = true;
while { if !__for_first_153 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_153 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_funding_rate(self, entry, &[]);
if (parsed.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) != Value::Null) {
add_element_to_object(&mut fundingRates, &parsed.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), parsed.clone());
}
}
}
return self.index_by(self.filter_by_array(fundingRates, Value::Str("symbol".into()), &[symbols, Value::Bool(false)]), Value::Str("symbol".into()));
Value::Null
}
fn parse_long_short_ratio(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseLongShortRatio() is not supported yet".into()))));
Value::Null
}
fn parse_long_short_ratio_history(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut market = 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 rates: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_154: bool = true;
while { if !__for_first_154 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_154 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
rates.push(self.parse_long_short_ratio(entry, &[market.clone()]));
}
}
let mut sorted: Value = self.sort_by(Value::from(rates), Value::Str("timestamp".into()), &[]);
let mut symbol: Value = (if (market == Value::Null) { Value::Null } else { market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) });
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
fn handle_trigger_prices_and_params(&self, mut symbol: Value, mut params: Value, optional_args: &[Value]) -> Value {
let mut omitParams = get_arg(optional_args, 0, Value::Bool(true));
//
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), &[]);
let mut triggerPriceStr: Value = Value::Null;
let mut stopLossPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut stopLossPriceStr: Value = Value::Null;
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut takeProfitPriceStr: Value = Value::Null;
//
let mut keysToOmit: Vec<Value> = Vec::new();
if (triggerPrice != Value::Null) {
if omitParams.as_bool() == Some(true) {
keysToOmit.push(Value::Str("triggerPrice".into()));
keysToOmit.push(Value::Str("stopPrice".into()));
}
triggerPriceStr = self.price_to_precision(symbol.clone(), (match &triggerPrice { Value::Str(__parse_s) => __parse_s.trim().parse::<f64>().map(Value::Float).unwrap_or(Value::Null), Value::Float(__parse_f) => Value::Float(*__parse_f), Value::Int(__parse_n) => Value::Float(*__parse_n as f64), _ => Value::Null }));
}
if (stopLossPrice != Value::Null) {
if omitParams.as_bool() == Some(true) {
keysToOmit.push(Value::Str("stopLossPrice".into()));
}
stopLossPriceStr = self.price_to_precision(symbol.clone(), (match &stopLossPrice { Value::Str(__parse_s) => __parse_s.trim().parse::<f64>().map(Value::Float).unwrap_or(Value::Null), Value::Float(__parse_f) => Value::Float(*__parse_f), Value::Int(__parse_n) => Value::Float(*__parse_n as f64), _ => Value::Null }));
}
if (takeProfitPrice != Value::Null) {
if omitParams.as_bool() == Some(true) {
keysToOmit.push(Value::Str("takeProfitPrice".into()));
}
takeProfitPriceStr = self.price_to_precision(symbol, (match &takeProfitPrice { Value::Str(__parse_s) => __parse_s.trim().parse::<f64>().map(Value::Float).unwrap_or(Value::Null), Value::Float(__parse_f) => Value::Float(*__parse_f), Value::Int(__parse_n) => Value::Float(*__parse_n as f64), _ => Value::Null }));
}
let mut keysToOmitLength: f64 = ((keysToOmit.len() as i64) as f64);
let mut paramsOmitted: Value = (if (keysToOmitLength > ((0i64) as f64)) { self.omit(params.clone(), Value::from(keysToOmit), &[]) } else { params });
return Value::from(vec![triggerPriceStr, stopLossPriceStr, takeProfitPriceStr, paramsOmitted]);
Value::Null
}
fn handle_trigger_direction_and_params(&self, mut params: Value, optional_args: &[Value]) -> Value {
let mut exchangeSpecificKey = get_arg(optional_args, 0, Value::Null);
let mut allowEmpty = get_arg(optional_args, 1, Value::Bool(false));
/*
* @ignore
* @method
* @returns {[string, object]} the trigger-direction value and omited params
*/
let mut triggerDirection: Value = self.safe_string_k(params.clone(), "triggerDirection", &[]);
let mut exchangeSpecificDefined: bool = (exchangeSpecificKey != Value::Null) && (in_op(¶ms, &exchangeSpecificKey));
let mut paramsOmitted: Value = (if (triggerDirection != Value::Null) { self.omit(params.clone(), Value::Str("triggerDirection".into()), &[]) } else { params });
// throw exception if:
// A) if provided value is not unified (support old "up/down" strings too)
// B) if exchange specific "trigger direction key" (eg. "stopPriceSide") was not provided
if !(self.in_array(triggerDirection.clone(), Value::from(vec![Value::Str("ascending".into()), Value::Str("descending".into()), Value::Str("up".into()), Value::Str("down".into()), Value::Str("above".into()), Value::Str("below".into())])).as_bool() == Some(true)) && !exchangeSpecificDefined && !(allowEmpty.as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() : trigger orders require params[\"triggerDirection\"] to be either \"ascending\" or \"descending\"".into()))));
}
// if old format was provided, overwrite to new
if (triggerDirection.as_str() == Some("up")) || (triggerDirection.as_str() == Some("above")) {
triggerDirection = Value::Str("ascending".into());
} else if (triggerDirection.as_str() == Some("down")) || (triggerDirection.as_str() == Some("below")) {
triggerDirection = Value::Str("descending".into());
}
return Value::from(vec![triggerDirection, paramsOmitted]);
Value::Null
}
fn handle_trigger_and_params(&self, mut params: Value) -> Value {
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".into()), Value::Str("stop".into()), &[]);
let mut paramsOmitted: Value = (if (isTrigger.as_bool() == Some(true)) { self.omit(params.clone(), Value::from(vec![Value::Str("trigger".into()), Value::Str("stop".into())]), &[]) } else { params });
return Value::from(vec![isTrigger, paramsOmitted]);
Value::Null
}
fn is_trigger_order(&self, mut params: Value) -> Value {
return self.handle_trigger_and_params(params);
Value::Null
}
fn is_post_only(&self, mut isMarketOrder: Value, mut exchangeSpecificParam: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @ignore
* @method
* @param {string} type Order type
* @param {boolean} exchangeSpecificParam exchange specific postOnly
* @param {object} [params] exchange specific params
* @returns {boolean} true if a post only order, false otherwise
*/
let mut timeInForce: Value = self.safe_string_upper_k(params.clone(), "timeInForce", &[]);
// we assume timeInForce is uppercase from safeStringUpper (params, 'timeInForce')
let mut ioc: bool = timeInForce.as_str() == Some("IOC");
let mut fok: bool = timeInForce.as_str() == Some("FOK");
let mut timeInForcePostOnly: bool = timeInForce.as_str() == Some("PO");
let mut postOnly: bool = self.safe_bool2(params, Value::Str("postOnly".into()), Value::Str("post_only".into()), &[Value::Bool(false)]).as_bool() == Some(true) || timeInForcePostOnly || is_true(&exchangeSpecificParam);
if postOnly {
if ioc || fok {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" postOnly orders cannot have timeInForce equal to ".into())).into()), timeInForce)));
} else if is_true(&isMarketOrder) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" market orders cannot be postOnly".into()))));
} else {
return Value::Bool(true);
}
} else {
return Value::Bool(false);
}
Value::Null
}
fn handle_post_only(&self, mut isMarketOrder: Value, mut exchangeSpecificPostOnlyOption: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @ignore
* @method
* @param {string} type Order type
* @param {boolean} exchangeSpecificBoolean exchange specific postOnly
* @param {object} [params] exchange specific params
* @returns {Array}
*/
let mut timeInForce: Value = self.safe_string_upper_k(params.clone(), "timeInForce", &[]);
let mut ioc: bool = timeInForce.as_str() == Some("IOC");
let mut fok: bool = timeInForce.as_str() == Some("FOK");
let mut po: bool = timeInForce.as_str() == Some("PO");
let mut postOnly: bool = self.safe_bool_k(params.clone(), "postOnly", &[Value::Bool(false)]).as_bool() == Some(true) || po || is_true(&exchangeSpecificPostOnlyOption);
if postOnly {
if ioc || fok {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" postOnly orders cannot have timeInForce equal to ".into())).into()), timeInForce)));
} else if is_true(&isMarketOrder) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" market orders cannot be postOnly".into()))));
} else {
let mut keysToOmit: Value = Value::Null;
if po {
keysToOmit = Value::from(vec![Value::Str("timeInForce".into()), Value::Str("postOnly".into())]);
} else {
keysToOmit = Value::from(vec![Value::Str("postOnly".into())]);
}
let mut paramsOmitted: Value = self.omit(params.clone(), keysToOmit, &[]);
return Value::from(vec![Value::Bool(true), paramsOmitted]);
}
}
return Value::from(vec![Value::Bool(false), params]);
Value::Null
}
fn fetch_last_prices(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLastPrices() is not supported yet".into()))));
Value::Null
} }
fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_trading_fees", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTradingFees() is not supported yet".into()))));
Value::Null
} }
fn fetch_trading_fees_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTradingFeesWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_convert_currencies(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertCurrencies() is not supported yet".into()))));
Value::Null
} }
fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_open_interest(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_open_interest(self, interest, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseOpenInterest () is not supported yet".into()))));
Value::Null
}
fn parse_open_interests(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_155: bool = true;
while { if !__for_first_155 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_155 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_open_interest(self, entry, &[]);
if (parsed.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) != Value::Null) {
add_element_to_object(&mut result, &parsed.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), parsed.clone());
}
}
}
return self.index_by(self.filter_by_array(result, Value::Str("symbol".into()), &[symbols, Value::Bool(false)]), Value::Str("symbol".into()));
Value::Null
}
fn parse_open_interests_history(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut market = 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 interests: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_156: bool = true;
while { if !__for_first_156 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_156 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
let mut interest: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_open_interest(self, entry, &[market.clone()]);
interests.push(interest);
}
}
let mut sorted: Value = self.sort_by(Value::from(interests), Value::Str("timestamp".into()), &[]);
let mut symbol: Value = self.safe_string_k(market, "symbol", &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_funding_rate", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchFundingRates")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchFundingRates")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
self.load_markets(&[]).await;
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut symbolResolved: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate() supports contract markets only".into()))));
}
let mut rates: Value = self.fetch_funding_rates(&[Value::from(vec![symbolResolved.clone()]), params]).await;
let mut rate: Value = self.safe_dict(rates, symbolResolved.clone(), &[]);
if (rate == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate () returned no data for ".into())).into()), symbolResolved)));
} else {
return rate;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate () is not supported yet".into()))));
}
Value::Null
} }
fn fetch_funding_interval(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_funding_interval", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchFundingIntervals")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchFundingIntervals")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
self.load_markets(&[]).await;
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut symbolResolved: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingInterval() supports contract markets only".into()))));
}
let mut rates: Value = self.fetch_funding_intervals(&[Value::from(vec![symbolResolved.clone()]), params]).await;
let mut rate: Value = self.safe_dict(rates, symbolResolved.clone(), &[]);
if (rate == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingInterval() returned no data for ".into())).into()), symbolResolved)));
} else {
return rate;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingInterval() is not supported yet".into()))));
}
Value::Null
} }
fn fetch_mark_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
/*
* @method
* @name exchange#fetchMarkOHLCV
* @description fetches historical mark price candlestick data containing the open, high, low, and close price of a market
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {float[][]} A list of candles ordered as timestamp, open, high, low, close, undefined
*/
if (self.has.as_map().and_then(|__m| __m.get("fetchMarkOHLCV")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchMarkOHLCV")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), Value::Str("mark".into()));
m
});
return self.fetch_ohlcv(symbol, &[timeframe, since, limit, self.extend(request, &[params])]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMarkOHLCV () is not supported yet".into()))));
}
} }
fn fetch_index_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
/*
* @method
* @name exchange#fetchIndexOHLCV
* @description fetches historical index price candlestick data containing the open, high, low, and close price of a market
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {} A list of candles ordered as timestamp, open, high, low, close, undefined
*/
if (self.has.as_map().and_then(|__m| __m.get("fetchIndexOHLCV")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchIndexOHLCV")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), Value::Str("index".into()));
m
});
return self.fetch_ohlcv(symbol, &[timeframe, since, limit, self.extend(request, &[params])]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchIndexOHLCV () is not supported yet".into()))));
}
} }
fn fetch_premium_index_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_premium_index_ohlcv", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
/*
* @method
* @name exchange#fetchPremiumIndexOHLCV
* @description fetches historical premium index price candlestick data containing the open, high, low, and close price of a market
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {float[][]} A list of candles ordered as timestamp, open, high, low, close, undefined
*/
if (self.has.as_map().and_then(|__m| __m.get("fetchPremiumIndexOHLCV")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchPremiumIndexOHLCV")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), Value::Str("premiumIndex".into()));
m
});
return self.fetch_ohlcv(symbol, &[timeframe, since, limit, self.extend(request, &[params])]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPremiumIndexOHLCV () is not supported yet".into()))));
}
} }
fn handle_time_in_force(&self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @ignore
* @method
* Must add timeInForce to this.options to use this method
* @returns {string} returns the exchange specific value for timeInForce
*/
let mut timeInForce: Value = self.safe_string_upper_k(params, "timeInForce", &[]); // supported values GTC, IOC, PO
if (timeInForce != Value::Null) {
let mut exchangeValue: Value = self.safe_string(self.options.as_map().and_then(|__m| __m.get("timeInForce")).cloned().unwrap_or(Value::Null), timeInForce.clone(), &[]);
if (exchangeValue == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" does not support timeInForce \"".into())).into()), timeInForce).into()), Value::Str("\"".into()))));
}
return exchangeValue;
}
return Value::Null;
Value::Null
}
fn convert_type_to_account(&self, mut account: Value) -> Value {
/*
* @ignore
* @method
* Must add accountsByType to this.options to use this method
* @param {string} account key for account name in this.options['accountsByType']
* @returns the exchange specific account name or the isolated margin id for transfers
*/
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut lowercaseAccount: Value = (match &(account) { Value::Str(__s) => Value::Str(__s.to_lowercase().into()), _ => Value::Null });
if (matches!((&accountsByType, &lowercaseAccount), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
return accountsByType.as_map().and_then(|__m| lowercaseAccount.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
}
let mut markets: Value = self.markets.clone();
let mut marketsById: Value = self.markets_by_id.clone();
if ((markets != Value::Null) && (matches!((&markets, &account), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref())))) || ((marketsById != Value::Null) && (matches!((&marketsById, &account), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref())))) {
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, account.clone());
return market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
} else {
return account;
}
Value::Null
}
fn check_required_argument(&self, mut methodName: Value, mut argument: Value, mut argumentName: Value, optional_args: &[Value]) {
let mut options = get_arg(optional_args, 0, Value::from(vec![]));
/*
* @ignore
* @method
* @param {string} methodName the name of the method that the argument is being checked for
* @param {string} argument the argument's actual value provided
* @param {string} argumentName the name of the argument being checked (for logging purposes)
* @param {string[]} options a list of options that the argument can be
* @returns {undefined}
*/
let mut optionsLength: f64 = ((options.len() as i64) as f64);
if (argument == Value::Null) || ((optionsLength > ((0i64) as f64)) && (!(self.in_array(argument, options.clone()).as_bool() == Some(true)))) {
let mut messageOptions: Value = Value::Str(options.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(", ")).unwrap_or_default().into());
let mut message: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a ".into())).into()), argumentName).into()), Value::Str(" argument".into())).into());
if (!matches!(&messageOptions, Value::Str(__s15) if __s15 == "")) {
message = Value::Str(format!("{}{}", message, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(", one of ".into()), Value::Str("(".into())).into()), messageOptions).into()), Value::Str(")".into())).into())).into());
}
panic!("{}", crate::exchange_errors::arguments_required(message));
}
}
fn check_required_margin_argument(&self, mut methodName: Value, mut symbol: Value, mut marginMode: Value) {
/*
* @ignore
* @method
* @param {string} symbol unified symbol of the market
* @param {string} methodName name of the method that requires a symbol
* @param {string} marginMode is either 'isolated' or 'cross'
*/
if (marginMode.as_str() == Some("isolated")) && (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a symbol argument for isolated margin".into()))));
} else if (marginMode.as_str() == Some("cross")) && (symbol != Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() cannot have a symbol argument for cross margin".into()))));
}
}
fn parse_deposit_withdraw_fees(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut currencyIdKey = get_arg(optional_args, 1, Value::Null);
/*
* @ignore
* @method
* @param {object[]|object} response unparsed response from the exchange
* @param {string[]|undefined} codes the unified currency codes to fetch transactions fees for, returns all currencies when undefined
* @param {str} currencyIdKey *should only be undefined when response is a dictionary* the object key that corresponds to the currency id
* @returns {object} objects with withdraw and deposit fees, indexed by currency codes
*/
let mut depositWithdrawFees: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut isArray: bool = matches!(&response, Value::Arr(_));
let mut responseKeys: Value = response.clone();
if !isArray {
responseKeys = object_keys(&response);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_157: bool = true;
while { if !__for_first_157 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_157 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&responseKeys).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&responseKeys, &i);
let mut entry: Value = get_value(&responseKeys, &i);
let mut dictionary: Value = (if isArray { entry.clone() } else { get_value(&response, &entry) });
let mut currencyId: Value = entry;
if isArray {
currencyId = (if (currencyIdKey == Value::Null) { Value::Null } else { self.safe_string(dictionary.clone(), currencyIdKey.clone(), &[]) });
}
let mut currency: Value = self.safe_currency(currencyId, &[]);
let mut code: Value = self.safe_string_k(currency.clone(), "code", &[]);
if (codes == Value::Null) || self.in_array(code.clone(), codes.clone()).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut depositWithdrawFees { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), <Self as crate::exchange_generated::ExchangeBase>::parse_deposit_withdraw_fee(self, dictionary, &[currency])); }
}
}
}
return depositWithdrawFees;
Value::Null
}
fn parse_deposit_withdraw_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_deposit_withdraw_fee(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_deposit_withdraw_fee(self, fee, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut currency = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseDepositWithdrawFee() is not supported yet".into()))));
Value::Null
}
fn deposit_withdraw_fee(&self, mut info: Value) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info);
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
Value::Null
}
fn assign_default_deposit_withdraw_fees(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
/*
* @ignore
* @method
* @description Takes a depositWithdrawFee structure and assigns the default values for withdraw and deposit
* @param {object} fee A deposit withdraw fee structure
* @param {object} currency A currency structure, the response from this.currency ()
* @returns {object} A deposit withdraw fee structure
*/
let mut networkKeys: Value = object_keys(&crate::value::get_value_k(&fee, "networks"));
let mut numNetworks: f64 = ((networkKeys.len() as i64) as f64);
if (numNetworks == 1.0) {
{ let __be_tmp = crate::value::get_value_k(&get_value(&crate::value::get_value_k(&fee, "networks"), &networkKeys.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null)), "withdraw"); add_element_to_object(&mut fee, &Value::Str("withdraw".into()), __be_tmp); };
{ let __be_tmp = crate::value::get_value_k(&get_value(&crate::value::get_value_k(&fee, "networks"), &networkKeys.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null)), "deposit"); add_element_to_object(&mut fee, &Value::Str("deposit".into()), __be_tmp); };
return fee;
}
let mut currencyCode: Value = (match currency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
{
let mut i: Value = Value::Int(0);
let mut __for_first_158: bool = true;
while { if !__for_first_158 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_158 = false; i.as_f64().unwrap_or(f64::NAN) < numNetworks } {
let mut network: Value = networkKeys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (network.as_str() == currencyCode.as_str()) {
{ let __be_tmp = crate::value::get_value_k(&get_value(&crate::value::get_value_k(&fee, "networks"), &networkKeys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)), "withdraw"); add_element_to_object(&mut fee, &Value::Str("withdraw".into()), __be_tmp); };
{ let __be_tmp = crate::value::get_value_k(&get_value(&crate::value::get_value_k(&fee, "networks"), &networkKeys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)), "deposit"); add_element_to_object(&mut fee, &Value::Str("deposit".into()), __be_tmp); };
}
}
}
return fee;
Value::Null
}
fn parse_income(&self, mut info: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_income(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_income(self, info, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseIncome () is not supported yet".into()))));
Value::Null
}
fn parse_incomes(&self, mut incomes: Value, optional_args: &[Value]) -> Value {
let mut market = 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);
/*
* @ignore
* @method
* @description parses funding fee info from exchange response
* @param {object[]} incomes each item describes once instance of currency being received or paid
* @param {object} market ccxt market
* @param {int} [since] when defined, the response items are filtered to only include items after this timestamp
* @param {int} [limit] limits the number of items in the response
* @returns {object[]} an array of [funding history structures]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_159: bool = true;
while { if !__for_first_159 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_159 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&incomes).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&incomes, &i);
let mut entry: Value = get_value(&incomes, &i);
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_income(self, entry, &[market.clone()]);
result.push(parsed);
}
}
let mut sorted: Value = self.sort_by(Value::from(result), Value::Str("timestamp".into()), &[]);
let mut symbol: Value = self.safe_string_k(market, "symbol", &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
fn get_market_from_symbols(&self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
/*
* @param {string[]|undefined} symbols list of unified symbols (first element selects the market)
* @returns {MarketInterface|undefined} market structure for the first symbol, or undefined if symbols is undefined
* Overloads: non-null `string[]` input yields `MarketInterface`; optional input yields `Market`.
*/
if (symbols == Value::Null) {
return Value::Null;
}
let mut firstMarket: Value = self.safe_string(symbols, Value::Int(0), &[]);
if (firstMarket == Value::Null) {
return Value::Null;
}
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, firstMarket);
return market;
Value::Null
}
fn parse_ws_ohlc_vs(&self, mut ohlcvs: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timeframe = get_arg(optional_args, 1, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut results: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_160: bool = true;
while { if !__for_first_160 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_160 = false; i.as_f64().unwrap_or(f64::NAN) < ((ohlcvs.len() as i64) as f64) } {
results.push(self.parse_ws_ohlcv(ohlcvs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[market.clone()]));
}
}
return Value::from(results);
Value::Null
}
fn fetch_transactions(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
/*
* @method
* @name exchange#fetchTransactions
* @deprecated
* @description *DEPRECATED* use fetchDepositsWithdrawals instead
* @param {string} code unified currency code for the currency of the deposit/withdrawals, default is undefined
* @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
* @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
if (self.has.as_map().and_then(|__m| __m.get("fetchDepositsWithdrawals")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchDepositsWithdrawals")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.fetch_deposits_withdrawals(&[code, since, limit, params]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTransactions () is not supported yet".into()))));
}
} }
fn filter_by_array_positions(&self, mut objects: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut values = get_arg(optional_args, 0, Value::Null);
return self.to_array(self.filter_by_array(objects, key, &[values, Value::Bool(false)]));
Value::Null
}
fn filter_by_array_tickers(&self, mut objects: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut values = get_arg(optional_args, 0, Value::Null);
return self.index_by(self.filter_by_array(objects, key.clone(), &[values, Value::Bool(false)]), key);
Value::Null
}
fn filter_by_array_adl_ranks(&self, mut objects: Value, mut key: Value, optional_args: &[Value]) -> Value {
let mut values = get_arg(optional_args, 0, Value::Null);
let mut indexed = get_arg(optional_args, 1, Value::Bool(true));
return self.to_array(self.filter_by_array(objects, key, &[values, indexed]));
Value::Null
}
fn create_ohlcv_object(&self, mut symbol: Value, mut timeframe: Value, mut data: Value) -> Value {
let mut res: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if let Value::Dict(__d) = &mut res { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), Value::Map({
let mut m = indexmap::IndexMap::new();
m
})); }
add_element_to_object(get_value_mut(&mut res, &symbol), &timeframe, data);
return res;
Value::Null
}
fn handle_max_entries_per_request_and_params(&self, mut method: Value, optional_args: &[Value]) -> Value {
let mut maxEntriesPerRequest = 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 newMaxEntriesPerRequestparamsMaxEntriesPerRequestVariable = self.handle_option_integer_and_params(params, method, Value::Str("maxEntriesPerRequest".into()), &[]);
let mut newMaxEntriesPerRequest: Value = newMaxEntriesPerRequestparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxEntriesPerRequest: Value = newMaxEntriesPerRequestparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut maxEntriesPerRequestOption: Value = (if (newMaxEntriesPerRequest != Value::Null) { newMaxEntriesPerRequest } else { maxEntriesPerRequest });
let mut maxEntriesPerRequestResolved: Value = (if (maxEntriesPerRequestOption == Value::Null) { Value::Int(1000) } else { maxEntriesPerRequestOption }); // default to 1000
return Value::from(vec![maxEntriesPerRequestResolved, paramsMaxEntriesPerRequest]);
Value::Null
}
fn fetch_paginated_call_dynamic(&mut self, mut method: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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 maxEntriesPerRequest = get_arg(optional_args, 4, Value::Null);
let mut removeRepeated = get_arg(optional_args, 5, Value::Bool(true));
let mut maxCalls: Value = Value::Int(10);
let mut maxCallsPaginationCallsparamsPaginationCallsVariable = self.handle_option_integer_and_params(params, method.clone(), Value::Str("paginationCalls".into()), &[maxCalls]);
let mut maxCallsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut maxRetries: Value = Value::Int(3);
let mut maxRetriesOptionparamsMaxRetriesVariable = self.handle_option_integer_and_params(paramsPaginationCalls, method.clone(), Value::Str("maxRetries".into()), &[maxRetries]);
let mut maxRetriesOption: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxRetries: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut paginationDirectionparamsPaginationDirectionVariable = self.handle_option_and_params(paramsMaxRetries, method.clone(), Value::Str("paginationDirection".into()), &[Value::Str("backward".into())]);
let mut paginationDirection: Value = paginationDirectionparamsPaginationDirectionVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginationDirection: Value = paginationDirectionparamsPaginationDirectionVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut paginationTimestamp: Value = Value::Null;
let mut removeRepeatedOptionparamsRemoveRepeatedVariable = self.handle_option_and_params(paramsPaginationDirection, method.clone(), Value::Str("removeRepeated".into()), &[removeRepeated]);
let mut removeRepeatedOption: Value = removeRepeatedOptionparamsRemoveRepeatedVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsRemoveRepeated: Value = removeRepeatedOptionparamsRemoveRepeatedVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut calls: Value = Value::Int(0);
let mut result: Value = Value::from(vec![]);
let mut errors: Value = Value::Int(0);
let mut until: Value = self.safe_integer_n(paramsRemoveRepeated.clone(), Value::from(vec![Value::Str("until".into()), Value::Str("untill".into()), Value::Str("till".into())]), &[]); // do not omit it from params here
let mut maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable = self.handle_max_entries_per_request_and_params(method.clone(), &[maxEntriesPerRequest, paramsRemoveRepeated]);
let mut maxEntriesPerRequestOption: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxEntriesPerRequest: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (paginationDirection.as_str() == Some("forward")) {
if (since == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" pagination requires a since argument when paginationDirection set to forward".into()))));
}
paginationTimestamp = since.clone();
}
let mut shouldBreak: bool = false;
while (calls.as_f64().unwrap_or(f64::NAN) < maxCallsPaginationCalls.as_f64().unwrap_or(f64::NAN)) {
calls = (match (&(calls), &(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 (paginationDirection.as_str() == Some("backward")) {
// do it backwards, starting from the last
// UNTIL filtering is required in order to work
if (paginationTimestamp != Value::Null) {
if let Value::Dict(__d) = &mut paramsMaxEntriesPerRequest { std::sync::Arc::make_mut(__d).insert("until".into(), (match (&(paginationTimestamp), &(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 response: Value = self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (Value::Null).clone(), (maxEntriesPerRequestOption).clone(), (paramsMaxEntriesPerRequest).clone()]).await;
let mut responseLength: Value = get_array_length(&response);
if is_true(&self.verbose) {
let mut backwardMessage: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Dynamic pagination call ".into()), self.number_to_string(calls.clone())).into()), Value::Str(" method ".into())).into()), method).into()), Value::Str(" response length ".into())).into()), self.number_to_string(responseLength.clone())).into());
if (paginationTimestamp != Value::Null) {
backwardMessage = Value::Str(format!("{}{}", backwardMessage, Value::Str(format!("{}{}", Value::Str(" timestamp ".into()), self.number_to_string(paginationTimestamp.clone())).into())).into());
}
self.log(backwardMessage);
}
if (responseLength.as_f64() == Some(0.0)) {
shouldBreak = true;
break;
}
errors = Value::Int(0);
result = self.array_concat(result.clone(), response.clone());
let mut firstElement: Value = self.safe_value(response.clone(), Value::Int(0), &[]);
paginationTimestamp = self.safe_integer2(firstElement, Value::Str("timestamp".into()), Value::Int(0), &[]);
if (paginationTimestamp == Value::Null) {
shouldBreak = true;
break;
}
if (since != Value::Null) && (paginationTimestamp.as_f64().unwrap_or(f64::NAN) <= since.as_f64().unwrap_or(f64::NAN)) {
shouldBreak = true;
break;
}
} else {
// do it forwards, starting from the since
let mut response: Value = self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (paginationTimestamp).clone(), (maxEntriesPerRequestOption).clone(), (paramsMaxEntriesPerRequest).clone()]).await;
let mut responseLength: Value = get_array_length(&response);
if is_true(&self.verbose) {
let mut forwardMessage: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Dynamic pagination call ".into()), self.number_to_string(calls.clone())).into()), Value::Str(" method ".into())).into()), method).into()), Value::Str(" response length ".into())).into()), self.number_to_string(responseLength.clone())).into());
if (paginationTimestamp != Value::Null) {
forwardMessage = Value::Str(format!("{}{}", forwardMessage, Value::Str(format!("{}{}", Value::Str(" timestamp ".into()), self.number_to_string(paginationTimestamp.clone())).into())).into());
}
self.log(forwardMessage);
}
if (responseLength.as_f64() == Some(0.0)) {
shouldBreak = true;
break;
}
errors = Value::Int(0);
result = self.array_concat(result.clone(), response.clone());
let mut last: Value = self.safe_value(response, (match (&(responseLength), &(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 lastTimestamp: Value = self.safe_integer_k(last, "timestamp", &[Value::Int(0)]);
if (lastTimestamp == Value::Null) {
shouldBreak = true;
break;
}
let mut nextPaginationTimestamp: Value = (match (&(lastTimestamp), &(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 });
paginationTimestamp = nextPaginationTimestamp.clone();
if (until != Value::Null) && (nextPaginationTimestamp.as_f64().unwrap_or(f64::NAN) >= until.as_f64().unwrap_or(f64::NAN)) {
shouldBreak = true;
break;
}
}
}
if shouldBreak {
break;
}
}
let mut uniqueResults: Value = result.clone();
if is_true(&removeRepeatedOption) {
uniqueResults = self.remove_repeated_elements_from_array(result, &[]);
}
let mut key: Value = (if (method.as_str() == Some("fetchOHLCV")) { Value::Int(0) } else { Value::Str("timestamp".into()) });
let mut sortedRes: Value = self.sort_by(uniqueResults, key.clone(), &[]);
return self.filter_by_since_limit(sortedRes, &[since, limit, key]);
Value::Null
} }
fn safe_deterministic_call(&mut self, mut method: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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 timeframe = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut maxRetries: Value = Value::Int(3);
let mut maxRetriesOptionparamsMaxRetriesVariable = self.handle_option_integer_and_params(params, method.clone(), Value::Str("maxRetries".into()), &[maxRetries]);
let mut maxRetriesOption: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxRetries: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut errors: Value = Value::Int(0);
while errors.as_f64().unwrap_or(f64::NAN) <= maxRetriesOption.as_f64().unwrap_or(f64::NAN) {
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
if ((timeframe != Value::Null) && (timeframe.as_str() != Some(""))) && (method.as_str() != Some("fetchFundingRateHistory")) {
return self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (timeframe).clone(), (since).clone(), (limit).clone(), (paramsMaxRetries).clone()]).await;
} else {
return self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (since).clone(), (limit).clone(), (paramsMaxRetries).clone()]).await;
}
#[allow(unreachable_code)] { Value::Null }})).await;
match _try_result { Ok(__try_ok) => { if !matches!(__try_ok, Value::Null) { return __try_ok; } return Value::Null; } Err(_try_err) => { let e: Value = panic_to_value(_try_err);
if matches!(&e, Value::Str(__s) if __s.contains("[RateLimitExceeded]")) {
panic!("{}", e);
}
errors = (match (&(errors), &(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 errors.as_f64().unwrap_or(f64::NAN) > maxRetriesOption.as_f64().unwrap_or(f64::NAN) {
panic!("{}", e);
}
} }
}
return Value::from(vec![]);
Value::Null
} }
fn fetch_paginated_call_deterministic(&mut self, mut method: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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 timeframe = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut maxEntriesPerRequest = get_arg(optional_args, 5, Value::Null);
let mut maxCalls: Value = Value::Int(10);
let mut maxCallsPaginationCallsparamsPaginationCallsVariable = self.handle_option_integer_and_params(params, method.clone(), Value::Str("paginationCalls".into()), &[maxCalls]);
let mut maxCallsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable = self.handle_max_entries_per_request_and_params(method.clone(), &[maxEntriesPerRequest, paramsPaginationCalls]);
let mut maxEntriesPerRequestOption: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxEntriesPerRequest: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
// paginationDirection is only relevant to fetchPaginatedCallDynamic/Cursor; deterministic
// pagination always walks forward internally, so strip it here to avoid leaking an
// unrecognized param into the underlying exchange request (e.g. binance -1104 errors)
let mut paramsOmitted: Value = self.omit(paramsMaxEntriesPerRequest, Value::Str("paginationDirection".into()), &[]);
let mut current: Value = self.milliseconds();
let mut tasks: Vec<Value> = Vec::new();
let mut time: Value = (match (&(self.parse_timeframe(timeframe.clone())), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
let mut maxEntriesPerRequestValue: Value = self.require_value(maxEntriesPerRequestOption, &[Value::Str("fetchPaginatedCallDeterministic() maxEntriesPerRequest is required".into())]);
let mut step: Value = (match (&(time), &(self.parse_to_int(maxEntriesPerRequestValue.clone()))) { (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 until: Value = self.safe_integer2(paramsOmitted.clone(), Value::Str("until".into()), Value::Str("till".into()), &[]); // do not omit it here
let mut currentSince: Value = (match (&((match (&(current), &(((match (&(maxCallsPaginationCalls), &(step)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null })), &(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 (since != Value::Null) {
if (until != Value::Null) {
// the recent-window floor below would jump past a fully-historical [ since, until ]
// range and return an empty result - requiredCalls is validated against maxCalls
// further down, so anchoring at since directly is safe here,
// see https://github.com/ccxt/ccxt/issues/26252
currentSince = since.clone();
} else {
currentSince = crate::runtime::Math::max(¤tSince, &since);
}
} else {
currentSince = crate::runtime::Math::max(¤tSince, &Value::Int(1241440531000)); // avoid timestamps older than 2009
}
if (until != Value::Null) {
if (since == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchPaginatedCallDeterministic() requires a since argument when until is set".into()))));
}
let mut requiredCalls: Value = ((match ((((match (&(until), &(since)) { (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(), (step).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })).as_f64().map(|__x| Value::Float(__x.ceil())).unwrap_or(Value::Null);
if requiredCalls.as_f64().unwrap_or(f64::NAN) > maxCallsPaginationCalls.as_f64().unwrap_or(f64::NAN) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" the number of required calls is greater than the max number of calls allowed, either increase the paginationCalls or decrease the since-until gap. Current paginationCalls limit is ".into())).into()), Value::Str(format!("{}", maxCallsPaginationCalls).into())).into()), Value::Str(" required calls is ".into())).into()), Value::Str(format!("{}", requiredCalls).into()))));
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_161: bool = true;
while { if !__for_first_161 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_161 = false; i.as_f64().unwrap_or(f64::NAN) < maxCallsPaginationCalls.as_f64().unwrap_or(f64::NAN) } {
if (until != Value::Null) && (currentSince.as_f64().unwrap_or(f64::NAN) >= until.as_f64().unwrap_or(f64::NAN)) {
break;
}
if currentSince.as_f64().unwrap_or(f64::NAN) >= current.as_f64().unwrap_or(f64::NAN) {
break;
}
tasks.push(self.safe_deterministic_call(method.clone(), &[symbol.clone(), currentSince.clone(), maxEntriesPerRequestValue.clone(), timeframe.clone(), paramsOmitted.clone()]).await);
// this.sum keeps it numeric in PHP, where the regex transpiler turns `a + b` into string concatenation
currentSince = (match (&(self.sum(&[currentSince.clone(), step.clone()])), &(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 results: Value = promise_all(&Value::from(tasks)).await;
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_162: bool = true;
while { if !__for_first_162 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_162 = false; i.as_f64().unwrap_or(f64::NAN) < ((results.len() as i64) as f64) } {
result = self.array_concat(result.clone(), results.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
}
}
let mut uniqueResults: Value = self.remove_repeated_elements_from_array(result, &[]);
let mut key: Value = (if (method.as_str() == Some("fetchOHLCV")) { Value::Int(0) } else { Value::Str("timestamp".into()) });
return self.filter_by_since_limit(uniqueResults, &[since, limit, key]);
Value::Null
} }
// the 'symbol' slot is forwarded to `this[method]` untouched and is only compared against
// undefined here, so fetchPositions/fetchPositionsHistory legitimately pass a symbol list
fn fetch_paginated_call_cursor(&mut self, mut method: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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 cursorReceived = get_arg(optional_args, 4, Value::Null);
let mut cursorSent = get_arg(optional_args, 5, Value::Null);
let mut cursorIncrement = get_arg(optional_args, 6, Value::Null);
let mut maxEntriesPerRequest = get_arg(optional_args, 7, Value::Null);
let mut maxCalls: Value = Value::Int(10);
let mut maxCallsPaginationCallsparamsPaginationCallsVariable = self.handle_option_integer_and_params(params, method.clone(), Value::Str("paginationCalls".into()), &[maxCalls]);
let mut maxCallsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut maxRetries: Value = Value::Int(3);
let mut maxRetriesOptionparamsMaxRetriesVariable = self.handle_option_integer_and_params(paramsPaginationCalls, method.clone(), Value::Str("maxRetries".into()), &[maxRetries]);
let mut maxRetriesOption: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxRetries: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable = self.handle_max_entries_per_request_and_params(method.clone(), &[maxEntriesPerRequest, paramsMaxRetries]);
let mut maxEntriesPerRequestOption: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxEntriesPerRequest: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut cursorValue: Value = Value::Null;
let mut i: Value = Value::Int(0);
let mut errors: Value = Value::Int(0);
let mut result: Value = Value::from(vec![]);
let mut timeframe: Value = self.safe_string_k(paramsMaxEntriesPerRequest.clone(), "timeframe", &[]);
let mut paramsOmitted: Value = self.omit(paramsMaxEntriesPerRequest, Value::Str("timeframe".into()), &[]); // reading the timeframe from the method arguments to avoid changing the signature
let mut shouldBreak: bool = false;
while i.as_f64().unwrap_or(f64::NAN) < maxCallsPaginationCalls.as_f64().unwrap_or(f64::NAN) {
{
if (cursorValue != Value::Null) {
if (cursorIncrement != Value::Null) {
cursorValue = self.sum(&[self.parse_to_int(cursorValue.clone()), cursorIncrement.clone()]);
}
if let Value::Dict(__d) = &mut paramsOmitted { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&cursorSent), cursorValue.clone()); }
}
let mut response: Value = Value::Null;
if (method.as_str() == Some("fetchAccounts")) {
response = self.call_dynamic_checked(method.clone(), vec![(paramsOmitted).clone()]).await;
} else if (method.as_str() == Some("getLeverageTiersPaginated")) || (method.as_str() == Some("fetchPositions")) {
response = self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (paramsOmitted).clone()]).await;
} else if (method.as_str() == Some("fetchOpenInterestHistory")) {
if !matches!(&symbol, Value::Str(_)) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchPaginatedCallCursor() requires a symbol argument".into()))));
}
if (timeframe == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchPaginatedCallCursor() requires a timeframe argument".into()))));
}
response = self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (timeframe).clone(), (since).clone(), (maxEntriesPerRequestOption).clone(), (paramsOmitted).clone()]).await;
} else {
response = self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (since).clone(), (maxEntriesPerRequestOption).clone(), (paramsOmitted).clone()]).await;
}
errors = Value::Int(0);
if (response == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" fetchPaginatedCallCursor() returned empty response".into()))));
}
let mut responseLength: Value = Value::Int(response.len() as i64);
if is_true(&self.verbose) {
let mut cursorString: Value = (if (cursorValue == Value::Null) { Value::Str("".into()) } else { cursorValue.clone() });
let mut iteration: Value = ((match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }));
let mut cursorMessage: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Cursor pagination call ".into()), Value::Str(format!("{}", iteration).into())).into()), Value::Str(" method ".into())).into()), method).into()), Value::Str(" response length ".into())).into()), Value::Str(format!("{}", responseLength).into())).into()), Value::Str(" cursor ".into())).into()), cursorString).into());
self.log(cursorMessage);
}
if (responseLength.as_f64() == Some(0.0)) {
shouldBreak = true;
break;
}
if (response != Value::Null) {
result = self.array_concat(result.clone(), response.clone());
}
let mut last: Value = self.safe_dict(response.clone(), (match (&(responseLength), &(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 }), &[]);
// cursorValue = this.safeValue (last['info'], cursorReceived);
cursorValue = Value::Null; // search for the cursor
{
let mut j: Value = Value::Int(0);
let mut __for_first_163: bool = true;
while { if !__for_first_163 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_163 = false; j.as_f64().unwrap_or(f64::NAN) < responseLength.as_f64().unwrap_or(f64::NAN) } {
if (cursorValue == Value::Null) {
let mut index: Value = (match (&((match (&(responseLength), &(j)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null })), &(Value::Int(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 entry: Value = self.safe_dict(response.clone(), index, &[]);
let mut info: Value = self.safe_dict_k(entry, "info", &[]);
cursorValue = (if (cursorReceived == Value::Null) { Value::Null } else { self.safe_value(info, cursorReceived.clone(), &[]) });
}
}
}
if (cursorValue == Value::Null) {
shouldBreak = true;
break;
}
let mut lastTimestamp: Value = self.safe_integer_k(last, "timestamp", &[]);
if (since == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchPaginatedCallCursor() requires a since argument".into()))));
}
if (lastTimestamp != Value::Null) && lastTimestamp.as_f64().unwrap_or(f64::NAN) < since.as_f64().unwrap_or(f64::NAN) {
shouldBreak = true;
break;
}
}
if shouldBreak {
break;
}
i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null });
}
let mut sorted: Value = self.sort_cursor_paginated_result(result);
let mut key: Value = (if (method.as_str() == Some("fetchOHLCV")) { Value::Int(0) } else { Value::Str("timestamp".into()) });
return self.filter_by_since_limit(sorted, &[since, limit, key]);
Value::Null
} }
fn fetch_paginated_call_incremental(&mut self, mut method: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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 pageKey = get_arg(optional_args, 4, Value::Null);
let mut maxEntriesPerRequest = get_arg(optional_args, 5, Value::Null);
let mut maxCalls: Value = Value::Int(10);
let mut maxCallsPaginationCallsparamsPaginationCallsVariable = self.handle_option_integer_and_params(params, method.clone(), Value::Str("paginationCalls".into()), &[maxCalls]);
let mut maxCallsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginationCalls: Value = maxCallsPaginationCallsparamsPaginationCallsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut maxRetries: Value = Value::Int(3);
let mut maxRetriesOptionparamsMaxRetriesVariable = self.handle_option_integer_and_params(paramsPaginationCalls, method.clone(), Value::Str("maxRetries".into()), &[maxRetries]);
let mut maxRetriesOption: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxRetries: Value = maxRetriesOptionparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable = self.handle_max_entries_per_request_and_params(method.clone(), &[maxEntriesPerRequest, paramsMaxRetries]);
let mut maxEntriesPerRequestOption: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxEntriesPerRequest: Value = maxEntriesPerRequestOptionparamsMaxEntriesPerRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut i: Value = Value::Int(0);
let mut errors: Value = Value::Int(0);
let mut result: Value = Value::from(vec![]);
let mut shouldBreak: bool = false;
while i.as_f64().unwrap_or(f64::NAN) < maxCallsPaginationCalls.as_f64().unwrap_or(f64::NAN) {
{
if let Value::Dict(__d) = &mut paramsMaxEntriesPerRequest { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&pageKey), (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null })); }
let mut response: Value = self.call_dynamic_checked(method.clone(), vec![(symbol).clone(), (since).clone(), (maxEntriesPerRequestOption).clone(), (paramsMaxEntriesPerRequest).clone()]).await;
errors = Value::Int(0);
let mut responseLength: Value = get_array_length(&response);
if is_true(&self.verbose) {
let mut iteration: Value = ((match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }));
let mut incrementalMessage: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Incremental pagination call ".into()), Value::Str(format!("{}", iteration).into())).into()), Value::Str(" method ".into())).into()), method).into()), Value::Str(" response length ".into())).into()), Value::Str(format!("{}", responseLength).into())).into());
self.log(incrementalMessage);
}
if (responseLength.as_f64() == Some(0.0)) {
shouldBreak = true;
break;
}
result = self.array_concat(result.clone(), response);
}
if shouldBreak {
break;
}
i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null });
}
let mut sorted: Value = self.sort_cursor_paginated_result(result);
let mut key: Value = (if (method.as_str() == Some("fetchOHLCV")) { Value::Int(0) } else { Value::Str("timestamp".into()) });
return self.filter_by_since_limit(sorted, &[since, limit, key]);
Value::Null
} }
fn sort_cursor_paginated_result(&self, mut result: Value) -> Value {
let mut first: Value = self.safe_dict(result.clone(), Value::Int(0), &[]);
if (first != Value::Null) {
if (matches!(&first, Value::Dict(__d) if __d.contains_key("timestamp"))) {
return self.sort_by(result.clone(), Value::Str("timestamp".into()), &[Value::Bool(true)]);
}
if (matches!(&first, Value::Dict(__d) if __d.contains_key("id"))) {
return self.sort_by(result.clone(), Value::Str("id".into()), &[Value::Bool(true)]);
}
}
return result;
Value::Null
}
fn remove_repeated_elements_from_array(&self, mut input: Value, optional_args: &[Value]) -> Value {
let mut fallbackToTimestamp = get_arg(optional_args, 0, Value::Bool(true));
let mut uniqueDic: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut uniqueResult: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_164: bool = true;
while { if !__for_first_164 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_164 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&input).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&input, &i);
let mut entry: Value = get_value(&input, &i);
let mut uniqValue: Value = (if is_true(&fallbackToTimestamp) { self.safe_string_n(entry.clone(), Value::from(vec![Value::Str("id".into()), Value::Str("timestamp".into()), Value::Int(0)]), &[]) } else { self.safe_string_k(entry.clone(), "id", &[]) });
if (uniqValue != Value::Null) && !(matches!((&uniqueDic, &uniqValue), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let Value::Dict(__d) = &mut uniqueDic { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&uniqValue), Value::Int(1)); }
if let Value::Arr(__a) = &mut uniqueResult { std::sync::Arc::make_mut(__a).push(entry); }
}
}
}
let mut valuesLength: f64 = ((uniqueResult.len() as i64) as f64);
if valuesLength > ((0i64) as f64) {
return uniqueResult;
}
return input;
Value::Null
}
fn remove_repeated_trades_from_array(&self, mut input: Value) -> Value {
let mut uniqueResult: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_165: bool = true;
while { if !__for_first_165 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_165 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&input).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&input, &i);
let mut entry: Value = get_value(&input, &i);
let mut id: Value = self.safe_string_k(entry.clone(), "id", &[]);
if (id == Value::Null) {
let mut price: Value = self.safe_string_k(entry.clone(), "price", &[]);
let mut amount: Value = self.safe_string_k(entry.clone(), "amount", &[]);
let mut timestamp: Value = self.safe_string_k(entry.clone(), "timestamp", &[]);
let mut side: Value = self.safe_string_k(entry.clone(), "side", &[]);
// unique trade identifier
if (timestamp == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" removeRepeatedTradesFromArray() missing timestamp".into()))));
}
// optional parts are appended only when present, separators keep positions distinct
id = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("t_".into()), Value::Str(format!("{}", timestamp).into())).into()), Value::Str("_".into())).into());
if (side != Value::Null) {
id = Value::Str(format!("{}{}", id, side).into());
}
id = Value::Str(format!("{}{}", id, Value::Str("_".into())).into());
if (price != Value::Null) {
id = Value::Str(format!("{}{}", id, price).into());
}
id = Value::Str(format!("{}{}", id, Value::Str("_".into())).into());
if (amount != Value::Null) {
id = Value::Str(format!("{}{}", id, amount).into());
}
}
if (id != Value::Null) && !(matches!((&uniqueResult, &id), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let Value::Dict(__d) = &mut uniqueResult { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&id), entry); }
}
}
}
let mut values: Value = Value::Array(uniqueResult.as_map().map(|__m| __m.values().cloned().collect()).unwrap_or_default());
return values;
Value::Null
}
fn remove_keys_from_dict(&self, mut dict: Value, mut removeKeys: Value) -> Value {
let mut keys: Value = object_keys(&dict);
let mut newDict: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_166: bool = true;
while { if !__for_first_166 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_166 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if !(self.in_array(key.clone(), removeKeys.clone()).as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut newDict { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&key), dict.as_map().and_then(|__m| key.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null)); }
}
}
}
return newDict;
Value::Null
}
fn handle_until_option(&self, mut key: Value, mut request: Value, mut params: Value, optional_args: &[Value]) -> Value {
let mut multiplier = get_arg(optional_args, 0, Value::Int(1));
let mut until: Value = self.safe_integer2(params.clone(), Value::Str("until".into()), Value::Str("till".into()), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&key), self.parse_to_int((match (&(until), &(multiplier)) { (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 paramsOmitted: Value = (if (until != Value::Null) { self.omit(params.clone(), Value::from(vec![Value::Str("until".into()), Value::Str("till".into())]), &[]) } else { params });
return Value::from(vec![request, paramsOmitted]);
Value::Null
}
fn safe_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut symbol: Value = self.safe_string_k(interest.clone(), "symbol", &[]);
if (symbol == Value::Null) {
symbol = self.safe_string_k(market, "symbol", &[]);
}
return self.extend(interest.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("baseVolume".to_string(), self.safe_number_k(interest.clone(), "baseVolume", &[]));
m.insert("quoteVolume".to_string(), self.safe_number_k(interest.clone(), "quoteVolume", &[]));
m.insert("openInterestAmount".to_string(), self.safe_number_k(interest.clone(), "openInterestAmount", &[]));
m.insert("openInterestValue".to_string(), self.safe_number_k(interest.clone(), "openInterestValue", &[]));
m.insert("timestamp".to_string(), self.safe_integer_k(interest.clone(), "timestamp", &[]));
m.insert("datetime".to_string(), self.safe_string_k(interest.clone(), "datetime", &[]));
m.insert("info".to_string(), self.safe_value_k(interest, "info", &[]));
m
})]);
Value::Null
}
fn parse_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_liquidation(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_liquidation(self, liquidation, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseLiquidation () is not supported yet".into()))));
Value::Null
}
fn parse_liquidations(&self, mut liquidations: Value, optional_args: &[Value]) -> Value {
let mut market = 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);
/*
* @ignore
* @method
* @description parses liquidation info from the exchange response
* @param {object[]} liquidations each item describes an instance of a liquidation event
* @param {object} market ccxt market
* @param {int} [since] when defined, the response items are filtered to only include items after this timestamp
* @param {int} [limit] limits the number of items in the response
* @returns {object[]} an array of [liquidation structures]{@link https://docs.ccxt.com/?id=liquidation-structure}
*/
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_167: bool = true;
while { if !__for_first_167 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_167 = false; i.as_f64().unwrap_or(f64::NAN) < ((liquidations.len() as i64) as f64) } {
let mut entry: Value = liquidations.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_liquidation(self, entry, &[market.clone()]);
result.push(parsed);
}
}
let mut sorted: Value = self.sort_by(Value::from(result), Value::Str("timestamp".into()), &[]);
let mut symbol: Value = self.safe_string_k(market, "symbol", &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
fn parse_greeks(&self, mut greeks: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_greeks(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_greeks(self, greeks, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseGreeks () is not supported yet".into()))));
Value::Null
}
fn parse_all_greeks(&self, mut greeks: Value, 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
}));
//
// the value of greeks is either a dict or a list
//
let mut results: Vec<Value> = Vec::new();
if (matches!(&greeks, Value::Arr(_))) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_168: bool = true;
while { if !__for_first_168 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_168 = false; i.as_f64().unwrap_or(f64::NAN) < ((greeks.len() as i64) as f64) } {
let mut parsedTicker: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_greeks(self, greeks.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]);
let mut greek: Value = self.extend(parsedTicker, &[params.clone()]);
results.push(greek.clone());
}
}
} else {
let mut marketIds: Value = object_keys(&greeks);
{
let mut i: Value = Value::Int(0);
let mut __for_first_169: bool = true;
while { if !__for_first_169 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_169 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketIds.len() as i64) as f64) } {
let mut marketId: Value = marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut parsed: Value = <Self as crate::exchange_generated::ExchangeBase>::parse_greeks(self, get_value(&greeks, &marketId), &[market]);
let mut greek: Value = self.extend(parsed, &[params.clone()]);
results.push(greek);
}
}
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
return self.index_by(self.filter_by_array(Value::from(results), Value::Str("symbol".into()), &[symbolsNormalized, Value::Bool(false)]), Value::Str("symbol".into()));
Value::Null
}
fn parse_option(&self, mut chain: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut market = get_arg(optional_args, 1, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseOption () is not supported yet".into()))));
Value::Null
}
fn parse_option_chain(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut currencyKey = get_arg(optional_args, 0, Value::Null);
let mut symbolKey = get_arg(optional_args, 1, Value::Null);
let mut optionStructures: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_170: bool = true;
while { if !__for_first_170 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_170 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut info: Value = response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut currencyId: Value = (if (currencyKey == Value::Null) { Value::Null } else { self.safe_string(info.clone(), currencyKey.clone(), &[]) });
let mut currency: Value = self.safe_currency(currencyId, &[]);
let mut marketId: Value = (if (symbolKey == Value::Null) { Value::Null } else { self.safe_string(info.clone(), symbolKey.clone(), &[]) });
let mut market: Value = self.safe_market(&[marketId, Value::Null, Value::Null, Value::Str("option".into())]);
add_element_to_object(&mut optionStructures, &market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), self.parse_option(info, &[currency, market.clone()]));
}
}
return optionStructures;
Value::Null
}
fn parse_margin_modes(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut symbolKey = get_arg(optional_args, 1, Value::Null);
let mut marketType = get_arg(optional_args, 2, Value::Null);
let mut marginModeStructures: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut marketTypeResolved: Value = (if (marketType == Value::Null) { Value::Str("swap".into()) } else { marketType }); // default to swap
{
let mut i: Value = Value::Int(0);
let mut __for_first_171: bool = true;
while { if !__for_first_171 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_171 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut info: Value = response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = (if (symbolKey == Value::Null) { Value::Null } else { self.safe_string(info.clone(), symbolKey.clone(), &[]) });
let mut market: Value = self.safe_market(&[marketId, Value::Null, Value::Null, marketTypeResolved.clone()]);
if (symbols == Value::Null) || self.in_array(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), symbols.clone()).as_bool() == Some(true) {
add_element_to_object(&mut marginModeStructures, &market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), <Self as crate::exchange_generated::ExchangeBase>::parse_margin_mode(self, info, &[market.clone()]));
}
}
}
return marginModeStructures;
Value::Null
}
fn parse_margin_mode(&self, mut marginMode: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_margin_mode(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_margin_mode(self, marginMode, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseMarginMode () is not supported yet".into()))));
Value::Null
}
fn parse_leverages(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut symbolKey = get_arg(optional_args, 1, Value::Null);
let mut marketType = get_arg(optional_args, 2, Value::Null);
let mut leverageStructures: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut marketTypeResolved: Value = (if (marketType == Value::Null) { Value::Str("swap".into()) } else { marketType }); // default to swap
{
let mut i: Value = Value::Int(0);
let mut __for_first_172: bool = true;
while { if !__for_first_172 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_172 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut info: Value = response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = (if (symbolKey == Value::Null) { Value::Null } else { self.safe_string(info.clone(), symbolKey.clone(), &[]) });
let mut market: Value = self.safe_market(&[marketId, Value::Null, Value::Null, marketTypeResolved.clone()]);
if (symbols == Value::Null) || self.in_array(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), symbols.clone()).as_bool() == Some(true) {
add_element_to_object(&mut leverageStructures, &market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), <Self as crate::exchange_generated::ExchangeBase>::parse_leverage(self, info, &[market.clone()]));
}
}
}
return leverageStructures;
Value::Null
}
fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_leverage(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_leverage(self, leverage, crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseLeverage () is not supported yet".into()))));
Value::Null
}
fn parse_conversions(&self, mut conversions: Value, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut fromCurrencyKey = get_arg(optional_args, 1, Value::Null);
let mut toCurrencyKey = get_arg(optional_args, 2, Value::Null);
let mut since = get_arg(optional_args, 3, Value::Null);
let mut limit = get_arg(optional_args, 4, Value::Null);
let mut params = get_arg(optional_args, 5, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut conversionsArray: Value = self.to_array(conversions);
let mut result: Vec<Value> = Vec::new();
let mut fromCurrency: Value = Value::Null;
let mut toCurrency: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_173: bool = true;
while { if !__for_first_173 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_173 = false; i.as_f64().unwrap_or(f64::NAN) < ((conversionsArray.len() as i64) as f64) } {
let mut entry: Value = conversionsArray.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut fromId: Value = (if (fromCurrencyKey == Value::Null) { Value::Null } else { self.safe_string(entry.clone(), fromCurrencyKey.clone(), &[]) });
let mut toId: Value = (if (toCurrencyKey == Value::Null) { Value::Null } else { self.safe_string(entry.clone(), toCurrencyKey.clone(), &[]) });
if (fromId != Value::Null) {
fromCurrency = self.safe_currency(fromId, &[]);
}
if (toId != Value::Null) {
toCurrency = self.safe_currency(toId, &[]);
}
let mut conversion: Value = self.extend(<Self as crate::exchange_generated::ExchangeBase>::parse_conversion(self, entry, &[fromCurrency.clone(), toCurrency.clone()]), &[params.clone()]);
result.push(conversion);
}
}
let mut sorted: Value = self.sort_by(Value::from(result), Value::Str("timestamp".into()), &[]);
if (code == Value::Null) {
return self.filter_by_since_limit(sorted.clone(), &[since.clone(), limit.clone()]);
}
let mut currency: Value = self.safe_currency(code, &[]);
if (currency == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" parseConversions() could not resolve currency".into()))));
}
let mut currencyCode: Value = currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null);
let mut fromConversion: Value = self.filter_by(sorted.clone(), Value::Str("fromCurrency".into()), currencyCode.clone(), &[]);
let mut toConversion: Value = self.filter_by(sorted, Value::Str("toCurrency".into()), currencyCode, &[]);
let mut both: Value = self.array_concat(fromConversion, toConversion);
return self.filter_by_since_limit(both, &[since, limit]);
Value::Null
}
fn parse_conversion(&self, mut conversion: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_conversion(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_conversion(self, conversion.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null), crate::runtime::get_arg(optional_args, 1, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut fromCurrency = get_arg(optional_args, 0, Value::Null);
let mut toCurrency = get_arg(optional_args, 1, Value::Null);
if (conversion == Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseConversion () is not supported yet".into()))));
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseConversion () is not supported yet".into()))));
Value::Null
}
fn convert_expire_date(&self, mut date: Value) -> Value {
if (date == Value::Null) {
return Value::Null;
}
// parse YYMMDD to datetime string
let mut year: Value = date.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(0); let __j = __l.min(2); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut month: Value = date.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(2); let __j = __l.min(4); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut day: Value = date.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(4); let __j = __l.min(6); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
// the milliseconds are spelled out because every caller writes the result into
// expiryDatetime, which types.ts documents in the ISO 8601 form with them
let mut reconstructedDate: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("20".into()), year).into()), Value::Str("-".into())).into()), month).into()), Value::Str("-".into())).into()), day).into()), Value::Str("T00:00:00.000Z".into())).into());
return reconstructedDate;
Value::Null
}
fn convert_expire_date_to_market_id_date(&self, mut date: Value) -> Value {
if (date == Value::Null) {
return Value::Null;
}
// parse 240119 to 19JAN24
let mut year: Value = date.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(0); let __j = __l.min(2); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut monthRaw: Value = date.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(2); let __j = __l.min(4); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut month: Value = Value::Null;
let mut day: Value = date.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(4); let __j = __l.min(6); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
if (monthRaw.as_str() == Some("01")) {
month = Value::Str("JAN".into());
} else if (monthRaw.as_str() == Some("02")) {
month = Value::Str("FEB".into());
} else if (monthRaw.as_str() == Some("03")) {
month = Value::Str("MAR".into());
} else if (monthRaw.as_str() == Some("04")) {
month = Value::Str("APR".into());
} else if (monthRaw.as_str() == Some("05")) {
month = Value::Str("MAY".into());
} else if (monthRaw.as_str() == Some("06")) {
month = Value::Str("JUN".into());
} else if (monthRaw.as_str() == Some("07")) {
month = Value::Str("JUL".into());
} else if (monthRaw.as_str() == Some("08")) {
month = Value::Str("AUG".into());
} else if (monthRaw.as_str() == Some("09")) {
month = Value::Str("SEP".into());
} else if (monthRaw.as_str() == Some("10")) {
month = Value::Str("OCT".into());
} else if (monthRaw.as_str() == Some("11")) {
month = Value::Str("NOV".into());
} else if (monthRaw.as_str() == Some("12")) {
month = Value::Str("DEC".into());
}
if (month == Value::Null) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" invalid expiry date ".into())).into()), date)));
}
let mut reconstructedDate: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", day, month).into()), year).into());
return reconstructedDate;
Value::Null
}
fn convert_market_id_expire_date(&self, mut date: Value) -> Value {
if (date == Value::Null) {
return Value::Null;
}
// parse 03JAN24 to 240103.
let mut monthMappping: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("JAN".to_string(), Value::Str("01".into()));
m.insert("FEB".to_string(), Value::Str("02".into()));
m.insert("MAR".to_string(), Value::Str("03".into()));
m.insert("APR".to_string(), Value::Str("04".into()));
m.insert("MAY".to_string(), Value::Str("05".into()));
m.insert("JUN".to_string(), Value::Str("06".into()));
m.insert("JUL".to_string(), Value::Str("07".into()));
m.insert("AUG".to_string(), Value::Str("08".into()));
m.insert("SEP".to_string(), Value::Str("09".into()));
m.insert("OCT".to_string(), Value::Str("10".into()));
m.insert("NOV".to_string(), Value::Str("11".into()));
m.insert("DEC".to_string(), Value::Str("12".into()));
m
});
// if exchange omits first zero and provides i.e. '3JAN24' instead of '03JAN24'
let mut datePadded: Value = date.clone();
if (Value::Int(date.len() as i64).as_f64() == Some(6.0)) {
datePadded = Value::Str(format!("{}{}", Value::Str("0".into()), date).into());
}
let mut year: Value = datePadded.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(0); let __j = __l.min(2); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut monthName: Value = datePadded.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(2); let __j = __l.min(5); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut month: Value = self.safe_string(monthMappping, monthName, &[]);
let mut day: Value = datePadded.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(5); let __j = __l.min(7); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
if (month == Value::Null) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" invalid expiry date ".into())).into()), date)));
}
let mut reconstructedDate: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", day, month).into()), year).into());
return reconstructedDate;
Value::Null
}
fn load_markets_and_sign_in(&mut self) -> impl ::std::future::Future<Output = Value> + Send { async move {
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.sign_in(&[]).await])).await;
Value::Null
} }
fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_margin_modification(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_margin_modification(self, data.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
if (data == Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseMarginModification() is not supported yet".into()))));
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" parseMarginModification() is not supported yet".into()))));
Value::Null
}
fn parse_margin_modifications(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut symbolKey = get_arg(optional_args, 1, Value::Null);
let mut marketType = get_arg(optional_args, 2, Value::Null);
let mut marginModifications: Vec<Value> = Vec::new();
if (response == Value::Null) {
return Value::from(marginModifications);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_174: bool = true;
while { if !__for_first_174 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_174 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut info: Value = response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = (if (symbolKey == Value::Null) { Value::Null } else { self.safe_string(info.clone(), symbolKey.clone(), &[]) });
let mut market: Value = self.safe_market(&[marketId, Value::Null, Value::Null, marketType.clone()]);
if (symbols == Value::Null) || self.in_array(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), symbols.clone()).as_bool() == Some(true) {
marginModifications.push(<Self as crate::exchange_generated::ExchangeBase>::parse_margin_modification(self, info, &[market]));
}
}
}
return Value::from(marginModifications);
Value::Null
}
fn fetch_transfer(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTransfer () is not supported yet".into()))));
Value::Null
} }
fn fetch_transfers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTransfers () is not supported yet".into()))));
Value::Null
} }
fn un_watch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchOHLCV () is not supported yet".into()))));
Value::Null
} }
fn withdraw_ws(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" withdrawWs () is not supported yet".into()))));
Value::Null
} }
fn un_watch_my_trades(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchMyTrades () is not supported yet".into()))));
Value::Null
} }
fn fetch_orders_by_status_ws(&mut self, mut status: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrdersByStatusWs () is not supported yet".into()))));
Value::Null
} }
fn un_watch_bids_asks(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" unWatchBidsAsks () is not supported yet".into()))));
Value::Null
} }
fn clean_unsubscription(&self, mut client: Value, mut subHash: Value, mut unsubHash: Value, optional_args: &[Value]) {
let mut subHashIsPrefix = get_arg(optional_args, 0, Value::Bool(false));
if (unsubHash != Value::Null) && (in_op(&get_value(&client, &Value::Str("subscriptions".into())), &unsubHash)) {
remove(&mut get_value(&client, &Value::Str("subscriptions".into())), &unsubHash);
}
if !is_true(&subHashIsPrefix) {
if (subHash != Value::Null) && (in_op(&get_value(&client, &Value::Str("subscriptions".into())), &subHash)) {
remove(&mut get_value(&client, &Value::Str("subscriptions".into())), &subHash);
}
if (subHash != Value::Null) && (in_op(&get_value(&client, &Value::Str("futures".into())), &subHash)) {
let mut error = crate::exchange_errors::unsubscribe_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), subHash));
client.reject(&[Value::from(error.clone()), subHash.clone()]);
}
} else {
let mut clientSubscriptions: Value = object_keys(&get_value(&client, &Value::Str("subscriptions".into())));
{
let mut i: Value = Value::Int(0);
let mut __for_first_175: bool = true;
while { if !__for_first_175 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_175 = false; i.as_f64().unwrap_or(f64::NAN) < ((clientSubscriptions.len() as i64) as f64) } {
let mut sub: Value = clientSubscriptions.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (sub != Value::Null) && (subHash != Value::Null) && (sub.as_str().zip(subHash.as_str()).is_some_and(|(__s, __p)| __s.starts_with(__p))) {
remove(&mut get_value(&client, &Value::Str("subscriptions".into())), &sub);
}
}
}
let mut clientFutures: Value = object_keys(&get_value(&client, &Value::Str("futures".into())));
{
let mut i: Value = Value::Int(0);
let mut __for_first_176: bool = true;
while { if !__for_first_176 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_176 = false; i.as_f64().unwrap_or(f64::NAN) < ((clientFutures.len() as i64) as f64) } {
let mut future: Value = clientFutures.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (future != Value::Null) && (subHash != Value::Null) && (future.as_str().zip(subHash.as_str()).is_some_and(|(__s, __p)| __s.starts_with(__p))) {
let mut error = crate::exchange_errors::unsubscribe_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), future));
client.reject(&[Value::from(error), future]);
}
}
}
}
client.resolve(&[Value::Bool(true), unsubHash]);
}
fn clean_cache(&mut self, mut subscription: Value) {
let __subscription_empty = indexmap::IndexMap::new();
let subscription = subscription.as_map().unwrap_or(&__subscription_empty);
let mut topic: Option<String> = (match subscription.get("topic") { 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);
let mut symbols: Value = (match subscription.get("symbols") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::from(vec![]) });
let mut symbolsLength: f64 = ((symbols.len() as i64) as f64);
if (topic.as_deref() == Some("ohlcv")) {
let mut symbolsAndTimeframes: Value = (match subscription.get("symbolsAndTimeframes") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::from(vec![]) });
{
let mut i: Value = Value::Int(0);
let mut __for_first_177: bool = true;
while { if !__for_first_177 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_177 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbolsAndTimeframes.len() as i64) as f64) } {
let mut symbolAndTimeFrame: Value = get_value(&symbolsAndTimeframes, &i);
let mut symbolAndTimeFrame: Value = get_value(&symbolsAndTimeframes, &i);
let mut symbol: Value = self.safe_string(symbolAndTimeFrame.clone(), Value::Int(0), &[]);
let mut timeframe: Value = self.safe_string(symbolAndTimeFrame, Value::Int(1), &[]);
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cleanCache() requires a symbol argument".into()))));
}
if (timeframe == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cleanCache() requires a timeframe argument".into()))));
}
if (self.ohlcvs.clone() != Value::Null) && (matches!((&self.ohlcvs, &symbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if (in_op(&self.ohlcvs.as_map().and_then(|__m| symbol.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), &timeframe)) {
remove(&mut get_value(&self.ohlcvs, &symbol), &timeframe);
}
}
}
}
} else if symbolsLength > ((0i64) as f64) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_178: bool = true;
while { if !__for_first_178 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_178 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbols.len() as i64) as f64) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
if (topic.as_deref() == Some("trades")) {
if (matches!((&self.trades, &symbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let (Value::Dict(__d), Value::Str(__k)) = (&mut self.trades.clone(), &symbol) { std::sync::Arc::make_mut(__d).shift_remove(__k.as_ref()); }
}
} else if (topic.as_deref() == Some("orderbook")) {
if (matches!((&self.orderbooks, &symbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let (Value::Dict(__d), Value::Str(__k)) = (&mut self.orderbooks.clone(), &symbol) { std::sync::Arc::make_mut(__d).shift_remove(__k.as_ref()); }
}
} else if (topic.as_deref() == Some("ticker")) {
if (matches!((&self.tickers, &symbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let (Value::Dict(__d), Value::Str(__k)) = (&mut self.tickers.clone(), &symbol) { std::sync::Arc::make_mut(__d).shift_remove(__k.as_ref()); }
}
} else if (topic.as_deref() == Some("bidsasks")) {
if (matches!((&self.bidsasks, &symbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let (Value::Dict(__d), Value::Str(__k)) = (&mut self.bidsasks.clone(), &symbol) { std::sync::Arc::make_mut(__d).shift_remove(__k.as_ref()); }
}
}
}
}
} else {
if (topic.as_deref() == Some("myTrades")) && (self.myTrades.clone() != Value::Null) {
self.myTrades = Value::Null;
} else if (topic.as_deref() == Some("orders")) && (self.orders.clone() != Value::Null) {
self.orders = Value::Null;
} else if (topic.as_deref() == Some("positions")) && (self.positions.clone() != Value::Null) {
self.positions = Value::Null;
let mut clients: Value = Value::Array(self.clients.as_map().map(|__m| __m.values().cloned().collect()).unwrap_or_default());
{
let mut i: Value = Value::Int(0);
let mut __for_first_179: bool = true;
while { if !__for_first_179 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_179 = false; i.as_f64().unwrap_or(f64::NAN) < ((clients.len() as i64) as f64) } {
let mut client: Value = clients.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut futures: Value = get_value(&client, &Value::Str("futures".into()));
if (futures != Value::Null) && (matches!(&futures, Value::Dict(__d) if __d.contains_key("fetchPositionsSnapshot"))) {
remove(&mut futures, &Value::Str("fetchPositionsSnapshot".into()));
}
}
}
} else if ((topic.as_deref() == Some("ticker")) || (topic.as_deref() == Some("markPrice"))) && (self.tickers.clone() != Value::Null) {
let mut tickerSymbols: Value = Value::Array(self.tickers.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
{
let mut i: Value = Value::Int(0);
let mut __for_first_180: bool = true;
while { if !__for_first_180 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_180 = false; i.as_f64().unwrap_or(f64::NAN) < ((tickerSymbols.len() as i64) as f64) } {
let mut tickerSymbol: Value = tickerSymbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (matches!((&self.tickers, &tickerSymbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let (Value::Dict(__d), Value::Str(__k)) = (&mut self.tickers.clone(), &tickerSymbol) { std::sync::Arc::make_mut(__d).shift_remove(__k.as_ref()); }
}
}
}
} else if (topic.as_deref() == Some("bidsasks")) && (self.bidsasks.clone() != Value::Null) {
let mut bidsaskSymbols: Value = Value::Array(self.bidsasks.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
{
let mut i: Value = Value::Int(0);
let mut __for_first_181: bool = true;
while { if !__for_first_181 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_181 = false; i.as_f64().unwrap_or(f64::NAN) < ((bidsaskSymbols.len() as i64) as f64) } {
let mut bidsaskSymbol: Value = bidsaskSymbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (matches!((&self.bidsasks, &bidsaskSymbol), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
if let (Value::Dict(__d), Value::Str(__k)) = (&mut self.bidsasks.clone(), &bidsaskSymbol) { std::sync::Arc::make_mut(__d).shift_remove(__k.as_ref()); }
}
}
}
}
}
}
fn timeframe_from_milliseconds(&self, mut ms: Value) -> Value {
let mut msInt: Value = self.parse_to_int(ms);
if msInt.as_f64().unwrap_or(f64::NAN) <= ((0i64) as f64) {
return Value::Str("".into());
}
let mut second: Value = Value::Int(1000);
let mut minute: Value = (match (&(Value::Int(60)), &(second)) { (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 hour: Value = (match (&(Value::Int(60)), &(minute)) { (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 day: Value = (match (&(Value::Int(24)), &(hour)) { (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 week: Value = (match (&(Value::Int(7)), &(day)) { (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 ((match (&(msInt), &(week)) { (Value::Int(x), Value::Int(y)) if *y != 0 => Value::Int(x % y), (Value::Int(x), Value::Float(y)) if *y != 0.0 => Value::Float(*x as f64 % *y), (Value::Float(x), Value::Int(y)) if *y != 0 => Value::Float(*x % *y as f64), (Value::Float(x), Value::Float(y)) if *y != 0.0 => Value::Float(x % y), _ => Value::Null }).as_f64() == Some(0.0)) {
return Value::Str(format!("{}{}", Value::Str(format!("{}", self.parse_to_int((match ((msInt).as_f64(), (week).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))).into()), Value::Str("w".into())).into());
}
if ((match (&(msInt), &(day)) { (Value::Int(x), Value::Int(y)) if *y != 0 => Value::Int(x % y), (Value::Int(x), Value::Float(y)) if *y != 0.0 => Value::Float(*x as f64 % *y), (Value::Float(x), Value::Int(y)) if *y != 0 => Value::Float(*x % *y as f64), (Value::Float(x), Value::Float(y)) if *y != 0.0 => Value::Float(x % y), _ => Value::Null }).as_f64() == Some(0.0)) {
return Value::Str(format!("{}{}", Value::Str(format!("{}", self.parse_to_int((match ((msInt).as_f64(), (day).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))).into()), Value::Str("d".into())).into());
}
if ((match (&(msInt), &(hour)) { (Value::Int(x), Value::Int(y)) if *y != 0 => Value::Int(x % y), (Value::Int(x), Value::Float(y)) if *y != 0.0 => Value::Float(*x as f64 % *y), (Value::Float(x), Value::Int(y)) if *y != 0 => Value::Float(*x % *y as f64), (Value::Float(x), Value::Float(y)) if *y != 0.0 => Value::Float(x % y), _ => Value::Null }).as_f64() == Some(0.0)) {
return Value::Str(format!("{}{}", Value::Str(format!("{}", self.parse_to_int((match ((msInt).as_f64(), (hour).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))).into()), Value::Str("h".into())).into());
}
if ((match (&(msInt), &(minute)) { (Value::Int(x), Value::Int(y)) if *y != 0 => Value::Int(x % y), (Value::Int(x), Value::Float(y)) if *y != 0.0 => Value::Float(*x as f64 % *y), (Value::Float(x), Value::Int(y)) if *y != 0 => Value::Float(*x % *y as f64), (Value::Float(x), Value::Float(y)) if *y != 0.0 => Value::Float(x % y), _ => Value::Null }).as_f64() == Some(0.0)) {
return Value::Str(format!("{}{}", Value::Str(format!("{}", self.parse_to_int((match ((msInt).as_f64(), (minute).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))).into()), Value::Str("m".into())).into());
}
if ((match (&(msInt), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) if *y != 0 => Value::Int(x % y), (Value::Int(x), Value::Float(y)) if *y != 0.0 => Value::Float(*x as f64 % *y), (Value::Float(x), Value::Int(y)) if *y != 0 => Value::Float(*x % *y as f64), (Value::Float(x), Value::Float(y)) if *y != 0.0 => Value::Float(x % y), _ => Value::Null }).as_f64() == Some(0.0)) {
return Value::Str(format!("{}{}", Value::Str(format!("{}", self.parse_to_int((match ((msInt).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))).into()), Value::Str("s".into())).into());
}
return Value::Str("".into());
Value::Null
}
fn is_uta_enabled(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return Value::Bool(false);
Value::Null
} }
fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" closePosition() is not supported yet".into()))));
Value::Null
} }
fn close_all_positions(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" closeAllPositions() is not supported yet".into()))));
Value::Null
} }
fn edit_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" editOrders() is not supported yet".into()))));
Value::Null
} }
fn fetch_canceled_and_closed_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchCanceledAndClosedOrders() is not supported yet".into()))));
Value::Null
} }
fn fetch_position_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_position_history", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
/*
* @method
* @name exchange#fetchPositionHistory
* @description fetches the history of margin added or reduced from contract isolated positions
* @param {string} [symbol] unified market symbol
* @param {int} [since] timestamp in ms of the position
* @param {int} [limit] the maximum amount of candles to fetch, default=1000
* @param {object} params extra parameters specific to the exchange api endpoint
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
if (self.has.as_map().and_then(|__m| __m.get("fetchPositionsHistory")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchPositionsHistory")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.fetch_positions_history(&[Value::from(vec![symbol]), since, limit, params]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionHistory () is not supported yet".into()))));
}
} }
fn fetch_positions_history(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_positions_history", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsHistory () is not supported yet".into()))));
Value::Null
} }
fn fetch_positions_risk(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsRisk() is not supported yet".into()))));
Value::Null
} }
fn fetch_positions_for_symbol(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsForSymbol() is not supported yet".into()))));
Value::Null
} }
fn fetch_positions_for_symbol_ws(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsForSymbol() is not supported yet".into()))));
Value::Null
} }
fn watch_position(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchPosition() is not supported yet".into()))));
Value::Null
} }
fn watch_my_trades_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchMyTradesForSymbols() is not supported yet".into()))));
Value::Null
} }
fn watch_trades_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchTradesForSymbols() is not supported yet".into()))));
Value::Null
} }
fn fetch_bids_asks(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchBidsAsks() is not supported yet".into()))));
Value::Null
} }
fn fetch_mark_price(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchMarkPrices")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchMarkPrices")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
self.load_markets(&[]).await;
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut symbolResolved: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut tickers: Value = self.fetch_mark_prices(&[Value::from(vec![symbolResolved.clone()]), params]).await;
let mut ticker: Value = self.safe_dict(tickers, symbolResolved.clone(), &[]);
if (ticker == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchMarkPrices() could not find a ticker for ".into())).into()), symbolResolved)));
} else {
return ticker;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMarkPrices() is not supported yet".into()))));
}
Value::Null
} }
fn fetch_mark_prices(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMarkPrices() is not supported yet".into()))));
Value::Null
} }
fn watch_bids_asks(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchBidsAsks() is not supported yet".into()))));
Value::Null
} }
fn watch_mark_price(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchMarkPrice () is not supported yet".into()))));
Value::Null
} }
fn watch_mark_prices(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchMarkPrices () is not supported yet".into()))));
Value::Null
} }
fn fetch_l3_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchL3OrderBook() is not supported yet".into()))));
Value::Null
} }
fn watch_order_book_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchOrderBookForSymbols() is not supported yet".into()))));
Value::Null
} }
fn watch_orders_for_symbols(&mut self, mut symbols: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchOrdersForSymbols() is not supported yet".into()))));
Value::Null
} }
fn cancel_all_orders_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrdersWs() is not supported yet".into()))));
Value::Null
} }
fn cancel_order_ws(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrderWs() is not supported yet".into()))));
Value::Null
} }
fn cancel_orders_ws(&mut self, mut ids: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrdersWs() is not supported yet".into()))));
Value::Null
} }
fn create_limit_buy_order_ws(&mut self, mut symbol: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order_ws(symbol, Value::Str("limit".into()), Value::Str("buy".into()), amount, &[price, params]).await;
Value::Null
} }
fn create_limit_order_ws(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order_ws(symbol, Value::Str("limit".into()), side, amount, &[price, params]).await;
Value::Null
} }
fn create_limit_sell_order_ws(&mut self, mut symbol: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order_ws(symbol, Value::Str("limit".into()), Value::Str("sell".into()), amount, &[price, params]).await;
Value::Null
} }
fn create_market_buy_order_ws(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order_ws(symbol, Value::Str("market".into()), Value::Str("buy".into()), amount, &[Value::Null, params]).await;
Value::Null
} }
fn create_market_order_with_cost_ws(&mut self, mut symbol: Value, mut side: Value, mut cost: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createMarketOrderWithCostWs
* @description create a market order by providing the symbol, side and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} side 'buy' or 'sell'
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if ((self.has.as_map().and_then(|__m| __m.get("createMarketOrderWithCostWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketOrderWithCostWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) || (((self.has.as_map().and_then(|__m| __m.get("createMarketBuyOrderWithCostWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketBuyOrderWithCostWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) && ((self.has.as_map().and_then(|__m| __m.get("createMarketSellOrderWithCostWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketSellOrderWithCostWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)))) {
return self.create_order_ws(symbol, Value::Str("market".into()), side, cost, &[Value::Int(1), params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketOrderWithCostWs() is not supported yet".into()))));
Value::Null
} }
fn create_market_order_ws(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
return self.create_order_ws(symbol, Value::Str("market".into()), side, amount, &[price, params]).await;
Value::Null
} }
fn create_market_sell_order_ws(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order_ws(symbol, Value::Str("market".into()), Value::Str("sell".into()), amount, &[Value::Null, params]).await;
Value::Null
} }
fn create_order_with_take_profit_and_stop_loss_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut takeProfit = get_arg(optional_args, 1, Value::Null);
let mut stopLoss = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createOrderWithTakeProfitAndStopLossWs
* @description create an order with a stop loss or take profit attached (type 3)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} [takeProfit] the take profit price, in units of the quote currency
* @param {float} [stopLoss] the stop loss price, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.takeProfitType] *not available on all exchanges* 'limit' or 'market'
* @param {string} [params.stopLossType] *not available on all exchanges* 'limit' or 'market'
* @param {string} [params.takeProfitPriceType] *not available on all exchanges* 'last', 'mark' or 'index'
* @param {string} [params.stopLossPriceType] *not available on all exchanges* 'last', 'mark' or 'index'
* @param {float} [params.takeProfitLimitPrice] *not available on all exchanges* limit price for a limit take profit order
* @param {float} [params.stopLossLimitPrice] *not available on all exchanges* stop loss for a limit stop loss order
* @param {float} [params.takeProfitAmount] *not available on all exchanges* the amount for a take profit
* @param {float} [params.stopLossAmount] *not available on all exchanges* the amount for a stop loss
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
let mut paramsValue: Value = self.set_take_profit_and_stop_loss_params(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), takeProfit.clone(), stopLoss.clone(), params.clone()]);
if (self.has.as_map().and_then(|__m| __m.get("createOrderWithTakeProfitAndStopLossWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createOrderWithTakeProfitAndStopLossWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order_ws(symbol, type_var, side, amount, &[price, paramsValue]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrderWithTakeProfitAndStopLossWs() is not supported yet".into()))));
Value::Null
} }
fn create_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrderWs() is not supported yet".into()))));
Value::Null
} }
fn create_orders_ws(&mut self, mut orders: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrdersWs () is not supported yet".into()))));
Value::Null
} }
fn create_post_only_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("createPostOnlyOrderWs")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createPostOnlyOrderWs")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createPostOnlyOrderWs() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("postOnly".to_string(), Value::Bool(true));
m
})]);
return self.create_order_ws(symbol, type_var, side, amount, &[price, query]).await;
Value::Null
} }
fn create_reduce_only_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("createReduceOnlyOrderWs")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createReduceOnlyOrderWs")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createReduceOnlyOrderWs() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("reduceOnly".to_string(), Value::Bool(true));
m
})]);
return self.create_order_ws(symbol, type_var, side, amount, &[price, query]).await;
Value::Null
} }
fn create_stop_limit_order_ws(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, mut price: Value, mut triggerPrice: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("createStopLimitOrderWs")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createStopLimitOrderWs")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopLimitOrderWs() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), triggerPrice);
m
})]);
return self.create_order_ws(symbol, Value::Str("limit".into()), side, amount, &[price, query]).await;
Value::Null
} }
fn create_stop_loss_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut stopLossPrice = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createStopLossOrderWs
* @description create a trigger stop loss order (type 2)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} stopLossPrice the price to trigger the stop loss order, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (stopLossPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createStopLossOrderWs() requires a stopLossPrice argument".into()))));
}
let mut paramsExtended: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopLossPrice".to_string(), stopLossPrice);
m
})]);
if (self.has.as_map().and_then(|__m| __m.get("createStopLossOrderWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createStopLossOrderWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order_ws(symbol, type_var, side, amount, &[price, paramsExtended]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopLossOrderWs() is not supported yet".into()))));
Value::Null
} }
fn create_stop_market_order_ws(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, mut triggerPrice: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("createStopMarketOrderWs")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createStopMarketOrderWs")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopMarketOrderWs() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), triggerPrice);
m
})]);
return self.create_order_ws(symbol, Value::Str("market".into()), side, amount, &[Value::Null, query]).await;
Value::Null
} }
fn create_stop_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut triggerPrice = 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.has.as_map().and_then(|__m| __m.get("createStopOrderWs")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createStopOrderWs")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopOrderWs() is not supported yet".into()))));
}
if (triggerPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createStopOrderWs() requires a stopPrice argument".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), triggerPrice);
m
})]);
return self.create_order_ws(symbol, type_var, side, amount, &[price, query]).await;
Value::Null
} }
fn create_take_profit_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut takeProfitPrice = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTakeProfitOrderWs
* @description create a trigger take profit order (type 2)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} takeProfitPrice the price to trigger the take profit order, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (takeProfitPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTakeProfitOrderWs() requires a takeProfitPrice argument".into()))));
}
let mut paramsExtended: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("takeProfitPrice".to_string(), takeProfitPrice);
m
})]);
if (self.has.as_map().and_then(|__m| __m.get("createTakeProfitOrderWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTakeProfitOrderWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order_ws(symbol, type_var, side, amount, &[price, paramsExtended]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTakeProfitOrderWs() is not supported yet".into()))));
Value::Null
} }
fn create_trailing_amount_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut trailingAmount = get_arg(optional_args, 1, Value::Null);
let mut trailingTriggerPrice = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTrailingAmountOrderWs
* @description create a trailing order by providing the symbol, type, side, amount, price and trailingAmount
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency, or number of contracts
* @param {float} [price] the price for the order to be filled at, in units of the quote currency, ignored in market orders
* @param {float} trailingAmount the quote amount to trail away from the current market price
* @param {float} [trailingTriggerPrice] the price to activate a trailing order, default uses the price argument
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (trailingAmount == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTrailingAmountOrderWs() requires a trailingAmount argument".into()))));
}
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingAmount".into(), trailingAmount); }
if (trailingTriggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingTriggerPrice".into(), trailingTriggerPrice); }
}
if (self.has.as_map().and_then(|__m| __m.get("createTrailingAmountOrderWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTrailingAmountOrderWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order_ws(symbol, type_var, side, amount, &[price, params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTrailingAmountOrderWs() is not supported yet".into()))));
Value::Null
} }
fn create_trailing_percent_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut trailingPercent = get_arg(optional_args, 1, Value::Null);
let mut trailingTriggerPrice = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTrailingPercentOrderWs
* @description create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency, or number of contracts
* @param {float} [price] the price for the order to be filled at, in units of the quote currency, ignored in market orders
* @param {float} trailingPercent the percent to trail away from the current market price
* @param {float} [trailingTriggerPrice] the price to activate a trailing order, default uses the price argument
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (trailingPercent == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTrailingPercentOrderWs() requires a trailingPercent argument".into()))));
}
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingPercent".into(), trailingPercent); }
if (trailingTriggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingTriggerPrice".into(), trailingTriggerPrice); }
}
if (self.has.as_map().and_then(|__m| __m.get("createTrailingPercentOrderWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTrailingPercentOrderWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order_ws(symbol, type_var, side, amount, &[price, params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTrailingPercentOrderWs() is not supported yet".into()))));
Value::Null
} }
fn create_trigger_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut triggerPrice = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTriggerOrderWs
* @description create a trigger stop order (type 1)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} triggerPrice the price to trigger the stop order, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (triggerPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTriggerOrderWs() requires a triggerPrice argument".into()))));
}
let mut paramsExtended: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPrice".to_string(), triggerPrice);
m
})]);
if (self.has.as_map().and_then(|__m| __m.get("createTriggerOrderWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTriggerOrderWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order_ws(symbol, type_var, side, amount, &[price, paramsExtended]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTriggerOrderWs() is not supported yet".into()))));
Value::Null
} }
fn edit_order_ws(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
self.cancel_order_ws(id, &[symbol.clone()]).await;
return self.create_order_ws(symbol, type_var, side, amount, &[price, params]).await;
Value::Null
} }
fn fetch_closed_orders_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("fetchOrdersWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchOrdersWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut orders: Value = self.fetch_orders_ws(&[symbol, since, limit, params]).await;
return self.filter_by(orders, Value::Str("status".into()), Value::Str("closed".into()), &[]);
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchClosedOrdersWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_my_trades_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTradesWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_open_orders_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("fetchOrdersWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchOrdersWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut orders: Value = self.fetch_orders_ws(&[symbol, since, limit, params]).await;
return self.filter_by(orders, Value::Str("status".into()), Value::Str("open".into()), &[]);
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenOrdersWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_order_book_ws(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderBookWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_order_ws(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_orders_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrdersWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_position_ws(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_positions_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositions() is not supported yet".into()))));
Value::Null
} }
fn fetch_ticker_ws(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchTickersWs")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchTickersWs")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
self.load_markets(&[]).await;
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut symbolResolved: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut tickers: Value = self.fetch_tickers_ws(&[Value::from(vec![symbolResolved.clone()]), params]).await;
let mut ticker: Value = self.safe_dict(tickers, symbolResolved.clone(), &[]);
if (ticker == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchTickerWs() could not find a ticker for ".into())).into()), symbolResolved)));
} else {
return ticker;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTickerWs() is not supported yet".into()))));
}
Value::Null
} }
fn fetch_tickers_ws(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTickersWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_trades_ws(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTradesWs() is not supported yet".into()))));
Value::Null
} }
fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_trades", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTrades() is not supported yet".into()))));
Value::Null
} }
fn watch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchTrades() is not supported yet".into()))));
Value::Null
} }
fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_order_book", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderBook() is not supported yet".into()))));
Value::Null
} }
fn fetch_rest_order_book_safe(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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 fetchSnapshotMaxRetries: Value = self.handle_option(Value::Str("watchOrderBook".into()), Value::Str("maxRetries".into()), &[Value::Int(3)]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_182: bool = true;
while { if !__for_first_182 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_182 = false; i.as_f64().unwrap_or(f64::NAN) < fetchSnapshotMaxRetries.as_f64().unwrap_or(f64::NAN) } {
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
let mut orderBook: Value = self.fetch_order_book(symbol.clone(), &[limit.clone(), params.clone()]).await;
return orderBook;
#[allow(unreachable_code)] { Value::Null }})).await;
match _try_result { Ok(__try_ok) => { if !matches!(__try_ok, Value::Null) { return __try_ok; } return Value::Null; } Err(_try_err) => { let e: Value = panic_to_value(_try_err);
if is_equal(&((match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null })), &fetchSnapshotMaxRetries) {
panic!("{}", e);
}
} }
}
}
return Value::Null;
Value::Null
} }
fn watch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchOrderBook() is not supported yet".into()))));
Value::Null
} }
fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_open_interest", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchOpenInterests")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchOpenInterests")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut openInterests: Value = self.fetch_open_interests(&[Value::from(vec![symbol.clone()]), params]).await;
let mut openInterest: Value = self.safe_dict(openInterests, symbol, &[]);
return openInterest;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenInterest() is not supported yet".into()))));
}
Value::Null
} }
fn fetch_l2_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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 orderbook: Value = self.fetch_order_book(symbol, &[limit, params]).await;
return self.extend(orderbook.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asks".to_string(), self.sort_by(self.aggregate(orderbook.as_map().and_then(|__m| __m.get("asks")).cloned().unwrap_or(Value::Null)), Value::Int(0), &[]));
m.insert("bids".to_string(), self.sort_by(self.aggregate(orderbook.as_map().and_then(|__m| __m.get("bids")).cloned().unwrap_or(Value::Null)), Value::Int(0), &[Value::Bool(true)]));
m
})]);
Value::Null
} }
fn edit_limit_buy_order(&mut self, mut id: Value, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
return self.edit_limit_order(id, symbol, Value::Str("buy".into()), amount, &[price, params]).await;
Value::Null
} }
fn edit_limit_sell_order(&mut self, mut id: Value, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
return self.edit_limit_order(id, symbol, Value::Str("sell".into()), amount, &[price, params]).await;
Value::Null
} }
fn edit_limit_order(&mut self, mut id: Value, mut symbol: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
return self.edit_order(id, symbol, Value::Str("limit".into()), side, &[amount, price, params]).await;
Value::Null
} }
fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("edit_order", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(id.clone()); __args.push(symbol.clone()); __args.push(type_var.clone()); __args.push(side.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
self.cancel_order(id, &[symbol.clone()]).await;
return self.create_order(symbol, type_var, side, amount, &[price, params]).await;
Value::Null
} }
fn edit_order_with_client_order_id(&mut self, mut clientOrderId: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
let mut extendedParams: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clientOrderId".to_string(), clientOrderId);
m
})]);
return self.edit_order(Value::Str("".into()), symbol, type_var, side, &[amount, price, extendedParams]).await;
Value::Null
} }
fn fetch_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_position", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPosition() is not supported yet".into()))));
Value::Null
} }
fn watch_positions(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchPositions() is not supported yet".into()))));
Value::Null
} }
fn watch_position_for_symbols(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.watch_positions(&[symbols, since, limit, params]).await;
Value::Null
} }
fn fetch_positions(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_positions", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchPositions() is not supported yet".into()))));
Value::Null
} }
fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_ticker", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchTickers")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchTickers")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
self.load_markets(&[]).await;
let mut market: Value = <Self as crate::exchange_generated::ExchangeBase>::market(self, symbol);
let mut symbolResolved: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut tickers: Value = self.fetch_tickers(&[Value::from(vec![symbolResolved.clone()]), params]).await;
let mut ticker: Value = self.safe_dict(tickers, symbolResolved.clone(), &[]);
if (ticker == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchTickers() could not find a ticker for ".into())).into()), symbolResolved)));
} else {
return ticker;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTicker() is not supported yet".into()))));
}
Value::Null
} }
fn watch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchTicker() is not supported yet".into()))));
Value::Null
} }
fn fetch_tickers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_tickers", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTickers() is not supported yet".into()))));
Value::Null
} }
fn watch_tickers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchTickers() is not supported yet".into()))));
Value::Null
} }
fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_order", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(id.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() is not supported yet".into()))));
Value::Null
} }
/*
* @method
* @name fetchOrderWithClientOrderId
* @description create a market order by providing the symbol, side and cost
* @param {string} clientOrderId client order Id
* @param {string} symbol unified symbol of the market to create an order in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
fn fetch_order_with_client_order_id(&mut self, mut clientOrderId: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
let mut extendedParams: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clientOrderId".to_string(), clientOrderId);
m
})]);
return self.fetch_order(Value::Str("".into()), &[symbol, extendedParams]).await;
Value::Null
} }
fn fetch_order_status(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
// TODO: TypeScript: change method signature by replacing
// Promise<string> with Promise<Order['status']>.
let mut order: Value = self.fetch_order(id, &[symbol, params]).await;
return self.safe_string_k(order, "status", &[]);
Value::Null
} }
fn fetch_unified_order(&mut self, mut order: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_order(self.safe_string_k(order.clone(), "id", &[]), &[self.safe_string_k(order, "symbol", &[]), params]).await;
Value::Null
} }
fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("create_order", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol); __args.push(type_var); __args.push(side); __args.push(amount); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() is not supported yet".into()))));
Value::Null
} }
fn create_trailing_amount_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut trailingAmount = get_arg(optional_args, 1, Value::Null);
let mut trailingTriggerPrice = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTrailingAmountOrder
* @description create a trailing order by providing the symbol, type, side, amount, price and trailingAmount
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency, or number of contracts
* @param {float} [price] the price for the order to be filled at, in units of the quote currency, ignored in market orders
* @param {float} trailingAmount the quote amount to trail away from the current market price
* @param {float} [trailingTriggerPrice] the price to activate a trailing order, default uses the price argument
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (trailingAmount == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTrailingAmountOrder() requires a trailingAmount argument".into()))));
}
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingAmount".into(), trailingAmount); }
if (trailingTriggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingTriggerPrice".into(), trailingTriggerPrice); }
}
if (self.has.as_map().and_then(|__m| __m.get("createTrailingAmountOrder")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTrailingAmountOrder")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order(symbol, type_var, side, amount, &[price, params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTrailingAmountOrder() is not supported yet".into()))));
Value::Null
} }
fn create_trailing_percent_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut trailingPercent = get_arg(optional_args, 1, Value::Null);
let mut trailingTriggerPrice = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTrailingPercentOrder
* @description create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency, or number of contracts
* @param {float} [price] the price for the order to be filled at, in units of the quote currency, ignored in market orders
* @param {float} trailingPercent the percent to trail away from the current market price
* @param {float} [trailingTriggerPrice] the price to activate a trailing order, default uses the price argument
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (trailingPercent == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTrailingPercentOrder() requires a trailingPercent argument".into()))));
}
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingPercent".into(), trailingPercent); }
if (trailingTriggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut params { std::sync::Arc::make_mut(__d).insert("trailingTriggerPrice".into(), trailingTriggerPrice); }
}
if (self.has.as_map().and_then(|__m| __m.get("createTrailingPercentOrder")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTrailingPercentOrder")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order(symbol, type_var, side, amount, &[price, params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTrailingPercentOrder() is not supported yet".into()))));
Value::Null
} }
fn create_market_order_with_cost(&mut self, mut symbol: Value, mut side: Value, mut cost: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createMarketOrderWithCost
* @description create a market order by providing the symbol, side and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} side 'buy' or 'sell'
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if ((self.has.as_map().and_then(|__m| __m.get("createMarketOrderWithCost")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketOrderWithCost")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) || (((self.has.as_map().and_then(|__m| __m.get("createMarketBuyOrderWithCost")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketBuyOrderWithCost")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) && ((self.has.as_map().and_then(|__m| __m.get("createMarketSellOrderWithCost")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketSellOrderWithCost")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)))) {
return self.create_order(symbol, Value::Str("market".into()), side, cost, &[Value::Int(1), params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketOrderWithCost() is not supported yet".into()))));
Value::Null
} }
fn create_market_buy_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if ((match &(self.options.as_map().and_then(|__m| __m.get("createMarketBuyOrderRequiresPrice")).cloned().unwrap_or(Value::Null)) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) })) || ((self.has.as_map().and_then(|__m| __m.get("createMarketBuyOrderWithCost")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketBuyOrderWithCost")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) {
return self.create_order(symbol, Value::Str("market".into()), Value::Str("buy".into()), cost, &[Value::Int(1), params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketBuyOrderWithCost() is not supported yet".into()))));
Value::Null
} }
fn create_market_sell_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createMarketSellOrderWithCost
* @description create a market sell order by providing the symbol and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if ((match &(self.options.as_map().and_then(|__m| __m.get("createMarketSellOrderRequiresPrice")).cloned().unwrap_or(Value::Null)) { Value::Bool(__x) => *__x == true, __v => matches!((match __v { Value::Int(__n) => Some(*__n as f64), Value::Float(__f) => Some(*__f), Value::Str(__s) => __s.parse::<f64>().ok(), Value::Bool(__b) => Some(if *__b { 1.0 } else { 0.0 }), _ => None }), Some(__y) if __y == 1.0) })) || ((self.has.as_map().and_then(|__m| __m.get("createMarketSellOrderWithCost")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createMarketSellOrderWithCost")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) {
return self.create_order(symbol, Value::Str("market".into()), Value::Str("sell".into()), cost, &[Value::Int(1), params]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketSellOrderWithCost() is not supported yet".into()))));
Value::Null
} }
fn create_trigger_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut triggerPrice = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTriggerOrder
* @description create a trigger stop order (type 1)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} triggerPrice the price to trigger the stop order, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (triggerPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTriggerOrder() requires a triggerPrice argument".into()))));
}
let mut paramsExtended: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPrice".to_string(), triggerPrice);
m
})]);
if (self.has.as_map().and_then(|__m| __m.get("createTriggerOrder")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTriggerOrder")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order(symbol, type_var, side, amount, &[price, paramsExtended]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTriggerOrder() is not supported yet".into()))));
Value::Null
} }
fn create_stop_loss_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut stopLossPrice = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createStopLossOrder
* @description create a trigger stop loss order (type 2)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} stopLossPrice the price to trigger the stop loss order, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (stopLossPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createStopLossOrder() requires a stopLossPrice argument".into()))));
}
let mut paramsExtended: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopLossPrice".to_string(), stopLossPrice);
m
})]);
if (self.has.as_map().and_then(|__m| __m.get("createStopLossOrder")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createStopLossOrder")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order(symbol, type_var, side, amount, &[price, paramsExtended]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopLossOrder() is not supported yet".into()))));
Value::Null
} }
fn create_take_profit_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut takeProfitPrice = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createTakeProfitOrder
* @description create a trigger take profit order (type 2)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} takeProfitPrice the price to trigger the take profit order, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
if (takeProfitPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createTakeProfitOrder() requires a takeProfitPrice argument".into()))));
}
let mut paramsExtended: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("takeProfitPrice".to_string(), takeProfitPrice);
m
})]);
if (self.has.as_map().and_then(|__m| __m.get("createTakeProfitOrder")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createTakeProfitOrder")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order(symbol, type_var, side, amount, &[price, paramsExtended]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createTakeProfitOrder() is not supported yet".into()))));
Value::Null
} }
fn create_order_with_take_profit_and_stop_loss(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut takeProfit = get_arg(optional_args, 1, Value::Null);
let mut stopLoss = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @method
* @name createOrderWithTakeProfitAndStopLoss
* @description create an order with a stop loss or take profit attached (type 3)
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency or the number of contracts
* @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
* @param {float} [takeProfit] the take profit price, in units of the quote currency
* @param {float} [stopLoss] the stop loss price, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.takeProfitType] *not available on all exchanges* 'limit' or 'market'
* @param {string} [params.stopLossType] *not available on all exchanges* 'limit' or 'market'
* @param {string} [params.takeProfitPriceType] *not available on all exchanges* 'last', 'mark' or 'index'
* @param {string} [params.stopLossPriceType] *not available on all exchanges* 'last', 'mark' or 'index'
* @param {float} [params.takeProfitLimitPrice] *not available on all exchanges* limit price for a limit take profit order
* @param {float} [params.stopLossLimitPrice] *not available on all exchanges* stop loss for a limit stop loss order
* @param {float} [params.takeProfitAmount] *not available on all exchanges* the amount for a take profit
* @param {float} [params.stopLossAmount] *not available on all exchanges* the amount for a stop loss
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
let mut paramsValue: Value = self.set_take_profit_and_stop_loss_params(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), takeProfit.clone(), stopLoss.clone(), params.clone()]);
if (self.has.as_map().and_then(|__m| __m.get("createOrderWithTakeProfitAndStopLoss")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("createOrderWithTakeProfitAndStopLoss")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
return self.create_order(symbol, type_var, side, amount, &[price, paramsValue]).await;
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrderWithTakeProfitAndStopLoss() is not supported yet".into()))));
Value::Null
} }
fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("create_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(orders); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrders() is not supported yet".into()))));
Value::Null
} }
fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("cancel_order", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(id.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() is not supported yet".into()))));
Value::Null
} }
/*
* @method
* @name cancelOrderWithClientOrderId
* @description create a market order by providing the symbol, side and cost
* @param {string} clientOrderId client order Id
* @param {string} symbol unified symbol of the market to create an order in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
fn cancel_order_with_client_order_id(&mut self, mut clientOrderId: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
let mut extendedParams: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clientOrderId".to_string(), clientOrderId);
m
})]);
return self.cancel_order(Value::Str("".into()), &[symbol, extendedParams]).await;
Value::Null
} }
fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("cancel_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(ids); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrders() is not supported yet".into()))));
Value::Null
} }
/*
* @method
* @name cancelOrdersWithClientOrderIds
* @description create a market order by providing the symbol, side and cost
* @param {string[]} clientOrderIds client order Ids
* @param {string} symbol unified symbol of the market to create an order in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
fn cancel_orders_with_client_order_ids(&mut self, mut clientOrderIds: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
let mut extendedParams: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clientOrderIds".to_string(), clientOrderIds);
m
})]);
return self.cancel_orders(Value::from(vec![]), &[symbol, extendedParams]).await;
Value::Null
} }
fn cancel_all_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("cancel_all_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() is not supported yet".into()))));
Value::Null
} }
fn cancel_unified_order(&mut self, mut order: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.cancel_order(self.safe_string_k(order.clone(), "id", &[]), &[self.safe_string_k(order, "symbol", &[]), params]).await;
Value::Null
} }
fn fetch_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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.has.as_map().and_then(|__m| __m.get("fetchOpenOrders")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchOpenOrders")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) && ((self.has.as_map().and_then(|__m| __m.get("fetchClosedOrders")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchClosedOrders")).cloned().unwrap_or(Value::Null).as_bool() != Some(false))) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() is not supported yet, consider using fetchOpenOrders() and fetchClosedOrders() instead".into()))));
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() is not supported yet".into()))));
Value::Null
} }
fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderTrades() is not supported yet".into()))));
Value::Null
} }
fn watch_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchOrders() is not supported yet".into()))));
Value::Null
} }
fn fetch_open_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_open_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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.has.as_map().and_then(|__m| __m.get("fetchOrders")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchOrders")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut orders: Value = self.fetch_orders(&[symbol, since, limit, params]).await;
return self.filter_by(orders, Value::Str("status".into()), Value::Str("open".into()), &[]);
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenOrders() is not supported yet".into()))));
Value::Null
} }
fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_closed_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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.has.as_map().and_then(|__m| __m.get("fetchOrders")).cloned().unwrap_or(Value::Null) != Value::Null) && (self.has.as_map().and_then(|__m| __m.get("fetchOrders")).cloned().unwrap_or(Value::Null).as_bool() != Some(false)) {
let mut orders: Value = self.fetch_orders(&[symbol, since, limit, params]).await;
return self.filter_by(orders, Value::Str("status".into()), Value::Str("closed".into()), &[]);
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchClosedOrders() is not supported yet".into()))));
Value::Null
} }
fn fetch_canceled_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchCanceledOrders() is not supported yet".into()))));
Value::Null
} }
fn fetch_my_trades(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_my_trades", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() is not supported yet".into()))));
Value::Null
} }
fn watch_my_trades(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" watchMyTrades() is not supported yet".into()))));
Value::Null
} }
fn create_limit_order(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order(symbol, Value::Str("limit".into()), side, amount, &[price, params]).await;
Value::Null
} }
fn create_market_order(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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
}));
return self.create_order(symbol, Value::Str("market".into()), side, amount, &[price, params]).await;
Value::Null
} }
fn create_limit_buy_order(&mut self, mut symbol: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order(symbol, Value::Str("limit".into()), Value::Str("buy".into()), amount, &[price, params]).await;
Value::Null
} }
fn create_limit_sell_order(&mut self, mut symbol: Value, mut amount: Value, mut price: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order(symbol, Value::Str("limit".into()), Value::Str("sell".into()), amount, &[price, params]).await;
Value::Null
} }
fn create_market_buy_order(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order(symbol, Value::Str("market".into()), Value::Str("buy".into()), amount, &[Value::Null, params]).await;
Value::Null
} }
fn create_market_sell_order(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.create_order(symbol, Value::Str("market".into()), Value::Str("sell".into()), amount, &[Value::Null, params]).await;
Value::Null
} }
fn create_post_only_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("createPostOnlyOrder")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createPostOnlyOrder")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createPostOnlyOrder() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("postOnly".to_string(), Value::Bool(true));
m
})]);
return self.create_order(symbol, type_var, side, amount, &[price, query]).await;
Value::Null
} }
fn create_reduce_only_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
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.has.as_map().and_then(|__m| __m.get("createReduceOnlyOrder")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createReduceOnlyOrder")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createReduceOnlyOrder() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("reduceOnly".to_string(), Value::Bool(true));
m
})]);
return self.create_order(symbol, type_var, side, amount, &[price, query]).await;
Value::Null
} }
fn create_stop_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut triggerPrice = 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.has.as_map().and_then(|__m| __m.get("createStopOrder")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createStopOrder")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopOrder() is not supported yet".into()))));
}
if (triggerPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" create_stop_order() requires a stopPrice argument".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), triggerPrice);
m
})]);
return self.create_order(symbol, type_var, side, amount, &[price, query]).await;
Value::Null
} }
fn create_stop_limit_order(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, mut price: Value, mut triggerPrice: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("createStopLimitOrder")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createStopLimitOrder")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopLimitOrder() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), triggerPrice);
m
})]);
return self.create_order(symbol, Value::Str("limit".into()), side, amount, &[price, query]).await;
Value::Null
} }
fn create_stop_market_order(&mut self, mut symbol: Value, mut side: Value, mut amount: Value, mut triggerPrice: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("createStopMarketOrder")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("createStopMarketOrder")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createStopMarketOrder() is not supported yet".into()))));
}
let mut query: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), triggerPrice);
m
})]);
return self.create_order(symbol, Value::Str("market".into()), side, amount, &[Value::Null, query]).await;
Value::Null
} }
fn fetch_trading_fee(&mut self, mut symbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_trading_fee", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(symbol.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.has.as_map().and_then(|__m| __m.get("fetchTradingFees")).cloned().unwrap_or(Value::Null) == Value::Null) || (self.has.as_map().and_then(|__m| __m.get("fetchTradingFees")).cloned().unwrap_or(Value::Null).as_bool() == Some(false)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTradingFee() is not supported yet".into()))));
}
let mut fees: Value = self.fetch_trading_fees(&[params]).await;
let mut fee: Value = self.safe_dict(fees, symbol, &[]);
return fee;
Value::Null
} }
/// Base-method fall-through for a core's `call_dynamic`.
fn call_dynamic_base<'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 {
"account" => self.account(),
"add_key_in_array_items" => self.add_key_in_array_items(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"amount_to_precision" => self.amount_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"arrays_concat" => self.arrays_concat(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"assign_default_deposit_withdraw_fees" => self.assign_default_deposit_withdraw_fees(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"borrow_cross_margin" => self.borrow_cross_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"borrow_isolated_margin" => self.borrow_isolated_margin(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,
"borrow_margin" => self.borrow_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"build_ohlcvc" => self.build_ohlcvc(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"calculate_fee" => self.calculate_fee(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[5.min(args.len())..]),
"calculate_fee_with_rate" => self.calculate_fee_with_rate(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[5.min(args.len())..]),
"calculate_rate_limiter_cost" => self.calculate_rate_limiter_cost(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())..]),
"call_method" => self.call_method(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_all_contract_orders" => self.cancel_all_contract_orders(&args[..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_all_orders_after" => self.cancel_all_orders_after(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_all_orders_ws" => self.cancel_all_orders_ws(&args[..]).await,
"cancel_all_spot_orders" => self.cancel_all_spot_orders(&args[..]).await,
"cancel_contract_order" => self.cancel_contract_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_order_with_client_order_id" => self.cancel_order_with_client_order_id(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_order_ws" => self.cancel_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders_for_symbols" => self.cancel_orders_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders_with_client_order_ids" => self.cancel_orders_with_client_order_ids(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders_ws" => self.cancel_orders_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_spot_order" => self.cancel_spot_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_unified_order" => self.cancel_unified_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"check_address" => self.check_address(&args[..]),
"check_proxy_settings" => self.check_proxy_settings(&args[..]),
"check_proxy_url_settings" => self.check_proxy_url_settings(&args[..]),
"check_required_credentials" => self.check_required_credentials(&args[..]),
"check_ws_proxy_settings" => self.check_ws_proxy_settings(),
"close_all_positions" => self.close_all_positions(&args[..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"common_currency_code" => self.common_currency_code(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"convert_expire_date" => self.convert_expire_date(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"convert_expire_date_to_market_id_date" => self.convert_expire_date_to_market_id_date(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"convert_market_id_expire_date" => self.convert_market_id_expire_date(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"convert_ohlcv_to_trading_view" => self.convert_ohlcv_to_trading_view(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"convert_trading_view_to_ohlcv" => self.convert_trading_view_to_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"convert_type_to_account" => self.convert_type_to_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"cost_to_precision" => self.cost_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"create_ccxt_trade_id" => self.create_ccxt_trade_id(&args[..]),
"create_contract_orders" => self.create_contract_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"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_expired_option_market" => <Self as crate::exchange_generated::ExchangeBase>::create_expired_option_market(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"create_limit_buy_order" => self.create_limit_buy_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[3.min(args.len())..]).await,
"create_limit_buy_order_ws" => self.create_limit_buy_order_ws(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_limit_order" => self.create_limit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_limit_order_ws" => self.create_limit_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_limit_sell_order" => self.create_limit_sell_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[3.min(args.len())..]).await,
"create_limit_sell_order_ws" => self.create_limit_sell_order_ws(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_market_buy_order" => self.create_market_buy_order(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_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_market_buy_order_ws" => self.create_market_buy_order_ws(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_market_order" => self.create_market_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[3.min(args.len())..]).await,
"create_market_order_with_cost" => self.create_market_order_with_cost(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_market_order_with_cost_ws" => self.create_market_order_with_cost_ws(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_market_order_ws" => self.create_market_order_ws(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_market_sell_order" => self.create_market_sell_order(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_market_sell_order_with_cost" => self.create_market_sell_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_market_sell_order_ws" => self.create_market_sell_order_ws(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_ohlcv_object" => self.create_ohlcv_object(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)),
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_order_with_take_profit_and_stop_loss" => self.create_order_with_take_profit_and_stop_loss(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_order_with_take_profit_and_stop_loss_ws" => self.create_order_with_take_profit_and_stop_loss_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_order_ws" => self.create_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_orders_ws" => self.create_orders_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_post_only_order" => self.create_post_only_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_post_only_order_ws" => self.create_post_only_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_reduce_only_order" => self.create_reduce_only_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_reduce_only_order_ws" => self.create_reduce_only_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_spot_orders" => self.create_spot_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_stop_limit_order" => self.create_stop_limit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), &args[5.min(args.len())..]).await,
"create_stop_limit_order_ws" => self.create_stop_limit_order_ws(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[5.min(args.len())..]).await,
"create_stop_loss_order" => self.create_stop_loss_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_stop_loss_order_ws" => self.create_stop_loss_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_stop_market_order" => self.create_stop_market_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_stop_market_order_ws" => self.create_stop_market_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_stop_order" => self.create_stop_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_stop_order_ws" => self.create_stop_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_sub_account" => self.create_sub_account(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_take_profit_order" => self.create_take_profit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_take_profit_order_ws" => self.create_take_profit_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_trailing_amount_order" => self.create_trailing_amount_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_trailing_amount_order_ws" => self.create_trailing_amount_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_trailing_percent_order" => self.create_trailing_percent_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_trailing_percent_order_ws" => self.create_trailing_percent_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_trigger_order" => self.create_trigger_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_trigger_order_ws" => self.create_trigger_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_twap_order" => self.create_twap_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,
"currency" => self.currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"currency_id" => self.currency_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"currency_ids" => self.currency_ids(&args[..]),
"currency_to_precision" => self.currency_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"deposit_withdraw_fee" => self.deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"edit_limit_buy_order" => self.edit_limit_buy_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[3.min(args.len())..]).await,
"edit_limit_order" => self.edit_limit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"edit_limit_sell_order" => self.edit_limit_sell_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[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,
"edit_order_with_client_order_id" => self.edit_order_with_client_order_id(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"edit_order_ws" => self.edit_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"edit_orders" => self.edit_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"feature_value" => self.feature_value(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"feature_value_by_type" => self.feature_value_by_type(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"features_mapper" => self.features_mapper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"fee_to_precision" => self.fee_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"fetch" => self.fetch(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch2" => self.fetch2(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_accounts" => self.fetch_accounts(&args[..]).await,
"fetch_adl_rank" => self.fetch_adl_rank(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_all_greeks" => self.fetch_all_greeks(&args[..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_balance_ws" => self.fetch_balance_ws(&args[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&args[..]).await,
"fetch_borrow_interest" => self.fetch_borrow_interest(&args[..]).await,
"fetch_borrow_rate" => self.fetch_borrow_rate(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_canceled_and_closed_orders" => self.fetch_canceled_and_closed_orders(&args[..]).await,
"fetch_canceled_orders" => self.fetch_canceled_orders(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_closed_orders_ws" => self.fetch_closed_orders_ws(&args[..]).await,
"fetch_contract_deposit_address" => self.fetch_contract_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_contract_ohlcv" => self.fetch_contract_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_contract_tickers" => self.fetch_contract_tickers(&args[..]).await,
"fetch_convert_currencies" => self.fetch_convert_currencies(&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_convert_trade_history" => self.fetch_convert_trade_history(&args[..]).await,
"fetch_cross_borrow_rate" => self.fetch_cross_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_cross_borrow_rates" => self.fetch_cross_borrow_rates(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_addresses" => 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_withdraw_fee" => self.fetch_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args[..]).await,
"fetch_deposits_ws" => self.fetch_deposits_ws(&args[..]).await,
"fetch_free_balance" => self.fetch_free_balance(&args[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args[..]).await,
"fetch_funding_interval" => self.fetch_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_intervals" => self.fetch_funding_intervals(&args[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args[..]).await,
"fetch_greeks" => self.fetch_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_index_ohlcv" => self.fetch_index_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_isolated_borrow_rate" => self.fetch_isolated_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_isolated_borrow_rates" => self.fetch_isolated_borrow_rates(&args[..]).await,
"fetch_l2_order_book" => self.fetch_l2_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_l3_order_book" => self.fetch_l3_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_last_prices" => self.fetch_last_prices(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_ledger_entry" => self.fetch_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args[..]).await,
"fetch_leverages" => self.fetch_leverages(&args[..]).await,
"fetch_liquidations" => self.fetch_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_long_short_ratio" => self.fetch_long_short_ratio(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_long_short_ratio_history" => self.fetch_long_short_ratio_history(&args[..]).await,
"fetch_margin_adjustment_history" => self.fetch_margin_adjustment_history(&args[..]).await,
"fetch_margin_mode" => self.fetch_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_margin_modes" => self.fetch_margin_modes(&args[..]).await,
"fetch_mark_ohlcv" => self.fetch_mark_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_mark_price" => self.fetch_mark_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_mark_prices" => self.fetch_mark_prices(&args[..]).await,
"fetch_market_leverage_tiers" => self.fetch_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_my_liquidations" => self.fetch_my_liquidations(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_my_trades_ws" => self.fetch_my_trades_ws(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_ohlcv_ws" => self.fetch_ohlcv_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interests" => self.fetch_open_interests(&args[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_open_orders_ws" => self.fetch_open_orders_ws(&args[..]).await,
"fetch_option" => self.fetch_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_option_chain" => self.fetch_option_chain(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book_ws" => self.fetch_order_book_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_books" => self.fetch_order_books(&args[..]).await,
"fetch_order_status" => self.fetch_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_with_client_order_id" => self.fetch_order_with_client_order_id(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_ws" => self.fetch_order_ws(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_ws" => self.fetch_orders_by_status_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders_ws" => self.fetch_orders_ws(&args[..]).await,
"fetch_paginated_call_cursor" => self.fetch_paginated_call_cursor(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_paginated_call_deterministic" => self.fetch_paginated_call_deterministic(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_paginated_call_dynamic" => self.fetch_paginated_call_dynamic(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_paginated_call_incremental" => self.fetch_paginated_call_incremental(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_partial_balance" => self.fetch_partial_balance(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_payment_methods" => self.fetch_payment_methods(&args[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_position_adl_rank" => self.fetch_position_adl_rank(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_position_history" => self.fetch_position_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_position_mode" => self.fetch_position_mode(&args[..]).await,
"fetch_position_ws" => self.fetch_position_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_positions_adl_rank" => self.fetch_positions_adl_rank(&args[..]).await,
"fetch_positions_for_symbol" => self.fetch_positions_for_symbol(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions_for_symbol_ws" => self.fetch_positions_for_symbol_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args[..]).await,
"fetch_positions_risk" => self.fetch_positions_risk(&args[..]).await,
"fetch_positions_ws" => self.fetch_positions_ws(&args[..]).await,
"fetch_premium_index_ohlcv" => self.fetch_premium_index_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_rest_order_book_safe" => self.fetch_rest_order_book_safe(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_spot_ohlcv" => self.fetch_spot_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_spot_tickers" => self.fetch_spot_tickers(&args[..]).await,
"fetch_status" => self.fetch_status(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_ticker_ws" => self.fetch_ticker_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_tickers_ws" => self.fetch_tickers_ws(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_total_balance" => self.fetch_total_balance(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trades_ws" => self.fetch_trades_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_trading_fees_ws" => self.fetch_trading_fees_ws(&args[..]).await,
"fetch_trading_limits" => self.fetch_trading_limits(&args[..]).await,
"fetch_transaction_fee" => self.fetch_transaction_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_transaction_fees" => self.fetch_transaction_fees(&args[..]).await,
"fetch_transactions" => self.fetch_transactions(&args[..]).await,
"fetch_transfer" => self.fetch_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_transfers" => self.fetch_transfers(&args[..]).await,
"fetch_unified_order" => self.fetch_unified_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_used_balance" => self.fetch_used_balance(&args[..]).await,
"fetch_web_endpoint" => self.fetch_web_endpoint(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,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"fetch_withdrawals_ws" => self.fetch_withdrawals_ws(&args[..]).await,
"filter_by_array" => self.filter_by_array(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"filter_by_array_adl_ranks" => self.filter_by_array_adl_ranks(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"filter_by_array_positions" => self.filter_by_array_positions(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"filter_by_array_tickers" => self.filter_by_array_tickers(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"filter_by_currency_since_limit" => self.filter_by_currency_since_limit(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"filter_by_key" => self.filter_by_key(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"filter_by_limit" => self.filter_by_limit(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"filter_by_since_limit" => self.filter_by_since_limit(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"filter_by_symbol" => self.filter_by_symbol(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"filter_by_symbol_since_limit" => self.filter_by_symbol_since_limit(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"filter_by_symbols_since_limit" => self.filter_by_symbols_since_limit(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"filter_by_value_since_limit" => self.filter_by_value_since_limit(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"filter_out_by_array" => self.filter_out_by_array(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"find_broadly_matched_key" => self.find_broadly_matched_key(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"find_message_hashes" => self.find_message_hashes(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"find_nearest_ceiling" => self.find_nearest_ceiling(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"find_timeframe" => self.find_timeframe(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"force_string" => self.force_string(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"get_cache_index" => self.get_cache_index(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"get_default_options" => self.get_default_options(),
"get_describe_for_extended_ws_exchange" => self.get_describe_for_extended_ws_exchange(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)),
"get_list_from_object_values" => self.get_list_from_object_values(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"get_market_from_symbols" => self.get_market_from_symbols(&args[..]),
"get_supported_mapping" => self.get_supported_mapping(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"get_symbols_for_market_type" => self.get_symbols_for_market_type(&args[..]),
"handle_errors" => <Self as crate::exchange_generated::ExchangeBase>::handle_errors(self, 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)),
"handle_margin_mode_and_params" => self.handle_margin_mode_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_market_type_and_params" => self.handle_market_type_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_max_entries_per_request_and_params" => self.handle_max_entries_per_request_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_network_code_and_params" => self.handle_network_code_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_option" => self.handle_option(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"handle_option_and_params" => self.handle_option_and_params(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())..]),
"handle_option_and_params2" => self.handle_option_and_params2(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())..]),
"handle_option_bool_and_params" => self.handle_option_bool_and_params(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())..]),
"handle_option_bool_and_params2" => self.handle_option_bool_and_params2(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())..]),
"handle_option_integer_and_params" => self.handle_option_integer_and_params(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())..]),
"handle_option_integer_and_params2" => self.handle_option_integer_and_params2(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())..]),
"handle_option_string_and_params" => self.handle_option_string_and_params(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())..]),
"handle_option_string_and_params2" => self.handle_option_string_and_params2(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())..]),
"handle_param_bool" => self.handle_param_bool(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"handle_param_bool2" => self.handle_param_bool2(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())..]),
"handle_param_integer" => self.handle_param_integer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"handle_param_integer2" => self.handle_param_integer2(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())..]),
"handle_param_string" => self.handle_param_string(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"handle_param_string2" => self.handle_param_string2(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())..]),
"handle_post_only" => self.handle_post_only(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"handle_sub_type_and_params" => self.handle_sub_type_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_time_in_force" => self.handle_time_in_force(&args[..]),
"handle_trigger_and_params" => self.handle_trigger_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_trigger_direction_and_params" => self.handle_trigger_direction_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_trigger_prices_and_params" => self.handle_trigger_prices_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"handle_until_option" => self.handle_until_option(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())..]),
"implode_hostname" => self.implode_hostname(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"incrementing_nonce" => self.incrementing_nonce(),
"integer_precision_to_amount" => self.integer_precision_to_amount(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"invert_flat_string_dictionary" => self.invert_flat_string_dictionary(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"is_empty_string" => self.is_empty_string(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"is_leveraged_currency" => self.is_leveraged_currency(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"is_post_only" => self.is_post_only(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"is_round_number" => self.is_round_number(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"is_significant_precision" => self.is_significant_precision(),
"is_tick_precision" => self.is_tick_precision(),
"is_trigger_order" => self.is_trigger_order(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"is_uta_enabled" => self.is_uta_enabled(&args[..]).await,
"load_accounts" => self.load_accounts(&args[..]).await,
"load_markets" => self.load_markets(&args[..]).await,
"load_markets_and_sign_in" => self.load_markets_and_sign_in().await,
"load_time_difference" => self.load_time_difference(&args[..]).await,
"load_trading_limits" => self.load_trading_limits(&args[..]).await,
"market" => <Self as crate::exchange_generated::ExchangeBase>::market(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"market_codes" => self.market_codes(&args[..]),
"market_id" => self.market_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"market_ids" => self.market_ids(&args[..]),
"market_non_virtual" => self.market_non_virtual(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"market_or_null" => self.market_or_null(&args[..]),
"market_symbols" => self.market_symbols(&args[..]),
"markets_for_symbols" => self.markets_for_symbols(&args[..]),
"merge_balance_account" => self.merge_balance_account(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)),
"network_code_to_id" => self.network_code_to_id(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"network_id_to_code" => self.network_id_to_code(&args[..]),
"nonce" => <Self as crate::exchange_generated::ExchangeBase>::nonce(self),
"oath" => self.oath(),
"orderbook_checksum_message" => self.orderbook_checksum_message(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_account" => <Self as crate::exchange_generated::ExchangeBase>::parse_account(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_accounts" => self.parse_accounts(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_adl_rank" => <Self as crate::exchange_generated::ExchangeBase>::parse_adl_rank(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_adl_ranks" => self.parse_adl_ranks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_all_greeks" => self.parse_all_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_balance" => <Self as crate::exchange_generated::ExchangeBase>::parse_balance(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_borrow_interest" => <Self as crate::exchange_generated::ExchangeBase>::parse_borrow_interest(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_borrow_interests" => self.parse_borrow_interests(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_borrow_rate" => <Self as crate::exchange_generated::ExchangeBase>::parse_borrow_rate(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_borrow_rate_history" => self.parse_borrow_rate_history(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)),
"parse_conversion" => <Self as crate::exchange_generated::ExchangeBase>::parse_conversion(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_conversions" => self.parse_conversions(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_currencies" => self.parse_currencies(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => <Self as crate::exchange_generated::ExchangeBase>::parse_currency(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => <Self as crate::exchange_generated::ExchangeBase>::parse_deposit_address(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_deposit_addresses" => self.parse_deposit_addresses(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_deposit_withdraw_fee" => <Self as crate::exchange_generated::ExchangeBase>::parse_deposit_withdraw_fee(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_deposit_withdraw_fees" => self.parse_deposit_withdraw_fees(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_fee_numeric" => self.parse_fee_numeric(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => <Self as crate::exchange_generated::ExchangeBase>::parse_funding_rate(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate_histories" => self.parse_funding_rate_histories(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate_history" => <Self as crate::exchange_generated::ExchangeBase>::parse_funding_rate_history(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rates" => self.parse_funding_rates(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_greeks" => <Self as crate::exchange_generated::ExchangeBase>::parse_greeks(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_income" => <Self as crate::exchange_generated::ExchangeBase>::parse_income(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_incomes" => self.parse_incomes(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_isolated_borrow_rate" => self.parse_isolated_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_isolated_borrow_rates" => self.parse_isolated_borrow_rates(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_last_price" => <Self as crate::exchange_generated::ExchangeBase>::parse_last_price(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_last_prices" => self.parse_last_prices(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger" => self.parse_ledger(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => <Self as crate::exchange_generated::ExchangeBase>::parse_ledger_entry(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverage" => <Self as crate::exchange_generated::ExchangeBase>::parse_leverage(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverage_tiers" => self.parse_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverages" => self.parse_leverages(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_liquidation" => <Self as crate::exchange_generated::ExchangeBase>::parse_liquidation(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_liquidations" => self.parse_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_long_short_ratio" => self.parse_long_short_ratio(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_long_short_ratio_history" => self.parse_long_short_ratio_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_mode" => <Self as crate::exchange_generated::ExchangeBase>::parse_margin_mode(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_modes" => self.parse_margin_modes(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_modification" => <Self as crate::exchange_generated::ExchangeBase>::parse_margin_modification(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_modifications" => self.parse_margin_modifications(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market" => <Self as crate::exchange_generated::ExchangeBase>::parse_market(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_market_leverage_tiers" => <Self as crate::exchange_generated::ExchangeBase>::parse_market_leverage_tiers(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_markets" => self.parse_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlc_vs" => self.parse_ohlc_vs(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => <Self as crate::exchange_generated::ExchangeBase>::parse_ohlcv(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_open_interest" => <Self as crate::exchange_generated::ExchangeBase>::parse_open_interest(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_open_interests" => self.parse_open_interests(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_open_interests_history" => self.parse_open_interests_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_option" => self.parse_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_option_chain" => self.parse_option_chain(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => <Self as crate::exchange_generated::ExchangeBase>::parse_order(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_book" => <Self as crate::exchange_generated::ExchangeBase>::parse_order_book(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"parse_order_book_bid_ask" => self.parse_order_book_bid_ask(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_book_bid_ask_l3" => self.parse_order_book_bid_ask_l3(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_book_bids_asks" => self.parse_order_book_bids_asks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_book_bids_asks_l3" => self.parse_order_book_bids_asks_l3(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_book_l3" => self.parse_order_book_l3(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"parse_orders" => self.parse_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_position" => <Self as crate::exchange_generated::ExchangeBase>::parse_position(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_positions" => self.parse_positions(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_precision" => self.parse_precision(&args[..]),
"parse_ticker" => <Self as crate::exchange_generated::ExchangeBase>::parse_ticker(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_tickers" => self.parse_tickers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_to_int" => self.parse_to_int(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_to_numeric" => self.parse_to_numeric(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_trade" => <Self as crate::exchange_generated::ExchangeBase>::parse_trade(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trades" => self.parse_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trades_helper" => self.parse_trades_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"parse_trading_view_ohlcv" => self.parse_trading_view_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => <Self as crate::exchange_generated::ExchangeBase>::parse_transaction(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transactions" => self.parse_transactions(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transfer" => <Self as crate::exchange_generated::ExchangeBase>::parse_transfer(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transfers" => self.parse_transfers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_ohlc_vs" => self.parse_ws_ohlc_vs(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_ohlcv" => self.parse_ws_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_order" => self.parse_ws_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_order_trade" => self.parse_ws_order_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_trades" => self.parse_ws_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parsed_fee_and_fees" => self.parsed_fee_and_fees(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"price_to_precision" => self.price_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"reduce_fees_by_currency" => self.reduce_fees_by_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"remove_keys_from_dict" => self.remove_keys_from_dict(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"remove_repeated_elements_from_array" => self.remove_repeated_elements_from_array(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"remove_repeated_trades_from_array" => self.remove_repeated_trades_from_array(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"repay_cross_margin" => self.repay_cross_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"repay_isolated_margin" => self.repay_isolated_margin(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,
"repay_margin" => self.repay_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"request" => self.request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"require_value" => self.require_value(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"resolve_path" => self.resolve_path(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"safe_balance" => self.safe_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"safe_bool" => self.safe_bool(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_bool2" => self.safe_bool2(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())..]),
"safe_bool_n" => self.safe_bool_n(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_currency" => self.safe_currency(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_currency_code" => self.safe_currency_code(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_currency_structure" => self.safe_currency_structure(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"safe_deterministic_call" => self.safe_deterministic_call(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"safe_dict" => self.safe_dict(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_dict2" => self.safe_dict2(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())..]),
"safe_dict_n" => self.safe_dict_n(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_integer_omit_zero" => self.safe_integer_omit_zero(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_ledger_entry" => self.safe_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_liquidation" => self.safe_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_list" => self.safe_list(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_list2" => self.safe_list2(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())..]),
"safe_list_n" => self.safe_list_n(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_market" => self.safe_market(&args[..]),
"safe_market_structure" => self.safe_market_structure(&args[..]),
"safe_network" => self.safe_network(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"safe_number" => self.safe_number(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_number2" => self.safe_number2(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())..]),
"safe_number_n" => self.safe_number_n(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_number_omit_zero" => self.safe_number_omit_zero(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"safe_open_interest" => self.safe_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_order" => self.safe_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_position" => self.safe_position(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"safe_symbol" => self.safe_symbol(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_ticker" => self.safe_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_trade" => self.safe_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"select_network_key_from_networks" => self.select_network_key_from_networks(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())..]),
"set_headers" => self.set_headers(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"set_margin" => self.set_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"set_markets" => self.set_markets(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"set_markets_from_exchange" => self.set_markets_from_exchange(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"set_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"set_take_profit_and_stop_loss_params" => self.set_take_profit_and_stop_loss_params(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())..]),
"sign" => <Self as crate::exchange_generated::ExchangeBase>::sign(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"sign_in" => self.sign_in(&args[..]).await,
"sort_cursor_paginated_result" => self.sort_cursor_paginated_result(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"string_to_base16" => self.string_to_base16(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"symbol" => self.symbol(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"timeframe_from_milliseconds" => self.timeframe_from_milliseconds(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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,
"un_watch_bids_asks" => self.un_watch_bids_asks(&args[..]).await,
"un_watch_funding_rate" => self.un_watch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_funding_rates" => self.un_watch_funding_rates(&args[..]).await,
"un_watch_mark_price" => self.un_watch_mark_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_mark_prices" => self.un_watch_mark_prices(&args[..]).await,
"un_watch_my_trades" => self.un_watch_my_trades(&args[..]).await,
"un_watch_ohlcv" => self.un_watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_ohlcv_for_symbols" => self.un_watch_ohlcv_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_order_book" => self.un_watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_order_book_for_symbols" => self.un_watch_order_book_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_orders" => self.un_watch_orders(&args[..]).await,
"un_watch_positions" => self.un_watch_positions(&args[..]).await,
"un_watch_ticker" => self.un_watch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_tickers" => self.un_watch_tickers(&args[..]).await,
"un_watch_trades" => self.un_watch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"un_watch_trades_for_symbols" => self.un_watch_trades_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"url_encoder_for_proxy_url" => self.url_encoder_for_proxy_url(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"watch_balance" => self.watch_balance(&args[..]).await,
"watch_bids_asks" => self.watch_bids_asks(&args[..]).await,
"watch_funding_rate" => self.watch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_funding_rates" => self.watch_funding_rates(&args[..]).await,
"watch_funding_rates_for_symbols" => self.watch_funding_rates_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_liquidations" => self.watch_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_liquidations_for_symbols" => self.watch_liquidations_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_mark_price" => self.watch_mark_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_mark_prices" => self.watch_mark_prices(&args[..]).await,
"watch_my_liquidations" => self.watch_my_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_my_liquidations_for_symbols" => self.watch_my_liquidations_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_my_trades" => self.watch_my_trades(&args[..]).await,
"watch_my_trades_for_symbols" => self.watch_my_trades_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_ohlcv" => self.watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_ohlcv_for_symbols" => self.watch_ohlcv_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_order_book" => self.watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_order_book_for_symbols" => self.watch_order_book_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_orders" => self.watch_orders(&args[..]).await,
"watch_orders_for_symbols" => self.watch_orders_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_position" => self.watch_position(&args[..]).await,
"watch_position_for_symbols" => self.watch_position_for_symbols(&args[..]).await,
"watch_positions" => self.watch_positions(&args[..]).await,
"watch_ticker" => self.watch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_tickers" => self.watch_tickers(&args[..]).await,
"watch_trades" => self.watch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_trades_for_symbols" => self.watch_trades_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.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,
"withdraw_ws" => self.withdraw_ws(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,
// Implicit-API endpoints (`publicGetX`) exist only as inherent
// methods on the venue's `<id>_api.rs`, which no name-based
// dispatch arm covers — a static-request test named after one
// (bingx's accountV1PrivateGetAccountApiRestrictions) otherwise
// computes a null url. Route them the way those wrappers do.
// Guarded on the api block so a genuinely unknown name still
// returns Null rather than panicking inside call_method.
//
// Returning Null keeps an optional probe cheap, but a dynamic
// re-entry (`fetchPaginatedCall*` / `fetchWebEndpoint`, which
// reach here via `method_name_to_snake_case`) must not silently
// see an empty page — so record the miss for
// `crate::exchange::call_dynamic_required` to raise on.
_ => {
if self.internals.implicit_api.is_empty() {
self.build_implicit_api();
}
if self.internals.implicit_api.contains_key(method) {
self.call_method(crate::Value::Str(method.to_string().into()), &args[..]).await
} else {
self.internals.dynamic_dispatch_miss = Some(method.to_string());
crate::Value::Null
}
}
}
})
}
}