#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
use crate::exchange::CallDynamicChecked;
pub struct BtseCore {
pub exchange: crate::exchange::Exchange,
}
impl BtseCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { exchange: crate::exchange::Exchange::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = BtseCore::describe(self);
self.initialize_properties(described);
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for BtseCore {
fn nonce(&self, ) -> crate::Value {
BtseCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
BtseCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_position(self, position, &[market])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_funding_rate(self, rate, &[market])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
BtseCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_open_interest(self, interest, &[market])
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_funding_rate_history(self, entry, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
BtseCore::parse_transaction(self, transaction, &[currency])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
BtseCore::parse_margin_mode(self, margin_mode, &[market])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
BtseCore::sign(self, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
BtseCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BtseCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_all_orders_after" => self.cancel_all_orders_after(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,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_contract_order" => self.create_contract_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" => 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_spot_order" => self.create_spot_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" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&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_ledger" => self.fetch_ledger(&args[..]).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_margin_mode" => self.fetch_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).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_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interest" => self.fetch_open_interest(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_order" => self.fetch_open_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order_book" => self.fetch_order_book(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_position_mode" => self.fetch_position_mode(&args[..]).await,
"fetch_positions" => self.fetch_positions(&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_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"futures_request_id" => self.futures_request_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null),
args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"parse_balance_list" => self.parse_balance_list(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_mode" => self.parse_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"request_wallet_history_rows" => self.request_wallet_history_rows(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_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.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_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BtseCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BtseCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BtseCore {
pub fn describe(&self) -> Value {
return self.deep_extend(self.super_describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("btse".into()));
m.insert("name".to_string(), Value::Str("BTSE".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("VG".into())]));
m.insert("rateLimit".to_string(), (match ((Value::Int(1000)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m.insert("version".to_string(), Value::Str("v3".into()));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(false));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("cancelOrdersWithClientOrderId".to_string(), Value::Bool(false));
m.insert("cancelOrderWithClientOrderId".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createLimitBuyOrder".to_string(), Value::Bool(true));
m.insert("createLimitOrder".to_string(), Value::Bool(true));
m.insert("createLimitSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(false));
m.insert("createStopLossOrder".to_string(), Value::Bool(false));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(true));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("deposit".to_string(), Value::Bool(false));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("editOrders".to_string(), Value::Bool(false));
m.insert("editOrderWithClientOrderId".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Bool(false));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(false));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(false));
m.insert("fetchConvertQuote".to_string(), Value::Bool(false));
m.insert("fetchConvertTrade".to_string(), Value::Bool(false));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(false));
m.insert("fetchDeposit".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchL2OrderBook".to_string(), Value::Bool(false));
m.insert("fetchL3OrderBook".to_string(), Value::Bool(false));
m.insert("fetchLastPrices".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(true));
m.insert("fetchMarginModes".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(true));
m.insert("fetchOpenOrder".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(false));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchOrderWithClientOrderId".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTradingLimits".to_string(), Value::Bool(false));
m.insert("fetchTransactionFee".to_string(), Value::Bool(false));
m.insert("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawAddresses".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(false));
m.insert("watchMyLiquidationsForSymbols".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(false));
m.insert("ws".to_string(), Value::Bool(false));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/879ce771-6db1-4d8f-868a-77c9621635dc".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.btse.com".into()));
m.insert("private".to_string(), Value::Str("https://api.btse.com".into()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://testapi.btse.io".into()));
m.insert("private".to_string(), Value::Str("https://testapi.btse.io".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.btse.com".into()));
m.insert("doc".to_string(), Value::Str("https://support.btse.com/en/support/solutions/articles/43000044751-btse-api".into()));
m.insert("referral".to_string(), Value::Str("https://www.btse.com/referral/o2tjIXx5".into()));
m.insert("fees".to_string(), Value::Str("https://support.btse.com/en/support/solutions/articles/43000064283".into()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/market_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/ohlcv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/price".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/orderbook".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/orderbook/L2".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/market_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/ohlcv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/price".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/orderbook".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/orderbook/L2".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/funding_history".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/market/risk_limit".to_string(), Value::Int(5));
m.insert("spot/api/v3.2/availableCurrencyNetworks".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/exchangeRate".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/crypto/networks".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/assets/exchangeRate".to_string(), Value::Int(15));
m.insert("public-api/market/v1/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/exchangeInfo".to_string(), Value::Int(3));
m.insert("public-api/market/v1/orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/ticker/price".to_string(), Value::Int(3));
m.insert("public-api/market/v1/ticker/indices".to_string(), Value::Int(3));
m.insert("public-api/market/v1/ticker/l1".to_string(), Value::Int(3));
m.insert("public-api/market/v1/recentFundingHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/riskLimits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/wallet/v1/crypto/list".to_string(), Value::Int(15));
m.insert("public-api/otc/v1/markets".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/user/open_orders".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/user/trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/user/fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/invest/products".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/orders".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/history".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/user/open_orders".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/user/trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/leverage".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/margin_setting".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/wallet".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/wallet_history".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/unifiedWallet/margin".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/margin".to_string(), Value::Int(5));
m.insert("otc/api/v1/getMarket".to_string(), Value::Int(1));
m.insert("spot/api/v3.2/user/wallet".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("spot/api/v3.2/user/wallet_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("spot/api/v3.3/user/wallet/address".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/availableCurrencies".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/subaccount/wallet/history".to_string(), Value::Int(15));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v4/trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v4/trade/trade_history".to_string(), Value::Int(5));
m.insert("spot/api/v4/trade/fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v3/trade/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/margin_setting".to_string(), Value::Int(5));
m.insert("public-api/wallet/v1/assets".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("public-api/wallet/v1/user/walletHistory".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/crypto/address".to_string(), Value::Int(15));
m.insert("public-api/otc/v1/quotes".to_string(), Value::Int(1));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/order/peg".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/order/cancelAllAfter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v3.3/invest/deposit".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/renew".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/redeem".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order/peg".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order/cancelAllAfter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v2.3/order/close_position".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/leverage".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/settle_in".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/order/bind/tpsl".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/wallet/transfer".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/subaccount/wallet/transfer".to_string(), Value::Int(5));
m.insert("otc/api/v1/quote".to_string(), Value::Int(1));
m.insert("otc/api/v1/accept/{quoteId}".to_string(), Value::Int(1));
m.insert("otc/api/v1/reject/{quoteId}".to_string(), Value::Int(1));
m.insert("otc/api/v1/queryOrder/{quoteId}".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/user/wallet/address".to_string(), Value::Int(15));
m.insert("spot/api/v3.3/user/wallet/withdraw".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/user/wallet/convert".to_string(), Value::Int(15));
m.insert("spot/api/v3.3/user/wallet/transfer".to_string(), Value::Int(15));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v4/trade/orders/cancel_all_after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v4/trade/orders/algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders/cancel_all_after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders/algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/settle_in".to_string(), Value::Int(5));
m.insert("futures/api/v3/trade/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v3/trade/positions/tpsl".to_string(), Value::Int(1));
m.insert("futures/api/v3/trade/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public-api/wallet/v1/user/crypto/address".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/crypto/withdraw".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/assets/sendTo".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/assets/convert".to_string(), Value::Int(15));
m.insert("public-api/otc/v1/quotes".to_string(), Value::Int(1));
m.insert("public-api/otc/v1/quotes/accept".to_string(), Value::Int(1));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/user/wallet/address".to_string(), Value::Int(15));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v4/trade/orders/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/positions".to_string(), Value::Int(1));
m.insert("public-api/wallet/v1/user/crypto/address".to_string(), Value::Int(15));
m
}));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Bool(true));
m.insert("last".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(false));
m
}));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(false));
m
}));
m.insert("price".to_string(), Value::Bool(false));
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("daysBack".to_string(), Value::Null);
m.insert("limit".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOpenOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(300));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Bool(false));
m.insert("last".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("daysBack".to_string(), Value::Null);
m.insert("limit".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOpenOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(300));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("contract".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("contract".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1".into()));
m.insert("5m".to_string(), Value::Str("5".into()));
m.insert("15m".to_string(), Value::Str("15".into()));
m.insert("30m".to_string(), Value::Str("30".into()));
m.insert("1h".to_string(), Value::Str("60".into()));
m.insert("4h".to_string(), Value::Str("240".into()));
m.insert("6h".to_string(), Value::Str("360".into()));
m.insert("1d".to_string(), Value::Str("1440".into()));
m.insert("1w".to_string(), Value::Str("10080".into()));
m.insert("1M".to_string(), Value::Str("43200".into()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0002".into()), &[]));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0002".into()), &[]));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.00055".into()), &[]));
m
}));
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("-2".to_string(), Value::Str("BadRequest".into()));
m.insert("-7".to_string(), Value::Str("AuthenticationError".into()));
m.insert("-7006".to_string(), Value::Str("BadSymbol".into()));
m.insert("-11".to_string(), Value::Str("ExchangeNotAvailable".into()));
m.insert("1".to_string(), Value::Str("ExchangeNotAvailable".into()));
m.insert("8".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("11".to_string(), Value::Str("BadRequest".into()));
m.insert("12".to_string(), Value::Str("BadRequest".into()));
m.insert("13".to_string(), Value::Str("BadRequest".into()));
m.insert("15".to_string(), Value::Str("InvalidOrder".into()));
m.insert("16".to_string(), Value::Str("OrderNotFound".into()));
m.insert("17".to_string(), Value::Str("ExchangeError".into()));
m.insert("28".to_string(), Value::Str("ExchangeError".into()));
m.insert("41".to_string(), Value::Str("BadRequest".into()));
m.insert("64".to_string(), Value::Str("ExchangeError".into()));
m.insert("101".to_string(), Value::Str("InvalidOrder".into()));
m.insert("133".to_string(), Value::Str("InvalidOrder".into()));
m.insert("134".to_string(), Value::Str("BadRequest".into()));
m.insert("135".to_string(), Value::Str("BadRequest".into()));
m.insert("300".to_string(), Value::Str("InvalidOrder".into()));
m.insert("301".to_string(), Value::Str("InvalidOrder".into()));
m.insert("302".to_string(), Value::Str("InvalidOrder".into()));
m.insert("303".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("304".to_string(), Value::Str("InvalidOrder".into()));
m.insert("305".to_string(), Value::Str("InvalidOrder".into()));
m.insert("1003".to_string(), Value::Str("InvalidOrder".into()));
m.insert("1004".to_string(), Value::Str("InvalidOrder".into()));
m.insert("4003".to_string(), Value::Str("InvalidOrder".into()));
m.insert("4005".to_string(), Value::Str("InvalidOrder".into()));
m.insert("4051".to_string(), Value::Str("InvalidOrder".into()));
m.insert("10002".to_string(), Value::Str("AuthenticationError".into()));
m.insert("10010004".to_string(), Value::Str("BadRequest".into()));
m.insert("11000001".to_string(), Value::Str("BadRequest".into()));
m.insert("51523".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("33001001".to_string(), Value::Str("InvalidOrder".into()));
m.insert("33001003".to_string(), Value::Str("InvalidOrder".into()));
m.insert("33199101".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("33199120".to_string(), Value::Str("InvalidOrder".into()));
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Order not found".to_string(), Value::Str("OrderNotFound".into()));
m.insert("Insufficient wallet balance".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("Insufficient balance".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("Authentication Failed".to_string(), Value::Str("AuthenticationError".into()));
m.insert("Authenticate failed".to_string(), Value::Str("AuthenticationError".into()));
m.insert("Signature verification failed".to_string(), Value::Str("AuthenticationError".into()));
m.insert("api parameter is mandatory".to_string(), Value::Str("AuthenticationError".into()));
m.insert("Invalid nonce".to_string(), Value::Str("InvalidNonce".into()));
m.insert("Invalid order size".to_string(), Value::Str("InvalidOrder".into()));
m.insert("Invalid order price".to_string(), Value::Str("InvalidOrder".into()));
m.insert("Maximum open orders exceeded".to_string(), Value::Str("InvalidOrder".into()));
m.insert("Rate limit exceeded".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("auto-deleveraging".to_string(), Value::Str("InvalidOrder".into()));
m.insert("BADREQUEST".to_string(), Value::Str("BadRequest".into()));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("GTC".into()));
m.insert("IOC".to_string(), Value::Str("IOC".into()));
m.insert("FOK".to_string(), Value::Str("FOK".into()));
m.insert("HALFSEC".to_string(), Value::Str("HALFSEC".into()));
m.insert("HALFMIN".to_string(), Value::Str("HALFMIN".into()));
m.insert("FIVEMIN".to_string(), Value::Str("FIVEMIN".into()));
m.insert("HOUR".to_string(), Value::Str("HOUR".into()));
m.insert("TWELVEHOUR".to_string(), Value::Str("TWELVEHOUR".into()));
m.insert("DAY".to_string(), Value::Str("DAY".into()));
m.insert("WEEK".to_string(), Value::Str("WEEK".into()));
m.insert("MONTH".to_string(), Value::Str("MONTH".into()));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
})]);
Value::Null
}
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_spot_api_v33_time(&[params]).await;
return self.safe_timestamp_k(response, "epoch", &[]);
Value::Null
}
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if matches!(self.safe_bool_k(self.options.clone(), "adjustForTimeDifference", &[Value::Bool(false)]), Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut response: Value = self.public_get_public_api_market_v1_markets(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut markets: Value = self.safe_list_k(data, "symbols", &[Value::from(vec![])]);
return self.parse_markets(markets);
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut marketType: Option<String> = self.safe_string_k(market.clone(), "type", &[]).as_str().map(str::to_owned);
let mut isSpot: bool = marketType.as_deref() == Some("Spot");
let mut isFuture: bool = marketType.as_deref() == Some("FuturesTimeBased");
let mut isSwap: bool = marketType.as_deref() == Some("FuturesPerpetual");
let mut id: Option<String> = self.safe_string_k_opt(market.clone(), "symbol", &[]);
let mut baseId: Option<String> = self.safe_string_k_opt(market.clone(), "baseCurrency", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCurrency", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut maxAmountString: Option<String> = self.safe_string_k_opt(market.clone(), "maxOrderSize", &[]);
let mut minAmountString: Option<String> = self.safe_string_k_opt(market.clone(), "minOrderSize", &[]);
let mut minPriceString: Option<String> = self.safe_string_k_opt(market.clone(), "minOrderPrice", &[]);
let mut pricePrecision: Option<String> = self.safe_string_k_opt(market.clone(), "minPriceIncrement", &[]);
let mut amountPrecision: Option<String> = self.safe_string_k_opt(market.clone(), "minSizeIncrement", &[]);
let mut active: Option<bool> = self.safe_bool_k_opt(market.clone(), "active", &[]);
let mut type_var: String = "spot".to_string();
let mut expiry: Value = Value::Null;
let mut contractSize: Value = Value::Null;
if !(isSpot) {
symbol = Value::Str(format!("{}{}", symbol, Value::Str(format!("{}{}", Value::Str(":".into()), quote).into())).into());
contractSize = self.safe_string_k(market.clone(), "contractSize", &[]);
if isFuture {
expiry = self.safe_integer_k(market.clone(), "contractEndTime", &[]);
symbol = Value::Str(format!("{}{}", symbol, Value::Str(format!("{}{}", Value::Str("-".into()), self.yymmdd(expiry.clone(), &[])).into())).into());
type_var = "future".to_string();
} else {
type_var = "swap".to_string();
}
}
let mut fees: Value = self.safe_dict_k(self.fees.clone(), "contract", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if isSpot {
fees = self.safe_dict_k(self.fees.clone(), "spot", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), (if isSpot { Value::Null } else { quote }));
m.insert("baseId".to_string(), baseId.map(Value::from).unwrap_or(Value::Null));
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), (if isSpot { Value::Null } else { quoteId }));
m.insert("type".to_string(), Value::from(type_var));
m.insert("spot".to_string(), Value::Bool(isSpot.clone()));
m.insert("margin".to_string(), (if isSpot { Value::Bool(false) } else { Value::Null }));
m.insert("swap".to_string(), Value::Bool(isSwap.clone()));
m.insert("future".to_string(), Value::Bool(isFuture.clone()));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active.map(Value::Bool).unwrap_or(Value::Null));
m.insert("contract".to_string(), Value::Bool(isSwap || isFuture));
m.insert("linear".to_string(), (if isSpot { Value::Null } else { Value::Bool(true) }));
m.insert("inverse".to_string(), (if isSpot { Value::Null } else { Value::Bool(false) }));
m.insert("taker".to_string(), self.safe_number_k(fees.clone(), "taker", &[]));
m.insert("maker".to_string(), self.safe_number_k(fees, "maker", &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSize, &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(amountPrecision.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("price".to_string(), self.parse_number(pricePrecision.map(Value::from).unwrap_or(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(), self.parse_number(minAmountString.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("max".to_string(), self.parse_number(maxAmountString.map(Value::from).unwrap_or(Value::Null), &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minPriceString.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut maxLimit: Value = Value::Int(300);
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), maxLimit.clone()]).await;
}
let mut market: Value = self.market(symbol);
let mut interval: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("resolution".to_string(), interval);
m
});
if (limit != Value::Null) {
request.insert("limit".into(), crate::runtime::Math::min(&limit, &maxLimit));
} else {
request.insert("limit".into(), maxLimit.clone());
}
if (since != Value::Null) {
request.insert("start".into(), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(paramsPaginate, Value::Str("fetchOHLCV".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
if (since != Value::Null) {
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut maxDelta: Value = (match (&((match (&(duration), &(maxLimit)) { (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(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 }); if ((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().unwrap_or(f64::NAN) < maxDelta.as_f64().unwrap_or(f64::NAN) {
request.insert("end".into(), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
} else {
request.insert("end".into(), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
}
let __ws_arg_0 = self.extend(Value::Map(request), &[paramsUntil]);
let mut response: Value = self.public_get_public_api_market_v1_klines(&[__ws_arg_0]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_ohlc_vs(data, &[market, timeframe, since, limit]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_timestamp(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv, Value::Int(5), &[])]);
Value::Null
}
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("depth".into(), crate::runtime::Math::min(&limit, &Value::Int(50))); }
let __ws_arg_1 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_public_api_market_v1_orderbook(&[__ws_arg_1]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "timestamp", &[]);
return self.parse_order_book(data, market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), &[timestamp, Value::Str("bids".into()), Value::Str("asks".into())]);
Value::Null
}
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
if !matches!(self.safe_bool_k(market.clone(), "contract", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() supports contract markets only".into()))));
}
let mut period: Value = Value::Null;
let mut paramsPeriod: Value = Value::Null;
{ let __destr_tmp: Vec<Value> = self.handle_option_string_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("period".into()), &[]).as_array().cloned().unwrap_or_default(); period = __destr_tmp.get(0).cloned().unwrap_or(Value::Null); paramsPeriod = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }
if (period == Value::Null) {
period = Value::Str("7D".into());
if (since != Value::Null) {
let mut now: Value = self.milliseconds();
let mut twoWeeksAgo: Value = (match (&(now), &(Value::Int(1209600000))) { (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 oneWeekAgo: Value = (match (&(now), &(Value::Int(604800000))) { (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.as_f64().unwrap_or(f64::NAN) < twoWeeksAgo.as_f64().unwrap_or(f64::NAN) {
period = Value::Str("1M".into());
} else if since.as_f64().unwrap_or(f64::NAN) < oneWeekAgo.as_f64().unwrap_or(f64::NAN) {
period = Value::Str("2W".into());
}
}
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("period".to_string(), period);
m
});
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(paramsPeriod, Value::Str("fetchFundingRateHistory".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_2 = self.extend(Value::Map(request), &[paramsUntil]);
let mut response: Value = self.public_get_public_api_market_v1_recent_funding_history(&[__ws_arg_2]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
if (until == Value::Null) {
return self.parse_funding_rate_histories(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
}
let mut rates: Value = self.parse_funding_rate_histories(data, &[market, since, limit]);
let mut result: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_479: bool = true;
while { if !__for_first_479 { i += 1; } __for_first_479 = false; i < (rates.len() as i64) } {
let mut rate: Value = rates.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut timestamp: Value = self.safe_integer_k(rate.clone(), "timestamp", &[]);
if (timestamp == Value::Null) || (timestamp.as_f64().unwrap_or(f64::NAN) <= until.as_f64().unwrap_or(f64::NAN)) {
result.push(rate);
}
}
}
return Value::from(result);
Value::Null
}
pub fn parse_funding_rate_history(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Option<i64> = self.safe_integer_k(contract.clone(), "timestamp", &[]).as_i64();
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(Value::Null, &[market]));
m.insert("fundingRate".to_string(), self.safe_number_k(contract, "rate", &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m
});
Value::Null
}
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let marketTypeparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchBalance".into()), &[Value::Null, params, Value::Str("spot".into())]).as_array().cloned().unwrap_or_default();
let mut marketType: Value = marketTypeparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
let mut walletResponse: Value = self.private_get_public_api_wallet_v1_user_assets(&[paramsMarketType.clone()]).await;
response = self.safe_list_k(walletResponse, "data", &[Value::from(vec![])]);
} else {
let walletparamsWalletVariable: Vec<Value> = self.handle_option_string_and_params(paramsMarketType, Value::Str("fetchBalance".into()), Value::Str("wallet".into()), &[Value::Str("CROSS@".into())]).as_array().cloned().unwrap_or_default();
let mut wallet: Value = walletparamsWalletVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsWallet: Value = walletparamsWalletVariable.get(1).cloned().unwrap_or(Value::Null);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("wallet".to_string(), wallet);
m
});
let __ws_arg_3 = self.extend(Value::Map(request), &[paramsWallet]);
response = self.private_get_futures_api_v23_user_wallet(&[__ws_arg_3]).await;
}
return self.parse_balance_list(response);
Value::Null
}
pub fn parse_balance_list(&self, mut response: Value) -> Value {
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut totals: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut frees: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut useds: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_482: bool = true;
while { if !__for_first_482 { i += 1; } __for_first_482 = false; i < (response.len() as i64) } {
let mut row: Value = self.safe_dict(response.clone(), Value::Int(i), &[]);
let mut assets: Value = self.safe_list_k(row.clone(), "assets", &[]);
if (assets != Value::Null) {
let mut inUse: Value = self.safe_list_k(row.clone(), "assetsInUse", &[Value::from(vec![])]);
{
let mut j: i64 = 0;
let mut __for_first_480: bool = true;
while { if !__for_first_480 { j += 1; } __for_first_480 = false; j < (inUse.len() as i64) } {
let mut usedRow: Value = self.safe_dict(inUse.clone(), Value::Int(j), &[]);
let mut usedCode: Value = self.safe_currency_code(self.safe_string_k(usedRow.clone(), "currency", &[]), &[]);
if (usedCode == Value::Null) {
continue;
}
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(Value::Map(useds.clone()), usedCode.clone(), &[Value::Str("0".into())]), &self.safe_string_k(usedRow, "balance", &[])); useds.insert(crate::runtime::stringify_param(&usedCode), __be_tmp); }
}
}
{
let mut j: i64 = 0;
let mut __for_first_481: bool = true;
while { if !__for_first_481 { j += 1; } __for_first_481 = false; j < (assets.len() as i64) } {
let mut assetRow: Value = self.safe_dict(assets.clone(), Value::Int(j), &[]);
let mut code: Value = self.safe_currency_code(self.safe_string_k(assetRow.clone(), "currency", &[]), &[]);
if (code == Value::Null) {
continue;
}
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(Value::Map(totals.clone()), code.clone(), &[Value::Str("0".into())]), &self.safe_string_k(assetRow, "balance", &[])); totals.insert(crate::runtime::stringify_param(&code), __be_tmp); }
{ let __be_tmp = self.safe_string(Value::Map(useds.clone()), code.clone(), &[Value::Str("0".into())]); useds.insert(crate::runtime::stringify_param(&code), __be_tmp); }
}
}
} else {
let mut code: Value = self.safe_currency_code(self.safe_string2(row.clone(), Value::Str("asset".into()), Value::Str("currency".into()), &[]), &[]);
if (code == Value::Null) {
continue;
}
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(Value::Map(totals.clone()), code.clone(), &[Value::Str("0".into())]), &self.safe_string2(row.clone(), Value::Str("totalAmount".into()), Value::Str("total".into()), &[])); totals.insert(crate::runtime::stringify_param(&code), __be_tmp); }
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(Value::Map(frees.clone()), code.clone(), &[Value::Str("0".into())]), &self.safe_string2(row, Value::Str("availableAmount".into()), Value::Str("available".into()), &[])); frees.insert(crate::runtime::stringify_param(&code), __be_tmp); }
}
}
}
let mut codes: Vec<Value> = Value::Array(totals.keys().map(|__k| Value::Str(__k.clone().into())).collect()).as_array().cloned().unwrap_or_default();
{
let mut i: i64 = 0;
let mut __for_first_483: bool = true;
while { if !__for_first_483 { i += 1; } __for_first_483 = false; i < (codes.len() as i64) } {
let mut code: Value = codes.get(i as usize).cloned().unwrap_or(Value::Null);
let mut account: indexmap::IndexMap<String, Value> = self.account().as_map().cloned().unwrap_or_default();
account.insert("total".into(), self.safe_string(Value::Map(totals.clone()), code.clone(), &[]));
account.insert("free".into(), self.safe_string(Value::Map(frees.clone()), code.clone(), &[]));
account.insert("used".into(), self.safe_string(Value::Map(useds.clone()), code.clone(), &[]));
result.insert(crate::runtime::stringify_param(&code), Value::Map(account));
}
}
return self.safe_balance(Value::Map(result));
Value::Null
}
pub async fn fetch_leverage_tiers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (symbolsNormalized != Value::Null) {
let mut length: f64 = ((symbolsNormalized.len() as i64) as f64);
if (length == 1.0) {
let mut requestedSymbol: Option<String> = self.safe_string_opt(symbolsNormalized.clone(), Value::Int(0), &[]);
let mut market: Value = self.market(requestedSymbol.map(Value::from).unwrap_or(Value::Null));
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
}
let __ws_arg_4 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_public_api_market_v1_risk_limits(&[__ws_arg_4]).await;
let mut single: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![single])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_485: bool = true;
while { if !__for_first_485 { i += 1; } __for_first_485 = false; i < (data.len() as i64) } {
let mut entry: Value = self.safe_dict(data.clone(), Value::Int(i), &[]);
let mut marketId: Option<String> = self.safe_string_k_opt(entry.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone().map(Value::from).unwrap_or(Value::Null)]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if (symbolsNormalized == Value::Null) || self.in_array(symbol.clone(), symbolsNormalized.clone()).as_bool() == Some(true) {
let mut levels: Vec<Value> = self.safe_list_k(entry, "riskLimits", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut tiers: Value = Value::from(vec![]);
let mut minNotional: Value = Value::Null;
{
let mut j: Value = Value::Int(0);
let mut __for_first_484: bool = true;
while { if !__for_first_484 { if let Value::Int(n) = &mut j { *n += 1; } } __for_first_484 = false; j.as_f64().unwrap_or(f64::NAN) < ((levels.len() as i64) as f64) } {
let mut level: Value = levels.get(j.as_i64().unwrap_or(-1) as usize).cloned().unwrap_or(Value::Null);
let mut maxNotional: Value = self.safe_number_k(level.clone(), "value", &[]);
if let Value::Arr(__a) = &mut tiers { std::sync::Arc::make_mut(__a).push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_integer_k(level.clone(), "level", &[]));
m.insert("symbol".to_string(), symbol.clone());
m.insert("currency".to_string(), market.as_map().and_then(|__m| __m.get("settle")).cloned().unwrap_or(Value::Null));
m.insert("minNotional".to_string(), (if (j.as_f64() == Some(0.0)) { Value::Int(0) } else { minNotional.clone() }));
m.insert("maxNotional".to_string(), maxNotional.clone());
m.insert("maintenanceMarginRate".to_string(), Value::Null);
m.insert("maxLeverage".to_string(), Value::Null);
m.insert("info".to_string(), level);
m
})); }
minNotional = maxNotional;
}
}
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), tiers); }; }
}
}
return result;
Value::Null
}
pub async fn fetch_market_leverage_tiers(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !matches!(self.safe_bool_k(market, "contract", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchMarketLeverageTiers() supports contract markets only".into()))));
}
let mut result: Value = self.fetch_leverage_tiers(&[Value::from(vec![symbol.clone()]), params]).await;
let mut tiers: Value = self.safe_list(result, symbol, &[]);
return tiers;
Value::Null
}
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols, Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("type".into()), &[]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[paramsOmitted]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_tickers(data, &[symbolsNormalized]);
Value::Null
}
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_5 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[__ws_arg_5]).await;
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut data: Value = self.safe_dict_k(response, "data", &[self.safe_dict(rows, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})])]);
return self.parse_ticker(data, &[market]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(ticker.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone().map(Value::from).unwrap_or(Value::Null), market]);
let mut last: Option<String> = self.safe_string_k_opt(ticker.clone(), "lastPrice", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "amount", &[]);
if (baseVolume != Value::Null) && (marketResolved != Value::Null) && matches!((self.safe_bool_k(marketResolved.clone(), "contract", &[Value::Bool(false)])), Value::Bool(true)) {
let mut contractSizeString: Value = self.number_to_string(marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null));
if (contractSizeString != Value::Null) {
baseVolume = crate::precise::Precise::stringMul(&baseVolume, &contractSizeString);
}
}
let mut timestamp: Value = self.safe_timestamp_k(ticker.clone(), "closeTime", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[marketResolved.clone()]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "highPrice", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "lowPrice", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "bidPrice", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bidQty", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "askPrice", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "askQty", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "openPrice", &[]));
m.insert("close".to_string(), last.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("last".to_string(), last.map(Value::from).unwrap_or(Value::Null));
m.insert("previousClose".to_string(), self.safe_string_k(ticker.clone(), "prevClosePrice", &[]));
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "priceChange", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume);
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "volume", &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if matches!(self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenInterest() symbol does not support market ".into())).into()), symbol)));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_6 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[__ws_arg_6]).await;
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut interest: Value = self.safe_dict_k(response, "data", &[self.safe_dict(rows, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})])]);
return self.parse_open_interest(interest, &[market]);
Value::Null
}
pub async fn fetch_open_interests(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[params]).await;
let mut data: Vec<Value> = self.safe_list_k(response, "data", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut rows: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_486: bool = true;
while { if !__for_first_486 { i += 1; } __for_first_486 = false; i < (data.len() as i64) } {
let mut row: Value = data.get(i as usize).cloned().unwrap_or(Value::Null);
if (self.safe_string_k(row.clone(), "openInterest", &[]) != Value::Null) {
rows.push(row);
}
}
}
return self.parse_open_interests(Value::from(rows), &[symbolsNormalized]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(interest.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut timestamp: Value = self.safe_timestamp_k(interest.clone(), "closeTime", &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("openInterestAmount".to_string(), self.safe_number_k(interest.clone(), "openInterest", &[]));
m.insert("openInterestValue".to_string(), self.safe_number_k(interest.clone(), "openInterestUSD", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("info".to_string(), interest);
m
}), &[marketResolved]);
Value::Null
}
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
if matches!(self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate() symbol does not support spot markets".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_7 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[__ws_arg_7]).await;
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut data: Value = self.safe_dict_k(response, "data", &[self.safe_dict(rows, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})])]);
return self.parse_funding_rate(data, &[market]);
Value::Null
}
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[params]).await;
let mut data: Vec<Value> = self.safe_list_k(response, "data", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut rows: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_487: bool = true;
while { if !__for_first_487 { i += 1; } __for_first_487 = false; i < (data.len() as i64) } {
let mut row: Value = data.get(i as usize).cloned().unwrap_or(Value::Null);
if (self.safe_string_k(row.clone(), "fundingRate", &[]) != Value::Null) {
rows.push(row);
}
}
}
return self.parse_funding_rates(Value::from(rows), &[symbolsNormalized]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(contract.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut timestamp: Value = self.safe_timestamp_k(contract.clone(), "closeTime", &[]);
let mut nextFundingTimestamp: Value = self.safe_integer_omit_zero(contract.clone(), Value::Str("nextFundingTime".into()), &[]);
let mut fundingIntervalMinutes: Value = self.safe_integer_k(contract.clone(), "fundingIntervalMinutes", &[]);
let mut interval: Value = Value::Null;
if (fundingIntervalMinutes != Value::Null) && (fundingIntervalMinutes.as_f64().unwrap_or(f64::NAN) >= ((60i64) as f64)) {
let mut hours: Value = self.parse_to_int((match ((fundingIntervalMinutes).as_f64(), (Value::Int(60)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
interval = Value::Str(format!("{}{}", Value::Str(format!("{}", hours).into()), Value::Str("h".into())).into());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("fundingRate".to_string(), self.safe_number_k(contract, "fundingRate", &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), interval);
m
});
Value::Null
}
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(500))); }
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(params, Value::Str("fetchTrades".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_8 = self.extend(Value::Map(request), &[paramsUntil]);
let mut response: Value = self.public_get_public_api_market_v1_trades(&[__ws_arg_8]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
if (until == Value::Null) {
return self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
}
let mut trades: Value = self.parse_trades(data, &[market, since, limit]);
let mut result: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_488: bool = true;
while { if !__for_first_488 { i += 1; } __for_first_488 = false; i < (trades.len() as i64) } {
let mut trade: Value = trades.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
if (timestamp == Value::Null) || (timestamp.as_f64().unwrap_or(f64::NAN) <= until.as_f64().unwrap_or(f64::NAN)) {
result.push(trade);
}
}
}
return Value::from(result);
Value::Null
}
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut paginate: bool = self.safe_bool_k_opt(params.clone(), "paginate", &[Value::Bool(false)]).unwrap_or(false);
if paginate {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), self.omit(params.clone(), Value::Str("paginate".into()), &[])]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbol != Value::Null) {
market = self.market(symbol.clone());
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[])); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("count".into(), limit.clone()); }
}
let mut paramsUntil: Value = Value::Null;
{ let __destr_tmp: Vec<Value> = self.handle_until_option(Value::Str("endTime".into()), request.clone(), params, &[]).as_array().cloned().unwrap_or_default(); request = __destr_tmp.get(0).cloned().unwrap_or(Value::Null); paramsUntil = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }
let marketTypeparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchMyTrades".into()), &[market.clone(), paramsUntil, Value::Str("spot".into())]).as_array().cloned().unwrap_or_default();
let mut marketType: Value = marketTypeparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() requires a symbol argument for spot markets".into()))));
}
let __ws_arg_9 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_get_spot_api_v4_trade_trade_history(&[__ws_arg_9]).await;
} else {
request = self.omit(request.clone(), Value::Str("count".into()), &[]);
if (symbol != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), self.futures_request_id(self.market(symbol))); }
}
let __ws_arg_10 = self.extend(request, &[paramsMarketType]);
response = self.private_get_futures_api_v3_trade_trade_history(&[__ws_arg_10]).await;
}
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
return self.parse_trades(rows, &[market, since, limit]);
Value::Null
}
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut clientOrderId: Option<String> = self.safe_string_k_opt(params.clone(), "clientOrderId", &[]);
if (clientOrderId.is_none()) && (id == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderTrades() requires an id argument or a clientOrderId parameter".into()))));
}
let mut orderIdParams: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (clientOrderId.is_none()) {
orderIdParams = ({
let mut m = indexmap::IndexMap::new();
m.insert("orderID".to_string(), id);
m
});
} else {
orderIdParams = ({
let mut m = indexmap::IndexMap::new();
m.insert("clOrderID".to_string(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
m
});
}
let __ws_arg_11 = self.extend(params, &[Value::Map(orderIdParams)]);
return self.fetch_my_trades(&[symbol, since, limit, __ws_arg_11]).await;
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("positionId".into()), Value::Str("symbol".into()), &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut timestamp: Option<i64> = self.safe_integer_k(trade.clone(), "timestamp", &[]).as_i64();
let mut fee: Value = Value::Null;
let mut feeCost: Value = self.safe_number_k(trade.clone(), "feeAmount", &[]);
if (feeCost != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost);
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(trade.clone(), "feeCurrency", &[]), &[]));
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("id".to_string(), self.safe_string_n(trade.clone(), Value::from(vec![Value::Str("tradeId".into()), Value::Str("serialId".into()), Value::Str("id".into())]), &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("type".to_string(), self.parse_order_type(self.safe_string2(trade.clone(), Value::Str("orderType".into()), Value::Str("type".into()), &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("side".to_string(), self.safe_string_lower2(trade.clone(), Value::Str("side".into()), Value::Str("orderSide".into()), &[]));
m.insert("takerOrMaker".to_string(), Value::Null);
m.insert("price".to_string(), self.safe_string_n(trade.clone(), Value::from(vec![Value::Str("filledPrice".into()), Value::Str("avgFilledPrice".into()), Value::Str("price".into())]), &[]));
m.insert("amount".to_string(), self.safe_string2(trade, Value::Str("filledSize".into()), Value::Str("size".into()), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m
}), &[marketResolved]);
Value::Null
}
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if matches!(self.safe_bool_k(market, "spot", &[Value::Bool(false)]), Value::Bool(true)) {
return self.create_spot_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else {
return self.create_contract_order(symbol, type_var, side, amount, &[price, params]).await;
}
Value::Null
}
pub async fn create_spot_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut typeValue: Value = (if let Some(__s) = type_var.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
let mut upperSide: Value = (if let Some(__s) = side.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("orderSide".to_string(), upperSide.clone());
m
});
let mut clientOrderId: Option<String> = self.safe_string_k_opt(params.clone(), "clientOrderId", &[]);
if (clientOrderId.is_some()) {
request.insert("clOrderId".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
}
let mut query: Value = self.omit(params, Value::Str("clientOrderId".into()), &[]);
let mut isMarketOrder: Value = (Value::Bool(typeValue.as_str() == Some("MARKET")));
let mut isLimitOrder: bool = typeValue.as_str() == Some("LIMIT");
let mut postOnly: Value = Value::Bool(false);
{ let __destr_tmp: Vec<Value> = self.handle_post_only(isMarketOrder.clone(), postOnly.clone(), &[query.clone()]).as_array().cloned().unwrap_or_default(); postOnly = __destr_tmp.get(0).cloned().unwrap_or(Value::Null); query = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }; if postOnly.as_bool() == Some(true) {
request.insert("postOnly".into(), Value::Bool(true));
}
let mut timeInForce: Value = self.handle_time_in_force(&[query.clone()]);
if (timeInForce != Value::Null) {
request.insert("timeInForce".into(), timeInForce);
}
let mut triggerPrice: Option<String> = self.safe_string_k_opt(query.clone(), "triggerPrice", &[]);
let mut takeProfitPrice: Option<String> = self.safe_string_k_opt(query.clone(), "takeProfitPrice", &[]);
let mut stopLossPrice: Option<String> = self.safe_string_k_opt(query.clone(), "stopLossPrice", &[]);
let mut isTriggerOrder: bool = (triggerPrice.is_some()) || (takeProfitPrice.is_some());
let mut isStopLossOrder: bool = stopLossPrice.is_some();
let mut isConditionalOrder: bool = (isTriggerOrder || isStopLossOrder) && (matches!(&isMarketOrder, Value::Bool(true)) || isLimitOrder);
let mut isAlgoOrder: bool = isConditionalOrder || (!(matches!(&isMarketOrder, Value::Bool(true))) && !isLimitOrder);
if isLimitOrder || (typeValue.as_str() == Some("PEG")) || (typeValue.as_str() == Some("OCO")) {
if (price == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a price argument for ".into())).into()), typeValue).into()), Value::Str(" orders".into()))));
}
}
let mut needsQuoteSize: bool = (matches!(&isMarketOrder, Value::Bool(true)) || (typeValue.as_str() == Some("TRAILING"))) && (upperSide.as_str() == Some("BUY"));
if needsQuoteSize {
let mut quoteAmount: Value = Value::Null;
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp: Vec<Value> = self.handle_option_bool_and_params(query.clone(), Value::Str("createOrder".into()), Value::Str("createMarketBuyOrderRequiresPrice".into()), &[Value::Bool(true)]).as_array().cloned().unwrap_or_default(); createMarketBuyOrderRequiresPrice = __destr_tmp.get(0).cloned().unwrap_or(Value::Null); query = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }
let mut cost: Option<String> = self.safe_string_k_opt(query.clone(), "cost", &[]);
query = self.omit(query.clone(), Value::Str("cost".into()), &[]);
if (cost.is_some()) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost.map(Value::from).unwrap_or(Value::Null));
} else if createMarketBuyOrderRequiresPrice.as_bool() == Some(true) {
if (price == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend, alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument".into()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
quoteAmount = self.cost_to_precision(symbol.clone(), crate::precise::Precise::stringMul(&amountString, &priceString));
}
} else {
quoteAmount = self.cost_to_precision(symbol.clone(), self.number_to_string(amount.clone()));
}
request.insert("quoteOrderSize".into(), quoteAmount);
} else {
request.insert("orderSize".into(), self.amount_to_precision(symbol.clone(), amount));
}
let mut response: Value = Value::Null;
if !isAlgoOrder {
request.insert("orderType".into(), typeValue.clone());
if isLimitOrder {
request.insert("orderPrice".into(), self.price_to_precision(symbol.clone(), price.clone()));
}
let __ws_arg_12 = self.extend(Value::Map(request.clone()), &[query.clone()]);
response = self.private_post_spot_api_v4_trade_orders(&[__ws_arg_12]).await;
} else {
if isConditionalOrder {
request.insert("orderType".into(), Value::Str("CONDITIONAL".into()));
let mut triggerOrderType: Value = Value::Null;
let mut triggerPriceToSend: Value = Value::Null;
if isStopLossOrder {
triggerOrderType = Value::Str("STOP_LOSS".into());
if isLimitOrder {
triggerOrderType = Value::Str("STOP_LOSS_LIMIT".into());
}
triggerPriceToSend = stopLossPrice.map(Value::from).unwrap_or(Value::Null);
} else {
triggerOrderType = Value::Str("TAKE_PROFIT".into());
if isLimitOrder {
triggerOrderType = Value::Str("TAKE_PROFIT_LIMIT".into());
}
triggerPriceToSend = triggerPrice.clone().map(Value::from).unwrap_or(Value::Null);
if (triggerPriceToSend == Value::Null) {
triggerPriceToSend = takeProfitPrice.map(Value::from).unwrap_or(Value::Null);
}
}
if isLimitOrder {
request.insert("orderPrice".into(), self.price_to_precision(symbol.clone(), price.clone()));
}
request.insert("triggerOrderType".into(), triggerOrderType);
request.insert("triggerPrice".into(), self.price_to_precision(symbol.clone(), triggerPriceToSend));
let mut triggerPriceType: Value = self.safe_string_k(query.clone(), "triggerPriceType", &[Value::Str("last".into())]);
request.insert("triggerPriceType".into(), self.encode_trigger_price_type(triggerPriceType.clone()).map(Value::from).unwrap_or(Value::Null));
query = self.omit(query.clone(), Value::from(vec![Value::Str("triggerPrice".into()), Value::Str("takeProfitPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("triggerPriceType".into())]), &[]);
} else {
request.insert("orderType".into(), typeValue.clone());
if (typeValue.as_str() == Some("OCO")) {
request.insert("takeProfitOrderPrice".into(), self.price_to_precision(symbol.clone(), price.clone()));
let mut stopPrice: Option<String> = self.safe_string_k_opt(query.clone(), "stopPrice", &[]);
if (stopPrice.is_some()) {
request.insert("stopLossOrderPrice".into(), self.price_to_precision(symbol.clone(), stopPrice.map(Value::from).unwrap_or(Value::Null)));
}
if (triggerPrice.is_some()) {
request.insert("stopLossTriggerPrice".into(), self.price_to_precision(symbol.clone(), triggerPrice.map(Value::from).unwrap_or(Value::Null)));
}
let mut triggerPriceType: Value = self.safe_string_k(query.clone(), "triggerPriceType", &[Value::Str("last".into())]);
request.insert("stopLossTriggerPriceType".into(), self.encode_trigger_price_type(triggerPriceType.clone()).map(Value::from).unwrap_or(Value::Null));
query = self.omit(query.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("triggerPriceType".into())]), &[]);
} else if (typeValue.as_str() == Some("PEG")) {
request.insert("orderPrice".into(), self.price_to_precision(symbol.clone(), price));
} else if (typeValue.as_str() == Some("TRAILING")) {
let mut trailingAmount: Option<String> = self.safe_string_k_opt(query.clone(), "trailingAmount", &[]);
let mut trailingPercent: Option<String> = self.safe_string_k_opt(query.clone(), "trailingPercent", &[]);
if (trailingAmount.is_some()) {
request.insert("trailValue".into(), self.price_to_precision(symbol, trailingAmount.map(Value::from).unwrap_or(Value::Null)));
request.insert("trailValueType".into(), Value::Str("DISTANCE".into()));
} else if (trailingPercent.is_some()) {
request.insert("trailValue".into(), trailingPercent.map(Value::from).unwrap_or(Value::Null));
request.insert("trailValueType".into(), Value::Str("PERCENTAGE".into()));
}
let mut triggerPriceType: Value = self.safe_string_k(query.clone(), "triggerPriceType", &[Value::Str("last".into())]);
request.insert("triggerPriceType".into(), self.encode_trigger_price_type(triggerPriceType).map(Value::from).unwrap_or(Value::Null));
query = self.omit(query.clone(), Value::from(vec![Value::Str("trailingAmount".into()), Value::Str("trailingPercent".into()), Value::Str("triggerPriceType".into())]), &[]);
}
}
let __ws_arg_13 = self.extend(Value::Map(request), &[query]);
response = self.private_post_spot_api_v4_trade_orders_algo(&[__ws_arg_13]).await;
}
let mut order: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[market]);
Value::Null
}
pub async fn create_contract_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut typeValue: Value = (if let Some(__s) = type_var.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m.insert("orderSide".to_string(), (if let Some(__s) = side.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }));
m.insert("orderSize".to_string(), self.amount_to_precision(symbol.clone(), amount));
m
});
let mut clientOrderId: Option<String> = self.safe_string_k_opt(params.clone(), "clientOrderId", &[]);
if (clientOrderId.is_some()) {
request.insert("clOrderId".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
}
let mut query: Value = self.omit(params, Value::Str("clientOrderId".into()), &[]);
let mut positionMode: Option<String> = self.safe_string_k(query.clone(), "positionMode", &[]).as_str().map(str::to_owned);
if (positionMode.is_none()) {
let mut hedged: Value = Value::Bool(false);
{ let __destr_tmp: Vec<Value> = self.handle_option_bool_and_params(query.clone(), Value::Str("createOrder".into()), Value::Str("hedged".into()), &[hedged.clone()]).as_array().cloned().unwrap_or_default(); hedged = __destr_tmp.get(0).cloned().unwrap_or(Value::Null); query = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }
let mut marginMode: Value = Value::Str("cross".into());
{ let __destr_tmp: Vec<Value> = self.handle_option_string_and_params(query.clone(), Value::Str("createOrder".into()), Value::Str("marginMode".into()), &[marginMode.clone()]).as_array().cloned().unwrap_or_default(); marginMode = __destr_tmp.get(0).cloned().unwrap_or(Value::Null); query = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }
if (marginMode.as_str() == Some("isolated")) {
if hedged.as_bool() == Some(true) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" createOrder() cannot use isolated margin with hedged positions".into()))));
}
request.insert("positionMode".into(), Value::Str("ISOLATED".into()));
} else if hedged.as_bool() == Some(true) {
request.insert("positionMode".into(), Value::Str("HEDGE".into()));
}
}
let mut isMarketOrder: Value = (Value::Bool(typeValue.as_str() == Some("MARKET")));
let mut isLimitOrder: bool = typeValue.as_str() == Some("LIMIT");
let mut postOnly: Value = Value::Bool(false);
{ let __destr_tmp: Vec<Value> = self.handle_post_only(isMarketOrder.clone(), postOnly.clone(), &[query.clone()]).as_array().cloned().unwrap_or_default(); postOnly = __destr_tmp.get(0).cloned().unwrap_or(Value::Null); query = __destr_tmp.get(1).cloned().unwrap_or(Value::Null); }; if postOnly.as_bool() == Some(true) {
request.insert("postOnly".into(), Value::Bool(true));
}
let mut timeInForce: Value = self.handle_time_in_force(&[query.clone()]);
if (timeInForce != Value::Null) {
request.insert("timeInForce".into(), timeInForce);
}
let mut triggerPrice: Option<String> = self.safe_string_k_opt(query.clone(), "triggerPrice", &[]);
let mut takeProfitPrice: Option<String> = self.safe_string_k_opt(query.clone(), "takeProfitPrice", &[]);
let mut stopLossPrice: Option<String> = self.safe_string_k_opt(query.clone(), "stopLossPrice", &[]);
let mut isTriggerOrder: bool = (triggerPrice.is_some()) || (takeProfitPrice.is_some());
let mut isStopLossOrder: bool = stopLossPrice.is_some();
let mut isConditionalOrder: bool = (isTriggerOrder || isStopLossOrder) && (matches!(&isMarketOrder, Value::Bool(true)) || isLimitOrder);
let mut isAlgoOrder: bool = isConditionalOrder || (!(matches!(&isMarketOrder, Value::Bool(true))) && !isLimitOrder);
if isLimitOrder || (typeValue.as_str() == Some("OCO")) {
if (price == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a price argument for ".into())).into()), typeValue).into()), Value::Str(" orders".into()))));
}
}
let mut takeProfit: Value = self.safe_dict_k(query.clone(), "takeProfit", &[]);
let mut stopLoss: Value = self.safe_dict_k(query.clone(), "stopLoss", &[]);
if (takeProfit != Value::Null) || (stopLoss != Value::Null) {
let mut takeProfitTriggerPrice: Option<String> = self.safe_string_k_opt(takeProfit.clone(), "triggerPrice", &[]);
let mut stopLossTriggerPrice: Option<String> = self.safe_string_k_opt(stopLoss.clone(), "triggerPrice", &[]);
if (takeProfitTriggerPrice.is_some()) {
request.insert("takeProfitTriggerPrice".into(), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.map(Value::from).unwrap_or(Value::Null)));
let mut takeProfitTriggerPriceType: Option<String> = self.safe_string_k_opt(takeProfit, "priceType", &[]);
if (takeProfitTriggerPriceType.is_some()) {
request.insert("takeProfitTriggerType".into(), self.encode_trigger_price_type(takeProfitTriggerPriceType.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
}
}
if (stopLossTriggerPrice.is_some()) {
request.insert("stopLossTriggerPrice".into(), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.map(Value::from).unwrap_or(Value::Null)));
let mut stopLossTriggerPriceType: Option<String> = self.safe_string_k_opt(stopLoss, "priceType", &[]);
if (stopLossTriggerPriceType.is_some()) {
request.insert("stopLossTriggerType".into(), self.encode_trigger_price_type(stopLossTriggerPriceType.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
}
}
query = self.omit(query.clone(), Value::from(vec![Value::Str("takeProfit".into()), Value::Str("stopLoss".into())]), &[]);
}
let mut response: Value = Value::Null;
if !isAlgoOrder {
request.insert("orderType".into(), typeValue.clone());
if isLimitOrder {
request.insert("orderPrice".into(), self.price_to_precision(symbol.clone(), price.clone()));
}
let __ws_arg_14 = self.extend(Value::Map(request.clone()), &[query.clone()]);
response = self.private_post_futures_api_v3_trade_orders(&[__ws_arg_14]).await;
} else {
if isConditionalOrder {
request.insert("orderType".into(), Value::Str("CONDITIONAL".into()));
let mut triggerPriceToSend: Value = triggerPrice.clone().map(Value::from).unwrap_or(Value::Null);
if (triggerPriceToSend == Value::Null) {
triggerPriceToSend = takeProfitPrice.map(Value::from).unwrap_or(Value::Null);
}
if (triggerPriceToSend == Value::Null) {
triggerPriceToSend = stopLossPrice.map(Value::from).unwrap_or(Value::Null);
}
request.insert("triggerPrice".into(), self.price_to_precision(symbol.clone(), triggerPriceToSend));
let mut triggerPriceType: Value = self.safe_string_k(query.clone(), "triggerPriceType", &[Value::Str("mark".into())]);
request.insert("triggerType".into(), self.encode_trigger_price_type(triggerPriceType.clone()).map(Value::from).unwrap_or(Value::Null));
if isLimitOrder {
request.insert("orderPrice".into(), self.price_to_precision(symbol.clone(), price.clone()));
}
query = self.omit(query.clone(), Value::from(vec![Value::Str("triggerPrice".into()), Value::Str("takeProfitPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("triggerPriceType".into())]), &[]);
} else {
request.insert("orderType".into(), typeValue.clone());
if (typeValue.as_str() == Some("OCO")) {
request.insert("takeProfitOrderPrice".into(), self.price_to_precision(symbol.clone(), price.clone()));
let mut stopPrice: Option<String> = self.safe_string_k_opt(query.clone(), "stopPrice", &[]);
if (stopPrice.is_some()) {
request.insert("stopLossOrderPrice".into(), self.price_to_precision(symbol.clone(), stopPrice.map(Value::from).unwrap_or(Value::Null)));
}
if (triggerPrice.is_some()) {
request.insert("stopLossTriggerPrice".into(), self.price_to_precision(symbol.clone(), triggerPrice.map(Value::from).unwrap_or(Value::Null)));
}
let mut triggerPriceType: Value = self.safe_string_k(query.clone(), "triggerPriceType", &[Value::Str("mark".into())]);
request.insert("stopLossTriggerType".into(), self.encode_trigger_price_type(triggerPriceType.clone()).map(Value::from).unwrap_or(Value::Null));
query = self.omit(query.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("triggerPriceType".into())]), &[]);
} else if (typeValue.as_str() == Some("PEG")) {
if (price != Value::Null) {
request.insert("orderPrice".into(), self.price_to_precision(symbol.clone(), price));
}
} else if (typeValue.as_str() == Some("TRAILING")) {
let mut trailingAmount: Option<String> = self.safe_string_k_opt(query.clone(), "trailingAmount", &[]);
let mut trailingPercent: Option<String> = self.safe_string_k_opt(query.clone(), "trailingPercent", &[]);
if (trailingAmount.is_some()) {
request.insert("trailValue".into(), self.price_to_precision(symbol, trailingAmount.map(Value::from).unwrap_or(Value::Null)));
request.insert("trailValueType".into(), Value::Str("DISTANCE".into()));
} else if (trailingPercent.is_some()) {
request.insert("trailValue".into(), trailingPercent.map(Value::from).unwrap_or(Value::Null));
request.insert("trailValueType".into(), Value::Str("PERCENTAGE".into()));
}
let mut triggerPriceType: Value = self.safe_string_k(query.clone(), "triggerPriceType", &[Value::Str("mark".into())]);
request.insert("trailTriggerPriceType".into(), self.encode_trigger_price_type(triggerPriceType).map(Value::from).unwrap_or(Value::Null));
query = self.omit(query.clone(), Value::from(vec![Value::Str("trailingAmount".into()), Value::Str("trailingPercent".into()), Value::Str("triggerPriceType".into())]), &[]);
}
}
let __ws_arg_15 = self.extend(Value::Map(request), &[query]);
response = self.private_post_futures_api_v3_trade_orders_algo(&[__ws_arg_15]).await;
}
let mut order: Value = response.clone();
if (matches!(&response, Value::Arr(_))) {
order = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_order(order, &[market]);
Value::Null
}
pub fn encode_trigger_price_type(&self, mut priceType: Value) -> Option<String> {
let mut priceTypes: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Str("LAST_PRICE".into()));
m.insert("mark".to_string(), Value::Str("MARK_PRICE".into()));
m.insert("index".to_string(), Value::Str("INDEX_PRICE".into()));
m.insert("lastPrice".to_string(), Value::Str("LAST_PRICE".into()));
m.insert("markPrice".to_string(), Value::Str("MARK_PRICE".into()));
m.insert("indexPrice".to_string(), Value::Str("INDEX_PRICE".into()));
m
});
return self.safe_string(Value::Map(priceTypes), priceType.clone(), &[priceType.clone()]).as_str().map(str::to_owned);
}
pub async fn fetch_open_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Option<String> = self.safe_string_k_opt(params.clone(), "clientOrderId", &[]);
if (clientOrderId.is_some()) {
request.insert("clOrderId".into(), clientOrderId.clone().map(Value::from).unwrap_or(Value::Null));
} else if (id == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenOrder() requires an id argument or a clientOrderId parameter".into()))));
} else {
request.insert("orderId".into(), id);
}
let mut paramsOmitted: Value = (if (clientOrderId.is_some()) { self.omit(params.clone(), Value::Str("clientOrderId".into()), &[]) } else { params });
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let marketTypeparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchOrder".into()), &[market.clone(), paramsOmitted, Value::Str("spot".into())]).as_array().cloned().unwrap_or_default();
let mut marketType: Value = marketTypeparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
let __ws_arg_16 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.private_get_spot_api_v4_trade_order(&[__ws_arg_16]).await;
} else {
let __ws_arg_17 = self.extend(Value::Map(request), &[paramsMarketType]);
response = self.private_get_futures_api_v3_trade_orders(&[__ws_arg_17]).await;
}
let mut order: Value = self.safe_value_k(response.clone(), "data", &[response.clone()]);
if (matches!(&order, Value::Arr(_))) {
order = self.safe_dict(order.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_order(order, &[market]);
Value::Null
}
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Option<String> = self.safe_string_k_opt(params.clone(), "clientOrderId", &[]);
if (clientOrderId.is_some()) {
request.insert("clOrderId".into(), clientOrderId.clone().map(Value::from).unwrap_or(Value::Null));
} else if (id == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" editOrder() requires an id argument or a clientOrderId parameter".into()))));
} else {
request.insert("orderId".into(), id.clone());
}
let mut paramsOmitted: Value = (if (clientOrderId.is_some()) { self.omit(params.clone(), Value::Str("clientOrderId".into()), &[]) } else { params });
let mut triggerPrice: Option<String> = self.safe_string_k_opt(paramsOmitted.clone(), "triggerPrice", &[]);
if (triggerPrice.is_some()) {
request.insert("triggerPrice".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone().map(Value::from).unwrap_or(Value::Null)));
}
let mut query: Value = (if (triggerPrice.is_some()) { self.omit(paramsOmitted.clone(), Value::Str("triggerPrice".into()), &[]) } else { paramsOmitted });
if (amount != Value::Null) {
request.insert("orderSize".into(), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if (price != Value::Null) {
request.insert("orderPrice".into(), self.price_to_precision(symbol, price.clone()));
}
let mut isSlide: bool = self.safe_bool_k_opt(query.clone(), "slide", &[Value::Bool(false)]).unwrap_or(false);
if (amount == Value::Null) && (price == Value::Null) && (triggerPrice.is_none()) && (!(isSlide)) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" editOrder() requires an amount argument, a price argument or a triggerPrice parameter".into()))));
}
let mut response: Value = Value::Null;
if matches!(self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]), Value::Bool(true)) {
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_18 = self.extend(Value::Map(request.clone()), &[query.clone()]);
response = self.private_put_spot_api_v4_trade_orders(&[__ws_arg_18]).await;
} else {
request.insert("symbol".into(), self.futures_request_id(market.clone()));
if (triggerPrice.is_some()) {
if (amount != Value::Null) || (price != Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" editOrder() can not amend the trigger price together with the price or the amount on contract markets".into()))));
}
request.insert("amendType".into(), Value::Str("TRIGGER_PRICE".into()));
} else if (amount != Value::Null) && (price != Value::Null) {
request.insert("amendType".into(), Value::Str("ALL".into()));
} else if (amount != Value::Null) {
request.insert("amendType".into(), Value::Str("SIZE".into()));
} else {
request.insert("amendType".into(), Value::Str("PRICE".into()));
}
let __ws_arg_19 = self.extend(Value::Map(request), &[query]);
response = self.private_put_futures_api_v3_trade_orders(&[__ws_arg_19]).await;
}
let mut order: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[market]);
Value::Null
}
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() requires a symbol argument".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Option<String> = self.safe_string_k_opt(params.clone(), "clientOrderId", &[]);
if (clientOrderId.is_some()) {
request.insert("clOrderId".into(), clientOrderId.clone().map(Value::from).unwrap_or(Value::Null));
} else if (id == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() requires an id argument or a clientOrderId parameter".into()))));
} else {
request.insert("orderId".into(), id);
}
let mut paramsOmitted: Value = (if (clientOrderId.is_some()) { self.omit(params.clone(), Value::Str("clientOrderId".into()), &[]) } else { params });
let mut response: Value = Value::Null;
if matches!(self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]), Value::Bool(true)) {
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_20 = self.extend(Value::Map(request.clone()), &[paramsOmitted.clone()]);
response = self.private_delete_spot_api_v4_trade_orders(&[__ws_arg_20]).await;
} else {
request.insert("symbol".into(), self.futures_request_id(market.clone()));
let __ws_arg_21 = self.extend(Value::Map(request), &[paramsOmitted]);
response = self.private_delete_futures_api_v3_trade_orders(&[__ws_arg_21]).await;
}
let mut order: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order, &[market]);
Value::Null
}
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: String = "spot".to_string();
let marketTypeOptionparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("cancelAllOrders".into()), &[market.clone(), params, Value::from(marketType)]).as_array().cloned().unwrap_or_default();
let mut marketTypeOption: Value = marketTypeOptionparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeOptionparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if (marketTypeOption.as_str() == Some("spot")) {
request.insert("symbol".into(), Value::Str("ALL".into()));
if (symbol != Value::Null) {
request.insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[]));
}
let __ws_arg_22 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.private_delete_spot_api_v4_trade_orders_all(&[__ws_arg_22]).await;
} else {
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() requires a symbol argument for contract markets".into()))));
}
request.insert("symbol".into(), self.futures_request_id(self.market(symbol)));
let __ws_arg_23 = self.extend(Value::Map(request), &[paramsMarketType]);
response = self.private_delete_futures_api_v23_order(&[__ws_arg_23]).await;
}
return self.parse_orders(response, &[market]);
Value::Null
}
pub async fn cancel_all_orders_after(&mut self, mut timeout: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut marketType: String = "spot".to_string();
let marketTypeOptionparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("cancelAllOrdersAfter".into()), &[Value::Null, params, Value::from(marketType)]).as_array().cloned().unwrap_or_default();
let mut marketTypeOption: Value = marketTypeOptionparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeOptionparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
if (marketTypeOption.as_str() == Some("spot")) {
request.insert("timeout".into(), timeout.clone());
let __ws_arg_24 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.private_post_spot_api_v4_trade_orders_cancel_all_after(&[__ws_arg_24]).await;
} else {
request.insert("timeoutMs".into(), timeout);
let __ws_arg_25 = self.extend(Value::Map(request), &[paramsMarketType]);
response = self.private_post_futures_api_v3_trade_orders_cancel_all_after(&[__ws_arg_25]).await;
}
return response;
Value::Null
}
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: String = "spot".to_string();
let marketTypeOptionparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".into()), &[market.clone(), params, Value::from(marketType)]).as_array().cloned().unwrap_or_default();
let mut marketTypeOption: Value = marketTypeOptionparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeOptionparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketTypeOption.as_str() == Some("spot")) {
if (symbol != Value::Null) {
request.insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[]));
}
let __ws_arg_26 = self.extend(Value::Map(request.clone()), &[paramsMarketType.clone()]);
response = self.private_get_spot_api_v4_trade_orders(&[__ws_arg_26]).await;
} else {
if (symbol != Value::Null) {
request.insert("symbol".into(), self.futures_request_id(self.market(symbol)));
}
let __ws_arg_27 = self.extend(Value::Map(request), &[paramsMarketType]);
response = self.private_get_futures_api_v3_trade_orders(&[__ws_arg_27]).await;
}
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
return self.parse_orders(rows, &[market, since, limit]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("symbol".into()), Value::Str("market".into()), &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut timestamp: Option<i64> = self.safe_integer_k(order.clone(), "timestamp", &[]).as_i64();
let mut rawStatus: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("status".into()), Value::Str("orderState".into()), &[]);
let mut rawType: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("orderType".into()), Value::Str("type".into()), &[]);
let mut status: Value = self.parse_order_status(rawStatus.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null);
let mut orderType: Value = self.parse_order_type(rawType.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null);
if (orderType.as_str() == Some("market")) && (status.as_str() == Some("open")) {
status = Value::Str("closed".into());
}
let mut rawTimeInForce: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("time_in_force".into()), Value::Str("timeInForce".into()), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string2(order.clone(), Value::Str("orderID".into()), Value::Str("orderId".into()), &[]));
m.insert("clientOrderId".to_string(), self.safe_string2(order.clone(), Value::Str("clOrderID".into()), Value::Str("clOrderId".into()), &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("status".to_string(), status);
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), orderType);
m.insert("timeInForce".to_string(), self.parse_time_in_force(rawTimeInForce.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("postOnly".to_string(), self.safe_bool_k(order.clone(), "postOnly", &[]));
m.insert("reduceOnly".to_string(), self.safe_bool_k(order.clone(), "reduceOnly", &[]));
m.insert("side".to_string(), self.safe_string_lower2(order.clone(), Value::Str("side".into()), Value::Str("orderSide".into()), &[]));
m.insert("price".to_string(), self.safe_string2(order.clone(), Value::Str("price".into()), Value::Str("orderPrice".into()), &[]));
m.insert("triggerPrice".to_string(), self.omit_zero(self.safe_string2(order.clone(), Value::Str("triggerOriginalPrice".into()), Value::Str("triggerPrice".into()), &[])));
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_string_n(order.clone(), Value::from(vec![Value::Str("currentOrderBaseSize".into()), Value::Str("currentOrderSize".into()), Value::Str("orderSize".into())]), &[]));
m.insert("filled".to_string(), self.safe_string_n(order.clone(), Value::from(vec![Value::Str("totalFilledBaseSize".into()), Value::Str("totalFilledSize".into()), Value::Str("filledSize".into())]), &[]));
m.insert("remaining".to_string(), self.safe_string2(order.clone(), Value::Str("remainingOrderBaseSize".into()), Value::Str("remainingSize".into()), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("average".to_string(), self.omit_zero(self.safe_string2(order, Value::Str("avgFilledPrice".into()), Value::Str("averageFillPrice".into()), &[])));
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("2".to_string(), Value::Str("open".into()));
m.insert("3".to_string(), Value::Str("closed".into()));
m.insert("4".to_string(), Value::Str("closed".into()));
m.insert("5".to_string(), Value::Str("open".into()));
m.insert("6".to_string(), Value::Str("canceled".into()));
m.insert("7".to_string(), Value::Str("refunded".into()));
m.insert("8".to_string(), Value::Str("rejected".into()));
m.insert("9".to_string(), Value::Str("open".into()));
m.insert("10".to_string(), Value::Str("open".into()));
m.insert("15".to_string(), Value::Str("rejected".into()));
m.insert("16".to_string(), Value::Str("rejected".into()));
m.insert("17".to_string(), Value::Str("rejected".into()));
m.insert("123".to_string(), Value::Str("open".into()));
m.insert("STATUS_ACTIVE".to_string(), Value::Str("open".into()));
m.insert("STATUS_INACTIVE".to_string(), Value::Str("canceled".into()));
m.insert("ORDER_INSERTED".to_string(), Value::Str("open".into()));
m.insert("ORDER_PARTIALLY_TRANSACTED".to_string(), Value::Str("open".into()));
m.insert("ORDER_FULLY_TRANSACTED".to_string(), Value::Str("closed".into()));
m.insert("ORDER_CANCELLED".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_order_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("76".to_string(), Value::Str("limit".into()));
m.insert("77".to_string(), Value::Str("market".into()));
m.insert("80".to_string(), Value::Str("limit".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Option<String> {
let mut values: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("GTC".into()));
m.insert("IOC".to_string(), Value::Str("IOC".into()));
m.insert("FOK".to_string(), Value::Str("FOK".into()));
m.insert("HALFSEC".to_string(), Value::Str("GTD".into()));
m.insert("HALFMIN".to_string(), Value::Str("GTD".into()));
m.insert("FIVEMIN".to_string(), Value::Str("GTD".into()));
m.insert("HOUR".to_string(), Value::Str("GTD".into()));
m.insert("TWELVEHOUR".to_string(), Value::Str("GTD".into()));
m.insert("DAY".to_string(), Value::Str("GTD".into()));
m.insert("WEEK".to_string(), Value::Str("GTD".into()));
m.insert("MONTH".to_string(), Value::Str("GTD".into()));
m
});
return self.safe_string(Value::Map(values), timeInForce.clone(), &[timeInForce.clone()]).as_str().map(str::to_owned);
}
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut response: Value = Value::Null;
let mut marketType: String = "spot".to_string();
let marketTypeOptionparamsMarketTypeVariable: Vec<Value> = self.handle_market_type_and_params(Value::Str("fetchTradingFees".into()), &[Value::Null, params, Value::from(marketType.clone())]).as_array().cloned().unwrap_or_default();
let mut marketTypeOption: Value = marketTypeOptionparamsMarketTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeOptionparamsMarketTypeVariable.get(1).cloned().unwrap_or(Value::Null);
if (marketTypeOption.as_str() == Some("spot")) {
response = self.private_get_spot_api_v4_trade_fees(&[paramsMarketType.clone()]).await;
} else {
response = self.private_get_futures_api_v23_user_fees(&[paramsMarketType]).await;
}
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
let mut responseList: Value = self.array_concat(Value::from(vec![]), rows);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_489: bool = true;
while { if !__for_first_489 { i += 1; } __for_first_489 = false; i < (responseList.len() as i64) } {
let mut feeInfo: Value = self.safe_dict(responseList.clone(), Value::Int(i), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Option<String> = self.safe_string_k_opt(feeInfo.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null)]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut makerFee: Value = self.safe_number_k(feeInfo.clone(), "makerFee", &[]);
let mut takerFee: Value = self.safe_number_k(feeInfo.clone(), "takerFee", &[]);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), feeInfo);
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), makerFee);
m.insert("taker".to_string(), takerFee);
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
})); }
}
}
return result;
Value::Null
}
pub async fn request_wallet_history_rows(&mut self, mut methodName: Value, mut historyTypes: Value, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut typesList: Value = self.safe_list(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("types".to_string(), historyTypes);
m
}), Value::Str("types".into()), &[Value::from(vec![])]);
self.load_markets(&[]).await;
let mut walletType: Value = self.safe_string_k(params.clone(), "walletType", &[Value::Str("SPOT".into())]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("walletType".to_string(), walletType.clone());
m
});
request.insert("historyTypes".into(), json_stringify(&typesList));
let mut paramsOmitted: Value = self.omit(params, Value::Str("walletType".into()), &[]);
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
request.insert("asset".into(), self.safe_string_k(currency.clone(), "id", &[]));
} else if (walletType.as_str() == Some("SPOT")) {
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 code argument for the spot wallet history".into()))));
}
if (since != Value::Null) {
request.insert("startTime".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("pageSize".into(), limit.clone());
}
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(paramsOmitted, methodName, Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
request.insert("endTime".into(), until);
}
let __ws_arg_28 = self.extend(Value::Map(request), &[paramsUntil]);
let mut response: Value = self.private_get_public_api_wallet_v1_user_wallet_history(&[__ws_arg_28]).await;
let mut rawRows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
let mut allowed: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_490: bool = true;
while { if !__for_first_490 { i += 1; } __for_first_490 = false; i < (typesList.len() as i64) } {
let mut historyType: Value = self.safe_string(typesList.clone(), Value::Int(i), &[Value::Str("".into())]);
if let Value::Dict(__d) = &mut allowed { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&historyType), Value::Bool(true)); }
add_element_to_object(&mut allowed, &self.capitalize((if let Some(__s) = historyType.as_str() { Value::Str(__s.to_lowercase().into()) } else { Value::Null })), Value::Bool(true));
}
}
let mut rows: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_491: bool = true;
while { if !__for_first_491 { i += 1; } __for_first_491 = false; i < (rawRows.len() as i64) } {
let mut entry: Value = self.safe_dict(rawRows.clone(), Value::Int(i), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut type_var: Value = self.safe_string_k(entry.clone(), "type", &[Value::Str("".into())]);
if (matches!((&allowed, &type_var), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
rows.push(entry);
}
}
}
return self.parse_transactions(Value::from(rows), &[currency, since, limit]);
Value::Null
}
pub async fn fetch_deposits_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.request_wallet_history_rows(Value::Str("fetchDepositsWithdrawals".into()), Value::from(vec![Value::Str("DEPOSIT".into()), Value::Str("WITHDRAW".into())]), &[code, since, limit, params]).await;
Value::Null
}
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.request_wallet_history_rows(Value::Str("fetchDeposits".into()), Value::from(vec![Value::Str("DEPOSIT".into())]), &[code, since, limit, params]).await;
Value::Null
}
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.request_wallet_history_rows(Value::Str("fetchWithdrawals".into()), Value::from(vec![Value::Str("WITHDRAW".into())]), &[code, since, limit, params]).await;
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyId: Option<String> = self.safe_string2_opt(transaction.clone(), Value::Str("currency".into()), Value::Str("asset".into()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]);
let mut timestamp: Option<i64> = self.safe_integer2(transaction.clone(), Value::Str("timestamp".into()), Value::Str("transactionTime".into()), &[]).as_i64();
let mut networkId: Option<String> = self.safe_string2_opt(transaction.clone(), Value::Str("currencyNetwork".into()), Value::Str("cryptoNetwork".into()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string2(transaction.clone(), Value::Str("orderId".into()), Value::Str("transactionRef".into()), &[]));
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "txId", &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("network".to_string(), self.network_id_to_code(&[networkId.map(Value::from).unwrap_or(Value::Null), code.clone()]));
m.insert("address".to_string(), self.safe_string_k(transaction.clone(), "toAddress", &[]));
m.insert("addressTo".to_string(), self.safe_string_k(transaction.clone(), "toAddress", &[]));
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_transaction_type(self.safe_string_k(transaction.clone(), "type", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("updated".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), self.safe_string_k(transaction.clone(), "description", &[]));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("cost".to_string(), self.safe_number2(transaction, Value::Str("fees".into()), Value::Str("fee".into()), &[]));
m
}));
m
});
Value::Null
}
pub fn parse_transaction_type(&self, mut type_var: Value) -> Option<String> {
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("Deposit".to_string(), Value::Str("deposit".into()));
m.insert("Withdraw".to_string(), Value::Str("withdrawal".into()));
m.insert("DEPOSIT".to_string(), Value::Str("deposit".into()));
m.insert("WITHDRAW".to_string(), Value::Str("withdrawal".into()));
m
});
return self.safe_string(Value::Map(types), type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_transaction_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("PROCESSING".to_string(), Value::Str("pending".into()));
m.insert("PENDING".to_string(), Value::Str("pending".into()));
m.insert("COMPLETED".to_string(), Value::Str("ok".into()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".into()));
m.insert("EXPIRED".to_string(), Value::Str("canceled".into()));
m.insert("FAILURE".to_string(), Value::Str("failed".into()));
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut walletType: Value = self.safe_string_k(params.clone(), "walletType", &[Value::Str("SPOT".into())]);
request.insert("walletType".into(), walletType.clone());
let mut paramsOmitted: Value = self.omit(params, Value::Str("walletType".into()), &[]);
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
request.insert("asset".into(), self.safe_string_k(currency.clone(), "id", &[]));
} else if (walletType.as_str() == Some("SPOT")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchLedger() requires a code argument for the spot wallet history".into()))));
}
if (since != Value::Null) {
request.insert("startTime".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("pageSize".into(), limit.clone());
}
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(paramsOmitted, Value::Str("fetchLedger".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
request.insert("endTime".into(), until);
}
let __ws_arg_29 = self.extend(Value::Map(request), &[paramsUntil]);
let mut response: Value = self.private_get_public_api_wallet_v1_user_wallet_history(&[__ws_arg_29]).await;
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
return self.parse_ledger(rows, &[currency, since, limit]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyId: Option<String> = self.safe_string2_opt(item.clone(), Value::Str("currency".into()), Value::Str("asset".into()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]);
let mut timestamp: Option<i64> = self.safe_integer2(item.clone(), Value::Str("timestamp".into()), Value::Str("transactionTime".into()), &[]).as_i64();
let mut type_var: Option<String> = self.safe_string_k_opt(item.clone(), "type", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string2(item.clone(), Value::Str("orderId".into()), Value::Str("transactionRef".into()), &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("direction".to_string(), self.parse_ledger_entry_direction(type_var.clone().map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("account".to_string(), self.safe_string2(item.clone(), Value::Str("wallet".into()), Value::Str("walletName".into()), &[]));
m.insert("referenceId".to_string(), self.safe_string_k(item.clone(), "txId", &[]));
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_ledger_entry_type(type_var.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.safe_number_k(item.clone(), "amount", &[]));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(item.clone(), "status", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("cost".to_string(), self.safe_number2(item, Value::Str("fees".into()), Value::Str("fee".into()), &[]));
m
}));
m
});
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Option<String> {
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("Deposit".to_string(), Value::Str("transaction".into()));
m.insert("Withdraw".to_string(), Value::Str("transaction".into()));
m.insert("Convert fiat".to_string(), Value::Str("trade".into()));
m.insert("Transfer_Out".to_string(), Value::Str("transfer".into()));
m.insert("Transfer_In".to_string(), Value::Str("transfer".into()));
m.insert("ReferralEarning".to_string(), Value::Str("referral".into()));
m.insert("Sub Account Transfer In".to_string(), Value::Str("transfer".into()));
m.insert("Sub Account Transfer Out".to_string(), Value::Str("transfer".into()));
m.insert("express buy".to_string(), Value::Str("trade".into()));
m.insert("spot trading fee rebate".to_string(), Value::Str("rebate".into()));
m.insert("futures trading fee rebate".to_string(), Value::Str("rebate".into()));
m.insert("general trading fee rebate".to_string(), Value::Str("rebate".into()));
m.insert("DEPOSIT".to_string(), Value::Str("transaction".into()));
m.insert("WITHDRAW".to_string(), Value::Str("transaction".into()));
m.insert("CONVERT".to_string(), Value::Str("trade".into()));
m.insert("ASSET_CONVERSION".to_string(), Value::Str("trade".into()));
m.insert("SEND".to_string(), Value::Str("transfer".into()));
m.insert("RECEIVE".to_string(), Value::Str("transfer".into()));
m.insert("REFERRAL".to_string(), Value::Str("referral".into()));
m.insert("TRANSFER_IN".to_string(), Value::Str("transfer".into()));
m.insert("TRANSFER_OUT".to_string(), Value::Str("transfer".into()));
m.insert("SUB_ACCOUNT_TRANSFER_IN".to_string(), Value::Str("transfer".into()));
m.insert("SUB_ACCOUNT_TRANSFER_OUT".to_string(), Value::Str("transfer".into()));
m.insert("REALIZED_PNL".to_string(), Value::Str("trade".into()));
m.insert("FUNDING".to_string(), Value::Str("fee".into()));
m
});
return self.safe_string(Value::Map(types), type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_ledger_entry_direction(&self, mut type_var: Value) -> Option<String> {
let mut directions: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("Deposit".to_string(), Value::Str("in".into()));
m.insert("Withdraw".to_string(), Value::Str("out".into()));
m.insert("Transfer_Out".to_string(), Value::Str("out".into()));
m.insert("Transfer_In".to_string(), Value::Str("in".into()));
m.insert("ReferralEarning".to_string(), Value::Str("in".into()));
m.insert("Sub Account Transfer In".to_string(), Value::Str("in".into()));
m.insert("Sub Account Transfer Out".to_string(), Value::Str("out".into()));
m.insert("spot trading fee rebate".to_string(), Value::Str("in".into()));
m.insert("futures trading fee rebate".to_string(), Value::Str("in".into()));
m.insert("general trading fee rebate".to_string(), Value::Str("in".into()));
m.insert("trial fund".to_string(), Value::Str("in".into()));
m.insert("token voucher in".to_string(), Value::Str("in".into()));
m.insert("token voucher out".to_string(), Value::Str("out".into()));
m.insert("Strategy Income".to_string(), Value::Str("in".into()));
m.insert("Strategy Pay".to_string(), Value::Str("out".into()));
m.insert("DEPOSIT".to_string(), Value::Str("in".into()));
m.insert("WITHDRAW".to_string(), Value::Str("out".into()));
m.insert("RECEIVE".to_string(), Value::Str("in".into()));
m.insert("SEND".to_string(), Value::Str("out".into()));
m.insert("REFERRAL".to_string(), Value::Str("in".into()));
m.insert("GET_PAID".to_string(), Value::Str("in".into()));
m.insert("PAID".to_string(), Value::Str("out".into()));
m.insert("TRANSFER_IN".to_string(), Value::Str("in".into()));
m.insert("TRANSFER_OUT".to_string(), Value::Str("out".into()));
m.insert("SUB_ACCOUNT_TRANSFER_IN".to_string(), Value::Str("in".into()));
m.insert("SUB_ACCOUNT_TRANSFER_OUT".to_string(), Value::Str("out".into()));
m.insert("INVEST".to_string(), Value::Str("out".into()));
m.insert("REDEEM".to_string(), Value::Str("in".into()));
m
});
return self.safe_string(Value::Map(directions), type_var, &[]).as_str().map(str::to_owned);
}
pub async fn fetch_trading_fee(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut response: Value = Value::Null;
if matches!(self.safe_bool_k(market, "spot", &[Value::Bool(false)]), Value::Bool(true)) {
let __ws_arg_30 = self.extend(Value::Map(request.clone()), &[params.clone()]);
response = self.private_get_spot_api_v4_trade_fees(&[__ws_arg_30]).await;
} else {
let __ws_arg_31 = self.extend(Value::Map(request), &[params]);
response = self.private_get_futures_api_v23_user_fees(&[__ws_arg_31]).await;
}
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
let mut feeInfo: Value = self.safe_dict(rows, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut makerFee: Value = self.safe_number_k(feeInfo.clone(), "makerFee", &[]);
let mut takerFee: Value = self.safe_number_k(feeInfo.clone(), "takerFee", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), feeInfo);
m.insert("symbol".to_string(), symbol);
m.insert("maker".to_string(), makerFee);
m.insert("taker".to_string(), takerFee);
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.private_get_futures_api_v3_trade_positions(&[params]).await;
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
return self.parse_positions(rows, &[symbolsNormalized]);
Value::Null
}
pub async fn fetch_positions_for_symbol(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let __ws_arg_32 = self.futures_request_id(market);
let mut paramsExtended: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), __ws_arg_32);
m
}), &[params]);
return self.fetch_positions(&[Value::from(vec![symbol]), paramsExtended]).await;
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(position.clone(), "positionId", &[]);
if (marketId.is_some()) {
let mut parts: Value = Value::Array(if let Some(__s) = marketId.as_deref() { __s.split("|").map(Value::from).collect() } else { Vec::new() });
marketId = self.safe_string_opt(parts, Value::Int(0), &[]);
} else {
marketId = self.safe_string_k_opt(position.clone(), "symbol", &[]);
}
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut timestamp: Option<i64> = self.safe_integer_k(position.clone(), "timestamp", &[]).as_i64();
let mut marginType: Option<String> = self.safe_string_k_opt(position.clone(), "marginType", &[]);
let mut side: Value = self.safe_string_lower2(position.clone(), Value::Str("positionDirection".into()), Value::Str("side".into()), &[]);
let mut positionMode: Option<String> = self.safe_string_k(position.clone(), "positionMode", &[]).as_str().map(str::to_owned);
let mut hedged: Value = Value::Bool((positionMode.as_deref() == Some("HEDGE")) || (positionMode.as_deref() == Some("ISOLATED")));
let mut takeProfitOrder: Value = self.safe_dict_k(position.clone(), "takeProfitOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut takeProfitPrice: Option<String> = self.safe_string_k_opt(takeProfitOrder, "triggerPrice", &[]);
let mut stopLossOrder: Value = self.safe_dict_k(position.clone(), "stopLossOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut stopLossPrice: Option<String> = self.safe_string_k_opt(stopLossOrder, "triggerPrice", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_k(position.clone(), "positionId", &[]));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("entryPrice".to_string(), self.parse_number(self.safe_string_k(position.clone(), "entryPrice", &[]), &[]));
m.insert("markPrice".to_string(), self.parse_number(self.safe_string_k(position.clone(), "markPrice", &[]), &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), self.parse_number(takeProfitPrice.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("stopLossPrice".to_string(), self.parse_number(stopLossPrice.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("notional".to_string(), self.parse_number(self.safe_string2(position.clone(), Value::Str("notionalValue".into()), Value::Str("orderValue".into()), &[]), &[]));
m.insert("collateral".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), self.parse_number(self.safe_string_k(position.clone(), "unrealizedProfitLoss", &[]), &[]));
m.insert("realizedPnl".to_string(), Value::Null);
m.insert("side".to_string(), self.parse_position_side(side).map(Value::from).unwrap_or(Value::Null));
m.insert("contracts".to_string(), self.parse_number(self.safe_string_k(position.clone(), "size", &[]), &[]));
m.insert("contractSize".to_string(), self.parse_number(self.safe_string_k(position.clone(), "contractSize", &[]), &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("hedged".to_string(), hedged);
m.insert("maintenanceMargin".to_string(), self.parse_number(self.safe_string_k(position.clone(), "totalMaintenanceMargin", &[]), &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.parse_number(self.safe_string_k(position.clone(), "currentLeverage", &[]), &[]));
m.insert("liquidationPrice".to_string(), self.parse_number(self.safe_string_k(position, "liquidationPrice", &[]), &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("marginMode".to_string(), self.parse_margin_mode_type(marginType.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("percentage".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn parse_margin_mode_type(&self, mut marginMode: Value) -> Option<String> {
let mut marginModes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("91".to_string(), Value::Str("cross".into()));
m.insert("92".to_string(), Value::Str("isolated".into()));
m.insert("CROSS".to_string(), Value::Str("cross".into()));
m.insert("ISOLATED".to_string(), Value::Str("isolated".into()));
m
});
return self.safe_string(marginModes, marginMode.clone(), &[marginMode.clone()]).as_str().map(str::to_owned);
}
pub fn parse_position_side(&self, mut side: Value) -> Option<String> {
let mut sides: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("buy".to_string(), Value::Str("long".into()));
m.insert("sell".to_string(), Value::Str("short".into()));
m
});
return self.safe_string(Value::Map(sides), side.clone(), &[side.clone()]).as_str().map(str::to_owned);
}
pub async fn fetch_position_mode(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionMode() requires a symbol argument".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market));
m
});
let __ws_arg_33 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_get_futures_api_v3_trade_position_mode(&[__ws_arg_33]).await;
let mut data: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positionMode: Option<String> = self.safe_string_k(data.clone(), "positionMode", &[]).as_str().map(str::to_owned);
let mut hedged: Value = Value::Bool((positionMode.as_deref() == Some("HEDGE")) || (positionMode.as_deref() == Some("ISOLATED")));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data);
m.insert("hedged".to_string(), hedged);
m
});
Value::Null
}
pub async fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setPositionMode() requires a symbol argument".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut positionMode: String = "ONE_WAY".to_string();
if hedged.as_bool() == Some(true) {
positionMode = "HEDGE".to_string();
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market));
m.insert("positionMode".to_string(), Value::from(positionMode));
m
});
let __ws_arg_34 = self.extend(Value::Map(request), &[params]);
return self.private_post_futures_api_v3_trade_position_mode(&[__ws_arg_34]).await;
Value::Null
}
pub async fn fetch_margin_mode(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m
});
let __ws_arg_35 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_get_futures_api_v3_trade_leverage(&[__ws_arg_35]).await;
let mut data: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_mode(data, &[market]);
Value::Null
}
pub fn parse_margin_mode(&self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(marginMode.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut positionMode: Option<String> = self.safe_string_lower_k(marginMode.clone(), "marginMode", &[]).as_str().map(str::to_owned);
let mut marginModeValue: String = "cross".to_string();
if (positionMode.as_deref() == Some("isolated")) {
marginModeValue = "isolated".to_string();
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), marginMode);
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("marginMode".to_string(), Value::from(marginModeValue));
m
});
Value::Null
}
pub async fn set_margin_mode(&mut self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() requires a symbol argument".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut marginModeValue: Value = (if let Some(__s) = marginMode.as_str() { Value::Str(__s.to_lowercase().into()) } else { Value::Null });
let mut positionMode: String = "ONE_WAY".to_string();
if (marginModeValue.as_str() != Some("cross")) && (marginModeValue.as_str() != Some("isolated")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() marginMode argument should be either cross or isolated".into()))));
}
let mut hedged: bool = self.safe_bool_k_opt(params.clone(), "hedged", &[Value::Bool(false)]).unwrap_or(false);
if (marginModeValue.as_str() == Some("cross")) {
if !(matches!(¶ms, Value::Dict(__d) if __d.contains_key("hedged"))) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() requires a hedged parameter for cross margin mode".into()))));
} else if hedged {
positionMode = "HEDGE".to_string();
}
} else if (matches!(¶ms, Value::Dict(__d) if __d.contains_key("hedged"))) && !(hedged) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() hedged parameter cannot be false for isolated margin mode".into()))));
} else {
positionMode = "ISOLATED".to_string();
}
let mut paramsOmitted: Value = self.omit(params, Value::Str("hedged".into()), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market));
m.insert("positionMode".to_string(), Value::from(positionMode));
m
});
let __ws_arg_36 = self.extend(Value::Map(request), &[paramsOmitted]);
return self.private_post_futures_api_v3_trade_position_mode(&[__ws_arg_36]).await;
Value::Null
}
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut positionId: Option<String> = self.safe_string_k(params.clone(), "positionId", &[]).as_str().map(str::to_owned);
if (positionId.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" closePosition() requires a positionId parameter".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m
});
let orderTypeparamsOrderTypeVariable: Vec<Value> = self.handle_option_string_and_params(params, Value::Str("closePosition".into()), Value::Str("type".into()), &[Value::Str("market".into())]).as_array().cloned().unwrap_or_default();
let mut orderType: Value = orderTypeparamsOrderTypeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsOrderType: Value = orderTypeparamsOrderTypeVariable.get(1).cloned().unwrap_or(Value::Null);
let mut typeUpper: Value = (if let Some(__s) = orderType.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
request.insert("orderType".into(), typeUpper.clone());
if (typeUpper.as_str() == Some("LIMIT")) {
let mut price: Option<String> = self.safe_string_k_opt(paramsOrderType.clone(), "price", &[]);
if (price.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" closePosition() requires a price parameter for limit orders".into()))));
}
request.insert("orderPrice".into(), self.price_to_precision(symbol, price.map(Value::from).unwrap_or(Value::Null)));
}
let mut paramsOmitted: Value = (if (typeUpper.as_str() == Some("LIMIT")) { self.omit(paramsOrderType.clone(), Value::Str("price".into()), &[]) } else { paramsOrderType });
let __ws_arg_37 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.private_delete_futures_api_v3_trade_positions(&[__ws_arg_37]).await;
let mut order: Value = self.safe_dict(response.clone(), Value::Int(0), &[response]);
return self.parse_order(order, &[market]);
Value::Null
}
pub async fn fetch_leverage(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market));
m
});
let __ws_arg_38 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_get_futures_api_v3_trade_leverage(&[__ws_arg_38]).await;
let mut safeResponse: Value = Value::from(vec![]);
if (matches!(&response, Value::Arr(_))) {
safeResponse = response.clone();
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m.insert("symbol".to_string(), symbol);
m
});
let mut longLeverage: Value = Value::Null;
let mut shortLeverage: Value = Value::Null;
let mut marginMode: Value = Value::Null;
{
let mut i: i64 = 0;
let mut __for_first_492: bool = true;
while { if !__for_first_492 { i += 1; } __for_first_492 = false; i < (safeResponse.len() as i64) } {
let mut entrty: Value = self.safe_dict(safeResponse.clone(), Value::Int(i), &[]);
let mut leverageValue: Value = self.safe_integer_k(entrty.clone(), "leverage", &[]);
let mut positionDirection: Option<String> = self.safe_string_k(entrty.clone(), "positionDirection", &[]).as_str().map(str::to_owned);
marginMode = self.safe_string_lower_k(entrty, "marginMode", &[]);
if (positionDirection.as_deref() == Some("LONG")) {
longLeverage = leverageValue.clone();
} else if (positionDirection.as_deref() == Some("SHORT")) {
shortLeverage = leverageValue.clone();
} else if (positionDirection.is_none()) {
longLeverage = leverageValue.clone();
shortLeverage = leverageValue;
}
}
}
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("marginMode".into(), marginMode); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("longLeverage".into(), longLeverage); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("shortLeverage".into(), shortLeverage); }
return result;
Value::Null
}
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market));
m.insert("leverage".to_string(), leverage);
m
});
let marginModeparamsMarginModeVariable: Vec<Value> = self.handle_margin_mode_and_params(Value::Str("setLeverage".into()), &[params]).as_array().cloned().unwrap_or_default();
let mut marginMode: Value = marginModeparamsMarginModeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.get(1).cloned().unwrap_or(Value::Null);
if (marginMode != Value::Null) {
request.insert("marginMode".into(), (if let Some(__s) = marginMode.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }));
}
let __ws_arg_39 = self.extend(Value::Map(request), &[paramsMarginMode]);
let mut response: Value = self.private_post_futures_api_v3_trade_leverage(&[__ws_arg_39]).await;
return response;
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) || (response == Value::Null) {
return Value::Null;
}
let mut success: bool = self.safe_bool_k_opt(response.clone(), "success", &[Value::Bool(true)]).unwrap_or(true);
if !(success) {
let mut spotErrorCode: Option<String> = self.safe_string_k_opt(response.clone(), "code", &[]);
let mut spotMessage: Option<String> = self.safe_string_k_opt(response.clone(), "msg", &[]);
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), spotErrorCode.map(Value::from).unwrap_or(Value::Null), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), spotMessage.map(Value::from).unwrap_or(Value::Null), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut errorCode: Option<String> = self.safe_string_k_opt(response.clone(), "errorCode", &[]);
if (errorCode.is_some()) {
let mut message: Option<String> = self.safe_string_k_opt(response.clone(), "message", &[]);
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode.clone().map(Value::from).unwrap_or(Value::Null), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message.map(Value::from).unwrap_or(Value::Null), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut legacyErrorText: Option<String> = self.safe_string_k(response.clone(), "error", &[]).as_str().map(str::to_owned);
let mut legacyEnumCode: Option<String> = self.safe_string_k_opt(response.clone(), "code", &[]);
if (legacyErrorText.is_some()) && (legacyEnumCode.is_some()) {
let mut legacyMessage: Option<String> = self.safe_string_k_opt(response.clone(), "message", &[]);
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), legacyEnumCode.clone().map(Value::from).unwrap_or(Value::Null), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), legacyMessage.map(Value::from).unwrap_or(Value::Null), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut rows: Value = Value::from(vec![]);
if (matches!(&response, Value::Arr(_))) {
rows = response.clone();
} else {
rows = Value::from(vec![response]);
}
{
let mut i: i64 = 0;
let mut __for_first_493: bool = true;
while { if !__for_first_493 { i += 1; } __for_first_493 = false; i < (rows.len() as i64) } {
let mut row: Value = self.safe_dict(rows.clone(), Value::Int(i), &[]);
let mut status: Option<String> = self.safe_string_k_opt(row.clone(), "status", &[]);
if (status.is_some()) {
let mut message: Value = self.safe_string_k(row, "message", &[]);
let mut embedded: Value = self.parse_json_value(message.clone());
if (embedded != Value::Null) {
message = self.safe_string_k(embedded, "default_msg", &[message.clone()]);
}
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), status.map(Value::from).unwrap_or(Value::Null), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback);
}
}
}
return Value::Null;
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __api_empty = Vec::new();
let api = api.as_array().unwrap_or(&__api_empty);
let mut apiName: Value = api.get(0).cloned().unwrap_or(Value::Null);
let mut requestBody: Value = Value::Null;
let mut requestHeaders: Value = Value::Null;
let mut apiUrl: Option<String> = self.safe_string_opt(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), apiName.clone(), &[]);
if (apiUrl.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", apiUrl.map(Value::from).unwrap_or(Value::Null), Value::Str("/".into())).into()), self.implode_params(path.clone(), params.clone())).into());
let mut query: Value = self.omit(params, self.extract_params(path.clone()), &[]);
let mut isBodyDelete: bool = (method.as_str() == Some("DELETE")) && (path.as_str().unwrap_or("").starts_with("futures/api/v3/"));
let mut queryString: Value = Value::Str("".into());
if ((method.as_str() == Some("GET")) || (method.as_str() == Some("DELETE"))) && !isBodyDelete {
if ((Value::Array(query.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).len() as i64) as f64) > ((0i64) as f64) {
queryString = self.urlencode(query.clone(), &[]);
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), queryString).into())).into());
}
}
if (apiName.as_str() == Some("private")) {
self.check_required_credentials(&[]);
let mut nonce: Value = self.nonce();
let mut bodyString: Value = json_stringify(&query);
if ((method.as_str() == Some("GET")) || (method.as_str() == Some("DELETE"))) && !isBodyDelete {
bodyString = Value::Str("".into());
} else {
requestBody = bodyString.clone();
}
let mut signPath: Value = Value::Null;
if (path.as_str().unwrap_or("").starts_with("public-api/")) {
signPath = Value::Str(format!("{}{}", Value::Str("/".into()), path).into());
} else {
signPath = self.clean_path(path).map(Value::from).unwrap_or(Value::Null);
}
let mut payload: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", signPath, Value::Str(format!("{}", nonce).into())).into()), bodyString).into());
let mut signature: Value = self.hmac(self.encode(payload), self.encode(self.secret.clone()), Value::Str("sha384".into()), &[]);
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("request-api".to_string(), self.apiKey.clone());
m.insert("request-nonce".to_string(), self.number_to_string(nonce));
m.insert("request-sign".to_string(), signature);
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m.insert("BROKER-ID".to_string(), Value::Str("ccxt".into()));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), requestBody);
m.insert("headers".to_string(), requestHeaders);
m
});
Value::Null
}
pub fn futures_request_id(&self, mut market: Value) -> Value {
let __market_empty = indexmap::IndexMap::new();
let market = market.as_map().unwrap_or(&__market_empty);
let mut marketInfo: Value = (match market.get("info") { Some(__v) if matches!(__v, Value::Dict(_)) => __v.clone(), _ => Value::Map({
let mut m = indexmap::IndexMap::new();
m
}) });
return self.safe_string_k(marketInfo, "tradeCurrency", &[(match market.get("id") { 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 })]);
Value::Null
}
pub fn clean_path(&self, mut path: Value) -> Option<String> {
let mut result: Value = path.as_str().map(|__s| Value::Str(__s.replace("spot", "").into())).unwrap_or_else(|| path.clone());
result = result.as_str().map(|__s| Value::Str(__s.replace("futures", "").into())).unwrap_or_else(|| result.clone());
result = result.as_str().map(|__s| Value::Str(__s.replace("otc", "").into())).unwrap_or_else(|| result.clone());
return result.as_str().map(str::to_owned);
}
pub fn nonce(&self) -> Value {
return (match (&(self.milliseconds()), &(self.safe_integer_k(self.options.clone(), "timeDifference", &[Value::Int(0)]))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
Value::Null
}
}