#![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 BitfinexCore {
pub exchange: crate::exchange::Exchange,
}
impl BitfinexCore {
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 = BitfinexCore::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 BitfinexCore {
fn nonce(&self, ) -> crate::Value {
BitfinexCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
BitfinexCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_position(self, position, &[market])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_funding_rate(self, rate, &[market])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
BitfinexCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
BitfinexCore::parse_transfer(self, transfer, &[currency])
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_open_interest(self, interest, &[market])
}
fn parse_liquidation(&self, liquidation: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_liquidation(self, liquidation, &[market])
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_funding_rate_history(self, entry, &[market])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
BitfinexCore::parse_margin_modification(self, data, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
BitfinexCore::parse_transaction(self, transaction, &[currency])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
#[allow(invalid_reference_casting)]
let me = unsafe { &mut *(self as *const BitfinexCore as *mut BitfinexCore) };
BitfinexCore::sign(me, 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 {
BitfinexCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BitfinexCore {
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 {
"amount_to_precision" => self.amount_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_deposit_address" => self.create_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_order_request" => self.create_order_request(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())..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.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_closed_order" => self.fetch_closed_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args[..]).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_liquidations" => self.fetch_liquidations(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_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interests" => self.fetch_open_interests(&args[..]).await,
"fetch_open_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" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_status" => self.fetch_status(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"get_currency_name" => self.get_currency_name(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)),
"is_fiat" => self.is_fiat(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"parse_currencies_custom" => self.parse_currencies_custom(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)),
"parse_currency_custom" => self.parse_currency_custom(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)),
"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_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_liquidation" => self.parse_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_modification" => self.parse_margin_modification(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_order_flags" => self.parse_order_flags(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"price_to_precision" => self.price_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"set_margin" => self.set_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BitfinexCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BitfinexCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BitfinexCore {
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("bitfinex".into()));
m.insert("name".to_string(), Value::Str("Bitfinex".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("VG".into())]));
m.insert("version".to_string(), Value::Str("v2".into()));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(true));
m.insert("createLimitOrder".to_string(), Value::Bool(true));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".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(true));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".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("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchClosedOrder".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Str("emulated".into()));
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("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(true));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("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(true));
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(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(false));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactionFees".to_string(), Value::Null);
m.insert("fetchTransactions".to_string(), Value::Str("emulated".into()));
m.insert("fetchVolatilityHistory".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("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15m".to_string(), Value::Str("15m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("3h".to_string(), Value::Str("3h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("12h".to_string(), Value::Str("12h".into()));
m.insert("1d".to_string(), Value::Str("1D".into()));
m.insert("1w".to_string(), Value::Str("7D".into()));
m.insert("2w".to_string(), Value::Str("14D".into()));
m.insert("1M".to_string(), Value::Str("1M".into()));
m
}));
m.insert("rateLimit".to_string(), Value::Int(250));
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/4a8e947f-ab46-481a-a8ae-8b20e9b03178".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Str("https://api.bitfinex.com".into()));
m.insert("public".to_string(), Value::Str("https://api-pub.bitfinex.com".into()));
m.insert("private".to_string(), Value::Str("https://api.bitfinex.com".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.bitfinex.com".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://docs.bitfinex.com/v2/docs/".into()), Value::Str("https://github.com/bitfinexcom/bitfinex-api-node".into())]));
m.insert("fees".to_string(), Value::Str("https://www.bitfinex.com/fees".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("conf/{config}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:{action}:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:{action}:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:sym".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:label".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:unit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:undl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:pool".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:explorer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:tx:fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:tx:method".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:pair:exchange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:pair:margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:pair:futures".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:competitions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:pair".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:pair:futures".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:tx:status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("platform/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("ticker/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("tickers/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("trades/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("book/{symbol}/{precision}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P0".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P3".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/R0".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:{side}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:{side}/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:{side}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:long/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:long/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:short/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:short/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}:{period}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("status/{type}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("status/deriv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("status/deriv/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("liquidations/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(80));
m
}));
m.insert("rankings/{key}:{timeframe}:{symbol}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("rankings/{key}:{timeframe}:{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("pulse/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("pulse/profile/{nickname}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("funding/stats/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("ext/vasps".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("calc/trade/avg".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("calc/fx".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("auth/r/wallets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/wallets/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/submit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/multi".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/cancel/multi".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/otc/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/order/{symbol}:{id}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/trades/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/trades/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/ledgers/{currency}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/ledgers/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/margin/{key}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/margin/base".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/margin/sym_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/position/claim".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/position/increase:".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/position/increase/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions/audit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions/snap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/position/update/funding/type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/deriv/collateral/set".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/deriv/collateral/limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/offer/submit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/offer/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/offer/cancel/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/auto".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/keep".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/trades/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/trades/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/funding/{key}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/logins/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/permissions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/token".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/audit/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/r/deposit/address/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/w/deposit/invoice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/r/ext/invoice/payments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/r/movements/{currency}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/movements/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/movements/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/alerts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(5.34));
m
}));
m.insert("auth/w/alert/set".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/alert/price:{symbol}:{price}/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/alert/{type}:{symbol}:{price}/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/calc/order/avail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/settings/set".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/settings/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/pulse/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/pulse/add".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(16));
m
}));
m.insert("auth/w/pulse/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/ext/wallets/deposits/request".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/ext/wallets/withdrawals/request".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/ext/wallets/transfers/free/count".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("get".into()));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(false));
m.insert("maker".to_string(), self.parse_number(Value::Str("0".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0".into()), &[]));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::SIGNIFICANT_DIGITS));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fetchOrderBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("precision".to_string(), Value::Str("R0".into()));
m
}));
m.insert("fetchCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultPrecision".to_string(), Value::Int(8));
m
}));
m.insert("exchangeTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".into()));
m.insert("EXCHANGE MARKET".to_string(), Value::Str("market".into()));
m.insert("LIMIT".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE LIMIT".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE STOP".to_string(), Value::Str("market".into()));
m.insert("EXCHANGE FOK".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE STOP LIMIT".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE IOC".to_string(), Value::Str("limit".into()));
m
}));
m.insert("orderTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), Value::Str("EXCHANGE MARKET".into()));
m.insert("limit".to_string(), Value::Str("EXCHANGE LIMIT".into()));
m
}));
m.insert("fiat".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USD".to_string(), Value::Str("USD".into()));
m.insert("EUR".to_string(), Value::Str("EUR".into()));
m.insert("JPY".to_string(), Value::Str("JPY".into()));
m.insert("GBP".to_string(), Value::Str("GBP".into()));
m.insert("CHN".to_string(), Value::Str("CHN".into()));
m
}));
m.insert("v2AccountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("exchange".into()));
m.insert("exchange".to_string(), Value::Str("exchange".into()));
m.insert("funding".to_string(), Value::Str("funding".into()));
m.insert("margin".to_string(), Value::Str("margin".into()));
m.insert("derivatives".to_string(), Value::Str("margin".into()));
m.insert("future".to_string(), Value::Str("margin".into()));
m.insert("swap".to_string(), Value::Str("margin".into()));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("includeFee".to_string(), Value::Bool(false));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BITCOIN".into()));
m.insert("LTC".to_string(), Value::Str("LITECOIN".into()));
m.insert("ERC20".to_string(), Value::Str("ETHEREUM".into()));
m.insert("OMNI".to_string(), Value::Str("TETHERUSO".into()));
m.insert("LIQUID".to_string(), Value::Str("TETHERUSL".into()));
m.insert("TRC20".to_string(), Value::Str("TETHERUSX".into()));
m.insert("EOS".to_string(), Value::Str("TETHERUSS".into()));
m.insert("AVAX".to_string(), Value::Str("TETHERUSDTAVAX".into()));
m.insert("SOL".to_string(), Value::Str("TETHERUSDTSOL".into()));
m.insert("ALGO".to_string(), Value::Str("TETHERUSDTALG".into()));
m.insert("BCH".to_string(), Value::Str("TETHERUSDTBCH".into()));
m.insert("KSM".to_string(), Value::Str("TETHERUSDTKSM".into()));
m.insert("DVF".to_string(), Value::Str("TETHERUSDTDVF".into()));
m.insert("OMG".to_string(), Value::Str("TETHERUSDTOMG".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TETHERUSE".to_string(), Value::Str("ERC20".into()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
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("trailing".to_string(), Value::Bool(true));
m.insert("leverage".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(75));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(2500));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(10000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.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("11010".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("10001".to_string(), Value::Str("PermissionDenied".into()));
m.insert("10020".to_string(), Value::Str("BadRequest".into()));
m.insert("10100".to_string(), Value::Str("AuthenticationError".into()));
m.insert("10114".to_string(), Value::Str("InvalidNonce".into()));
m.insert("20060".to_string(), Value::Str("OnMaintenance".into()));
m.insert("temporarily_unavailable".to_string(), Value::Str("ExchangeNotAvailable".into()));
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("available balance is only".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("not enough exchange balance".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("Order not found".to_string(), Value::Str("OrderNotFound".into()));
m.insert("symbol: invalid".to_string(), Value::Str("BadSymbol".into()));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("UST".to_string(), Value::Str("USDT".into()));
m.insert("EUTF0".to_string(), Value::Str("EURT".into()));
m.insert("USTF0".to_string(), Value::Str("USDT".into()));
m.insert("ALG".to_string(), Value::Str("ALGO".into()));
m.insert("AMP".to_string(), Value::Str("AMPL".into()));
m.insert("ATO".to_string(), Value::Str("ATOM".into()));
m.insert("BCHABC".to_string(), Value::Str("XEC".into()));
m.insert("BCHN".to_string(), Value::Str("BCH".into()));
m.insert("DAT".to_string(), Value::Str("DATA".into()));
m.insert("DOG".to_string(), Value::Str("MDOGE".into()));
m.insert("DSH".to_string(), Value::Str("DASH".into()));
m.insert("EDO".to_string(), Value::Str("PNT".into()));
m.insert("EUS".to_string(), Value::Str("EURS".into()));
m.insert("EUT".to_string(), Value::Str("EURT".into()));
m.insert("HTX".to_string(), Value::Str("HT".into()));
m.insert("IDX".to_string(), Value::Str("ID".into()));
m.insert("IOT".to_string(), Value::Str("IOTA".into()));
m.insert("IQX".to_string(), Value::Str("IQ".into()));
m.insert("LUNA".to_string(), Value::Str("LUNC".into()));
m.insert("LUNA2".to_string(), Value::Str("LUNA".into()));
m.insert("MNA".to_string(), Value::Str("MANA".into()));
m.insert("ORS".to_string(), Value::Str("ORS Group".into()));
m.insert("PAS".to_string(), Value::Str("PASS".into()));
m.insert("QSH".to_string(), Value::Str("QASH".into()));
m.insert("QTM".to_string(), Value::Str("QTUM".into()));
m.insert("RBT".to_string(), Value::Str("RBTC".into()));
m.insert("SNG".to_string(), Value::Str("SNGLS".into()));
m.insert("STJ".to_string(), Value::Str("STORJ".into()));
m.insert("TERRAUST".to_string(), Value::Str("USTC".into()));
m.insert("TSD".to_string(), Value::Str("TUSD".into()));
m.insert("YGG".to_string(), Value::Str("YEED".into()));
m.insert("YYW".to_string(), Value::Str("YOYOW".into()));
m.insert("UDC".to_string(), Value::Str("USDC".into()));
m.insert("VSY".to_string(), Value::Str("VSYS".into()));
m.insert("WAX".to_string(), Value::Str("WAXP".into()));
m.insert("XCH".to_string(), Value::Str("XCHF".into()));
m.insert("ZBT".to_string(), Value::Str("ZB".into()));
m
}));
m
})]);
Value::Null
}
pub fn is_fiat(&self, mut code: Value) -> Value {
let mut fiat: indexmap::IndexMap<String, Value> = self.safe_dict_k(self.options.clone(), "fiat", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]).as_map().cloned().unwrap_or_default();
return (Value::Bool(matches!(&code, Value::Str(__k) if fiat.contains_key(__k.as_ref()))));
Value::Null
}
pub fn get_currency_name(&self, mut code: Value) -> Value {
if (in_op(&self.options.as_map().and_then(|__m| __m.get("currencyNames")).cloned().unwrap_or(Value::Null), &code)) {
return get_value(&self.options.as_map().and_then(|__m| __m.get("currencyNames")).cloned().unwrap_or(Value::Null), &code);
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), code).into()), Value::Str(" not supported for withdrawal".into()))));
Value::Null
}
pub fn amount_to_precision(&self, mut symbol: Value, mut amount: Value) -> Value {
let mut symbolValue: Value = self.safe_symbol(symbol, &[]);
let mut market: indexmap::IndexMap<String, Value> = self.market(symbolValue).as_map().cloned().unwrap_or_default();
return self.decimal_to_precision(amount, Value::Int(crate::runtime::TRUNCATE), self.safe_value_k(market.get("precision").cloned().unwrap_or(Value::Null), "amount", &[]), &[Value::Int(crate::runtime::DECIMAL_PLACES)]);
Value::Null
}
pub fn price_to_precision(&self, mut symbol: Value, mut price: Value) -> Value {
let mut symbolValue: Value = self.safe_symbol(symbol, &[]);
let mut market: indexmap::IndexMap<String, Value> = self.market(symbolValue).as_map().cloned().unwrap_or_default();
let mut priceValue: Value = self.decimal_to_precision(price, Value::Int(crate::runtime::ROUND), self.safe_value_k(market.get("precision").cloned().unwrap_or(Value::Null), "price", &[]), &[self.precisionMode.clone()]);
return self.decimal_to_precision(priceValue, Value::Int(crate::runtime::TRUNCATE), Value::Int(8), &[Value::Int(crate::runtime::DECIMAL_PLACES)]);
Value::Null
}
pub async fn fetch_status(&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_platform_status(&[params]).await;
let mut statusRaw: Option<String> = self.safe_string_opt(response.clone(), Value::Int(0), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), self.safe_string(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("maintenance".into()));
m.insert("1".to_string(), Value::Str("ok".into()));
m
}), statusRaw.clone().map(Value::from).unwrap_or(Value::Null), &[statusRaw.map(Value::from).unwrap_or(Value::Null)]));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response);
m
});
Value::Null
}
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut labels: Value = Value::from(vec![Value::Str("pub:info:pair".into()), Value::Str("pub:info:pair:futures".into()), Value::Str("pub:list:pair:securities".into()), Value::Str("pub:list:pair:margin".into())]);
let mut config: Value = Value::Str(labels.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",")).unwrap_or_default().into());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("config".to_string(), config);
m
});
let __ws_arg_0 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_conf_config(&[__ws_arg_0]).await;
let mut spotMarketsInfo: Value = self.safe_list(response.clone(), Value::Int(0), &[Value::from(vec![])]);
let mut futuresMarketsInfo: Value = self.safe_list(response.clone(), Value::Int(1), &[Value::from(vec![])]);
let mut marginIds: Value = self.safe_list(response, Value::Int(3), &[Value::from(vec![])]);
let mut markets: Value = self.array_concat(spotMarketsInfo, futuresMarketsInfo);
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("marginIds".into(), marginIds); }
return self.parse_markets(markets);
Value::Null
}
pub fn parse_market(&self, mut pairObj: Value) -> Value {
let mut marginIds: Value = self.safe_list_k(self.options.clone(), "marginIds", &[Value::from(vec![])]);
let mut id: Value = self.safe_string_upper(pairObj.clone(), Value::Int(0), &[Value::Str("".into())]);
let mut market: Value = self.safe_list(pairObj, Value::Int(1), &[Value::from(vec![])]);
let mut spot: bool = true;
let mut type_var: Value = Value::Null;
if id.as_str().unwrap_or("").contains("F0") {
spot = false;
type_var = Value::Str("swap".into());
} else {
type_var = Value::Str("spot".into());
}
let mut swap: bool = type_var.as_str() == Some("swap");
let mut baseId: Value = Value::Null;
let mut quoteId: Value = Value::Null;
if id.as_str().unwrap_or("").contains(":") {
let mut parts: Vec<Value> = Value::Array(if let Some(__s) = id.as_str() { __s.split(":").map(Value::from).collect() } else { Vec::new() }).as_array().cloned().unwrap_or_default();
baseId = parts.get(0).cloned().unwrap_or(Value::Null);
quoteId = parts.get(1).cloned().unwrap_or(Value::Null);
} else {
baseId = id.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(0); let __j = __l.min(3); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(Value::from).unwrap_or(Value::Null);
quoteId = id.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(3); let __j = __l.min(6); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(Value::from).unwrap_or(Value::Null);
}
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut splitBase: Value = Value::Array(if let Some(__s) = base.as_str() { __s.split("F0").map(Value::from).collect() } else { Vec::new() });
let mut splitQuote: Value = Value::Array(if let Some(__s) = quote.as_str() { __s.split("F0").map(Value::from).collect() } else { Vec::new() });
base = self.safe_string(splitBase, Value::Int(0), &[]);
quote = self.safe_string(splitQuote, Value::Int(0), &[]);
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 settle: Value = Value::Null;
let mut settleId: Value = Value::Null;
if swap {
settle = quote.clone();
settleId = quote.clone();
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), settle).into());
}
let mut minOrderSizeString: Option<String> = self.safe_string_opt(market.clone(), Value::Int(3), &[]);
let mut maxOrderSizeString: Option<String> = self.safe_string_opt(market.clone(), Value::Int(4), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str(format!("{}{}", Value::Str("t".into()), id).into()));
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), settle);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), type_var);
m.insert("spot".to_string(), Value::Bool(spot.clone()));
m.insert("margin".to_string(), Value::Bool((spot && self.in_array(id, marginIds).as_bool() == Some(true))));
m.insert("swap".to_string(), Value::Bool(swap.clone()));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool(true));
m.insert("contract".to_string(), Value::Bool(!(spot)));
m.insert("linear".to_string(), (if swap { Value::Bool(true) } else { Value::Null }));
m.insert("inverse".to_string(), (if swap { Value::Bool(false) } else { Value::Null }));
m.insert("maker".to_string(), self.safe_number(self.fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null), Value::Str("maker".into()), &[]));
m.insert("taker".to_string(), self.safe_number(self.fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null), Value::Str("taker".into()), &[]));
m.insert("contractSize".to_string(), (if swap { self.parse_number(Value::Str("1".into()), &[]) } else { Value::Null }));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Int(8));
m.insert("price".to_string(), Value::Int(5));
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(minOrderSizeString.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("max".to_string(), self.parse_number(maxOrderSizeString.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(Value::Str("1e-8".into()), &[]));
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_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut labels: Value = Value::from(vec![Value::Str("pub:list:currency".into()), Value::Str("pub:map:currency:sym".into()), Value::Str("pub:map:currency:label".into()), Value::Str("pub:map:currency:unit".into()), Value::Str("pub:map:currency:undl".into()), Value::Str("pub:map:currency:pool".into()), Value::Str("pub:map:currency:explorer".into()),
Value::Str("pub:map:currency:tx:fee".into()), Value::Str("pub:map:tx:method".into()), Value::Str("pub:info:tx:status".into()), Value::Str("pub:list:currency:margin".into())]);
let mut config: Value = Value::Str(labels.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",")).unwrap_or_default().into());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("config".to_string(), config);
m
});
let __ws_arg_1 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_conf_config(&[__ws_arg_1]).await;
let mut networks: Value = self.safe_list(response.clone(), Value::Int(8), &[Value::from(vec![])]);
let mut indexed: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("sym".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(1), &[Value::from(vec![])]), Value::Int(0)));
m.insert("label".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(2), &[Value::from(vec![])]), Value::Int(0)));
m.insert("unit".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(3), &[Value::from(vec![])]), Value::Int(0)));
m.insert("undl".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(4), &[Value::from(vec![])]), Value::Int(0)));
m.insert("pool".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(5), &[Value::from(vec![])]), Value::Int(0)));
m.insert("explorer".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(6), &[Value::from(vec![])]), Value::Int(0)));
m.insert("fees".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(7), &[Value::from(vec![])]), Value::Int(0)));
m.insert("networks".to_string(), networks.clone());
m.insert("statuses".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(9), &[Value::from(vec![])]), Value::Int(0)));
m.insert("marginables".to_string(), self.safe_list(response.clone(), Value::Int(10), &[Value::from(vec![])]));
m
});
let mut indexedNetworks: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_342: bool = true;
while { if !__for_first_342 { i += 1; } __for_first_342 = false; i < (networks.len() as i64) } {
let mut networkObj: Value = self.safe_list(networks.clone(), Value::Int(i), &[]);
let mut networkId: Option<String> = self.safe_string_opt(networkObj.clone(), Value::Int(0), &[]);
let mut valuesList: Value = self.safe_list(networkObj, Value::Int(1), &[]);
let mut networkName: Option<String> = self.safe_string_opt(valuesList, Value::Int(0), &[]);
let mut networksList: Value = self.safe_list(Value::Map(indexedNetworks.clone()), networkName.clone().map(Value::from).unwrap_or(Value::Null), &[Value::from(vec![])]);
if let Value::Arr(__a) = &mut networksList { std::sync::Arc::make_mut(__a).push(networkId.map(Value::from).unwrap_or(Value::Null)); }
indexedNetworks.insert(networkName.as_deref().unwrap_or("null").to_string(), networksList);
}
}
let mut ids: Value = self.safe_list(response, Value::Int(0), &[Value::from(vec![])]);
return self.parse_currencies_custom(ids, Value::Map(indexed), Value::Map(indexedNetworks));
Value::Null
}
pub fn parse_currencies_custom(&self, mut ids: Value, mut indexed: Value, mut indexedNetworks: Value) -> Value {
let mut allowedIds: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_343: bool = true;
while { if !__for_first_343 { i += 1; } __for_first_343 = false; i < (ids.len() as i64) } {
let mut id: Value = self.safe_string(ids.clone(), Value::Int(i), &[Value::Str("".into())]);
if (id.as_str().unwrap_or("").ends_with("F0")) {
continue;
}
allowedIds.push(id);
}
}
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut arr: Value = self.to_array(Value::from(allowedIds));
{
let mut i: i64 = 0;
let mut __for_first_344: bool = true;
while { if !__for_first_344 { i += 1; } __for_first_344 = false; i < (arr.len() as i64) } {
let mut parsed: Value = self.parse_currency_custom(arr.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null), indexed.clone(), indexedNetworks.clone());
let mut code: Value = self.safe_string_k(parsed.clone(), "code", &[Value::Str("".into())]);
result.insert(crate::runtime::stringify_param(&code), parsed);
}
}
return Value::Map(result);
Value::Null
}
pub fn parse_currency_custom(&self, mut id: Value, mut indexed: Value, mut indexedNetworks: Value) -> Value {
let __indexed_empty = indexmap::IndexMap::new();
let indexed = indexed.as_map().unwrap_or(&__indexed_empty);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut label: Value = self.safe_list(indexed.get("label").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut name: Option<String> = self.safe_string_opt(label.clone(), Value::Int(1), &[]);
let mut pool: Value = self.safe_list(indexed.get("pool").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut rawType: Option<String> = self.safe_string(pool.clone(), Value::Int(1), &[]).as_str().map(str::to_owned);
let mut explorer: Value = (match indexed.get("explorer") { Some(__v) if matches!(__v, Value::Dict(_)) => __v.clone(), _ => Value::Map({
let mut m = indexmap::IndexMap::new();
m
}) });
let mut isCryptoCoin: bool = (rawType.is_some()) || (matches!((&explorer, &id), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))); let mut type_var: Value = (if isCryptoCoin { Value::Str("crypto".into()) } else { Value::Null });
let mut feeValues: Value = self.safe_list(indexed.get("fees").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut fees: Value = self.safe_list(feeValues.clone(), Value::Int(1), &[Value::from(vec![])]);
let mut fee: Value = self.safe_number(fees, Value::Int(1), &[]);
let mut undl: Value = self.safe_list(indexed.get("undl").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut defaultCurrencyPrecision: Value = self.safe_string_k(self.options.clone(), "defaultCurrencyPrecision", &[Value::Str("8".into())]); let mut precision: Value = self.number_to_string(self.handle_option(Value::Str("fetchCurrencies".into()), Value::Str("defaultPrecision".into()), &[defaultCurrencyPrecision]));
let mut networks: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut networkIds: Value = self.safe_list(indexedNetworks, id.clone(), &[Value::from(vec![])]);
{
let mut j: i64 = 0;
let mut __for_first_345: bool = true;
while { if !__for_first_345 { j += 1; } __for_first_345 = false; j < (networkIds.len() as i64) } {
let mut networkId: Option<String> = self.safe_string_opt(networkIds.clone(), Value::Int(j), &[]);
if (networkId.is_none()) {
continue;
}
let mut network: Value = self.network_id_to_code(&[networkId.clone().map(Value::from).unwrap_or(Value::Null), code.clone()]);
let mut dwStatuses: Value = self.safe_list(indexed.get("statuses").cloned().unwrap_or(Value::Null), networkId.clone().map(Value::from).unwrap_or(Value::Null), &[Value::from(vec![])]);
if (network != Value::Null) {
networks.insert(crate::runtime::stringify_param(&network), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), networkId.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("id".to_string(), (if let Some(__s) = networkId.as_deref() { Value::Str(__s.to_lowercase().into()) } else { Value::Null }));
m.insert("network".to_string(), network.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool(self.safe_integer(dwStatuses.clone(), Value::Int(1), &[]).as_f64() == Some(1.0)));
m.insert("withdraw".to_string(), Value::Bool(self.safe_integer(dwStatuses, Value::Int(2), &[]).as_f64() == Some(1.0)));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("code".to_string(), code);
m.insert("info".to_string(), Value::from(vec![id.clone(), label, pool, feeValues, undl]));
m.insert("type".to_string(), type_var);
m.insert("name".to_string(), name.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("active".to_string(), Value::Bool(true));
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m.insert("precision".to_string(), self.parse_number(precision, &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), fee);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), Value::Map(networks));
m.insert("margin".to_string(), self.in_array(id, indexed.get("marginables").cloned().unwrap_or(Value::Null)));
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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "v2AccountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut requestedType: Value = self.safe_string_k(params.clone(), "type", &[Value::Str("exchange".into())]);
let mut accountType: Value = self.safe_string(accountsByType.clone(), requestedType.clone(), &[requestedType.clone()]);
if (accountType == Value::Null) {
let mut keys: Value = Value::Array(accountsByType.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchBalance() type parameter must be one of ".into())).into()), Value::Str(keys.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(", ")).unwrap_or_default().into()))));
}
let mut isDerivative: bool = requestedType.as_str() == Some("derivatives");
let mut query: Value = self.omit(params, Value::Str("type".into()), &[]);
let mut response: Value = self.private_post_auth_r_wallets(&[query]).await;
let mut balances: Value = self.to_array(response.clone());
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
});
{
let mut i: i64 = 0;
let mut __for_first_346: bool = true;
while { if !__for_first_346 { i += 1; } __for_first_346 = false; i < (balances.len() as i64) } {
let mut balance: Value = self.safe_list(balances.clone(), Value::Int(i), &[]);
let mut account: indexmap::IndexMap<String, Value> = self.account().as_map().cloned().unwrap_or_default();
let mut interest: Option<String> = self.safe_string_opt(balance.clone(), Value::Int(3), &[]);
if (interest.as_deref() != Some("0")) {
account.insert("debt".into(), interest.map(Value::from).unwrap_or(Value::Null));
}
let mut type_var: Option<String> = self.safe_string_opt(balance.clone(), Value::Int(0), &[]);
let mut currencyId: Value = self.safe_string_lower(balance.clone(), Value::Int(1), &[Value::Str("".into())]);
let mut isDerivativeCode: bool = (currencyId != Value::Null) && (Value::Bool(currencyId.as_str().unwrap_or("").ends_with("f0")).as_bool() == Some(true));
let mut derivativeCondition: bool = !isDerivative || isDerivativeCode;
if (accountType.as_str() == type_var.as_deref()) && derivativeCondition {
let mut code: Value = self.safe_currency_code(currencyId, &[]);
account.insert("total".into(), self.safe_string(balance.clone(), Value::Int(2), &[]));
account.insert("free".into(), self.safe_string(balance, Value::Int(4), &[]));
if (code != Value::Null) {
result.insert(crate::runtime::stringify_param(&code), Value::Map(account));
}
}
}
}
return self.safe_balance(Value::Map(result));
Value::Null
}
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "v2AccountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Option<String> = self.safe_string_opt(accountsByType.clone(), fromAccount.clone(), &[]);
if (fromId.is_none()) {
let mut keys: Value = Value::Array(accountsByType.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" transfer() fromAccount must be one of ".into())).into()), Value::Str(keys.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(", ")).unwrap_or_default().into()))));
}
let mut toId: Option<String> = self.safe_string_opt(accountsByType.clone(), toAccount.clone(), &[]);
if (toId.is_none()) {
let mut keys: Value = Value::Array(accountsByType.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" transfer() toAccount must be one of ".into())).into()), Value::Str(keys.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(", ")).unwrap_or_default().into()))));
}
let mut currency: Value = self.currency(code.clone());
let mut fromCurrencyId: Value = self.convert_derivatives_id(currency.clone(), fromAccount).map(Value::from).unwrap_or(Value::Null);
let mut toCurrencyId: Value = self.convert_derivatives_id(currency.clone(), toAccount).map(Value::from).unwrap_or(Value::Null);
let mut requestedAmount: Value = self.currency_to_precision(code, amount, &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), requestedAmount);
m.insert("currency".to_string(), fromCurrencyId);
m.insert("currency_to".to_string(), toCurrencyId);
m.insert("from".to_string(), fromId.map(Value::from).unwrap_or(Value::Null));
m.insert("to".to_string(), toId.map(Value::from).unwrap_or(Value::Null));
m
});
let __ws_arg_2 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_post_auth_w_transfer(&[__ws_arg_2]).await;
let mut error: Option<String> = self.safe_string(response.clone(), Value::Int(0), &[]).as_str().map(str::to_owned);
if (error.as_deref() == Some("error")) {
let mut message: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".into())]);
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), message.clone(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message).into()));
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message)));
}
return self.parse_transfer(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), response);
m
}), &[currency]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let __transfer_empty = indexmap::IndexMap::new();
let transfer = transfer.as_map().unwrap_or(&__transfer_empty);
let mut result: Value = (match transfer.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut timestamp: Option<i64> = self.safe_integer(result.clone(), Value::Int(0), &[]).as_i64();
let mut info: Value = self.safe_list(result.clone(), Value::Int(4), &[]);
let mut fromAccount: Option<String> = self.safe_string_opt(info.clone(), Value::Int(1), &[]);
let mut toAccount: Option<String> = self.safe_string_opt(info.clone(), Value::Int(2), &[]);
let mut currencyId: Option<String> = self.safe_string_opt(info.clone(), Value::Int(5), &[]);
let mut status: Option<String> = self.safe_string_opt(result.clone(), Value::Int(6), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("status".to_string(), self.parse_transfer_status(status.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), self.safe_number(info, Value::Int(7), &[]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]));
m.insert("fromAccount".to_string(), fromAccount.map(Value::from).unwrap_or(Value::Null));
m.insert("toAccount".to_string(), toAccount.map(Value::from).unwrap_or(Value::Null));
m.insert("info".to_string(), result);
m
});
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("SUCCESS".to_string(), Value::Str("ok".into()));
m.insert("ERROR".to_string(), Value::Str("failed".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 fn convert_derivatives_id(&self, mut currency: Value, mut type_var: Value) -> Option<String> {
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
let mut info: Value = (match currency.get("info") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut transferId: Option<String> = self.safe_string_opt(info.clone(), Value::Int(0), &[]);
let mut underlying: Value = self.safe_list(info.clone(), Value::Int(4), &[Value::from(vec![])]);
if (type_var.as_str() == Some("derivatives")) {
let mut derivativesId: Value = self.safe_string(underlying.clone(), Value::Int(0), &[self.safe_string(info, Value::Int(0), &[Value::Str("".into())])]);
if !(derivativesId.as_str().unwrap_or("").ends_with("F0")) {
return Value::Str(format!("{}{}", derivativesId, Value::Str("F0".into())).into()).as_str().map(str::to_owned);
}
return derivativesId.as_str().map(str::to_owned);
} else if (type_var.as_str() != Some("margin")) {
return self.safe_string(underlying, Value::Int(1), &[transferId.clone().map(Value::from).unwrap_or(Value::Null)]).as_str().map(str::to_owned);
}
return transferId.as_deref().map(str::to_owned);
}
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut precision: Value = self.handle_option(Value::Str("fetchOrderBook".into()), Value::Str("precision".into()), &[Value::Str("R0".into())]);
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.insert("precision".to_string(), precision);
m
});
if (limit != Value::Null) {
request.insert("len".into(), limit);
}
let mut fullRequest: Value = self.extend(Value::Map(request), &[params]);
let mut orderbook: Value = self.public_get_book_symbol_precision(&[fullRequest.clone()]).await;
let mut timestamp: Value = self.milliseconds();
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("bids".to_string(), Value::from(vec![]));
m.insert("asks".to_string(), Value::from(vec![]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("nonce".to_string(), Value::Null);
m
});
let mut priceIndex: Value = (if (self.safe_string_k(fullRequest, "precision", &[]).as_str() == Some("R0")) { Value::Int(1) } else { Value::Int(0) });
let mut orders: Value = self.to_array(orderbook);
{
let mut i: i64 = 0;
let mut __for_first_347: bool = true;
while { if !__for_first_347 { i += 1; } __for_first_347 = false; i < (orders.len() as i64) } {
let mut order: Value = orders.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut price: Value = self.safe_number(order.clone(), priceIndex.clone(), &[]);
let mut signedAmount: Option<String> = self.safe_string_opt(order, Value::Int(2), &[]);
let mut amount: Value = crate::precise::Precise::stringAbs(&signedAmount.clone().map(Value::from).unwrap_or(Value::Null));
let mut side: Value = Value::Str("asks".into());
if crate::precise::Precise::stringGt(&signedAmount.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) {
side = Value::Str("bids".into());
}
crate::runtime::append_to_object_array(&mut result, &side, Value::from(vec![price, self.parse_number(amount, &[])]));
}
}
{ let __be_tmp = self.sort_by(crate::value::get_value_k(&result, "bids"), Value::Int(0), &[Value::Bool(true)]); if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("bids".into(), __be_tmp); } }
{ let __be_tmp = self.sort_by(crate::value::get_value_k(&result, "asks"), Value::Int(0), &[]); if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("asks".into(), __be_tmp); } }
return result;
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut length: f64 = ((ticker.len() as i64) as f64);
let mut firstValue: Option<String> = self.safe_string_opt(ticker.clone(), Value::Int(0), &[]);
let mut hasMarketId: bool = (firstValue.is_some()) && ((firstValue.as_deref().unwrap_or("").starts_with("t")) || (firstValue.as_deref().unwrap_or("").starts_with("f")));
let mut isFetchTicker: bool = !hasMarketId;
let mut symbol: Value = Value::Null;
let mut minusIndex: Value = Value::Int(0);
if isFetchTicker {
minusIndex = Value::Int(1);
}
let mut marketId: Option<String> = self.safe_string_opt(ticker.clone(), Value::Int(0), &[]);
let mut marketResolved: Value = Value::Null;
if isFetchTicker {
marketResolved = market.clone();
} else {
marketResolved = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
}
let mut isFundingCurrency: bool = length >= ((17i64) as f64);
symbol = self.safe_symbol(Value::Null, &[marketResolved.clone()]);
let mut last: Value = Value::Null;
let mut bid: Value = Value::Null;
let mut ask: Value = Value::Null;
let mut change: Value = Value::Null;
let mut percentage: Value = Value::Null;
let mut volume: Value = Value::Null;
let mut high: Value = Value::Null;
let mut low: Value = Value::Null;
if isFundingCurrency {
last = self.safe_string(ticker.clone(), (match (&(Value::Int(10)), &(minusIndex)) { (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 }), &[]);
bid = self.safe_string(ticker.clone(), (match (&(Value::Int(2)), &(minusIndex)) { (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 }), &[]);
ask = self.safe_string(ticker.clone(), (match (&(Value::Int(5)), &(minusIndex)) { (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 }), &[]);
change = self.safe_string(ticker.clone(), (match (&(Value::Int(8)), &(minusIndex)) { (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 }), &[]);
volume = self.safe_string(ticker.clone(), (match (&(Value::Int(11)), &(minusIndex)) { (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 }), &[]);
high = self.safe_string(ticker.clone(), (match (&(Value::Int(12)), &(minusIndex)) { (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 }), &[]);
low = self.safe_string(ticker.clone(), (match (&(Value::Int(13)), &(minusIndex)) { (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 }), &[]);
} else {
last = self.safe_string(ticker.clone(), (match (&(Value::Int(7)), &(minusIndex)) { (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 }), &[]);
bid = self.safe_string(ticker.clone(), (match (&(Value::Int(1)), &(minusIndex)) { (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 }), &[]);
ask = self.safe_string(ticker.clone(), (match (&(Value::Int(3)), &(minusIndex)) { (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 }), &[]);
change = self.safe_string(ticker.clone(), (match (&(Value::Int(5)), &(minusIndex)) { (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 }), &[]);
percentage = self.safe_string(ticker.clone(), (match (&(Value::Int(6)), &(minusIndex)) { (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 }), &[]);
percentage = crate::precise::Precise::stringMul(&percentage, &Value::Str("100".into()));
volume = self.safe_string(ticker.clone(), (match (&(Value::Int(8)), &(minusIndex)) { (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 }), &[]);
high = self.safe_string(ticker.clone(), (match (&(Value::Int(9)), &(minusIndex)) { (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 }), &[]);
low = self.safe_string(ticker.clone(), (match (&(Value::Int(10)), &(minusIndex)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null }), &[]);
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), high);
m.insert("low".to_string(), low);
m.insert("bid".to_string(), bid);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), ask);
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), change);
m.insert("percentage".to_string(), percentage);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), volume);
m.insert("quoteVolume".to_string(), Value::Null);
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut 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 ids: Value = self.market_ids(&[symbolsNormalized.clone()]);
request.insert("symbols".into(), Value::Str(ids.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",")).unwrap_or_default().into()));
} else {
request.insert("symbols".into(), Value::Str("ALL".into()));
}
let __ws_arg_3 = self.extend(Value::Map(request), &[params]);
let mut tickers: Value = self.public_get_tickers(&[__ws_arg_3]).await;
return self.parse_tickers(tickers, &[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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_4 = self.extend(Value::Map(request), &[params]);
let mut ticker: Value = self.public_get_ticker_symbol(&[__ws_arg_4]).await;
return self.parse_ticker(ticker, &[market]);
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 __trade_empty = indexmap::IndexMap::new();
let trade = trade.as_map().unwrap_or(&__trade_empty);
let mut tradeList: Value = (match trade.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::from(vec![]) });
let mut tradeLength: f64 = ((tradeList.len() as i64) as f64);
let mut isPrivate: bool = tradeLength > ((5i64) as f64);
let mut id: Option<String> = self.safe_string_opt(tradeList.clone(), Value::Int(0), &[]);
let mut amountIndex: Value = (if isPrivate { Value::Int(4) } else { Value::Int(2) });
let mut side: Value = Value::Null;
let mut amountString: Value = self.safe_string(tradeList.clone(), amountIndex, &[]);
let mut priceIndex: Value = (if isPrivate { Value::Int(5) } else { Value::Int(3) });
let mut priceString: Option<String> = self.safe_string_opt(tradeList.clone(), priceIndex, &[]);
if (amountString.as_str().unwrap_or("").starts_with("-")) {
side = Value::Str("sell".into());
amountString = crate::precise::Precise::stringAbs(&amountString);
} else {
side = Value::Str("buy".into());
}
let mut orderId: Value = Value::Null;
let mut takerOrMaker: Value = Value::Null;
let mut type_var: Value = Value::Null;
let mut fee: Value = Value::Null;
let mut symbol: Value = self.safe_symbol(Value::Null, &[market.clone()]);
let mut timestampIndex: Value = (if isPrivate { Value::Int(2) } else { Value::Int(1) });
let mut timestamp: Option<i64> = self.safe_integer(tradeList.clone(), timestampIndex, &[]).as_i64();
if isPrivate {
let mut marketId: Value = tradeList.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
symbol = self.safe_symbol(marketId, &[]);
orderId = self.safe_string(tradeList.clone(), Value::Int(3), &[]);
let mut maker: Option<i64> = self.safe_integer(tradeList.clone(), Value::Int(8), &[]).as_i64();
takerOrMaker = (if (maker == Some(1)) { Value::Str("maker".into()) } else { Value::Str("taker".into()) });
let mut feeCostString: Value = self.safe_string(tradeList.clone(), Value::Int(9), &[]);
feeCostString = crate::precise::Precise::stringNeg(&feeCostString);
let mut feeCurrencyId: Option<String> = self.safe_string_opt(tradeList.clone(), Value::Int(10), &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId.map(Value::from).unwrap_or(Value::Null), &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString);
m.insert("currency".to_string(), feeCurrency);
m
});
let mut orderType: Value = tradeList.as_array().and_then(|__arr| __arr.get(6)).cloned().unwrap_or(Value::Null);
type_var = self.safe_string(self.options.as_map().and_then(|__m| __m.get("exchangeTypes")).cloned().unwrap_or(Value::Null), orderType, &[]);
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("symbol".to_string(), symbol);
m.insert("order".to_string(), orderId);
m.insert("side".to_string(), side);
m.insert("type".to_string(), type_var);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("price".to_string(), priceString.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amountString);
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("info".to_string(), tradeList);
m
}), &[market]);
Value::Null
}
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchTrades".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_dynamic(Value::Str("fetchTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Int(10000)]).await;
}
let mut market: Value = self.market(symbol);
let mut sort: String = "-1".to_string();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
request.insert("start".into(), since);
sort = "1".to_string();
}
if (limit != Value::Null) {
request.insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(10000))); }
request.insert("sort".into(), Value::from(sort.clone()));
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), paramsPaginate, &[]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_5 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_trades_symbol_hist(&[__ws_arg_5]).await;
let mut rawTrades: Value = self.to_array(response);
let mut trades: Value = self.sort_by(rawTrades, Value::Int(1), &[]);
let mut tradesList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_348: bool = true;
while { if !__for_first_348 { i += 1; } __for_first_348 = false; i < (trades.len() as i64) } {
tradesList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(trades.clone(), Value::Int(i), &[]));
m
})); }
}
return self.parse_trades(Value::from(tradesList), &[market, Value::Null, limit]);
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::Int(100));
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("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(), Value::Int(10000)]).await;
}
let mut market: Value = self.market(symbol);
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(10000) } else { crate::runtime::Math::min(&limit, &Value::Int(10000)) });
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("timeframe".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m.insert("limit".to_string(), limitResolved.clone());
m
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
request.insert("sort".into(), Value::Int(1));
}
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), paramsPaginate, &[]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_6 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_candles_trade_timeframe_symbol_hist(&[__ws_arg_6]).await;
return self.parse_ohlc_vs(self.to_array(response), &[market, timeframe, since, limitResolved]);
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_integer(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv, Value::Int(5), &[])]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
if (status == Value::Null) {
return None;
}
let mut parts: Value = Value::Array(if let Some(__s) = status.as_str() { __s.split(" ").map(Value::from).collect() } else { Vec::new() });
let mut state: Option<String> = self.safe_string_opt(parts, Value::Int(0), &[]);
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("ACTIVE".to_string(), Value::Str("open".into()));
m.insert("PARTIALLY".to_string(), Value::Str("open".into()));
m.insert("EXECUTED".to_string(), Value::Str("closed".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("INSUFFICIENT".to_string(), Value::Str("canceled".into()));
m.insert("POSTONLY CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("RSN_DUST".to_string(), Value::Str("rejected".into()));
m.insert("RSN_PAUSE".to_string(), Value::Str("rejected".into()));
m.insert("IOC CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("FILLORKILL CANCELED".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(Value::Map(statuses), state.map(Value::from).unwrap_or(Value::Null), &[status]).as_str().map(str::to_owned);
}
pub fn parse_order_flags(&self, mut flags: Value) -> Value {
let mut flagValues: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1024".to_string(), Value::from(vec![Value::Str("reduceOnly".into())]));
m.insert("4096".to_string(), Value::from(vec![Value::Str("postOnly".into())]));
m.insert("5120".to_string(), Value::from(vec![Value::Str("reduceOnly".into()), Value::Str("postOnly".into())]));
m
});
return self.safe_list(flagValues, flags, &[Value::from(vec![])]);
Value::Null
}
pub fn parse_time_in_force(&self, mut orderType: Value) -> Option<String> {
let mut orderTypes: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("EXCHANGE IOC".to_string(), Value::Str("IOC".into()));
m.insert("EXCHANGE FOK".to_string(), Value::Str("FOK".into()));
m.insert("IOC".to_string(), Value::Str("IOC".into()));
m.insert("FOK".to_string(), Value::Str("FOK".into()));
m
});
return self.safe_string(Value::Map(orderTypes), orderType, &[Value::Str("GTC".into())]).as_str().map(str::to_owned);
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let __order_empty = indexmap::IndexMap::new();
let order = order.as_map().unwrap_or(&__order_empty);
let mut orderList: Value = (match order.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut id: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(0), &[]);
let mut marketId: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(3), &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut timestamp: Option<i64> = self.safe_integer(orderList.clone(), Value::Int(5), &[]).as_i64();
let mut remaining: Value = crate::precise::Precise::stringAbs(&self.safe_string(orderList.clone(), Value::Int(6), &[]));
let mut signedAmount: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(7), &[]);
let mut amount: Value = crate::precise::Precise::stringAbs(&signedAmount.clone().map(Value::from).unwrap_or(Value::Null));
let mut side: String = "buy".to_string();
if crate::precise::Precise::stringLt(&signedAmount.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) {
side = "sell".to_string();
}
let mut orderType: Value = self.safe_string(orderList.clone(), Value::Int(8), &[]);
let mut type_var: Option<String> = self.safe_string_opt(self.safe_dict_k(self.options.clone(), "exchangeTypes", &[]), orderType.clone(), &[]);
let mut timeInForce: Value = self.parse_time_in_force(orderType.clone()).map(Value::from).unwrap_or(Value::Null);
let mut rawFlags: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(12), &[]);
let mut flags: Value = self.parse_order_flags(rawFlags.clone().map(Value::from).unwrap_or(Value::Null));
let mut postOnly: Value = Value::Bool(false);
{
let mut i: i64 = 0;
let mut __for_first_349: bool = true;
while { if !__for_first_349 { i += 1; } __for_first_349 = false; i < (flags.len() as i64) } {
if (self.safe_string(flags.clone(), Value::Int(i), &[]).as_str() == Some("postOnly")) {
postOnly = Value::Bool(true);
}
}
}
let mut price: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(16), &[]);
let mut triggerPrice: Value = Value::Null;
if (orderType.as_str() == Some("EXCHANGE STOP")) || (orderType.as_str() == Some("EXCHANGE STOP LIMIT")) {
price = None;
triggerPrice = self.safe_string(orderList.clone(), Value::Int(16), &[]);
if (orderType.as_str() == Some("EXCHANGE STOP LIMIT")) {
price = self.safe_string_opt(orderList.clone(), Value::Int(19), &[]);
}
}
let mut status: Value = Value::Null;
let mut statusString: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(13), &[]);
if (statusString.is_some()) {
let mut parts: Value = Value::Array(if let Some(__s) = statusString.as_deref() { __s.split(" @ ").map(Value::from).collect() } else { Vec::new() });
status = self.parse_order_status(self.safe_string(parts, Value::Int(0), &[])).map(Value::from).unwrap_or(Value::Null);
}
let mut average: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(17), &[]);
let mut clientOrderId: Option<String> = self.safe_string_opt(orderList.clone(), Value::Int(2), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), orderList);
m.insert("id".to_string(), id.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("clientOrderId".to_string(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), type_var.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), postOnly);
m.insert("side".to_string(), Value::from(side.clone()));
m.insert("price".to_string(), price.map(Value::from).unwrap_or(Value::Null));
m.insert("triggerPrice".to_string(), triggerPrice);
m.insert("amount".to_string(), amount);
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), average.map(Value::from).unwrap_or(Value::Null));
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), remaining);
m.insert("status".to_string(), status);
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m
}), &[market]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
let mut market: Value = self.market(symbol.clone());
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount);
amountString = (if (side.as_str() == Some("buy")) { amountString.clone() } else { crate::precise::Precise::stringNeg(&amountString) });
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("amount".to_string(), amountString);
m
});
let mut triggerPrice: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]);
let mut trailingAmount: Option<String> = self.safe_string_k_opt(params.clone(), "trailingAmount", &[]);
let mut timeInForce: Option<String> = self.safe_string_k(params.clone(), "timeInForce", &[]).as_str().map(str::to_owned);
let mut postOnlyParam: bool = self.safe_bool_k_opt(params.clone(), "postOnly", &[Value::Bool(false)]).unwrap_or(false);
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut clientOrderId: Value = self.safe_integer2(params.clone(), Value::Str("cid".into()), Value::Str("clientOrderId".into()), &[]);
let mut orderType: Value = (if let Some(__s) = type_var.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
if (trailingAmount.is_some()) {
orderType = Value::Str("TRAILING STOP".into());
request.insert("price_trailing".into(), trailingAmount.map(Value::from).unwrap_or(Value::Null));
} else if (triggerPrice.is_some()) {
request.insert("price".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone().map(Value::from).unwrap_or(Value::Null)));
if (type_var.as_str() == Some("limit")) {
orderType = Value::Str("STOP LIMIT".into());
request.insert("price_aux_limit".into(), self.price_to_precision(symbol.clone(), price.clone()));
} else {
orderType = Value::Str("STOP".into());
}
}
let mut ioc: bool = timeInForce.as_deref() == Some("IOC");
let mut fok: bool = timeInForce.as_deref() == Some("FOK");
let mut postOnly: bool = postOnlyParam || (timeInForce.as_deref() == Some("PO"));
if (ioc || fok) && (price == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a price argument with IOC and FOK orders".into()))));
}
if (ioc || fok) && (type_var.as_str() == Some("market")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() does not allow market IOC and FOK orders".into()))));
}
if (type_var.as_str() != Some("market")) && (triggerPrice.is_none()) {
request.insert("price".into(), self.price_to_precision(symbol, price));
}
if ioc {
orderType = Value::Str("IOC".into());
} else if fok {
orderType = Value::Str("FOK".into());
}
let marginModeparamsMarginModeVariable: Vec<Value> = self.handle_margin_mode_and_params(Value::Str("createOrder".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 matches!((self.safe_bool_k(market, "spot", &[Value::Bool(false)])), Value::Bool(true)) && (marginMode == Value::Null) {
orderType = Value::Str(format!("{}{}", Value::Str("EXCHANGE ".into()), orderType).into());
}
request.insert("type".into(), orderType);
let mut flags: Value = Value::Int(0);
if postOnly && reduceOnly.as_bool() == Some(true) {
flags = Value::Int(5120);
} else if postOnly {
flags = Value::Int(4096);
} else if reduceOnly.as_bool() == Some(true) {
flags = Value::Int(1024);
}
if (flags.as_f64() != Some(0.0)) {
request.insert("flags".into(), flags);
}
if (clientOrderId != Value::Null) {
request.insert("cid".into(), clientOrderId);
}
let mut paramsOmitted: Value = self.omit(paramsMarginMode, Value::from(vec![Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), Value::Str("timeInForce".into()), Value::Str("postOnly".into()), Value::Str("reduceOnly".into()), Value::Str("trailingAmount".into()), Value::Str("clientOrderId".into())]), &[]);
return self.extend(Value::Map(request), &[paramsOmitted]);
Value::Null
}
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_order_request(symbol, type_var, side, amount, &[price, params]);
let mut response: Value = self.private_post_auth_w_order_submit(&[request]).await;
let mut status: Value = self.safe_string(response.clone(), Value::Int(6), &[Value::Str("".into())]);
if (status.as_str() != Some("SUCCESS")) {
let errorCode: String = self.safe_string_opt(response.clone(), Value::Int(5), &[Value::Str("".into())]).unwrap_or_default();
let errorText: String = self.safe_string_opt(response.clone(), Value::Int(7), &[Value::Str("".into())]).unwrap_or_default();
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), status).into()), Value::Str(": ".into())).into()),
errorText).into()), Value::Str(" (#".into())).into()), errorCode).into()), Value::Str(")".into()))));
}
let mut orders: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut order: Value = self.safe_list(orders, Value::Int(0), &[]);
let mut newOrder: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(Value::Map(newOrder), &[market]);
Value::Null
}
pub async fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_350: bool = true;
while { if !__for_first_350 { i += 1; } __for_first_350 = false; i < (orders.len() as i64) } {
let mut rawOrder: Value = self.safe_dict(orders.clone(), Value::Int(i), &[]);
let mut symbol: Option<String> = self.safe_string_k_opt(rawOrder.clone(), "symbol", &[]);
let mut type_var: Option<String> = self.safe_string_k_opt(rawOrder.clone(), "type", &[]);
let mut side: Option<String> = self.safe_string_k_opt(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_number_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_number_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder, "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_order_request(symbol.map(Value::from).unwrap_or(Value::Null), type_var.map(Value::from).unwrap_or(Value::Null), side.map(Value::from).unwrap_or(Value::Null), amount, &[price, orderParams]);
ordersRequests.push(Value::from(vec![Value::Str("on".into()), orderRequest]));
}
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("ops".to_string(), Value::from(ordersRequests));
m
});
let mut response: Value = self.private_post_auth_w_order_multi(&[Value::Map(request)]).await;
let mut results: Vec<Value> = Vec::new();
let mut data: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
{
let mut i: i64 = 0;
let mut __for_first_351: bool = true;
while { if !__for_first_351 { i += 1; } __for_first_351 = false; i < (data.len() as i64) } {
results.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(self.safe_list(self.safe_list(data.clone(), Value::Int(i), &[]), Value::Int(4), &[]), Value::Int(0), &[]));
m
}));
}
}
return self.parse_orders(Value::from(results), &[]);
Value::Null
}
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("all".to_string(), Value::Int(1));
m
});
let __ws_arg_7 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_post_auth_w_order_cancel_multi(&[__ws_arg_7]).await;
let mut orders: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut ordersList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_352: bool = true;
while { if !__for_first_352 { i += 1; } __for_first_352 = false; i < (orders.len() as i64) } {
ordersList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(orders.clone(), Value::Int(i), &[]));
m
}));
}
}
return self.parse_orders(Value::from(ordersList), &[]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut cid: Option<i64> = self.safe_integer2(params.clone(), Value::Str("cid".into()), Value::Str("clientOrderId".into()), &[]).as_i64(); let mut request: Value = Value::Null;
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
if (cid.is_some()) {
let mut cidDate: Option<String> = self.safe_string_k_opt(params.clone(), "cidDate", &[]); if (cidDate.is_none()) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" canceling an order by clientOrderId ('cid') requires both 'cid' and 'cid_date' ('YYYY-MM-DD')".into()))));
}
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cid".to_string(), Value::from(cid));
m.insert("cid_date".to_string(), cidDate.map(Value::from).unwrap_or(Value::Null));
m
});
} else {
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.parse_to_int(id));
m
});
}
let mut paramsOmitted: Value = (if (cid.is_some()) { self.omit(params.clone(), Value::from(vec![Value::Str("cid".into()), Value::Str("clientOrderId".into())]), &[]) } else { params });
let __ws_arg_8 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_post_auth_w_order_cancel(&[__ws_arg_8]).await;
let mut order: Value = self.safe_value(response, Value::Int(4), &[]);
let mut newOrder: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(Value::Map(newOrder), &[market]);
Value::Null
}
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut numericIds: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_353: bool = true;
while { if !__for_first_353 { i += 1; } __for_first_353 = false; i < (ids.len() as i64) } {
numericIds.push(self.parse_to_numeric(self.safe_string(ids.clone(), Value::Int(i), &[])));
}
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::from(numericIds));
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let __ws_arg_9 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_post_auth_w_order_cancel_multi(&[__ws_arg_9]).await;
let mut orders: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut ordersList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_354: bool = true;
while { if !__for_first_354 { i += 1; } __for_first_354 = false; i < (orders.len() as i64) } {
ordersList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(orders.clone(), Value::Int(i), &[]));
m
}));
}
}
return self.parse_orders(Value::from(ordersList), &[market]);
Value::Null
}
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
}));
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::from(vec![self.parse_to_int(id.clone())]));
m
});
let __ws_arg_10 = self.extend(Value::Map(request), &[params]);
let mut orders: Value = self.fetch_open_orders(&[symbol, Value::Null, Value::Null, __ws_arg_10]).await;
let mut order: Value = self.safe_dict(orders, Value::Int(0), &[]);
if (order == Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" order ".into())).into()), id).into()), Value::Str(" not found".into()))));
}
return order;
Value::Null
}
pub async fn fetch_closed_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
}));
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::from(vec![self.parse_to_int(id.clone())]));
m
});
let __ws_arg_11 = self.extend(Value::Map(request), &[params]);
let mut orders: Value = self.fetch_closed_orders(&[symbol, Value::Null, Value::Null, __ws_arg_11]).await;
let mut order: Value = self.safe_dict(orders, Value::Int(0), &[]);
if (order == Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" order ".into())).into()), id).into()), Value::Str(" not found".into()))));
}
return order;
Value::Null
}
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if (symbol == Value::Null) {
let __ws_arg_12 = self.extend(Value::Map(request.clone()), &[params.clone()]);
response = self.private_post_auth_r_orders(&[__ws_arg_12]).await;
} else {
market = self.market(symbol);
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_13 = self.extend(Value::Map(request), &[params]);
response = self.private_post_auth_r_orders_symbol(&[__ws_arg_13]).await;
}
let mut ordersList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_355: bool = true;
while { if !__for_first_355 { i += 1; } __for_first_355 = false; i < (response.len() as i64) } {
ordersList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(response.clone(), Value::Int(i), &[]));
m
}));
}
}
return self.parse_orders(Value::from(ordersList), &[market, since, limit]);
Value::Null
}
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchClosedOrders".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchClosedOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone()); }
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), paramsPaginate, &[]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if (symbol == Value::Null) {
let __ws_arg_14 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_post_auth_r_orders_hist(&[__ws_arg_14]).await;
} else {
market = self.market(symbol);
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_15 = self.extend(requestUntil, &[paramsUntil]);
response = self.private_post_auth_r_orders_symbol_hist(&[__ws_arg_15]).await;
}
let mut ordersList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_356: bool = true;
while { if !__for_first_356 { i += 1; } __for_first_356 = false; i < (response.len() as i64) } {
ordersList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(response.clone(), Value::Int(i), &[]));
m
}));
}
}
return self.parse_orders(Value::from(ordersList), &[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
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderTrades() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut orderId: Value = self.parse_to_int(id);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId);
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_16 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_post_auth_r_order_symbol_id_trades(&[__ws_arg_16]).await;
let mut rawTrades: Value = self.to_array(response);
let mut tradesList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_357: bool = true;
while { if !__for_first_357 { i += 1; } __for_first_357 = false; i < (rawTrades.len() as i64) } {
tradesList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(rawTrades.clone(), Value::Int(i), &[]));
m
})); }
}
return self.parse_trades(Value::from(tradesList), &[market, since, limit]);
Value::Null
}
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("end".to_string(), self.milliseconds());
m
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone()); }
let mut response: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_17 = self.extend(Value::Map(request.clone()), &[params.clone()]);
response = self.private_post_auth_r_trades_symbol_hist(&[__ws_arg_17]).await;
} else {
let __ws_arg_18 = self.extend(Value::Map(request), &[params]);
response = self.private_post_auth_r_trades_hist(&[__ws_arg_18]).await;
}
let mut tradesList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_358: bool = true;
while { if !__for_first_358 { i += 1; } __for_first_358 = false; i < (response.len() as i64) } {
tradesList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(response.clone(), Value::Int(i), &[]));
m
})); }
}
return self.parse_trades(Value::from(tradesList), &[market, since, limit]);
Value::Null
}
pub async fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("op_renew".to_string(), Value::Int(1));
m
});
let __ws_arg_19 = self.extend(Value::Map(request), &[params]);
return self.fetch_deposit_address(code, &[__ws_arg_19]).await;
Value::Null
}
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut networkParam: Value = self.safe_string_k(params.clone(), "network", &[code.clone()]);
let mut network: Value = self.safe_string(self.networkAliases.clone(), networkParam.clone(), &[networkParam.clone()]);
let mut currencyNetworks: Value = self.safe_dict_k(currency, "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyNetwork: Value = self.safe_dict(currencyNetworks, network, &[]);
let mut networkId: Option<String> = self.safe_string_k_opt(currencyNetwork, "id", &[]);
if (networkId.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddress() could not find a network for '".into())).into()), code).into()), Value::Str("'. You can specify it by providing the 'network' value inside params".into()))));
}
let mut wallet: Value = self.safe_string_k(params.clone(), "wallet", &[Value::Str("exchange".into())]); let mut paramsOmitted: Value = self.omit(params, Value::Str("network".into()), &[Value::Str("wallet".into())]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), networkId.map(Value::from).unwrap_or(Value::Null));
m.insert("wallet".to_string(), wallet);
m.insert("op_renew".to_string(), Value::Int(0));
m
});
let __ws_arg_20 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.private_post_auth_w_deposit_address(&[__ws_arg_20]).await;
let mut result: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::from(vec![])]);
let mut poolAddress: Value = self.safe_string(result.clone(), Value::Int(5), &[]);
let mut address: Value = (if (poolAddress == Value::Null) { self.safe_string(result.clone(), Value::Int(4), &[]) } else { poolAddress.clone() });
let mut tag: Value = (if (poolAddress == Value::Null) { Value::Null } else { self.safe_string(result, Value::Int(4), &[]) });
self.check_address(&[address.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("address".to_string(), address);
m.insert("tag".to_string(), tag);
m.insert("network".to_string(), Value::Null);
m.insert("info".to_string(), response);
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("SUCCESS".to_string(), Value::Str("ok".into()));
m.insert("COMPLETED".to_string(), Value::Str("ok".into()));
m.insert("ERROR".to_string(), Value::Str("failed".into()));
m.insert("FAILURE".to_string(), Value::Str("failed".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("PENDING APPROVAL".to_string(), Value::Str("pending".into()));
m.insert("PENDING".to_string(), Value::Str("pending".into()));
m.insert("PENDING REVIEW".to_string(), Value::Str("pending".into()));
m.insert("PENDING CANCELLATION".to_string(), Value::Str("pending".into()));
m.insert("SENDING".to_string(), Value::Str("pending".into()));
m.insert("USER APPROVED".to_string(), Value::Str("pending".into()));
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut transactionLength: f64 = ((transaction.len() as i64) as f64);
let mut timestamp: Value = Value::Null;
let mut updated: Value = Value::Null;
let mut code: Value = Value::Null;
let mut amount: Value = Value::Null;
let mut id: Value = Value::Null;
let mut status: Value = Value::Null;
let mut tag: Value = Value::Null;
let mut type_var: Value = Value::Null;
let mut feeCost: Value = Value::Null;
let mut txid: Value = Value::Null;
let mut addressTo: Value = Value::Null;
let mut network: Value = Value::Null;
let mut comment: Value = Value::Null;
if (transactionLength == 8.0) {
let mut data: Value = self.safe_list(transaction.clone(), Value::Int(4), &[Value::from(vec![])]);
timestamp = self.safe_integer(transaction.clone(), Value::Int(0), &[]);
if (currency != Value::Null) {
code = self.safe_string_k(currency.clone(), "code", &[]);
}
feeCost = self.safe_string(data.clone(), Value::Int(8), &[]);
if (feeCost != Value::Null) {
feeCost = crate::precise::Precise::stringAbs(&feeCost);
}
amount = self.safe_number(data.clone(), Value::Int(5), &[]);
let mut withdrawId: Option<i64> = self.safe_integer(data.clone(), Value::Int(0), &[]).as_i64();
id = Value::from(withdrawId);
status = Value::Str("ok".into());
if (withdrawId == Some(0)) {
id = Value::Null;
status = Value::Str("failed".into());
}
tag = self.safe_string(data.clone(), Value::Int(3), &[]);
type_var = Value::Str("withdrawal".into());
let mut networkId: Option<String> = self.safe_string_opt(data, Value::Int(2), &[]);
network = self.network_id_to_code(&[(if let Some(__s) = networkId.as_deref() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }), code.clone()]); } else if (transactionLength == 22.0) {
id = self.safe_string(transaction.clone(), Value::Int(0), &[]);
let mut currencyId: Option<String> = self.safe_string_opt(transaction.clone(), Value::Int(1), &[]);
code = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]);
let mut networkId: Option<String> = self.safe_string_opt(transaction.clone(), Value::Int(2), &[]);
network = self.network_id_to_code(&[networkId.map(Value::from).unwrap_or(Value::Null), code.clone()]);
timestamp = self.safe_integer(transaction.clone(), Value::Int(5), &[]);
updated = self.safe_integer(transaction.clone(), Value::Int(6), &[]);
status = self.parse_transaction_status(self.safe_string(transaction.clone(), Value::Int(9), &[])).map(Value::from).unwrap_or(Value::Null);
let mut signedAmount: Option<String> = self.safe_string_opt(transaction.clone(), Value::Int(12), &[]);
amount = crate::precise::Precise::stringAbs(&signedAmount.clone().map(Value::from).unwrap_or(Value::Null));
if (signedAmount.is_some()) {
if crate::precise::Precise::stringLt(&signedAmount.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) {
type_var = Value::Str("withdrawal".into());
} else {
type_var = Value::Str("deposit".into());
}
}
feeCost = self.safe_string(transaction.clone(), Value::Int(13), &[]);
if (feeCost != Value::Null) {
feeCost = crate::precise::Precise::stringAbs(&feeCost);
}
addressTo = self.safe_string(transaction.clone(), Value::Int(16), &[]);
txid = self.safe_string(transaction.clone(), Value::Int(20), &[]);
comment = self.safe_string(transaction.clone(), Value::Int(21), &[]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction);
m.insert("id".to_string(), id);
m.insert("txid".to_string(), txid);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), network);
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("status".to_string(), status);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("address".to_string(), addressTo.clone());
m.insert("addressFrom".to_string(), Value::Null);
m.insert("addressTo".to_string(), addressTo);
m.insert("tag".to_string(), tag.clone());
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), tag);
m.insert("updated".to_string(), updated);
m.insert("comment".to_string(), comment);
m.insert("internal".to_string(), 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.parse_number(feeCost, &[]));
m.insert("rate".to_string(), Value::Null);
m
}));
m
});
Value::Null
}
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_post_auth_r_summary(&[params]).await;
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut fiat: indexmap::IndexMap<String, Value> = self.safe_dict_k(self.options.clone(), "fiat", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]).as_map().cloned().unwrap_or_default();
let mut feeData: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::from(vec![])]);
let mut makerData: Value = self.safe_list(feeData.clone(), Value::Int(0), &[Value::from(vec![])]);
let mut takerData: Value = self.safe_list(feeData, Value::Int(1), &[Value::from(vec![])]);
let mut makerFee: Value = self.safe_number(makerData.clone(), Value::Int(0), &[]);
let mut makerFeeFiat: Value = self.safe_number(makerData.clone(), Value::Int(2), &[]);
let mut makerFeeDeriv: Value = self.safe_number(makerData, Value::Int(5), &[]);
let mut takerFee: Value = self.safe_number(takerData.clone(), Value::Int(0), &[]);
let mut takerFeeFiat: Value = self.safe_number(takerData.clone(), Value::Int(2), &[]);
let mut takerFeeDeriv: Value = self.safe_number(takerData, Value::Int(5), &[]);
{
let mut i: i64 = 0;
let mut __for_first_359: bool = true;
while { if !__for_first_359 { i += 1; } __for_first_359 = false; i < (self.symbols.len() as i64) } {
let mut symbol: Value = self.safe_string(self.symbols.clone(), Value::Int(i), &[Value::Str("".into())]);
let mut market: Value = self.market(symbol.clone());
let mut fee: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
if (matches!(&market.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null), Value::Str(__k) if fiat.contains_key(__k.as_ref()))) {
fee.insert("maker".into(), makerFeeFiat.clone());
fee.insert("taker".into(), takerFeeFiat.clone());
} else if matches!(self.safe_bool_k(market, "contract", &[Value::Bool(false)]), Value::Bool(true)) {
fee.insert("maker".into(), makerFeeDeriv.clone());
fee.insert("taker".into(), takerFeeDeriv.clone());
} else {
fee.insert("maker".into(), makerFee.clone());
fee.insert("taker".into(), takerFee.clone());
}
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), Value::Map(fee)); }
}
}
return result;
Value::Null
}
pub async fn fetch_deposits_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = Value::Null;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone()); }
let mut response: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
request.insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_21 = self.extend(Value::Map(request.clone()), &[params.clone()]);
let mut currencyMovements: Value = self.private_post_auth_r_movements_currency_hist(&[__ws_arg_21]).await;
response = self.to_array(currencyMovements);
} else {
let __ws_arg_22 = self.extend(Value::Map(request), &[params]);
let mut movements: Value = self.private_post_auth_r_movements_hist(&[__ws_arg_22]).await;
response = self.to_array(movements);
}
return self.parse_transactions(response, &[currency, since, limit]);
Value::Null
}
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let tagparamsWithdrawTagVariable: Vec<Value> = self.handle_param_string(params, Value::Str("tag".into()), &[]).as_array().cloned().unwrap_or_default();
let mut tag: Value = tagparamsWithdrawTagVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagparamsWithdrawTagVariable.get(1).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut networkParam: Value = self.safe_string_k(paramsWithdrawTag.clone(), "network", &[code.clone()]);
let mut network: Value = self.safe_string(self.networkAliases.clone(), networkParam.clone(), &[networkParam.clone()]);
let mut paramsOmitted: Value = self.omit(paramsWithdrawTag, Value::Str("network".into()), &[]);
let mut currencyNetworks: Value = self.safe_dict_k(currency.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyNetwork: Value = self.safe_dict(currencyNetworks, network, &[]);
let mut networkId: Option<String> = self.safe_string_k_opt(currencyNetwork, "id", &[]);
if (networkId.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" withdraw() could not find a network for '".into())).into()), code).into()), Value::Str("'. You can specify it by providing the 'network' value inside params".into()))));
}
let mut wallet: Value = self.safe_string_k(paramsOmitted.clone(), "wallet", &[Value::Str("exchange".into())]); let mut paramsOmitted2: Value = self.omit(paramsOmitted, Value::Str("network".into()), &[Value::Str("wallet".into())]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), networkId.map(Value::from).unwrap_or(Value::Null));
m.insert("wallet".to_string(), wallet);
m.insert("amount".to_string(), self.number_to_string(amount));
m.insert("address".to_string(), address);
m
});
if (tag != Value::Null) {
request.insert("payment_id".into(), tag);
}
let mut withdrawOptions: Value = self.safe_dict_k(self.options.clone(), "withdraw", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut includeFee: bool = self.safe_bool_k_opt(withdrawOptions, "includeFee", &[Value::Bool(false)]).unwrap_or(false);
if includeFee {
request.insert("fee_deduct".into(), Value::Int(1));
}
let __ws_arg_23 = self.extend(Value::Map(request), &[paramsOmitted2]);
let mut response: Value = self.private_post_auth_w_withdraw(&[__ws_arg_23]).await;
let mut statusMessage: Option<String> = self.safe_string(response.clone(), Value::Int(0), &[]).as_str().map(str::to_owned);
if (statusMessage.as_deref() == Some("error")) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), response).into());
let mut message: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".into())]);
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut text: Option<String> = self.safe_string_opt(response.clone(), Value::Int(7), &[]);
if (text.as_deref() != Some("success")) {
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), text.clone().map(Value::from).unwrap_or(Value::Null), text.map(Value::from).unwrap_or(Value::Null));
}
return self.parse_transaction(response, &[currency]);
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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.private_post_auth_r_positions(&[params]).await;
let mut rawPositions: Value = self.to_array(response);
let mut positionsList: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_360: bool = true;
while { if !__for_first_360 { i += 1; } __for_first_360 = false; i < (rawPositions.len() as i64) } {
positionsList.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(rawPositions.clone(), Value::Int(i), &[]));
m
}));
}
}
return self.parse_positions(Value::from(positionsList), &[symbolsNormalized]);
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 __position_empty = indexmap::IndexMap::new();
let position = position.as_map().unwrap_or(&__position_empty);
let mut positionList: Value = (match position.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut marketId: Option<String> = self.safe_string_opt(positionList.clone(), Value::Int(0), &[]);
let mut amount: Option<String> = self.safe_string_opt(positionList.clone(), Value::Int(2), &[]);
let mut timestamp: Option<i64> = self.safe_integer(positionList.clone(), Value::Int(12), &[]).as_i64();
let mut meta: Value = self.safe_string(positionList.clone(), Value::Int(19), &[]);
let mut tradePrice: Option<String> = self.safe_string_k_opt(meta.clone(), "trade_price", &[]);
let mut tradeAmount: Option<String> = self.safe_string_k_opt(meta, "trade_amount", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), positionList.clone());
m.insert("id".to_string(), self.safe_string(positionList.clone(), Value::Int(11), &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market]));
m.insert("notional".to_string(), self.parse_number(amount.clone().map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("liquidationPrice".to_string(), self.safe_number(positionList.clone(), Value::Int(8), &[]));
m.insert("entryPrice".to_string(), self.safe_number(positionList.clone(), Value::Int(3), &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number(positionList.clone(), Value::Int(6), &[]));
m.insert("percentage".to_string(), self.safe_number(positionList.clone(), Value::Int(7), &[]));
m.insert("contracts".to_string(), Value::Null);
m.insert("contractSize".to_string(), Value::Null);
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), (if crate::precise::Precise::stringGt(&amount.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) { Value::Str("long".into()) } else { Value::Str("short".into()) }));
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer(positionList.clone(), Value::Int(13), &[]));
m.insert("maintenanceMargin".to_string(), self.safe_number(positionList.clone(), Value::Int(18), &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("collateral".to_string(), self.safe_number(positionList.clone(), Value::Int(17), &[]));
m.insert("initialMargin".to_string(), self.parse_number(crate::precise::Precise::stringMul(&tradeAmount.clone().map(Value::from).unwrap_or(Value::Null), &tradePrice.clone().map(Value::from).unwrap_or(Value::Null)), &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number(positionList, Value::Int(9), &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn nonce(&self) -> Value {
return self.milliseconds();
Value::Null
}
pub fn sign(&mut 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 request: Value = Value::Str(format!("{}{}", Value::Str("/".into()), self.implode_params(path.clone(), params.clone())).into());
let mut query: Value = self.omit(params, self.extract_params(path), &[]);
if (apiName.as_str() == Some("v1")) {
request = Value::Str(format!("{}{}", Value::Str("v1".into()), request).into());
} else {
request = Value::Str(format!("{}{}", self.version.clone(), request).into());
}
let mut apiUrl: Option<String> = self.safe_string_opt(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), 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()), request).into());
let mut requestBody: Value = Value::Null;
let mut requestHeaders: Value = Value::Null;
if (apiName.as_str() == Some("public")) {
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) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into())).into());
}
}
if (apiName.as_str() == Some("private")) {
self.check_required_credentials(&[]);
let mut nonce: Value = Value::Str(format!("{}", self.incrementing_nonce()).into());
requestBody = json_stringify(&query);
let mut auth: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("/api/".into()), request).into()), nonce).into()), requestBody).into());
let mut signature: Value = self.hmac(self.encode(auth), self.encode(self.secret.clone()), Value::Str("sha384".into()), &[]);
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bfx-nonce".to_string(), nonce);
m.insert("bfx-apikey".to_string(), self.apiKey.clone());
m.insert("bfx-signature".to_string(), signature);
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
}
let mut bodyResolved: Value = requestBody;
let mut headersResolved: Value = requestHeaders;
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), bodyResolved);
m.insert("headers".to_string(), headersResolved);
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response != Value::Null) {
if !(matches!(&response, Value::Arr(_))) {
let mut message: Option<String> = self.safe_string2_opt(response.clone(), Value::Str("message".into()), Value::Str("error".into()), &[]);
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), message.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(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body)));
}
} else if (response.as_str() == Some("")) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" returned empty response".into()))));
}
if (code.as_f64() == Some(429.0)) {
panic!("{}", crate::exchange_errors::rate_limit_exceeded(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body)));
}
if (code.as_f64() == Some(500.0)) {
let mut errorCode: Value = self.safe_string(response.clone(), Value::Int(1), &[Value::Str("".into())]);
let mut errorText: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".into())]);
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), errorText).into());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), errorText.clone(), feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode.clone(), feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorText.clone(), feedback);
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), errorText).into()), Value::Str(" (#".into())).into()), errorCode).into()), Value::Str(")".into()))));
}
return response;
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
if (type_var == Value::Null) {
return Value::Null;
} else if type_var.as_str().unwrap_or("").contains("fee") || type_var.as_str().unwrap_or("").contains("charged") {
return Value::Str("fee".into());
} else if type_var.as_str().unwrap_or("").contains("rebate") {
return Value::Str("rebate".into());
} else if type_var.as_str().unwrap_or("").contains("deposit") || type_var.as_str().unwrap_or("").contains("withdrawal") {
return Value::Str("transaction".into());
} else if type_var.as_str().unwrap_or("").contains("transfer") {
return Value::Str("transfer".into());
} else if type_var.as_str().unwrap_or("").contains("payment") {
return Value::Str("payout".into());
} else if type_var.as_str().unwrap_or("").contains("exchange") || type_var.as_str().unwrap_or("").contains("position") {
return Value::Str("trade".into());
} else {
return type_var;
}
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 itemList: Value = self.safe_list_k(item.clone(), "result", &[Value::from(vec![])]);
let mut type_var: Value = Value::Null;
let mut id: Option<String> = self.safe_string_opt(itemList.clone(), Value::Int(0), &[]);
let mut currencyId: Option<String> = self.safe_string_opt(itemList.clone(), Value::Int(1), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone().map(Value::from).unwrap_or(Value::Null), &[currency.clone()]);
let mut currencyResolved: Value = self.safe_currency(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]);
let mut timestamp: Option<i64> = self.safe_integer(itemList.clone(), Value::Int(3), &[]).as_i64();
let mut amount: Value = self.safe_number(itemList.clone(), Value::Int(5), &[]);
let mut after: Value = self.safe_number(itemList.clone(), Value::Int(6), &[]);
let mut description: Option<String> = self.safe_string_opt(itemList, Value::Int(8), &[]);
if (description.is_some()) {
let mut parts: Value = Value::Array(if let Some(__s) = description.as_deref() { __s.split(" @ ").map(Value::from).collect() } else { Vec::new() });
let mut first: Value = self.safe_string_lower(parts, Value::Int(0), &[]);
type_var = self.parse_ledger_entry_type(first);
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item);
m.insert("id".to_string(), id.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("direction".to_string(), Value::Null);
m.insert("account".to_string(), Value::Null);
m.insert("referenceId".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code);
m.insert("amount".to_string(), amount);
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), after);
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currencyResolved]);
Value::Null
}
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchLedger".into()), Value::Str("paginate".into()), &[Value::Bool(false)]).as_array().cloned().unwrap_or_default();
let mut paginate: Value = paginateparamsPaginateVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.get(1).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchLedger".into()), &[code.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Int(2500)]).await;
}
let mut currency: Value = Value::Null;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), paramsPaginate, &[]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_24 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_post_auth_r_ledgers_currency_hist(&[__ws_arg_24]).await;
} else {
let __ws_arg_25 = self.extend(requestUntil, &[paramsUntil]);
response = self.private_post_auth_r_ledgers_hist(&[__ws_arg_25]).await;
}
let mut ledgerObjects: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_361: bool = true;
while { if !__for_first_361 { i += 1; } __for_first_361 = false; i < (response.len() as i64) } {
ledgerObjects.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), self.safe_list(response.clone(), Value::Int(i), &[]));
m
}));
}
}
return self.parse_ledger(Value::from(ledgerObjects), &[currency, since, limit]);
Value::Null
}
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbols == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRates() requires a symbols argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("keys".to_string(), Value::Str(marketIds.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",")).unwrap_or_default().into()));
m
});
let __ws_arg_26 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_26]).await;
return self.parse_funding_rates(response, &[symbols]);
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()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".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("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone(), Value::Int(5000)]).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
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
}
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), paramsPaginate, &[]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_27 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_status_deriv_symbol_hist(&[__ws_arg_27]).await;
let mut rawRatesData: Value = self.to_array(response);
let mut rates: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_362: bool = true;
while { if !__for_first_362 { i += 1; } __for_first_362 = false; i < (rawRatesData.len() as i64) } {
let mut fr: Value = rawRatesData.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut rate: Value = self.parse_funding_rate_history(fr, &[market.clone()]);
rates.push(rate);
}
}
let mut reversedArray: Value = Value::from(vec![]);
let mut rawRates: Value = self.filter_by_symbol_since_limit(Value::from(rates), &[symbol, since, limit]);
let mut ratesLength: Value = Value::Int(rawRates.len() as i64);
{
let mut i: Value = Value::Int(0);
let mut __for_first_363: bool = true;
while { if !__for_first_363 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_363 = false; i.as_f64().unwrap_or(f64::NAN) < ratesLength.as_f64().unwrap_or(f64::NAN) } {
let mut index: Value = (match (&((match (&(ratesLength), &(i)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null })),
&(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
let mut valueAtIndex: Value = get_value(&rawRates, &index);
if let Value::Arr(__a) = &mut reversedArray { std::sync::Arc::make_mut(__a).push(valueAtIndex); }
}
}
return reversedArray;
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_opt(contract.clone(), Value::Int(0), &[]);
let mut timestamp: Option<i64> = self.safe_integer(contract.clone(), Value::Int(1), &[]).as_i64();
let mut nextFundingTimestamp: Option<i64> = self.safe_integer(contract.clone(), Value::Int(8), &[]).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(marketId.map(Value::from).unwrap_or(Value::Null), &[market]));
m.insert("markPrice".to_string(), self.safe_number(contract.clone(), Value::Int(15), &[]));
m.insert("indexPrice".to_string(), self.safe_number(contract.clone(), Value::Int(3), &[]));
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("fundingRate".to_string(), self.safe_number(contract.clone(), Value::Int(12), &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), self.safe_number(contract, Value::Int(9), &[]));
m.insert("nextFundingTimestamp".to_string(), Value::from(nextFundingTimestamp));
m.insert("nextFundingDatetime".to_string(), self.iso8601(Value::from(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(), Value::Null);
m
});
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(contract.clone(), Value::Int(0), &[]).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(contract, Value::Int(11), &[]));
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_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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut marketIds: Value = Value::from(vec![Value::Str("ALL".into())]);
if (symbolsNormalized != Value::Null) {
marketIds = self.market_ids(&[symbolsNormalized.clone()]);
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("keys".to_string(), Value::Str(marketIds.as_array().map(|__a| __a.iter().map(|__v| __v.to_string()).collect::<Vec<String>>().join(",")).unwrap_or_default().into()));
m
});
let __ws_arg_28 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_28]).await;
return self.parse_open_interests(response, &[symbolsNormalized]);
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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("keys".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_29 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_29]).await;
let mut oi: Value = self.safe_list(response, Value::Int(0), &[]);
return self.parse_open_interest(oi, &[market]);
Value::Null
}
pub async fn fetch_open_interest_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchOpenInterestHistory".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("fetchOpenInterestHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone(), Value::Int(5000)]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), paramsPaginate, &[]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_30 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_status_deriv_symbol_hist(&[__ws_arg_30]).await;
return self.parse_open_interests_history(response, &[market, since, limit]);
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 interestLength: Value = get_array_length(&interest);
let mut openInterestIndex: Value = (if (interestLength.as_f64() == Some(23.0)) { Value::Int(17) } else { Value::Int(18) });
let mut timestamp: Option<i64> = self.safe_integer(interest.clone(), Value::Int(1), &[]).as_i64();
let mut marketId: Option<String> = self.safe_string_opt(interest.clone(), Value::Int(0), &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market.clone(), Value::Null, Value::Str("swap".into())]));
m.insert("openInterestAmount".to_string(), self.safe_number(interest.clone(), openInterestIndex, &[]));
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("info".to_string(), interest);
m
}), &[market]);
Value::Null
}
pub async fn fetch_liquidations(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let paginateparamsPaginateVariable: Vec<Value> = self.handle_option_bool_and_params(params, Value::Str("fetchLiquidations".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("fetchLiquidations".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone(), Value::Int(500)]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
request.insert("start".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), paramsPaginate, &[]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
let __ws_arg_31 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_liquidations_hist(&[__ws_arg_31]).await;
return self.parse_liquidations(self.to_array(response), &[market, since, limit]);
Value::Null
}
pub fn parse_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut entry: Value = self.safe_list(liquidation, Value::Int(0), &[]);
let mut timestamp: Option<i64> = self.safe_integer(entry.clone(), Value::Int(2), &[]).as_i64();
let mut marketId: Option<String> = self.safe_string_opt(entry.clone(), Value::Int(4), &[]);
let mut contracts: Value = crate::precise::Precise::stringAbs(&self.safe_string(entry.clone(), Value::Int(5), &[]));
let mut contractSize: Option<String> = self.safe_string_k_opt(market.clone(), "contractSize", &[]);
let mut baseValue: Value = crate::precise::Precise::stringMul(&contracts, &contractSize.clone().map(Value::from).unwrap_or(Value::Null));
let mut price: Option<String> = self.safe_string_opt(entry.clone(), Value::Int(11), &[]);
let mut sideFlag: Option<i64> = self.safe_integer(entry.clone(), Value::Int(8), &[]).as_i64();
let mut side: String = "sell".to_string();
if (sideFlag == Some(1)) {
side = "buy".to_string();
}
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry);
m.insert("symbol".to_string(), self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market, Value::Null, Value::Str("contract".into())]));
m.insert("contracts".to_string(), self.parse_number(contracts, &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSize.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("price".to_string(), self.parse_number(price.clone().map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("side".to_string(), Value::from(side));
m.insert("baseValue".to_string(), self.parse_number(baseValue.clone(), &[]));
m.insert("quoteValue".to_string(), self.parse_number(crate::precise::Precise::stringMul(&baseValue, &price.clone().map(Value::from).unwrap_or(Value::Null)), &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m
}), &[]);
Value::Null
}
pub async fn set_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if !matches!(self.safe_bool_k(market.clone(), "swap", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setMargin() only support swap 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.insert("collateral".to_string(), self.parse_to_numeric(amount));
m
});
let __ws_arg_32 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_post_auth_w_deriv_collateral_set(&[__ws_arg_32]).await;
let mut data: Value = self.safe_value(response, Value::Int(0), &[]);
return self.parse_margin_modification(data, &[market]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marginStatusRaw: Option<i64> = self.safe_integer(data.clone(), Value::Int(0), &[]).as_i64();
let mut marginStatus: String = "failed".to_string();
if (marginStatusRaw == Some(1)) {
marginStatus = "ok".to_string();
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data);
m.insert("symbol".to_string(), self.safe_string_k(market, "symbol", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("status".to_string(), Value::from(marginStatus));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::from(vec![self.parse_to_numeric(id)]));
m
});
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if (symbol == Value::Null) {
let __ws_arg_33 = self.extend(Value::Map(request.clone()), &[params.clone()]);
response = self.private_post_auth_r_orders(&[__ws_arg_33]).await;
} else {
market = self.market(symbol);
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_34 = self.extend(Value::Map(request), &[params]);
response = self.private_post_auth_r_orders_symbol(&[__ws_arg_34]).await;
}
let mut order: Value = self.safe_list(response, Value::Int(0), &[]);
let mut newOrder: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(Value::Map(newOrder), &[market]);
Value::Null
}
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.parse_to_numeric(id.clone()));
m
});
if (amount != Value::Null) {
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount);
amountString = (if (side.as_str() == Some("buy")) { amountString.clone() } else { crate::precise::Precise::stringNeg(&amountString) });
request.insert("amount".into(), amountString);
}
let mut triggerPrice: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]);
let mut trailingAmount: Option<String> = self.safe_string_k_opt(params.clone(), "trailingAmount", &[]);
let mut timeInForce: Option<String> = self.safe_string_k(params.clone(), "timeInForce", &[]).as_str().map(str::to_owned);
let mut postOnlyParam: bool = self.safe_bool_k_opt(params.clone(), "postOnly", &[Value::Bool(false)]).unwrap_or(false);
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut clientOrderId: Value = self.safe_integer2(params.clone(), Value::Str("cid".into()), Value::Str("clientOrderId".into()), &[]);
if (trailingAmount.is_some()) {
request.insert("price_trailing".into(), trailingAmount.map(Value::from).unwrap_or(Value::Null));
} else if (triggerPrice.is_some()) {
request.insert("price".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone().map(Value::from).unwrap_or(Value::Null)));
if (type_var.as_str() == Some("limit")) {
request.insert("price_aux_limit".into(), self.price_to_precision(symbol.clone(), price.clone()));
}
}
let mut postOnly: bool = postOnlyParam || (timeInForce.as_deref() == Some("PO"));
if (type_var.as_str() != Some("market")) && (triggerPrice.is_none()) {
request.insert("price".into(), self.price_to_precision(symbol, price));
}
let mut flags: i64 = 0;
if postOnly && reduceOnly.as_bool() == Some(true) {
flags = 5120;
} else if postOnly {
flags = 4096;
} else if reduceOnly.as_bool() == Some(true) {
flags = 1024;
}
if (((flags as f64) != 0.0)) {
request.insert("flags".into(), Value::Int(flags));
}
if (clientOrderId != Value::Null) {
request.insert("cid".into(), clientOrderId);
}
let mut leverage: Value = self.safe_integer2(params.clone(), Value::Str("leverage".into()), Value::Str("lev".into()), &[]);
if (leverage != Value::Null) {
request.insert("lev".into(), leverage);
}
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), Value::Str("timeInForce".into()), Value::Str("postOnly".into()), Value::Str("reduceOnly".into()), Value::Str("trailingAmount".into()), Value::Str("clientOrderId".into()), Value::Str("leverage".into())]), &[]);
let __ws_arg_35 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.private_post_auth_w_order_update(&[__ws_arg_35]).await;
let mut status: Value = self.safe_string(response.clone(), Value::Int(6), &[Value::Str("".into())]);
if (status.as_str() != Some("SUCCESS")) {
let errorCode: String = self.safe_string_opt(response.clone(), Value::Int(5), &[Value::Str("".into())]).unwrap_or_default();
let errorText: String = self.safe_string_opt(response.clone(), Value::Int(7), &[Value::Str("".into())]).unwrap_or_default();
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), status).into()), Value::Str(": ".into())).into()),
errorText).into()), Value::Str(" (#".into())).into()), errorCode).into()), Value::Str(")".into()))));
}
let mut order: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut newOrder: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(Value::Map(newOrder), &[market]);
Value::Null
}
}