#![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 BackpackCore {
pub exchange: crate::exchange::Exchange,
}
impl BackpackCore {
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 = BackpackCore::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 BackpackCore {
fn nonce(&self, ) -> crate::Value {
BackpackCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
BackpackCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
BackpackCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_position(self, position, &[market])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_funding_rate(self, rate, &[market])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
BackpackCore::parse_deposit_address(self, depositAddress, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
BackpackCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_open_interest(self, interest, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
BackpackCore::parse_transaction(self, transaction, &[currency])
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
BackpackCore::parse_income(self, info, &[market])
}
fn parse_conversion(&self, conversion: crate::Value, from_currency: crate::Value, to_currency: crate::Value) -> crate::Value {
BackpackCore::parse_conversion(self, conversion, &[from_currency, to_currency])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
BackpackCore::sign(self, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
BackpackCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BackpackCore {
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 {
"accept_rfq_quote" => self.accept_rfq_quote(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,
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_convert_trade" => self.create_convert_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
"create_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,
"create_rfq_order" => self.create_rfq_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_convert_quote" => self.fetch_convert_quote(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"fetch_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" => self.fetch_deposits(&args[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_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_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_orders" => self.fetch_orders(&args[..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_securities" => self.fetch_securities(&args[..]).await,
"fetch_status" => self.fetch_status(&args[..]).await,
"fetch_stock_indicative_quote" => self.fetch_stock_indicative_quote(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"filter_stock_structures" => self.filter_stock_structures(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)),
"handle_stock_params" => self.handle_stock_params(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"nonce" => self.nonce(),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_conversion" => self.parse_conversion(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_income" => self.parse_income(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"rfq_conversion_market" => self.rfq_conversion_market(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"stock_data_request" => self.stock_data_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BackpackCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BackpackCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BackpackCore {
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("backpack".into()));
m.insert("name".to_string(), Value::Str("Backpack".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("JP".into())]));
m.insert("rateLimit".to_string(), Value::Int(50));
m.insert("version".to_string(), Value::Str("v1".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("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("cancelWithdraw".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createConvertTrade".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createLimitBuyOrder".to_string(), Value::Bool(true));
m.insert("createLimitOrder".to_string(), Value::Bool(true));
m.insert("createLimitSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(false));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(false));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(false));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(false));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(false));
m.insert("fetchConvertQuote".to_string(), Value::Bool(true));
m.insert("fetchConvertTrade".to_string(), Value::Bool(false));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
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("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::Str("emulated".into()));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(false));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("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(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".into()));
m.insert("3m".to_string(), Value::Str("3m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15".to_string(), Value::Str("15m".into()));
m.insert("30".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("2h".to_string(), Value::Str("2h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("8h".to_string(), Value::Str("8h".into()));
m.insert("12h".to_string(), Value::Str("12h".into()));
m.insert("1d".to_string(), Value::Str("1d".into()));
m.insert("3d".to_string(), Value::Str("3d".into()));
m.insert("1w".to_string(), Value::Str("1w".into()));
m.insert("1M".to_string(), Value::Str("1month".into()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/7f682234-3eb1-48ab-a5ec-250a3227c985".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.backpack.exchange".into()));
m.insert("private".to_string(), Value::Str("https://api.backpack.exchange".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://backpack.exchange/".into()));
m.insert("doc".to_string(), Value::Str("https://docs.backpack.exchange/".into()));
m.insert("referral".to_string(), Value::Str("https://backpack.exchange/join/ccxt".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("api/v1/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/borrowLend/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/borrowLend/markets/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/borrowLend/apy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/prediction".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/prediction/tags".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/market-sessions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/market-holidays".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/stockSessions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/stockHolidays".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/stockIndicativeQuote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/securities".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/markPrices".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/openInterest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/fundingRates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/wallets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/trades/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/limits/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/limits/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/limits/withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/borrowLend/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/borrowLend/position/liquidationPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/capital".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/capital/collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/capital/deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/capital/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/capital/withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/borrowLend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/borrowLend/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/dust".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/rfq/fill".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/quote/fill".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/settlement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/history/strategies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/strategy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/strategies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/orders".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("api/v1/account/convertDust".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/borrowLend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wapi/v1/capital/withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/rfq/accept".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/rfq/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/rfq/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/strategy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/strategy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/strategies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("patch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(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("GTC".to_string(), Value::Bool(true));
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(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("EXPIRE_MAKER".to_string(), Value::Bool(true));
m.insert("EXPIRE_TAKER".to_string(), Value::Bool(true));
m.insert("EXPIRE_BOTH".to_string(), Value::Bool(true));
m.insert("NONE".to_string(), Value::Bool(false));
m
}));
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(20));
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(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("paginate".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
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::Null);
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("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instructions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("accountQuery".into()));
m.insert("PATCH".to_string(), Value::Str("accountUpdate".into()));
m
}));
m.insert("api/v1/capital".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("balanceQuery".into()));
m
}));
m.insert("api/v1/account/limits/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("maxBorrowQuantity".into()));
m
}));
m.insert("api/v1/account/limits/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("maxOrderQuantity".into()));
m
}));
m.insert("api/v1/account/limits/withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("maxWithdrawalQuantity".into()));
m
}));
m.insert("api/v1/borrowLend/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("borrowLendPositionQuery".into()));
m
}));
m.insert("api/v1/borrowLend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("POST".to_string(), Value::Str("borrowLendExecute".into()));
m
}));
m.insert("wapi/v1/history/borrowLend/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("borrowPositionHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/borrowLend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("borrowHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/dust".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("dustHistoryQueryAll".into()));
m
}));
m.insert("api/v1/capital/collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("collateralQuery".into()));
m
}));
m.insert("wapi/v1/capital/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("depositAddressQuery".into()));
m
}));
m.insert("wapi/v1/capital/deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("depositQueryAll".into()));
m
}));
m.insert("wapi/v1/history/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("fillHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("fundingHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("interestHistoryQueryAll".into()));
m
}));
m.insert("api/v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("orderQuery".into()));
m.insert("POST".to_string(), Value::Str("orderExecute".into()));
m.insert("DELETE".to_string(), Value::Str("orderCancel".into()));
m
}));
m.insert("api/v1/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("orderQueryAll".into()));
m.insert("POST".to_string(), Value::Str("orderExecute".into()));
m.insert("DELETE".to_string(), Value::Str("orderCancelAll".into()));
m
}));
m.insert("wapi/v1/history/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("orderHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("pnlHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("rfqHistoryQueryAll".into()));
m
}));
m.insert("api/v1/rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("POST".to_string(), Value::Str("rfqSubmit".into()));
m
}));
m.insert("api/v1/rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("rfqQuery".into()));
m
}));
m.insert("api/v1/rfq/accept".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("POST".to_string(), Value::Str("quoteAccept".into()));
m
}));
m.insert("api/v1/rfq/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("POST".to_string(), Value::Str("rfqCancel".into()));
m
}));
m.insert("wapi/v1/history/rfq/fill".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("rfqFillHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/quote/fill".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("quoteFillHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("quoteHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/history/settlement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("settlementHistoryQueryAll".into()));
m
}));
m.insert("api/v1/position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("positionQuery".into()));
m
}));
m.insert("api/v1/rfq/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("POST".to_string(), Value::Str("quoteSubmit".into()));
m
}));
m.insert("wapi/v1/history/strategies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("strategyHistoryQueryAll".into()));
m
}));
m.insert("wapi/v1/capital/withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GET".to_string(), Value::Str("withdrawalQueryAll".into()));
m.insert("POST".to_string(), Value::Str("withdraw".into()));
m
}));
m
}));
m.insert("recvWindow".to_string(), Value::Int(5000));
m.insert("brokerId".to_string(), Value::Str("".into()));
m.insert("currencyIdsListForParseMarket".to_string(), Value::Null);
m.insert("broker".to_string(), Value::Str("".into()));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("APT".to_string(), Value::Str("Aptos".into()));
m.insert("ARBITRUM".to_string(), Value::Str("Arbitrum".into()));
m.insert("AVAX".to_string(), Value::Str("Avalanche".into()));
m.insert("BASE".to_string(), Value::Str("Base".into()));
m.insert("BERA".to_string(), Value::Str("Berachain".into()));
m.insert("BTC".to_string(), Value::Str("Bitcoin".into()));
m.insert("BCH".to_string(), Value::Str("BitcoinCash".into()));
m.insert("BEP20".to_string(), Value::Str("Bsc".into()));
m.insert("ADA".to_string(), Value::Str("Cardano".into()));
m.insert("DOGE".to_string(), Value::Str("Dogecoin".into()));
m.insert("ECLIPSE".to_string(), Value::Str("Eclipse".into()));
m.insert("EQUALSMONEY".to_string(), Value::Str("EqualsMoney".into()));
m.insert("ERC20".to_string(), Value::Str("Ethereum".into()));
m.insert("HYP".to_string(), Value::Str("Hyperliquid".into()));
m.insert("LTC".to_string(), Value::Str("Litecoin".into()));
m.insert("OPTIMISM".to_string(), Value::Str("Optimism".into()));
m.insert("MATIC".to_string(), Value::Str("Polygon".into()));
m.insert("SEI".to_string(), Value::Str("Sei".into()));
m.insert("SUI".to_string(), Value::Str("Sui".into()));
m.insert("SOL".to_string(), Value::Str("Solana".into()));
m.insert("STORY".to_string(), Value::Str("Story".into()));
m.insert("TRC20".to_string(), Value::Str("Tron".into()));
m.insert("XRP".to_string(), Value::Str("XRP".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("aptos".to_string(), Value::Str("APT".into()));
m.insert("arbitrum".to_string(), Value::Str("ARBITRUM".into()));
m.insert("avalanche".to_string(), Value::Str("AVAX".into()));
m.insert("base".to_string(), Value::Str("BASE".into()));
m.insert("berachain".to_string(), Value::Str("BERA".into()));
m.insert("bitcoin".to_string(), Value::Str("BTC".into()));
m.insert("bitcoincash".to_string(), Value::Str("BCH".into()));
m.insert("bsc".to_string(), Value::Str("BEP20".into()));
m.insert("cardano".to_string(), Value::Str("ADA".into()));
m.insert("dogecoin".to_string(), Value::Str("DOGE".into()));
m.insert("eclipse".to_string(), Value::Str("ECLIPSE".into()));
m.insert("equalsmoney".to_string(), Value::Str("EQUALSMONEY".into()));
m.insert("ethereum".to_string(), Value::Str("ERC20".into()));
m.insert("hyperliquid".to_string(), Value::Str("HYP".into()));
m.insert("litecoin".to_string(), Value::Str("LTC".into()));
m.insert("optimism".to_string(), Value::Str("OPTIMISM".into()));
m.insert("polygon".to_string(), Value::Str("MATIC".into()));
m.insert("sei".to_string(), Value::Str("SEI".into()));
m.insert("sui".to_string(), Value::Str("SUI".into()));
m.insert("solana".to_string(), Value::Str("SOL".into()));
m.insert("story".to_string(), Value::Str("STORY".into()));
m.insert("tron".to_string(), Value::Str("TRC20".into()));
m.insert("xrp".to_string(), Value::Str("XRP".into()));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("INVALID_CLIENT_REQUEST".to_string(), Value::Str("BadRequest".into()));
m.insert("INVALID_ORDER".to_string(), Value::Str("InvalidOrder".into()));
m.insert("ACCOUNT_LIQUIDATING".to_string(), Value::Str("BadRequest".into()));
m.insert("BORROW_LIMIT".to_string(), Value::Str("BadRequest".into()));
m.insert("BORROW_REQUIRES_LEND_REDEEM".to_string(), Value::Str("BadRequest".into()));
m.insert("FORBIDDEN".to_string(), Value::Str("OperationRejected".into()));
m.insert("INSUFFICIENT_FUNDS".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("INSUFFICIENT_MARGIN".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("INSUFFICIENT_SUPPLY".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("INVALID_ASSET".to_string(), Value::Str("BadRequest".into()));
m.insert("INVALID_MARKET".to_string(), Value::Str("BadSymbol".into()));
m.insert("INVALID_PRICE".to_string(), Value::Str("InvalidOrder".into()));
m.insert("INVALID_POSITION_ID".to_string(), Value::Str("BadRequest".into()));
m.insert("INVALID_QUANTITY".to_string(), Value::Str("BadRequest".into()));
m.insert("INVALID_RANGE".to_string(), Value::Str("BadRequest".into()));
m.insert("INVALID_SIGNATURE".to_string(), Value::Str("AuthenticationError".into()));
m.insert("INVALID_SOURCE".to_string(), Value::Str("BadRequest".into()));
m.insert("INVALID_SYMBOL".to_string(), Value::Str("BadSymbol".into()));
m.insert("INVALID_TWO_FACTOR_CODE".to_string(), Value::Str("BadRequest".into()));
m.insert("LEND_LIMIT".to_string(), Value::Str("BadRequest".into()));
m.insert("LEND_REQUIRES_BORROW_REPAY".to_string(), Value::Str("BadRequest".into()));
m.insert("MAINTENANCE".to_string(), Value::Str("ExchangeError".into()));
m.insert("MAX_LEVERAGE_REACHED".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("NOT_IMPLEMENTED".to_string(), Value::Str("OperationFailed".into()));
m.insert("ORDER_LIMIT".to_string(), Value::Str("OperationRejected".into()));
m.insert("POSITION_LIMIT".to_string(), Value::Str("OperationRejected".into()));
m.insert("PRECONDITION_FAILED".to_string(), Value::Str("OperationFailed".into()));
m.insert("RESOURCE_NOT_FOUND".to_string(), Value::Str("ExchangeNotAvailable".into()));
m.insert("SERVER_ERROR".to_string(), Value::Str("NetworkError".into()));
m.insert("TIMEOUT".to_string(), Value::Str("RequestTimeout".into()));
m.insert("TOO_MANY_REQUESTS".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("TRADING_PAUSED".to_string(), Value::Str("ExchangeNotAvailable".into()));
m.insert("UNAUTHORIZED".to_string(), Value::Str("AuthenticationError".into()));
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
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 selection: Value = self.handle_stock_params(Value::Str("fetchCurrencies".into()), params, &[]);
let mut stock: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut response: Value = self.public_get_api_v1_assets(&[query]).await;
let mut currencies: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_243: bool = true;
while { if !__for_first_243 { i += 1; } __for_first_243 = false; i < (response.len() as i64) } {
let mut currency: indexmap::IndexMap<String, Value> = self.parse_currency(self.safe_dict(response.clone(), Value::Int(i), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})])).as_map().cloned().unwrap_or_default();
if !(stock) || (self.safe_string(Value::Map(currency.clone()), Value::Str("type".into()), &[]).as_str() == Some("stock")) {
currencies.insert(crate::runtime::stringify_param(&(currency.get("code").cloned().unwrap_or(Value::Null))), Value::Map(currency));
}
}
}
return Value::Map(currencies);
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut currencyId: Option<String> = self.safe_string_k_opt(rawCurrency.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_string_k(rawCurrency.clone(), "symbol", &[Value::Str("".into())]);
let mut stock: bool = (symbol.as_str().unwrap_or("").ends_with(".US")) || (symbol.as_str().unwrap_or("").ends_with(".HK"));
let mut code: Value = self.safe_currency_code(currencyId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut networks: Vec<Value> = self.safe_list_k(rawCurrency.clone(), "tokens", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut parsedNetworks: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: i64 = 0;
let mut __for_first_244: bool = true;
while { if !__for_first_244 { j += 1; } __for_first_244 = false; j < (networks.len() as i64) } {
let mut network: Value = networks.get(j as usize).cloned().unwrap_or(Value::Null);
let mut networkId: Option<String> = self.safe_string_k_opt(network.clone(), "blockchain", &[]);
let mut networkIdLowerCase: Option<String> = self.safe_string_lower_k_opt(network.clone(), "blockchain", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkIdLowerCase.map(Value::from).unwrap_or(Value::Null), code.clone()]);
if (networkCode != Value::Null) {
parsedNetworks.insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId.map(Value::from).unwrap_or(Value::Null));
m.insert("network".to_string(), networkCode.clone());
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(network.clone(), "minimumWithdrawal", &[]));
m.insert("max".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(network.clone(), "maximumWithdrawal", &[])), &[]));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(network.clone(), "minimumDeposit", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(network.clone(), "depositEnabled", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(network.clone(), "withdrawEnabled", &[]));
m.insert("fee".to_string(), self.safe_number_k(network.clone(), "withdrawalFee", &[]));
m.insert("precision".to_string(), Value::Null);
m.insert("info".to_string(), network);
m
}));
}
}
}
let mut active: Value = Value::Null;
let mut deposit: Value = Value::Null;
let mut withdraw: Value = Value::Null;
if self.is_empty(Value::Map(parsedNetworks.clone())).as_bool() == Some(true) {
active = (if (stock) { Value::Null } else { Value::Bool(false) });
deposit = Value::Bool(false);
withdraw = Value::Bool(false);
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("code".to_string(), code);
m.insert("precision".to_string(), Value::Null);
m.insert("type".to_string(), (if (stock) { Value::Str("stock".into()) } else { Value::Str("crypto".into()) }));
m.insert("name".to_string(), self.safe_string_k(rawCurrency.clone(), "displayName", &[]));
m.insert("active".to_string(), active);
m.insert("deposit".to_string(), deposit);
m.insert("withdraw".to_string(), withdraw);
m.insert("fee".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), Value::Map(parsedNetworks));
m.insert("info".to_string(), rawCurrency);
m
}));
Value::Null
}
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if matches!(self.safe_bool_k(self.options.clone(), "adjustForTimeDifference", &[Value::Bool(false)]), Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut selection: Value = self.handle_stock_params(Value::Str("fetchMarkets".into()), params, &[]);
let mut stock: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketType: Option<String> = self.safe_string_k_opt(query.clone(), "marketType", &[]);
let mut requestedTypes: Value = self.safe_list_k(query.clone(), "marketType", &[Value::from(vec![Value::Str("SPOT".into()), Value::Str("PERP".into()), Value::Str("RFQ".into())])]);
if (marketType.is_some()) {
requestedTypes = Value::from(vec![marketType.clone().map(Value::from).unwrap_or(Value::Null)]);
}
let mut aliases: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".into()));
m.insert("swap".to_string(), Value::Str("PERP".into()));
m.insert("stock".to_string(), Value::Str("RFQ".into()));
m
});
let mut supportedTypes: Value = Value::from(vec![Value::Str("SPOT".into()), Value::Str("PERP".into()), Value::Str("RFQ".into())]);
let mut marketTypes: Value = Value::from(vec![]);
{
let mut i: i64 = 0;
let mut __for_first_245: bool = true;
while { if !__for_first_245 { i += 1; } __for_first_245 = false; i < (requestedTypes.len() as i64) } {
let mut requestedType: Value = self.safe_string(requestedTypes.clone(), Value::Int(i), &[Value::Str("".into())]);
let mut normalizedType: Value = self.safe_string(Value::Map(aliases.clone()), requestedType.clone(), &[requestedType.clone()]);
if !(self.in_array(normalizedType.clone(), supportedTypes.clone()).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchMarkets() unsupported marketType ".into())).into()), requestedType)));
}
if !(self.in_array(normalizedType.clone(), marketTypes.clone()).as_bool() == Some(true)) {
if let Value::Arr(__a) = &mut marketTypes { std::sync::Arc::make_mut(__a).push(normalizedType); }
}
}
}
let mut includeRfq: Value = self.in_array(Value::Str("RFQ".into()), marketTypes.clone());
let mut marketQuery: indexmap::IndexMap<String, Value> = self.omit(query.clone(), Value::Str("marketType".into()), &[]).as_map().cloned().unwrap_or_default();
if (matches!(&query, Value::Dict(__d) if __d.contains_key("marketType"))) {
marketQuery.insert("marketType".into(), marketTypes.clone());
}
let mut response: Value = self.public_get_api_v1_markets(&[Value::Map(marketQuery)]).await;
let mut securities: Value = Value::from(vec![]);
if includeRfq.as_bool() == Some(true) {
securities = self.fetch_securities(&[]).await;
}
let mut securityById: Value = self.index_by(securities.clone(), Value::Str("asset".into()));
let mut markets: Vec<Value> = Vec::new();
let mut marketIds: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_246: bool = true;
while { if !__for_first_246 { i += 1; } __for_first_246 = false; i < (response.len() as i64) } {
let mut rawMarket: Value = self.safe_dict(response.clone(), Value::Int(i), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rawType: Value = self.safe_string_k(rawMarket.clone(), "marketType", &[Value::Str("".into())]);
if !(self.in_array(rawType, marketTypes.clone()).as_bool() == Some(true)) {
continue;
}
let mut baseId: Option<String> = self.safe_string_k_opt(rawMarket.clone(), "baseSymbol", &[]);
let mut security: Value = self.safe_dict(securityById.clone(), baseId.map(Value::from).unwrap_or(Value::Null), &[]);
let __ws_arg_0 = self.extend(rawMarket.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("security".to_string(), security.clone());
m
})]);
let mut market: Value = self.parse_market((if (security == Value::Null) { rawMarket } else { __ws_arg_0 }));
if (market != Value::Null) {
let mut marketId: Option<String> = self.safe_string_k_opt(market.clone(), "id", &[]);
if (marketId.is_none()) || (matches!((&marketIds, &marketId.clone().map(Value::from).unwrap_or(Value::Null)), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
continue;
}
if let Value::Dict(__d) = &mut marketIds { std::sync::Arc::make_mut(__d).insert(marketId.as_deref().unwrap_or("null").to_string(), Value::Bool(true)); }
if !(stock) || matches!(self.safe_bool_k(market.clone(), "stock", &[Value::Bool(false)]), Value::Bool(true)) {
markets.push(market.clone());
}
}
}
}
if includeRfq.as_bool() == Some(true) {
{
let mut i: i64 = 0;
let mut __for_first_247: bool = true;
while { if !__for_first_247 { i += 1; } __for_first_247 = false; i < (securities.len() as i64) } {
let mut security: Value = securities.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut assetId: Option<String> = self.safe_string_k_opt(security.clone(), "asset", &[]);
if (assetId.is_none()) {
continue;
}
let mut marketId: Value = Value::Str(format!("{}{}", assetId.clone().map(Value::from).unwrap_or(Value::Null), Value::Str("_USDC_RFQ".into())).into());
if !(matches!((&marketIds, &marketId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
let mut market: Value = self.parse_market(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketId.clone());
m.insert("baseSymbol".to_string(), assetId.map(Value::from).unwrap_or(Value::Null));
m.insert("quoteSymbol".to_string(), Value::Str("USDC".into()));
m.insert("marketType".to_string(), Value::Str("RFQ".into()));
m.insert("rwaMarketType".to_string(), Value::Str("STOCK".into()));
m.insert("security".to_string(), security);
m
}));
if (market != Value::Null) {
if let Value::Dict(__d) = &mut marketIds { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&marketId), Value::Bool(true)); }
markets.push(market);
}
}
}
}
}
return Value::from(markets);
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut id: Option<String> = self.safe_string_k_opt(market.clone(), "symbol", &[]);
let mut baseId: Option<String> = self.safe_string_k_opt(market.clone(), "baseSymbol", &[]);
let mut quoteId: Option<String> = self.safe_string_k_opt(market.clone(), "quoteSymbol", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut filters: Value = self.safe_dict_k(market.clone(), "filters", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut priceFilter: Value = self.safe_dict_k(filters.clone(), "price", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut maxPrice: Value = self.safe_number_k(priceFilter.clone(), "maxPrice", &[]);
let mut minPrice: Value = self.safe_number_k(priceFilter.clone(), "minPrice", &[]);
let mut pricePrecision: Value = self.safe_number_k(priceFilter, "tickSize", &[]);
let mut quantityFilter: Value = self.safe_dict_k(filters, "quantity", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut maxQuantity: Value = self.safe_number_k(quantityFilter.clone(), "maxQuantity", &[]);
let mut minQuantity: Value = self.safe_number_k(quantityFilter.clone(), "minQuantity", &[]);
let mut amountPrecision: Value = self.safe_number_k(quantityFilter, "stepSize", &[]);
let mut type_var: Value = Value::Null;
let mut rawType: Option<String> = self.safe_string_k_opt(market.clone(), "marketType", &[]);
let mut rfq: Value = Value::Bool(rawType.as_deref() == Some("RFQ"));
let mut security: Value = self.safe_dict_k(market.clone(), "security", &[]);
let mut baseSymbol: Value = self.safe_string_k(market.clone(), "baseSymbol", &[Value::Str("".into())]);
let mut stock: Value = Value::Bool((self.safe_string_k(market.clone(), "rwaMarketType", &[]).as_str() == Some("STOCK")) || (security != Value::Null) || (baseSymbol.as_str().unwrap_or("").ends_with(".US")) || (baseSymbol.as_str().unwrap_or("").ends_with(".HK")));
let mut typeOfMarket: Option<String> = self.parse_market_type(rawType.clone().map(Value::from).unwrap_or(Value::Null));
let mut linear: Value = Value::Null;
let mut inverse: Value = Value::Null;
let mut settle: Value = Value::Null;
let mut settleId: Value = Value::Null;
let mut contractSize: Value = Value::Null;
if (typeOfMarket.as_deref() == Some("spot")) || matches!(&rfq, Value::Bool(true)) {
type_var = Value::Str("spot".into());
if matches!(&rfq, Value::Bool(true)) {
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str(".RFQ/".into())).into()), quote).into());
let mut sessions: Vec<Value> = self.safe_list_k(security.clone(), "sessions", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut stepSize: Value = Value::Null;
let mut minimum: Value = Value::Null;
let mut maximum: Value = Value::Null;
let mut unbounded: Value = Value::Bool(false);
{
let mut i: i64 = 0;
let mut __for_first_248: bool = true;
while { if !__for_first_248 { i += 1; } __for_first_248 = false; i < (sessions.len() as i64) } {
let mut sessionStep: Option<String> = self.safe_string_k_opt(sessions.get(i as usize).cloned().unwrap_or(Value::Null), "stepSize", &[]);
if (sessionStep.is_some()) && ((stepSize == Value::Null) || crate::precise::Precise::stringLt(&sessionStep.clone().map(Value::from).unwrap_or(Value::Null), &stepSize).as_bool() == Some(true)) {
stepSize = sessionStep.map(Value::from).unwrap_or(Value::Null);
}
let mut sessionMin: Option<String> = self.safe_string_k_opt(sessions.get(i as usize).cloned().unwrap_or(Value::Null), "minQuantity", &[]);
let mut sessionMax: Option<String> = self.safe_string_k_opt(sessions.get(i as usize).cloned().unwrap_or(Value::Null), "maxQuantity", &[]);
if (sessionMin.is_some()) && ((minimum == Value::Null) || crate::precise::Precise::stringLt(&sessionMin.clone().map(Value::from).unwrap_or(Value::Null), &minimum).as_bool() == Some(true)) {
minimum = sessionMin.map(Value::from).unwrap_or(Value::Null);
}
if (sessionMax.is_none()) {
unbounded = Value::Bool(true);
} else if (maximum == Value::Null) || crate::precise::Precise::stringGt(&sessionMax.clone().map(Value::from).unwrap_or(Value::Null), &maximum).as_bool() == Some(true) {
maximum = sessionMax.map(Value::from).unwrap_or(Value::Null);
}
}
}
let mut sessionsLength: f64 = ((sessions.len() as i64) as f64);
if sessionsLength > ((0i64) as f64) {
amountPrecision = self.parse_number(stepSize, &[]);
minQuantity = self.parse_number(minimum, &[]);
maxQuantity = (if (unbounded).as_bool() == Some(true) { Value::Null } else { self.parse_number(maximum, &[]) });
}
}
} else if (typeOfMarket.as_deref() == Some("swap")) {
type_var = Value::Str("swap".into());
linear = Value::Bool(true);
inverse = Value::Bool(false);
settleId = self.safe_string_k(market.clone(), "quoteSymbol", &[]);
settle = self.safe_currency_code(settleId.clone(), &[]);
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), quote).into()); contractSize = Value::Int(1);
} else {
return Value::Null;
}
let mut orderBookState: Option<String> = self.safe_string_k(market.clone(), "orderBookState", &[]).as_str().map(str::to_owned);
let mut active: Value = (if (matches!(&rfq, Value::Bool(true)) && (orderBookState.is_none())) { (Value::Bool((id.is_some()) || (self.safe_string_k(security, "asset", &[]) != Value::Null))) } else { (Value::Bool(orderBookState.as_deref() == Some("Open"))) });
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("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.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("quoteId".to_string(), quoteId.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), Value::Bool(type_var.as_str() == Some("spot")));
m.insert("margin".to_string(), Value::Bool((type_var.as_str() == Some("spot")) && !(matches!(&stock, Value::Bool(true))) && !(matches!(&rfq, Value::Bool(true)))));
m.insert("stock".to_string(), stock);
m.insert("executionModel".to_string(), (if (rfq).as_bool() == Some(true) { Value::Str("rfq".into()) } else { Value::Null }));
m.insert("swap".to_string(), Value::Bool(type_var.as_str() == Some("swap")));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active);
m.insert("contract".to_string(), Value::Bool(type_var.as_str() != Some("spot")));
m.insert("linear".to_string(), linear);
m.insert("inverse".to_string(), inverse);
m.insert("taker".to_string(), Value::Null);
m.insert("maker".to_string(), Value::Null);
m.insert("contractSize".to_string(), contractSize);
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(), amountPrecision);
m.insert("price".to_string(), pricePrecision);
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(), minQuantity);
m.insert("max".to_string(), maxQuantity);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minPrice);
m.insert("max".to_string(), maxPrice);
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(), self.parse8601(self.safe_string_k(market.clone(), "createdAt", &[])));
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
pub fn handle_stock_params(&self, mut methodName: Value, mut params: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut defaultStock: Value = self.safe_bool_k(market.clone(), "stock", &[Value::Bool(false)]);
let stockqueryVariable: Vec<Value> = self.handle_option_bool_and_params(params, methodName.clone(), Value::Str("stock".into()), &[defaultStock]).as_array().cloned().unwrap_or_default();
let mut stock: Value = stockqueryVariable.get(0).cloned().unwrap_or(Value::Null);
let mut query: Value = stockqueryVariable.get(1).cloned().unwrap_or(Value::Null);
if (market != Value::Null) && stock.as_bool() == Some(true) && !matches!(self.safe_bool_k(market, "stock", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a stock market".into()))));
}
return Value::from(vec![stock, query]);
Value::Null
}
pub async fn fetch_securities(&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_api_v1_securities(&[params]).await;
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("securities".into(), response.clone()); }
return response;
Value::Null
}
pub async fn fetch_stock_indicative_quote(&mut self, mut symbol: Value, mut side: 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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut selection: Value = self.handle_stock_params(Value::Str("fetchStockIndicativeQuote".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (market.as_map().and_then(|__m| __m.get("stock")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchStockIndicativeQuote() requires a stock market".into()))));
}
if (side.as_str() != Some("buy")) && (side.as_str() != Some("sell")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchStockIndicativeQuote() requires buy or sell".into()))));
}
if (amount == Value::Null) || !(crate::precise::Precise::stringGt(&self.number_to_string(amount.clone()), &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" fetchStockIndicativeQuote() requires a positive base share quantity".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("baseId")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), self.encode_order_side(side).map(Value::from).unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.number_to_string(amount));
m
});
let mut requestMethod: String = "publicGetApiV1StockIndicativeQuote".to_string();
let __ws_arg_1 = self.extend(query, &[Value::Map(request)]);
return self.call_dynamic_checked(Value::from(requestMethod), vec![(__ws_arg_1).clone()]).await;
Value::Null
}
pub fn rfq_conversion_market(&self, mut fromCode: Value, mut toCode: Value) -> Value {
let mut fromIsStock: Value = Value::Bool((fromCode.as_str().unwrap_or("").ends_with(".US")) || (fromCode.as_str().unwrap_or("").ends_with(".HK")));
let mut toIsStock: Value = Value::Bool((toCode.as_str().unwrap_or("").ends_with(".US")) || (toCode.as_str().unwrap_or("").ends_with(".HK")));
if (fromIsStock.as_bool() == toIsStock.as_bool()) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" conversion requires exactly one stock currency".into()))));
}
let mut stockCode: Value = fromCode.clone();
let mut quoteCode: Value = toCode.clone();
if !(matches!(&fromIsStock, Value::Bool(true))) {
stockCode = toCode;
quoteCode = fromCode;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", stockCode, Value::Str(".RFQ/".into())).into()), quoteCode).into());
let mut market: Value = self.safe_dict(self.markets.clone(), symbol.clone(), &[]);
if (market == Value::Null) || (self.safe_string_k(market.clone(), "executionModel", &[]).as_str() != Some("rfq")) || !matches!(self.safe_bool_k(market.clone(), "stock", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" conversion requires a listed stock RFQ market: ".into())).into()), symbol)));
}
return market;
Value::Null
}
pub fn parse_conversion(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut fromCurrency = get_arg(optional_args, 0, Value::Null);
let mut toCurrency = get_arg(optional_args, 1, Value::Null);
let __fromCurrency_empty = indexmap::IndexMap::new();
let fromCurrency = fromCurrency.as_map().unwrap_or(&__fromCurrency_empty);
let __toCurrency_empty = indexmap::IndexMap::new();
let toCurrency = toCurrency.as_map().unwrap_or(&__toCurrency_empty);
let mut fromCode: Value = (match fromCurrency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut toCode: Value = (match toCurrency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
if (fromCode == Value::Null) || (toCode == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" parseConversion() requires source and destination currencies".into()))));
}
let mut market: Value = self.rfq_conversion_market(fromCode.clone(), toCode.clone());
let mut fromIsBase: bool = fromCode.as_str() == self.safe_string_k(market, "base", &[]).as_str();
let mut filled: Value = self.safe_number_k(order.clone(), "filled", &[]);
let mut cost: Value = self.safe_number_k(order.clone(), "cost", &[]);
let mut fee: Value = self.safe_dict_k(order.clone(), "fee", &[]);
let mut timestamp: Option<i64> = self.safe_integer_k(order.clone(), "timestamp", &[]).as_i64();
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), self.safe_dict_k(order.clone(), "info", &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("id".to_string(), self.safe_string_k(order.clone(), "id", &[]));
m.insert("fromCurrency".to_string(), self.safe_currency_code(fromCode, &[]));
m.insert("fromAmount".to_string(), (if (fromIsBase) { filled.clone() } else { cost.clone() }));
m.insert("toCurrency".to_string(), self.safe_currency_code(toCode, &[]));
m.insert("toAmount".to_string(), (if (fromIsBase) { cost } else { filled }));
m.insert("price".to_string(), self.safe_number2(order, Value::Str("average".into()), Value::Str("price".into()), &[]));
m.insert("fee".to_string(), self.safe_number_k(fee, "cost", &[]));
m
});
Value::Null
}
pub async fn fetch_convert_quote(&mut self, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __params_empty = indexmap::IndexMap::new();
let params = params.as_map().unwrap_or(&__params_empty);
let mut amountString: Value = self.number_to_string(amount.clone());
if (amountString == Value::Null) || !(crate::precise::Precise::stringGt(&amountString, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() requires a positive amount".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.rfq_conversion_market(fromCode.clone(), toCode.clone());
let mut fromIsBase: bool = fromCode.as_str() == self.safe_string_k(market.clone(), "base", &[]).as_str();
let mut side: Value = (if (fromIsBase) { Value::Str("sell".into()) } else { Value::Str("buy".into()) });
if !fromIsBase {
let mut initialQuote: Value = self.fetch_stock_indicative_quote(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), side.clone(), Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m
})]).await;
let mut initialPrice: Option<String> = self.safe_string_k_opt(initialQuote.clone(), "price", &[]);
if !matches!(self.safe_bool_k(initialQuote.clone(), "available", &[Value::Bool(false)]), Value::Bool(true)) || (initialPrice.is_none()) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() stock indicative quote unavailable: ".into())).into()), self.safe_string_k(initialQuote, "reason", &[Value::Str("priceUnavailable".into())]))));
}
let mut priceParam: Value = (match params.get("price") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
if (priceParam == Value::Null) {
priceParam = initialPrice.map(Value::from).unwrap_or(Value::Null);
}
if !(crate::precise::Precise::stringGt(&priceParam, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() price must be positive".into()))));
}
let mut rawQuantity: Value = crate::precise::Precise::stringDivPrec(&amountString, &priceParam, &Value::Int(18));
let mut preciseQuantity: Value = self.amount_to_precision(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), self.parse_number(rawQuantity, &[]));
if (preciseQuantity == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() could not determine a stock quantity".into()))));
}
amountString = preciseQuantity;
if !(crate::precise::Precise::stringGt(&amountString, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() amount is too small for one stock increment".into()))));
}
}
let mut quote: Value = self.fetch_stock_indicative_quote(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), side.clone(), self.parse_number(amountString.clone(), &[]), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m
})]).await;
if !matches!(self.safe_bool_k(quote.clone(), "available", &[Value::Bool(false)]), Value::Bool(true)) || (self.safe_string_k(quote.clone(), "price", &[]) == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() stock indicative quote unavailable: ".into())).into()), self.safe_string_k(quote.clone(), "reason", &[Value::Str("priceUnavailable".into())]))));
}
if !fromIsBase {
let mut quoteQuantity: Option<String> = self.safe_string_k_opt(quote.clone(), "quoteQuantity", &[]);
let mut quantityFilter: Value = self.safe_dict_k(quote.clone(), "quantityFilter", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut stepSize: Option<String> = self.safe_string_k_opt(quantityFilter, "stepSize", &[]);
if (quoteQuantity.is_some()) && (stepSize.is_some()) && crate::precise::Precise::stringGt("eQuantity.clone().map(Value::from).unwrap_or(Value::Null), &self.number_to_string(amount.clone())).as_bool() == Some(true) {
let mut reducedQuantity: Value = crate::precise::Precise::stringSub(&amountString, &stepSize.clone().map(Value::from).unwrap_or(Value::Null));
if (reducedQuantity == Value::Null) || !(crate::precise::Precise::stringGt(&reducedQuantity, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() amount is too small for one stock increment".into()))));
}
amountString = reducedQuantity;
quote = self.fetch_stock_indicative_quote(market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), side, self.parse_number(amountString.clone(), &[]), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m
})]).await;
if !matches!(self.safe_bool_k(quote.clone(), "available", &[Value::Bool(false)]), Value::Bool(true)) || (self.safe_string_k(quote.clone(), "price", &[]) == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() stock indicative quote unavailable: ".into())).into()), self.safe_string_k(quote.clone(), "reason", &[Value::Str("priceUnavailable".into())]))));
}
}
let mut finalQuoteQuantity: Option<String> = self.safe_string_k_opt(quote.clone(), "quoteQuantity", &[]);
if (finalQuoteQuantity.is_some()) && crate::precise::Precise::stringGt(&finalQuoteQuantity.clone().map(Value::from).unwrap_or(Value::Null), &self.number_to_string(amount)).as_bool() == Some(true) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" fetchConvertQuote() rounded stock quantity exceeds the requested quote-currency amount".into()))));
}
}
let mut quoteAmount: Value = self.safe_number_k(quote.clone(), "quoteQuantity", &[]);
let mut baseAmount: Value = self.parse_number(amountString, &[]);
let mut fromCurrency: Value = self.safe_currency_code(fromCode, &[]);
let mut toCurrency: Value = self.safe_currency_code(toCode, &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), quote.clone());
m.insert("timestamp".to_string(), self.safe_integer_k(quote.clone(), "publishedAt", &[]));
m.insert("datetime".to_string(), self.iso8601(self.safe_integer_k(quote.clone(), "publishedAt", &[])));
m.insert("id".to_string(), Value::Null);
m.insert("fromCurrency".to_string(), fromCurrency);
m.insert("fromAmount".to_string(), (if (fromIsBase) { baseAmount.clone() } else { quoteAmount.clone() }));
m.insert("toCurrency".to_string(), toCurrency);
m.insert("toAmount".to_string(), (if (fromIsBase) { quoteAmount } else { baseAmount }));
m.insert("price".to_string(), self.safe_number_k(quote, "price", &[]));
m.insert("fee".to_string(), Value::Null);
m
});
Value::Null
}
pub async fn create_convert_trade(&mut self, mut id: Value, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.rfq_conversion_market(fromCode.clone(), toCode.clone());
let mut selection: Value = self.handle_stock_params(Value::Str("createConvertTrade".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut quoteId: Option<String> = self.safe_string_k_opt(query.clone(), "quoteId", &[]);
if (quoteId.is_some()) {
let mut acceptParams: Value = self.omit(query.clone(), Value::from(vec![Value::Str("quoteId".into()), Value::Str("price".into()), Value::Str("baseAmount".into()), Value::Str("clientOrderId".into())]), &[]);
let mut accepted: Value = self.accept_rfq_quote(id.clone(), quoteId.map(Value::from).unwrap_or(Value::Null), self.safe_symbol(Value::Null, &[market.clone()]), &[acceptParams]).await;
return self.parse_conversion(accepted, &[self.currency(fromCode.clone()), self.currency(toCode.clone())]);
}
if (amount == Value::Null) || !(crate::precise::Precise::stringGt(&self.number_to_string(amount.clone()), &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() requires a positive amount".into()))));
}
let mut fromIsBase: bool = fromCode.as_str() == self.safe_string_k(market.clone(), "base", &[]).as_str();
let mut side: Value = (if (fromIsBase) { Value::Str("sell".into()) } else { Value::Str("buy".into()) });
let mut quantity: Value = self.number_to_string(amount.clone());
let mut price: Value = self.safe_number_k(query.clone(), "price", &[]);
if !fromIsBase {
let mut baseAmount: Value = self.safe_number_k(query.clone(), "baseAmount", &[]);
if (baseAmount != Value::Null) {
quantity = self.number_to_string(baseAmount);
} else {
if (price == Value::Null) || !(crate::precise::Precise::stringGt(&self.number_to_string(price.clone()), &Value::Str("0".into())).as_bool() == Some(true)) {
let mut indicative: Value = self.fetch_stock_indicative_quote(self.safe_symbol(Value::Null, &[market.clone()]), side.clone(), Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m
})]).await;
if !matches!(self.safe_bool_k(indicative.clone(), "available", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() stock indicative quote unavailable: ".into())).into()), self.safe_string_k(indicative.clone(), "reason", &[Value::Str("priceUnavailable".into())]))));
}
price = self.safe_number_k(indicative.clone(), "price", &[]);
}
if (price == Value::Null) || !(crate::precise::Precise::stringGt(&self.number_to_string(price.clone()), &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() buying stock requires a positive price bound".into()))));
}
let mut rawQuantity: Value = crate::precise::Precise::stringDivPrec(&self.number_to_string(amount.clone()), &self.number_to_string(price.clone()), &Value::Int(18));
let mut preciseQuantity: Value = self.amount_to_precision(self.safe_symbol(Value::Null, &[market.clone()]), self.parse_number(rawQuantity, &[]));
if (preciseQuantity == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() could not determine a stock quantity".into()))));
}
quantity = preciseQuantity;
}
if (price == Value::Null) || !(crate::precise::Precise::stringGt(&self.number_to_string(price.clone()), &Value::Str("0".into())).as_bool() == Some(true)) {
let mut indicative: Value = self.fetch_stock_indicative_quote(self.safe_symbol(Value::Null, &[market.clone()]), side.clone(), self.parse_number(quantity.clone(), &[]), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m
})]).await;
if !matches!(self.safe_bool_k(indicative.clone(), "available", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() stock indicative quote unavailable: ".into())).into()), self.safe_string_k(indicative.clone(), "reason", &[Value::Str("priceUnavailable".into())]))));
}
price = self.safe_number_k(indicative, "price", &[]);
}
if (price == Value::Null) || !(crate::precise::Precise::stringGt(&self.number_to_string(price.clone()), &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() buying stock requires a positive price bound".into()))));
}
let mut quoteCost: Value = crate::precise::Precise::stringMul(&quantity, &self.number_to_string(price.clone()));
if crate::precise::Precise::stringGt("eCost, &self.number_to_string(amount.clone())).as_bool() == Some(true) {
let mut precision: Value = self.safe_dict_k(market.clone(), "precision", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut stepSize: Value = self.number_to_string(self.safe_number_k(precision, "amount", &[]));
if !(crate::precise::Precise::stringGt(&stepSize, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() cannot safely round stock quantity to the quote-currency budget".into()))));
}
let mut reducedQuantity: Value = crate::precise::Precise::stringSub(&quantity, &stepSize);
if (reducedQuantity == Value::Null) || !(crate::precise::Precise::stringGt(&reducedQuantity, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() stock quantity is too small for one increment".into()))));
}
quantity = reducedQuantity;
quoteCost = crate::precise::Precise::stringMul(&quantity, &self.number_to_string(price.clone()));
if !(crate::precise::Precise::stringGt(&quantity, &Value::Str("0".into())).as_bool() == Some(true)) || crate::precise::Precise::stringGt("eCost, &self.number_to_string(amount)).as_bool() == Some(true) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createConvertTrade() stock quantity exceeds the quote-currency amount".into()))));
}
}
}
let mut clientOrderId: Value = self.safe_integer_k(query.clone(), "clientOrderId", &[]);
if (clientOrderId == Value::Null) {
clientOrderId = self.safe_integer(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m
}), Value::Str("id".into()), &[]);
}
let mut orderParams: indexmap::IndexMap<String, Value> = self.omit(query, Value::from(vec![Value::Str("price".into()), Value::Str("baseAmount".into()), Value::Str("quoteId".into()), Value::Str("clientOrderId".into())]), &[]).as_map().cloned().unwrap_or_default();
if (clientOrderId != Value::Null) {
orderParams.insert("clientOrderId".into(), clientOrderId);
}
let __ws_arg_2 = self.safe_symbol(Value::Null, &[market]);
let __ws_arg_3 = self.parse_number(quantity, &[]);
let __ws_arg_4 = self.extend(Value::Map(orderParams), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m
})]);
let mut order: Value = self.create_rfq_order(__ws_arg_2, Value::Str("market".into()), side, __ws_arg_3, &[price, __ws_arg_4]).await;
return self.parse_conversion(order, &[self.currency(fromCode), self.currency(toCode)]);
Value::Null
}
pub fn stock_data_request(&self, mut methodName: Value, mut params: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut selection: Value = self.handle_stock_params(methodName.clone(), params, &[market.clone()]);
let mut stock: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut request: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[query.clone()]);
let mut source: Value = self.safe_string_k(query.clone(), "source", &[]);
let mut marketInfo: Value = self.safe_dict_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut isRfq: bool = (market != Value::Null) && (self.safe_string_k(marketInfo, "marketType", &[]).as_str() == Some("RFQ"));
if (source == Value::Null) {
source = (if (isRfq) { Value::Str("External".into()) } else { Value::Str("Venue".into()) });
}
if (source.as_str() != Some("Venue")) && (source.as_str() != Some("External")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() source must be Venue or External".into()))));
}
if (source.as_str() == Some("External")) {
if !(stock) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() External provider data requires a stock market symbol or params.stock=true when no symbol is provided".into()))));
}
if (market != Value::Null) && !matches!(self.safe_bool_k(market.clone(), "stock", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() External data requires a stock market".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("source".into(), source); }
if (methodName.as_str() == Some("fetchOHLCV")) {
let mut priceType: Option<String> = self.safe_string_k(query.clone(), "priceType", &[Value::Str("Last".into())]).as_str().map(str::to_owned);
let mut price: Option<String> = self.safe_string_k(query.clone(), "price", &[]).as_str().map(str::to_owned);
if (priceType.as_deref() != Some("Last")) || ((price.is_some()) && (price.as_deref() != Some("last"))) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchOHLCV() External data requires Last prices".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("priceType".into(), Value::Str("Last".into())); }
} else {
let mut interval: Value = self.safe_string_k(query, "interval", &[Value::Str("1d".into())]);
if (interval.as_str() != Some("1d")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() External tickers require interval=1d".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("interval".into(), interval); }
}
}
if (market != Value::Null) {
if isRfq {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.safe_string_k(market.clone(), "baseId", &[Value::Str("".into())]), Value::Str("_".into())).into()), self.safe_string_k(market.clone(), "quoteId", &[Value::Str("".into())])).into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), self.safe_string_k(market, "id", &[])); }
}
}
return request;
Value::Null
}
pub fn filter_stock_structures(&self, mut entries: Value) -> Value {
let __entries_empty = Vec::new();
let entries = entries.as_array().unwrap_or(&__entries_empty);
let mut result: Vec<Value> = Vec::new();
{
let mut i: Value = Value::Int(0);
let mut __for_first_249: bool = true;
while { if !__for_first_249 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_249 = false; i.as_f64().unwrap_or(f64::NAN) < ((entries.len() as i64) as f64) } {
let mut entry: Value = entries.get((i).as_i64().unwrap_or(-1) as usize).cloned().unwrap_or(Value::Null);
let mut symbol: Option<String> = self.safe_string_k_opt(entry.clone(), "symbol", &[]);
let mut market: Value = self.safe_dict(self.markets.clone(), symbol.map(Value::from).unwrap_or(Value::Null), &[]);
if matches!(self.safe_bool_k(market, "stock", &[Value::Bool(false)]), Value::Bool(true)) {
result.push(entry);
}
}
}
return Value::from(result);
Value::Null
}
pub fn parse_market_type(&self, mut type_var: Value) -> Option<String> {
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("SPOT".to_string(), Value::Str("spot".into()));
m.insert("PERP".to_string(), Value::Str("swap".into()));
m
});
return self.safe_string(Value::Map(types), type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
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 selection: Value = self.handle_stock_params(Value::Str("fetchTickers".into()), params.clone(), &[]);
let mut stockOnly: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut source: Option<String> = self.safe_string_k(query.clone(), "source", &[Value::Str("Venue".into())]).as_str().map(str::to_owned);
let mut symbolsLength: i64 = 0;
if (symbols != Value::Null) {
symbolsLength = symbols.len() as i64;
}
let mut symbolsResolved: Value = Value::Array(self.markets.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default());
if (((symbolsLength as f64) != 0.0)) {
symbolsResolved = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(false)]);
}
let mut hasRfqSymbol: bool = false;
let mut hasStockSymbol: bool = false;
if (symbols != Value::Null) {
{
let mut i: i64 = 0;
let mut __for_first_250: bool = true;
while { if !__for_first_250 { i += 1; } __for_first_250 = false; i < (symbolsResolved.len() as i64) } {
let mut market: Value = self.market(self.safe_string(symbolsResolved.clone(), Value::Int(i), &[]));
if (market.as_map().and_then(|__m| __m.get("stock")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
hasStockSymbol = true;
}
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
hasRfqSymbol = true;
}
}
}
}
let mut stockExplicitlyDisabled: bool = !(self.safe_bool2(params, Value::Str("stock".into()), Value::Str("defaultStock".into()), &[Value::Bool(true)]).as_bool() == Some(true));
let mut needsExternalRfqTickers: bool = (source.as_deref() == Some("Venue")) && (self.safe_string_k(query.clone(), "source", &[]) == Value::Null) && hasRfqSymbol && !stockExplicitlyDisabled;
let mut requestParams: Value = query.clone();
if (source.as_deref() == Some("External")) && (stockOnly || hasStockSymbol) && !(stockExplicitlyDisabled) {
requestParams = self.extend(query.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m
})]);
}
let mut request: Value = self.stock_data_request(Value::Str("fetchTickers".into()), requestParams, &[]);
let mut response: Value = self.public_get_api_v1_tickers(&[request]).await;
let mut tickers: Value = self.parse_tickers(response.clone(), &[]);
let mut responseById: Value = self.index_by(response, Value::Str("symbol".into()));
let mut externalResponse: Value = Value::from(vec![]);
let mut externalResponseById: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if needsExternalRfqTickers || (source.as_deref() == Some("External")) {
let mut externalParams: Value = self.extend(query, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(true));
m.insert("source".to_string(), Value::Str("External".into()));
m
})]);
externalResponse = self.public_get_api_v1_tickers(&[self.stock_data_request(Value::Str("fetchTickers".into()), externalParams, &[])]).await;
externalResponseById = self.index_by(externalResponse, Value::Str("symbol".into()));
}
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_251: bool = true;
while { if !__for_first_251 { i += 1; } __for_first_251 = false; i < (symbolsResolved.len() as i64) } {
let mut marketSymbol: Value = symbolsResolved.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(marketSymbol.clone());
if stockOnly && (market.as_map().and_then(|__m| __m.get("stock")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
continue;
}
let mut marketIsRfq: bool = self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ");
let mut ticker: Value = self.safe_dict(tickers.clone(), marketSymbol.clone(), &[]);
if (ticker != Value::Null) && ((source.as_deref() != Some("External")) || (market.as_map().and_then(|__m| __m.get("stock")).cloned().unwrap_or(Value::Null).as_bool() == Some(true))) {
result.insert(crate::runtime::stringify_param(&marketSymbol), ticker);
} else if marketIsRfq {
let mut underlyingId: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.safe_string_k(market.clone(), "baseId", &[Value::Str("".into())]), Value::Str("_".into())).into()), self.safe_string_k(market.clone(), "quoteId", &[Value::Str("".into())])).into());
let mut useExternal: bool = (source.as_deref() == Some("External")) || needsExternalRfqTickers;
let mut tickerSource: Value = (if (useExternal) { externalResponseById.clone() } else { responseById.clone() });
let mut underlyingTicker: Value = self.safe_dict(tickerSource, underlyingId, &[]);
if (underlyingTicker != Value::Null) {
result.insert(crate::runtime::stringify_param(&marketSymbol), self.parse_ticker(underlyingTicker, &[market]));
}
}
}
}
return self.filter_by_array_tickers(Value::Map(result), Value::Str("symbol".into()), &[symbols]);
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: Value = self.stock_data_request(Value::Str("fetchTicker".into()), params, &[market.clone()]);
let mut response: Value = self.public_get_api_v1_ticker(&[request]).await;
return self.parse_ticker(response, &[market]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(ticker.clone(), "symbol", &[]);
let mut marketResolved: Value = (if (market == Value::Null) { self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null)]) } else { market });
let mut open: Option<String> = self.safe_string_k_opt(ticker.clone(), "firstPrice", &[]);
let mut last: Option<String> = self.safe_string_k_opt(ticker.clone(), "lastPrice", &[]);
let mut high: Option<String> = self.safe_string_k_opt(ticker.clone(), "high", &[]);
let mut low: Option<String> = self.safe_string_k_opt(ticker.clone(), "low", &[]);
let mut baseVolume: Option<String> = self.safe_string_k_opt(ticker.clone(), "volume", &[]);
let mut quoteVolume: Option<String> = self.safe_string_k_opt(ticker.clone(), "quoteVolume", &[]);
let mut percentage: Value = Value::Null;
let mut percentageNumber: Value = self.safe_float_k(ticker.clone(), "priceChangePercent", &[]);
if (percentageNumber != Value::Null) {
percentage = crate::precise::Precise::stringMul(&self.safe_string_k(ticker.clone(), "priceChangePercent", &[]), &Value::Str("100".into()));
}
let mut change: Option<String> = self.safe_string_k_opt(ticker.clone(), "priceChange", &[]);
let mut parsedTicker: Value = self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(marketResolved.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), high.map(Value::from).unwrap_or(Value::Null));
m.insert("low".to_string(), low.map(Value::from).unwrap_or(Value::Null));
m.insert("bid".to_string(), Value::Null);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), Value::Null);
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), open.map(Value::from).unwrap_or(Value::Null));
m.insert("close".to_string(), last.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("last".to_string(), last.map(Value::from).unwrap_or(Value::Null));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), change.map(Value::from).unwrap_or(Value::Null));
m.insert("percentage".to_string(), percentage);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.map(Value::from).unwrap_or(Value::Null));
m.insert("quoteVolume".to_string(), quoteVolume.map(Value::from).unwrap_or(Value::Null));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
return parsedTicker;
Value::Null
}
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut selection: Value = self.handle_stock_params(Value::Str("fetchOrderBook".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut source: Option<String> = self.safe_string_k(query.clone(), "source", &[Value::Str("Venue".into())]).as_str().map(str::to_owned);
if (source.as_deref() != Some("Venue")) || (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderBook() requires a venue order-book market; use fetchStockIndicativeQuote() for size-specific RFQ prices".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut requestLimit: Value = Value::Null;
if (limit != Value::Null) {
let mut supportedLimits: Value = Value::from(vec![Value::Int(5), Value::Int(10), Value::Int(20), Value::Int(50), Value::Int(100), Value::Int(500)]);
requestLimit = Value::Int(500);
{
let mut i: i64 = 0;
let mut __for_first_252: bool = true;
while { if !__for_first_252 { i += 1; } __for_first_252 = false; i < (supportedLimits.len() as i64) } {
let mut supportedLimit: Value = self.safe_integer(supportedLimits.clone(), Value::Int(i), &[Value::Int(0)]);
if limit.as_f64().unwrap_or(f64::NAN) <= supportedLimit.as_f64().unwrap_or(f64::NAN) {
requestLimit = supportedLimit;
break;
}
}
}
request.insert("limit".into(), requestLimit);
}
let __ws_arg_5 = self.extend(Value::Map(request), &[self.omit(query, Value::Str("source".into()), &[])]);
let mut response: Value = self.public_get_api_v1_depth(&[__ws_arg_5]).await;
let mut microseconds: Value = self.safe_integer_k(response.clone(), "timestamp", &[]);
if (microseconds == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderBook() missing microseconds".into()))));
}
let mut timestamp: Value = self.parse_to_int((match ((microseconds).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
let mut orderbook: Value = self.parse_order_book(response.clone(), symbol, &[timestamp]);
orderbook.set_book_meta("nonce", self.safe_integer_k(response, "lastUpdateId", &[]));
if (limit != Value::Null) {
{ let __be_tmp = self.array_slice(crate::value::get_value_k(&orderbook, "bids"), Value::Int(0), &[limit.clone()]); if let Value::Dict(__r03d) = &mut orderbook { std::sync::Arc::make_mut(__r03d).insert("bids".into(), __be_tmp); } };
{ let __be_tmp = self.array_slice(crate::value::get_value_k(&orderbook, "asks"), Value::Int(0), &[limit]); if let Value::Dict(__r03d) = &mut orderbook { std::sync::Arc::make_mut(__r03d).insert("asks".into(), __be_tmp); } };
}
return orderbook;
Value::Null
}
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(2000);
let mut market: Value = self.market(symbol);
let mut interval: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
let mut duration: Value = (match (&(self.parse_timeframe(timeframe.clone())), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
let mut dataRequest: Value = self.stock_data_request(Value::Str("fetchOHLCV".into()), params, &[market.clone()]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(dataRequest.clone(), "symbol", &[]));
m.insert("interval".to_string(), interval);
m
});
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(self.omit(dataRequest, Value::Str("symbol".into()), &[]), Value::Str("fetchOHLCV".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
request.insert("endTime".into(), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))); }
let mut defaultLimit: Value = Value::Int(100);
let mut limitResolved: Value = limit;
if (limitResolved != Value::Null) {
limitResolved = crate::runtime::Math::min(&limitResolved, &maxLimit);
}
let mut windowLimit: Value = (if (limitResolved == Value::Null) { defaultLimit } else { limitResolved.clone() });
let mut now: Value = self.milliseconds();
let mut startTime: Value = since.clone();
let mut untilValue: Value = until;
if (startTime == Value::Null) {
if (untilValue == Value::Null) {
untilValue = now.clone();
}
startTime = (match (&(untilValue), &(((match (&(windowLimit), &(duration)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y),
_ => Value::Null })))) { (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 });
}
request.insert("startTime".into(), self.parse_to_int((match ((startTime).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
if (untilValue == Value::Null) {
let mut windowEnd: Value = self.sum(&[startTime, (match (&(windowLimit), &(duration)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })]);
untilValue = crate::runtime::Math::min(&now, &windowEnd);
}
request.insert("endTime".into(), self.parse_to_int((match ((untilValue).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
let mut price: Option<String> = self.safe_string_k_opt(paramsUntil.clone(), "price", &[]);
let mut paramsOmitted: Value = (if (price.is_some()) { self.omit(paramsUntil.clone(), Value::Str("price".into()), &[]) } else { paramsUntil });
if (price.is_some()) {
request.insert("priceType".into(), self.capitalize(price.map(Value::from).unwrap_or(Value::Null)));
}
let __ws_arg_6 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.public_get_api_v1_klines(&[__ws_arg_6]).await;
let mut ohlcvs: Value = self.to_array(response);
return self.parse_ohlc_vs(ohlcvs, &[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.parse8601(self.safe_string_k(ohlcv.clone(), "start", &[])), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv, "volume", &[])]);
Value::Null
}
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if matches!(self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate() symbol does not support market ".into())).into()), symbol)));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_7 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_api_v1_mark_prices(&[__ws_arg_7]).await;
let mut data: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(data, &[market]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(contract.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone().map(Value::from).unwrap_or(Value::Null), market]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[marketResolved]);
let mut nextFundingTimestamp: Option<i64> = self.safe_integer_k(contract.clone(), "nextFundingTimestamp", &[]).as_i64();
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol);
m.insert("markPrice".to_string(), self.safe_number_k(contract.clone(), "markPrice", &[]));
m.insert("indexPrice".to_string(), self.safe_number_k(contract.clone(), "indexPrice", &[]));
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract, "fundingRate", &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), 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::Str("1h".into()));
m
});
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.clone());
if matches!(self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]), Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenInterest() symbol does not support market ".into())).into()), symbol)));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_8 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_api_v1_open_interest(&[__ws_arg_8]).await;
let mut interest: Value = self.safe_dict(response, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_open_interest(interest, &[market]);
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 timestamp: Option<i64> = self.safe_integer_k(interest.clone(), "timestamp", &[]).as_i64();
let mut openInterest: Value = self.safe_number_k(interest.clone(), "openInterest", &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("openInterestAmount".to_string(), Value::Null);
m.insert("openInterestValue".to_string(), openInterest);
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_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 mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
let __ws_arg_9 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_api_v1_funding_rates(&[__ws_arg_9]).await;
let mut rates: Vec<Value> = Vec::new();
let mut rawRates: Value = self.to_array(response);
{
let mut i: i64 = 0;
let mut __for_first_253: bool = true;
while { if !__for_first_253 { i += 1; } __for_first_253 = false; i < (rawRates.len() as i64) } {
let mut rate: Value = rawRates.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut datetime: Option<String> = self.safe_string_k_opt(rate.clone(), "intervalEndTimestamp", &[]);
let mut timestamp: Value = self.parse8601(datetime.clone().map(Value::from).unwrap_or(Value::Null));
rates.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rate.clone());
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("fundingRate".to_string(), self.safe_number_k(rate, "fundingRate", &[]));
m.insert("timestamp".to_string(), timestamp);
m.insert("datetime".to_string(), datetime.map(Value::from).unwrap_or(Value::Null));
m
}));
}
}
let mut sorted: Value = self.sort_by(Value::from(rates), Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[self.safe_string_k(market, "symbol", &[]), since, limit]);
Value::Null
}
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut selection: Value = self.handle_stock_params(Value::Str("fetchTrades".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string_k(query.clone(), "source", &[Value::Str("Venue".into())]).as_str() != Some("Venue")) || (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTrades() only supports venue order-book trades; use fetchMyTrades() for RFQ fills".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
let mut response: Value = Value::Null;
let mut offset: Option<i64> = self.safe_integer_k(query.clone(), "offset", &[]).as_i64();
if (offset.is_some()) {
let __ws_arg_10 = self.extend(Value::Map(request.clone()), &[query.clone()]);
response = self.public_get_api_v1_trades_history(&[__ws_arg_10]).await;
} else {
let __ws_arg_11 = self.extend(Value::Map(request), &[query]);
response = self.public_get_api_v1_trades(&[__ws_arg_11]).await;
}
let mut responseList: Value = self.to_array(response);
return self.parse_trades(responseList, &[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 request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[]));
}
let mut selection: Value = self.handle_stock_params(Value::Str("fetchMyTrades".into()), params, &[market.clone()]);
let mut stock: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rfq: bool = self.safe_bool_k(query.clone(), "rfq", &[Value::Bool(false)]).as_bool() == Some(true) || (self.safe_string(self.safe_dict_k(market.clone(), "info", &[]), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ"));
let mut aggregate: bool = stock && (market == Value::Null) && !rfq;
if rfq && (market != Value::Null) && (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() != Some("RFQ")) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() rfq requires an RFQ market symbol".into()))));
}
let mut accountParams: Value = self.omit(query.clone(), Value::from(vec![Value::Str("rfq".into()), Value::Str("until".into())]), &[]);
let mut until: Value = self.safe_integer_k(query, "until", &[]);
if rfq || aggregate {
let mut rfqRequest: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (market != Value::Null) {
rfqRequest.insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[]));
}
if (limit != Value::Null) {
rfqRequest.insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
let mut rfqParams: Value = self.omit(accountParams.clone(), Value::from(vec![Value::Str("assetClass".into()), Value::Str("marketType".into()), Value::Str("from".into()), Value::Str("to".into())]), &[]);
let __ws_arg_12 = self.extend(Value::Map(rfqRequest), &[rfqParams]);
let mut rfqResponse: Value = self.private_get_wapi_v1_history_rfq_fill(&[__ws_arg_12]).await;
let mut rfqTrades: Value = self.parse_trades(rfqResponse, &[market.clone(), since.clone()]);
if aggregate {
let __ws_arg_13 = self.omit(accountParams.clone(), Value::from(vec![Value::Str("rfqId".into()), Value::Str("quoteId".into()), Value::Str("deferredSettlement".into())]), &[]);
let mut venueParams: Value = self.extend(__ws_arg_13, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("assetClass".to_string(), Value::Str("STOCK".into()));
m.insert("stock".to_string(), Value::Bool(false));
m
})]);
let mut venueTrades: Value = Box::pin(self.fetch_my_trades(&[Value::Null, since.clone(), limit.clone(), venueParams])).await;
rfqTrades = self.array_concat(rfqTrades.clone(), venueTrades);
}
if stock {
rfqTrades = self.filter_stock_structures(rfqTrades.clone());
}
let mut filtered: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_254: bool = true;
while { if !__for_first_254 { i += 1; } __for_first_254 = false; i < (rfqTrades.len() as i64) } {
let mut trade: Value = rfqTrades.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
if (until == Value::Null) || ((timestamp != Value::Null) && (timestamp.as_f64().unwrap_or(f64::NAN) <= until.as_f64().unwrap_or(f64::NAN))) {
filtered.push(trade);
}
}
}
let mut sorted: Value = self.sort_by(Value::from(filtered), Value::Str("timestamp".into()), &[]);
return self.filter_by_since_limit(sorted, &[since.clone(), limit.clone()]);
}
if (since != Value::Null) {
request.insert("from".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let mut paramsOmitted: Value = accountParams;
if stock {
request.insert("assetClass".into(), Value::Str("STOCK".into()));
}
if (until != Value::Null) {
request.insert("to".into(), until);
}
let mut fillType: Option<String> = self.safe_string_k(paramsOmitted.clone(), "fillType", &[]).as_str().map(str::to_owned);
if (fillType.is_none()) {
request.insert("fillType".into(), Value::Str("User".into())); }
let __ws_arg_14 = self.extend(paramsOmitted, &[Value::Map(request)]);
let mut response: Value = self.private_get_wapi_v1_history_fills(&[__ws_arg_14]).await;
let mut responseList: Value = self.to_array(response);
return self.parse_trades(responseList, &[market, since, limit]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut id: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("id".into()), Value::Str("tradeId".into()), &[]);
let mut marketId: Option<String> = self.safe_string_k_opt(trade.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut price: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("fillPrice".into()), Value::Str("price".into()), &[]);
let mut amount: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("fillQuantity".into()), Value::Str("quantity".into()), &[]);
let mut isBuyerMaker: Option<bool> = self.safe_bool_k_opt(trade.clone(), "isBuyerMaker", &[]);
let mut side: Value = self.parse_order_side(self.safe_string_k(trade.clone(), "side", &[])).map(Value::from).unwrap_or(Value::Null);
let mut isMaker: Option<bool> = self.safe_bool_k_opt(trade.clone(), "isMaker", &[]);
let mut takerOrMaker: Value = Value::Null;
if (isMaker.is_some()) {
takerOrMaker = (if isMaker == Some(true) { Value::Str("maker".into()) } else { Value::Str("taker".into()) });
} else if (isBuyerMaker.is_some()) {
takerOrMaker = Value::Str("taker".into());
side = (if isBuyerMaker == Some(true) { Value::Str("sell".into()) } else { Value::Str("buy".into()) });
}
let mut orderId: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("orderId".into()), Value::Str("rfqId".into()), &[]);
let mut fee: Value = Value::Null;
let mut feeAmount: Option<String> = self.safe_string_k_opt(trade.clone(), "fee", &[]);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
if (feeAmount.is_some()) {
let mut datetime: Option<String> = self.safe_string_k_opt(trade.clone(), "timestamp", &[]);
timestamp = self.parse8601(datetime.map(Value::from).unwrap_or(Value::Null));
}
let mut filledAt: Option<String> = self.safe_string_k_opt(trade.clone(), "filledAt", &[]);
if (filledAt.is_some()) {
timestamp = self.parse8601(filledAt.map(Value::from).unwrap_or(Value::Null));
}
let mut feeSymbol: Value = self.safe_currency_code(self.safe_string_k(trade.clone(), "feeSymbol", &[]), &[]);
if (feeAmount.is_some()) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeAmount.map(Value::from).unwrap_or(Value::Null));
m.insert("currency".to_string(), feeSymbol);
m.insert("rate".to_string(), Value::Null);
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("order".to_string(), orderId.map(Value::from).unwrap_or(Value::Null));
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("price".to_string(), price.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amount.map(Value::from).unwrap_or(Value::Null));
m.insert("cost".to_string(), self.safe_string2(trade, Value::Str("fillQuoteQuantity".into()), Value::Str("quoteQuantity".into()), &[]));
m.insert("fee".to_string(), fee);
m
}), &[marketResolved]);
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_api_v1_status(&[params]).await;
let mut status: Option<String> = self.safe_string_k_opt(response.clone(), "status", &[]);
if (status.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" fetchStatus() missing status".into()))));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), (if let Some(__s) = status.as_deref() { Value::Str(__s.to_lowercase().into()) } else { 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_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_api_v1_time(&[params]).await;
return self.safe_integer(response, Value::Int(0), &[self.milliseconds()]);
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 selection: Value = self.handle_stock_params(Value::Str("fetchBalance".into()), params, &[]);
let mut stock: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut response: Value = self.private_get_api_v1_capital(&[query]).await;
if stock {
let mut securities: Value = self.safe_list_k(self.options.clone(), "securities", &[]);
if (securities == Value::Null) {
securities = self.fetch_securities(&[]).await;
}
let mut securityIds: Value = self.index_by(securities, Value::Str("asset".into()));
let mut balances: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut assetIds: Vec<Value> = Value::Array(response.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).as_array().cloned().unwrap_or_default();
{
let mut i: i64 = 0;
let mut __for_first_255: bool = true;
while { if !__for_first_255 { i += 1; } __for_first_255 = false; i < (assetIds.len() as i64) } {
let mut assetId: Value = assetIds.get(i as usize).cloned().unwrap_or(Value::Null);
if (matches!((&securityIds, &assetId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
balances.insert(crate::runtime::stringify_param(&assetId), (if let (Some(__m), Some(__k)) = (response.as_map(), assetId.as_str()) { __m.get(__k).cloned().unwrap_or(Value::Null) } else { Value::Null }));
}
}
}
return self.parse_balance(Value::Map(balances));
}
return self.parse_balance(response);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut balanceKeys: Vec<Value> = Value::Array(response.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).as_array().cloned().unwrap_or_default();
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_256: bool = true;
while { if !__for_first_256 { i += 1; } __for_first_256 = false; i < (balanceKeys.len() as i64) } {
let mut id: Value = balanceKeys.get(i as usize).cloned().unwrap_or(Value::Null);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut balance: Value = self.safe_dict(response.clone(), id, &[]);
let mut account: indexmap::IndexMap<String, Value> = self.account().as_map().cloned().unwrap_or_default();
let mut locked: Option<String> = self.safe_string_k_opt(balance.clone(), "locked", &[]);
let mut staked: Option<String> = self.safe_string_k_opt(balance.clone(), "staked", &[]);
let mut used: Value = crate::precise::Precise::stringAdd(&locked.clone().map(Value::from).unwrap_or(Value::Null), &staked.clone().map(Value::from).unwrap_or(Value::Null));
account.insert("free".into(), self.safe_string_k(balance, "available", &[]));
account.insert("used".into(), used);
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 fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
}
if (since != Value::Null) {
request.insert("from".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone()); }
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(params, Value::Str("fetchDeposits".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
request.insert("endTime".into(), until);
}
let __ws_arg_15 = self.extend(Value::Map(request), &[paramsUntil]);
let mut response: Value = self.private_get_wapi_v1_capital_deposits(&[__ws_arg_15]).await;
return self.parse_transactions(response, &[currency, since, limit]);
Value::Null
}
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
}
if (since != Value::Null) {
request.insert("from".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let untilparamsUntilVariable: Vec<Value> = self.handle_option_integer_and_params(params, Value::Str("fetchWithdrawals".into()), Value::Str("until".into()), &[]).as_array().cloned().unwrap_or_default();
let mut until: Value = untilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
request.insert("to".into(), until);
}
let __ws_arg_16 = self.extend(Value::Map(request), &[paramsUntil]);
let mut response: Value = self.private_get_wapi_v1_capital_withdrawals(&[__ws_arg_16]).await;
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);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.number_to_string(amount));
m.insert("address".to_string(), address);
m
});
if (tag != Value::Null) {
request.insert("clientId".into(), tag); }
let networkCodequeryVariable: Vec<Value> = self.handle_network_code_and_params(paramsWithdrawTag).as_array().cloned().unwrap_or_default();
let mut networkCode: Value = networkCodequeryVariable.get(0).cloned().unwrap_or(Value::Null);
let mut query: Value = networkCodequeryVariable.get(1).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.network_code_to_id(networkCode, &[self.safe_string_k(currency.clone(), "code", &[])]);
if (networkId == Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" withdraw() requires a network parameter".into()))));
}
request.insert("blockchain".into(), networkId);
let __ws_arg_17 = self.extend(Value::Map(request), &[query]);
let mut response: Value = self.private_post_wapi_v1_capital_withdrawals(&[__ws_arg_17]).await;
return self.parse_transaction(response, &[currency]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut status: Value = self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])).map(Value::from).unwrap_or(Value::Null);
let mut id: Option<String> = self.safe_string_k_opt(transaction.clone(), "id", &[]);
let mut txid: Option<String> = self.safe_string_k_opt(transaction.clone(), "transactionHash", &[]);
let mut coin: Option<String> = self.safe_string_k_opt(transaction.clone(), "symbol", &[]);
let mut code: Value = self.safe_currency_code(coin.map(Value::from).unwrap_or(Value::Null), &[currency]);
let mut timestamp: Value = self.parse8601(self.safe_string_k(transaction.clone(), "createdAt", &[]));
let mut amount: Value = self.safe_number_k(transaction.clone(), "quantity", &[]);
let mut networkId: Value = self.safe_string_lower2(transaction.clone(), Value::Str("source".into()), Value::Str("blockchain".into()), &[]);
let mut network: Value = self.network_id_to_code(&[networkId, code.clone()]);
let mut addressTo: Option<String> = self.safe_string_k_opt(transaction.clone(), "toAddress", &[]);
let mut addressFrom: Option<String> = self.safe_string_k_opt(transaction.clone(), "fromAddress", &[]);
let mut tag: Option<String> = self.safe_string_k_opt(transaction.clone(), "platformMemo", &[]);
let mut feeCost: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
let mut internal: bool = self.safe_bool_k_opt(transaction.clone(), "isInternal", &[Value::Bool(false)]).unwrap_or(false);
let mut fee: Value = Value::Null;
if (feeCost != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost);
m.insert("currency".to_string(), code.clone());
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction);
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("txid".to_string(), txid.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("network".to_string(), network);
m.insert("address".to_string(), Value::Null);
m.insert("addressTo".to_string(), addressTo.map(Value::from).unwrap_or(Value::Null));
m.insert("addressFrom".to_string(), addressFrom.map(Value::from).unwrap_or(Value::Null));
m.insert("tag".to_string(), tag.map(Value::from).unwrap_or(Value::Null));
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("amount".to_string(), amount);
m.insert("currency".to_string(), code);
m.insert("status".to_string(), status);
m.insert("updated".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Bool(internal));
m.insert("comment".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
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("cancelled".to_string(), Value::Str("cancelled".into()));
m.insert("confirmed".to_string(), Value::Str("ok".into()));
m.insert("declined".to_string(), Value::Str("declined".into()));
m.insert("expired".to_string(), Value::Str("expired".into()));
m.insert("initiated".to_string(), Value::Str("initiated".into()));
m.insert("pending".to_string(), Value::Str("pending".into()));
m.insert("refunded".to_string(), Value::Str("refunded".into()));
m.insert("information required".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 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 networkCodeparamsNetworkCodeVariable: Vec<Value> = self.handle_network_code_and_params(params).as_array().cloned().unwrap_or_default();
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.get(1).cloned().unwrap_or(Value::Null);
if (networkCode == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddress() requires a network parameter, see https://docs.ccxt.com/?id=network-codes".into()))));
}
let mut currency: Value = self.currency(code);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("blockchain".to_string(), self.network_code_to_id(networkCode, &[self.safe_string_k(currency.clone(), "code", &[])]));
m
});
let __ws_arg_18 = self.extend(Value::Map(request), &[paramsNetworkCode]);
let mut response: Value = self.private_get_wapi_v1_capital_deposit_address(&[__ws_arg_18]).await;
return self.parse_deposit_address(response, &[currency]);
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut address: Option<String> = self.safe_string_k_opt(depositAddress.clone(), "address", &[]);
let mut currencyId: Option<String> = self.safe_string_k_opt(depositAddress.clone(), "currency", &[]);
let mut currencyResolved: indexmap::IndexMap<String, Value> = self.safe_currency(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]).as_map().cloned().unwrap_or_default();
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress);
m.insert("currency".to_string(), currencyResolved.get("code").cloned().unwrap_or(Value::Null));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.map(Value::from).unwrap_or(Value::Null));
m.insert("tag".to_string(), Value::Null);
m
});
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 selection: Value = self.handle_stock_params(Value::Str("createOrder".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection.clone(), Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let __ws_arg_19 = self.safe_bool(selection, Value::Int(0), &[Value::Bool(false)]);
let mut orderParams: Value = self.extend(query, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), __ws_arg_19);
m
})]);
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
let mut rfqResponse: Value = self.create_rfq_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]).await;
let mut rfqOrder: Value = self.safe_dict(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order".to_string(), rfqResponse);
m
}), Value::Str("order".into()), &[]);
return rfqOrder;
}
let mut orderRequest: Value = self.create_order_request(symbol, type_var, side, amount, &[price, orderParams]);
let mut response: Value = self.private_post_api_v1_order(&[orderRequest]).await;
return self.parse_order(response, &[market]);
Value::Null
}
pub async fn create_rfq_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut selection: Value = self.handle_stock_params(Value::Str("createRfqOrder".into()), params.clone(), &[market.clone()]);
let mut paramsResolved: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() != Some("RFQ")) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" createRfqOrder() requires an RFQ market".into()))));
}
if (type_var.as_str() != Some("market")) && (type_var.as_str() != Some("limit")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() RFQs support market or limit orders only".into()))));
}
if (side.as_str() != Some("buy")) && (side.as_str() != Some("sell")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires buy or sell".into()))));
}
if (amount == Value::Null) || !(crate::precise::Precise::stringGt(&self.number_to_string(amount.clone()), &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() RFQs require a positive base quantity".into()))));
}
let mut unsupported: Value = Value::from(vec![Value::Str("cost".into()), Value::Str("quoteQuantity".into()), Value::Str("postOnly".into()), Value::Str("triggerPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("takeProfitPrice".into()), Value::Str("stopLoss".into()), Value::Str("takeProfit".into()), Value::Str("reduceOnly".into()),
Value::Str("timeInForce".into()), Value::Str("selfTradePrevention".into())]);
{
let mut i: i64 = 0;
let mut __for_first_257: bool = true;
while { if !__for_first_257 { i += 1; } __for_first_257 = false; i < (unsupported.len() as i64) } {
let mut key: Value = unsupported.as_array().map(Vec::as_slice).unwrap_or_default().get(i as usize).cloned().unwrap_or(Value::Null);
if (matches!((¶msResolved, &key), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrder() RFQs do not support ".into())).into()), key)));
}
}
}
let mut executionMode: Value = self.safe_string_k(paramsResolved.clone(), "executionMode", &[Value::Str("Immediate".into())]);
if (executionMode.as_str() != Some("Immediate")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires Immediate RFQs to enforce the price bound; AwaitAccept has no engine-enforced limit price".into()))));
}
let mut quantity: Value = self.number_to_string(amount.clone());
let mut precision: Value = self.safe_dict_k(market.clone(), "precision", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_number_k(precision, "amount", &[]) != Value::Null) {
let mut preciseQuantity: Value = self.amount_to_precision(symbol.clone(), amount.clone());
if !(crate::precise::Precise::stringEq(&quantity, &preciseQuantity).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() RFQ quantity must match the share increment without rounding".into()))));
}
}
let mut limitPrice: Value = self.number_to_string(price);
if (type_var.as_str() == Some("limit")) {
if (limitPrice == Value::Null) || !(crate::precise::Precise::stringGt(&limitPrice, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() limit RFQs require a positive price".into()))));
}
}
if (market.as_map().and_then(|__m| __m.get("stock")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let mut indicative: Value = self.fetch_stock_indicative_quote(symbol, side.clone(), amount, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), Value::Bool(false));
m
})]).await;
let mut indicativePrice: Option<String> = self.safe_string_k_opt(indicative.clone(), "price", &[]);
if !matches!(self.safe_bool_k(indicative.clone(), "available", &[Value::Bool(false)]), Value::Bool(true)) || (indicativePrice.is_none()) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrder() stock indicative quote unavailable: ".into())).into()), self.safe_string_k(indicative.clone(), "reason", &[Value::Str("priceUnavailable".into())]))));
}
if (type_var.as_str() == Some("market")) && (limitPrice == Value::Null) {
limitPrice = indicativePrice.map(Value::from).unwrap_or(Value::Null);
}
let mut quantityFilter: Value = self.safe_dict_k(indicative, "quantityFilter", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut stepSize: Value = self.safe_string_k(quantityFilter.clone(), "stepSize", &[]);
let mut minimum: Option<String> = self.safe_string_k_opt(quantityFilter.clone(), "minQuantity", &[]);
let mut maximum: Value = self.safe_string_k(quantityFilter, "maxQuantity", &[]);
if (minimum.is_none()) || (stepSize == Value::Null) || !(crate::precise::Precise::stringGt(&stepSize, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() stock indicative quote is missing valid session quantity constraints".into()))));
}
if ((minimum.is_some()) && crate::precise::Precise::stringLt(&quantity, &minimum.clone().map(Value::from).unwrap_or(Value::Null)).as_bool() == Some(true)) || ((maximum != Value::Null) && crate::precise::Precise::stringGt(&quantity,
&maximum).as_bool() == Some(true)) || ((stepSize != Value::Null) && !(crate::precise::Precise::stringEq(&crate::precise::Precise::stringMod(&quantity, &stepSize), &Value::Str("0".into())).as_bool() == Some(true))) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() quantity does not match the current stock session constraints".into()))));
}
} else if (limitPrice == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() crypto market RFQs require an explicit price bound".into()))));
}
if (limitPrice != Value::Null) && !(crate::precise::Precise::stringGt(&limitPrice, &Value::Str("0".into())).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() RFQ price must be positive".into()))));
}
if (self.safe_integer_k(params.clone(), "orderExpiryTime", &[]) != Value::Null) && (executionMode.as_str() != Some("Immediate")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() resting RFQs require Immediate execution".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("side".to_string(), self.encode_order_side(side).map(Value::from).unwrap_or(Value::Null));
m.insert("quantity".to_string(), quantity);
m.insert("price".to_string(), limitPrice);
m.insert("executionMode".to_string(), executionMode);
m
});
let mut clientOrderId: Value = self.safe_integer_k(params, "clientOrderId", &[]);
if (clientOrderId != Value::Null) {
request.insert("clientId".into(), clientOrderId);
}
let mut query: Value = self.omit(paramsResolved, Value::Str("clientOrderId".into()), &[]);
let __ws_arg_20 = self.extend(query, &[Value::Map(request)]);
let mut response: Value = self.private_post_api_v1_rfq(&[__ws_arg_20]).await;
let mut order: Value = self.parse_order(response, &[market]);
if let Value::Dict(__rda) = &mut order { std::sync::Arc::make_mut(__rda).insert("type".to_string(), type_var); }
return order;
Value::Null
}
pub async fn accept_rfq_quote(&mut self, mut id: Value, mut quoteId: Value, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol);
let mut selection: Value = self.handle_stock_params(Value::Str("acceptRfqQuote".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() != Some("RFQ")) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" acceptRfqQuote() requires an RFQ market".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("rfqId".to_string(), id);
m.insert("quoteId".to_string(), quoteId);
m
});
let __ws_arg_21 = self.extend(query, &[Value::Map(request)]);
let mut response: Value = self.private_post_api_v1_rfq_accept(&[__ws_arg_21]).await;
return self.parse_order(response, &[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
}));
let mut selection: Value = self.handle_stock_params(Value::Str("createOrders".into()), params.clone(), &[]);
let mut query: Value = self.safe_dict(selection.clone(), Value::Int(1), &[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 stock: bool = self.safe_bool_opt(selection, Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
{
let mut i: i64 = 0;
let mut __for_first_258: bool = true;
while { if !__for_first_258 { i += 1; } __for_first_258 = false; i < (orders.len() as i64) } {
let mut rawOrder: Value = self.safe_dict(orders.clone(), Value::Int(i), &[]);
let mut marketId: 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 baseParams: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if stock || !matches!(self.safe_bool2(params.clone(), Value::Str("stock".into()), Value::Str("defaultStock".into()), &[Value::Bool(true)]), Value::Bool(true)) {
baseParams.insert("stock".into(), Value::Bool(stock));
}
let mut baseQuery: Value = self.extend(Value::Map(baseParams), &[query.clone()]);
let mut extendedParams: Value = self.extend(baseQuery, &[orderParams]);
let mut orderRequest: Value = self.create_order_request(marketId.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, extendedParams]);
ordersRequests.push(orderRequest);
}
}
let mut response: Value = self.private_post_api_v1_orders(&[Value::from(ordersRequests)]).await;
return self.parse_orders(response, &[]);
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 selection: Value = self.handle_stock_params(Value::Str("createOrder".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrders() does not support RFQ batches; use createOrder()".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("side".to_string(), self.encode_order_side(side).map(Value::from).unwrap_or(Value::Null));
m.insert("orderType".to_string(), self.capitalize(type_var.clone()));
m
});
let mut triggerPrice: Option<String> = self.safe_string_k_opt(query.clone(), "triggerPrice", &[]);
let mut isTriggerOrder: bool = triggerPrice.is_some();
let mut quantityKey: String = "quantity".to_string();
if isTriggerOrder {
quantityKey = "triggerQuantity".to_string();
}
let mut omitKeys: Vec<Value> = Vec::new();
if (type_var.as_str() == Some("limit")) {
request.insert("price".into(), self.price_to_precision(symbol.clone(), price));
request.insert(quantityKey.clone(), self.amount_to_precision(symbol.clone(), amount.clone()));
} else if (type_var.as_str() == Some("market")) {
let mut cost: Option<String> = self.safe_string2_opt(query.clone(), Value::Str("cost".into()), Value::Str("quoteQuantity".into()), &[]);
if (cost.is_some()) {
request.insert("quoteQuantity".into(), self.cost_to_precision(symbol.clone(), cost.map(Value::from).unwrap_or(Value::Null)));
omitKeys.push(Value::Str("cost".into()));
omitKeys.push(Value::Str("quoteQuantity".into()));
} else {
request.insert(quantityKey.clone(), self.amount_to_precision(symbol.clone(), amount));
}
}
if isTriggerOrder {
request.insert("triggerPrice".into(), self.price_to_precision(symbol.clone(), triggerPrice.map(Value::from).unwrap_or(Value::Null)));
omitKeys.push(Value::Str("triggerPrice".into()));
}
let mut clientOrderId: Value = self.safe_integer_k(query.clone(), "clientOrderId", &[]);
if (clientOrderId != Value::Null) {
request.insert("clientId".into(), clientOrderId);
omitKeys.push(Value::Str("clientOrderId".into()));
}
let postOnlyparamsPostOnlyVariable: Vec<Value> = self.handle_post_only(Value::Bool(type_var.as_str() == Some("market")), Value::Bool(false), &[self.omit(query, Value::from(omitKeys), &[])]).as_array().cloned().unwrap_or_default();
let mut postOnly: Value = postOnlyparamsPostOnlyVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = postOnlyparamsPostOnlyVariable.get(1).cloned().unwrap_or(Value::Null);
if postOnly.as_bool() == Some(true) {
add_element_to_object(&mut paramsPostOnly, &Value::Str("postOnly".into()), Value::Bool(true));
}
let mut bracketKeys: Vec<Value> = Vec::new();
let mut takeProfit: Value = self.safe_dict_k(paramsPostOnly.clone(), "takeProfit", &[]);
if (takeProfit != Value::Null) {
let mut takeProfitTriggerPrice: Option<String> = self.safe_string_k_opt(takeProfit.clone(), "triggerPrice", &[]);
if (takeProfitTriggerPrice.is_some()) {
request.insert("takeProfitTriggerPrice".into(), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.map(Value::from).unwrap_or(Value::Null)));
}
let mut takeProfitPrice: Option<String> = self.safe_string_k_opt(takeProfit, "price", &[]);
if (takeProfitPrice.is_some()) {
request.insert("takeProfitLimitPrice".into(), self.price_to_precision(symbol.clone(), takeProfitPrice.map(Value::from).unwrap_or(Value::Null)));
}
bracketKeys.push(Value::Str("takeProfit".into()));
}
let mut stopLoss: Value = self.safe_dict_k(paramsPostOnly.clone(), "stopLoss", &[]);
if (stopLoss != Value::Null) {
let mut stopLossTriggerPrice: Option<String> = self.safe_string_k_opt(stopLoss.clone(), "triggerPrice", &[]);
if (stopLossTriggerPrice.is_some()) {
request.insert("stopLossTriggerPrice".into(), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.map(Value::from).unwrap_or(Value::Null)));
}
let mut stopLossPrice: Option<String> = self.safe_string_k_opt(stopLoss, "price", &[]);
if (stopLossPrice.is_some()) {
request.insert("stopLossLimitPrice".into(), self.price_to_precision(symbol, stopLossPrice.map(Value::from).unwrap_or(Value::Null)));
}
bracketKeys.push(Value::Str("stopLoss".into()));
}
let selfTradePreventionparamsSelfTradePreventionVariable: Vec<Value> = self.handle_option_string_and_params(self.omit(paramsPostOnly, Value::from(bracketKeys), &[]), Value::Str("createOrder".into()), Value::Str("selfTradePrevention".into()), &[]).as_array().cloned().unwrap_or_default();
let mut selfTradePrevention: Value = selfTradePreventionparamsSelfTradePreventionVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsSelfTradePrevention: Value = selfTradePreventionparamsSelfTradePreventionVariable.get(1).cloned().unwrap_or(Value::Null);
if (selfTradePrevention != Value::Null) {
if (selfTradePrevention.as_str() == Some("EXPIRE_MAKER")) {
request.insert("selfTradePrevention".into(), Value::Str("RejectMaker".into()));
} else if (selfTradePrevention.as_str() == Some("EXPIRE_TAKER")) {
request.insert("selfTradePrevention".into(), Value::Str("RejectTaker".into()));
} else if (selfTradePrevention.as_str() == Some("EXPIRE_BOTH")) {
request.insert("selfTradePrevention".into(), Value::Str("RejectBoth".into()));
}
}
return self.extend(Value::Map(request), &[paramsSelfTradePrevention]);
Value::Null
}
pub fn encode_order_side(&self, mut side: Value) -> Option<String> {
let mut sides: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("buy".to_string(), Value::Str("Bid".into()));
m.insert("sell".to_string(), Value::Str("Ask".into()));
m
});
return self.safe_string(Value::Map(sides), side.clone(), &[side.clone()]).as_str().map(str::to_owned);
}
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;
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[]));
}
let mut selection: Value = self.handle_stock_params(Value::Str("fetchOpenOrders".into()), params, &[market.clone()]);
let mut stock: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rfq: bool = self.safe_bool_k(query.clone(), "rfq", &[Value::Bool(false)]).as_bool() == Some(true) || (self.safe_string(self.safe_dict_k(market.clone(), "info", &[]), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ"));
if rfq && (market != Value::Null) && (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() != Some("RFQ")) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenOrders() rfq requires an RFQ market symbol".into()))));
}
let mut accountParams: Value = self.omit(query, Value::Str("rfq".into()), &[]);
let mut response: Value = Value::from(vec![]);
if !rfq {
let mut venueParams: Value = self.omit(accountParams.clone(), Value::from(vec![Value::Str("rfqId".into()), Value::Str("deferredSettlement".into())]), &[]);
let __ws_arg_22 = self.extend(Value::Map(request.clone()), &[venueParams]);
response = self.private_get_api_v1_orders(&[__ws_arg_22]).await;
}
if rfq || (stock && (market == Value::Null)) {
let __ws_arg_23 = self.extend(Value::Map(request), &[self.omit(accountParams, Value::Str("marketType".into()), &[])]);
let mut rfqResponse: Value = self.private_get_api_v1_rfqs(&[__ws_arg_23]).await;
response = self.array_concat(response.clone(), rfqResponse);
}
let mut orders: Value = self.parse_orders(response, &[market, since.clone()]);
if stock {
orders = self.filter_stock_structures(orders.clone());
}
return self.filter_by_since_limit(self.sort_by(orders, Value::Str("timestamp".into()), &[]), &[since, limit]);
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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenOrder() requires a symbol argument".into()))));
}
let mut market: Value = self.market(symbol);
let mut selection: Value = self.handle_stock_params(Value::Str("fetchOpenOrder".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
let __ws_arg_24 = self.extend(query.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("rfqId".to_string(), id.clone());
m
})]);
let mut rfqResponse: Value = self.private_get_api_v1_rfqs(&[__ws_arg_24]).await;
{
let mut i: i64 = 0;
let mut __for_first_259: bool = true;
while { if !__for_first_259 { i += 1; } __for_first_259 = false; i < (rfqResponse.len() as i64) } {
let mut order: Value = self.parse_order(self.safe_dict(rfqResponse.clone(), Value::Int(i), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), &[market.clone()]);
if (order.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null).as_str() == id.as_str()) {
return order;
}
}
}
panic!("{}", crate::exchange_errors::order_not_found(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenOrder() RFQ ".into())).into()), id).into()), Value::Str(" not found".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("orderId".to_string(), id);
m
});
let __ws_arg_25 = self.extend(Value::Map(request), &[query]);
let mut response: Value = self.private_get_api_v1_order(&[__ws_arg_25]).await;
return self.parse_order(response, &[market]);
Value::Null
}
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() requires a symbol argument".into()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut selection: Value = self.handle_stock_params(Value::Str("fetchOrder".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection.clone(), Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rfq: bool = self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ");
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 rfq {
request.insert("rfqId".into(), id.clone());
} else {
request.insert("orderId".into(), id.clone());
}
let mut response: Value = Value::from(vec![]);
if rfq {
let __ws_arg_26 = self.extend(query.clone(), &[Value::Map(request.clone())]);
response = self.private_get_wapi_v1_history_rfq(&[__ws_arg_26]).await;
} else {
let __ws_arg_27 = self.extend(query.clone(), &[Value::Map(request)]);
response = self.private_get_wapi_v1_history_orders(&[__ws_arg_27]).await;
}
{
let mut i: i64 = 0;
let mut __for_first_260: bool = true;
while { if !__for_first_260 { i += 1; } __for_first_260 = false; i < (response.len() as i64) } {
let mut order: Value = self.parse_order(self.safe_dict(response.clone(), Value::Int(i), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), &[market.clone()]);
if (order.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null).as_str() == id.as_str()) {
return order;
}
}
}
let __ws_arg_28 = self.safe_bool(selection, Value::Int(0), &[Value::Bool(false)]);
let mut openOrderParams: Value = self.extend(query, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stock".to_string(), __ws_arg_28);
m
})]);
return self.fetch_open_order(id, &[symbol, openOrderParams]).await;
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;
}
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() requires a symbol argument".into()))));
}
let mut market: Value = self.market(symbol);
let mut selection: Value = self.handle_stock_params(Value::Str("cancelOrder".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
let mut clientOrderId: Value = self.safe_integer_k(query.clone(), "clientOrderId", &[]);
let mut rfqRequest: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (clientOrderId == Value::Null) {
rfqRequest.insert("rfqId".into(), id.clone());
} else {
rfqRequest.insert("clientId".into(), clientOrderId);
}
let __ws_arg_29 = self.extend(self.omit(query.clone(), Value::Str("clientOrderId".into()), &[]), &[Value::Map(rfqRequest)]);
let mut rfqResponse: Value = self.private_post_api_v1_rfq_cancel(&[__ws_arg_29]).await;
return self.parse_order(rfqResponse, &[market.clone()]);
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id);
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_30 = self.extend(Value::Map(request), &[query]);
let mut response: Value = self.private_delete_api_v1_order(&[__ws_arg_30]).await;
return self.parse_order(response, &[market]);
Value::Null
}
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() requires a symbol argument".into()))));
}
let mut market: Value = self.market(symbol);
let mut selection: Value = self.handle_stock_params(Value::Str("cancelAllOrders".into()), params, &[market.clone()]);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() does not support RFQs; cancel each RFQ explicitly with cancelOrder()".into()))));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_31 = self.extend(Value::Map(request), &[query]);
let mut response: Value = self.private_delete_api_v1_orders(&[__ws_arg_31]).await;
return self.parse_orders(response, &[market]);
Value::Null
}
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::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;
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[]));
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let mut selection: Value = self.handle_stock_params(Value::Str("fetchOrders".into()), params, &[market.clone()]);
let mut stock: bool = self.safe_bool_opt(selection.clone(), Value::Int(0), &[Value::Bool(false)]).unwrap_or(false);
let mut query: Value = self.safe_dict(selection, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rfq: bool = self.safe_bool_k(query.clone(), "rfq", &[Value::Bool(false)]).as_bool() == Some(true) || (self.safe_string(self.safe_dict_k(market.clone(), "info", &[]), Value::Str("marketType".into()), &[]).as_str() == Some("RFQ"));
if rfq && (market != Value::Null) && (self.safe_string(market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), Value::Str("marketType".into()), &[]).as_str() != Some("RFQ")) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() rfq requires an RFQ market symbol".into()))));
}
let mut accountParams: Value = self.omit(query, Value::Str("rfq".into()), &[]);
let mut response: Value = Value::from(vec![]);
if !rfq {
let mut venueParams: Value = self.omit(accountParams.clone(), Value::from(vec![Value::Str("rfqId".into()), Value::Str("status".into()), Value::Str("side".into()), Value::Str("deferredSettlement".into())]), &[]);
let __ws_arg_32 = self.extend(Value::Map(request.clone()), &[venueParams]);
response = self.private_get_wapi_v1_history_orders(&[__ws_arg_32]).await;
}
if rfq || (stock && (market == Value::Null)) {
let __ws_arg_33 = self.extend(Value::Map(request), &[self.omit(accountParams, Value::Str("marketType".into()), &[])]);
let mut rfqResponse: Value = self.private_get_wapi_v1_history_rfq(&[__ws_arg_33]).await;
response = self.array_concat(response.clone(), rfqResponse);
}
let mut orders: Value = self.parse_orders(response, &[market, since.clone()]);
if stock {
orders = self.filter_stock_structures(orders.clone());
}
return self.filter_by_since_limit(self.sort_by(orders, Value::Str("timestamp".into()), &[]), &[since, limit]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut rfq: Value = self.safe_dict_k(order.clone(), "rfq", &[]);
if (rfq != Value::Null) {
let mut parsed: Value = self.parse_order(rfq, &[market.clone()]);
if let Value::Dict(__rda) = &mut parsed { std::sync::Arc::make_mut(__rda).insert("info".to_string(), order.clone()); }
return parsed;
}
let mut timestamp: Value = self.safe_integer_k(order.clone(), "createdAt", &[]);
let mut timestamp2: Value = self.parse8601(self.safe_string_k(order.clone(), "createdAt", &[]));
if (timestamp2 != Value::Null) {
timestamp = timestamp2;
}
let mut id: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("id".into()), Value::Str("rfqId".into()), &[]);
let mut clientOrderId: Option<String> = self.safe_string_k_opt(order.clone(), "clientId", &[]);
let mut marketId: Option<String> = self.safe_string_k_opt(order.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone().map(Value::from).unwrap_or(Value::Null), market]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[marketResolved.clone()]);
let mut type_var: Value = self.safe_string_lower_k(order.clone(), "orderType", &[]);
if (type_var == Value::Null) && (self.safe_string_k(order.clone(), "rfqId", &[]) != Value::Null) && (self.safe_string_k(order.clone(), "price", &[]) != Value::Null) {
type_var = Value::Str("limit".into());
}
let mut timeInForce: Option<String> = self.safe_string_k_opt(order.clone(), "timeInForce", &[]);
let mut side: Value = self.parse_order_side(self.safe_string_k(order.clone(), "side", &[])).map(Value::from).unwrap_or(Value::Null);
let mut amount: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("quantity".into()), Value::Str("triggerQuantity".into()), &[]);
let mut price: Option<String> = self.safe_string_k_opt(order.clone(), "price", &[]);
let mut cost: Option<String> = self.safe_string_k_opt(order.clone(), "executedQuoteQuantity", &[]);
let mut status: Value = self.parse_order_status(self.safe_string_k(order.clone(), "status", &[])).map(Value::from).unwrap_or(Value::Null);
let mut triggerPrice: Option<String> = self.safe_string_k_opt(order.clone(), "triggerPrice", &[]);
let mut filled: Option<String> = self.safe_string_k_opt(order.clone(), "executedQuantity", &[]);
let mut reduceOnly: Option<bool> = self.safe_bool_k_opt(order.clone(), "reduceOnly", &[]);
let mut postOnly: Option<bool> = self.safe_bool_k_opt(order.clone(), "postOnly", &[]);
let mut stopLossPrice: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("stopLossLimitPrice".into()), Value::Str("stopLossTriggerPrice".into()), &[]);
let mut takeProfitPrice: Option<String> = self.safe_string2_opt(order.clone(), Value::Str("takeProfitLimitPrice".into()), Value::Str("takeProfitTriggerPrice".into()), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order);
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("clientOrderId".to_string(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), type_var);
m.insert("timeInForce".to_string(), timeInForce.map(Value::from).unwrap_or(Value::Null));
m.insert("postOnly".to_string(), postOnly.map(Value::Bool).unwrap_or(Value::Null));
m.insert("reduceOnly".to_string(), reduceOnly.map(Value::Bool).unwrap_or(Value::Null));
m.insert("side".to_string(), side);
m.insert("price".to_string(), price.map(Value::from).unwrap_or(Value::Null));
m.insert("triggerPrice".to_string(), triggerPrice.map(Value::from).unwrap_or(Value::Null));
m.insert("stopLossPrice".to_string(), stopLossPrice.map(Value::from).unwrap_or(Value::Null));
m.insert("takeProfitPrice".to_string(), takeProfitPrice.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amount.map(Value::from).unwrap_or(Value::Null));
m.insert("cost".to_string(), cost.map(Value::from).unwrap_or(Value::Null));
m.insert("average".to_string(), Value::Null);
m.insert("filled".to_string(), filled.map(Value::from).unwrap_or(Value::Null));
m.insert("remaining".to_string(), Value::Null);
m.insert("status".to_string(), status);
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("New".to_string(), Value::Str("open".into()));
m.insert("Filled".to_string(), Value::Str("closed".into()));
m.insert("Cancelled".to_string(), Value::Str("canceled".into()));
m.insert("Expired".to_string(), Value::Str("canceled".into()));
m.insert("PartiallyFilled".to_string(), Value::Str("open".into()));
m.insert("TriggerPending".to_string(), Value::Str("open".into()));
m.insert("TriggerFailed".to_string(), Value::Str("rejected".into()));
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_order_side(&self, mut side: Value) -> Option<String> {
let mut sides: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("Bid".to_string(), Value::Str("buy".into()));
m.insert("Ask".to_string(), Value::Str("sell".into()));
m
});
return self.safe_string(Value::Map(sides), side.clone(), &[side.clone()]).as_str().map(str::to_owned);
}
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 response: Value = self.private_get_api_v1_position(&[params]).await;
if self.is_empty(symbols.clone()).as_bool() == Some(true) {
return self.parse_positions(response.clone(), &[]);
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
return self.parse_positions(response, &[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 mut id: Option<String> = self.safe_string_k_opt(position.clone(), "positionId", &[]);
let mut marketId: Option<String> = self.safe_string_k_opt(position.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut symbol: Value = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut entryPrice: Value = self.safe_number_k(position.clone(), "entryPrice", &[]);
let mut markPrice: Value = self.safe_number_k(position.clone(), "markPrice", &[]);
let mut netCost: Option<String> = self.safe_string_k_opt(position.clone(), "netCost", &[]);
let mut hedged: Value = Value::Bool(false);
let mut side: Value = Value::Str("long".into());
if crate::precise::Precise::stringLt(&netCost.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) {
side = Value::Str("short".into());
}
if (netCost.is_none()) {
hedged = Value::Null;
side = Value::Null;
}
let mut unrealizedPnl: Value = self.safe_number_k(position.clone(), "pnlUnrealized", &[]);
let mut realizedPnl: Value = self.safe_number_k(position.clone(), "pnlRealized", &[]);
let mut liquidationPrice: Value = self.safe_number_k(position.clone(), "estLiquidationPrice", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), self.parse8601(self.safe_string_k(position.clone(), "timestamp", &[])));
m.insert("datetime".to_string(), self.iso8601(self.parse8601(self.safe_string_k(position.clone(), "timestamp", &[]))));
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("hedged".to_string(), hedged);
m.insert("side".to_string(), side);
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "netExposureQuantity", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("entryPrice".to_string(), entryPrice);
m.insert("markPrice".to_string(), markPrice);
m.insert("lastPrice".to_string(), Value::Null);
m.insert("notional".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&netCost.clone().map(Value::from).unwrap_or(Value::Null)), &[]));
m.insert("leverage".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), self.safe_number_k(position.clone(), "imf", &[]));
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), self.safe_number_k(position, "mmf", &[]));
m.insert("realizedPnl".to_string(), realizedPnl);
m.insert("unrealizedPnl".to_string(), unrealizedPnl);
m.insert("liquidationPrice".to_string(), liquidationPrice);
m.insert("marginMode".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
pub async fn fetch_funding_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 (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;
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[]));
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let __ws_arg_34 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_get_wapi_v1_history_funding(&[__ws_arg_34]).await;
return self.parse_incomes(response, &[market, since, limit]);
Value::Null
}
pub fn parse_income(&self, mut income: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(income.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market]);
let mut amount: Value = self.safe_number_k(income.clone(), "quantity", &[]);
let mut id: Option<String> = self.safe_string_k_opt(income.clone(), "userId", &[]);
let mut timestamp: Value = self.parse8601(self.safe_string_k(income.clone(), "intervalEndTimestamp", &[]));
let mut rate: Value = self.safe_number_k(income.clone(), "fundingRate", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), income);
m.insert("symbol".to_string(), symbol);
m.insert("code".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amount);
m.insert("rate".to_string(), rate);
m
});
Value::Null
}
pub fn nonce(&self) -> Value {
let mut timeDifference: Value = self.safe_integer_k(self.options.clone(), "timeDifference", &[]);
if (timeDifference == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" nonce() requires a numeric options[\"timeDifference\"]".into()))));
}
return (match (&(self.milliseconds()), &(timeDifference)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![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 endpoint: Value = Value::Str(format!("{}{}", Value::Str("/".into()), path).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 requestParams: Value = (if (matches!(¶ms, Value::Arr(_))) { params.clone() } else { self.omit(params.clone(), Value::from(vec![Value::Str("stock".into()), Value::Str("defaultStock".into()), Value::Str("rfq".into()), Value::Str("callerMethodName".into())]), &[]) });
let mut sortedParams: Value = (if (matches!(&requestParams, Value::Arr(_))) { requestParams.clone() } else { self.keysort(requestParams.clone(), &[]) });
let mut headersSigned: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut bodySigned: Value = Value::Null;
if (apiName.as_str() == Some("private")) {
self.check_required_credentials(&[]);
let mut ts: Value = self.number_to_string(self.nonce());
let mut recvWindow: Value = self.safe_string2(self.options.clone(), Value::Str("recvWindow".into()), Value::Str("X-Window".into()), &[Value::Str("5000".into())]);
let mut optionInstructions: Value = self.safe_dict_k(self.options.clone(), "instructions", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut optionPathInstructions: Value = self.safe_dict(optionInstructions, path.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut instruction: Value = self.safe_string(optionPathInstructions, method.clone(), &[Value::Str("".into())]);
let mut payload: Value = Value::Str("".into());
if (path.as_str() == Some("api/v1/orders")) && (method.as_str() == Some("POST")) {
payload = self.generate_batch_payload(sortedParams.clone(), ts.clone(), recvWindow.clone(), instruction.clone()).map(Value::from).unwrap_or(Value::Null);
} else {
let mut queryString: Value = self.urlencode(sortedParams.clone(), &[]);
if ((queryString.len() as i64) as f64) > ((0i64) as f64) {
queryString = Value::Str(format!("{}{}", queryString, Value::Str("&".into())).into());
}
payload = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("instruction=".into()), instruction).into()), Value::Str("&".into())).into()), queryString).into()),
Value::Str("timestamp=".into())).into()), ts).into()), Value::Str("&window=".into())).into()), recvWindow).into());
}
let mut secretBytes: Value = self.base64_to_binary(self.secret.clone(), &[]);
let mut seed: Value = self.array_slice(secretBytes, Value::Int(0), &[Value::Int(32)]);
let mut signature: Value = eddsa(self.encode(payload), seed, Value::Str("ed25519".into()));
headersSigned = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-Timestamp".to_string(), ts);
m.insert("X-Window".to_string(), recvWindow);
m.insert("X-API-Key".to_string(), self.apiKey.clone());
m.insert("X-Signature".to_string(), signature);
m.insert("X-Broker-Id".to_string(), Value::Str("1400".into()));
m
});
if (method.as_str() != Some("GET")) {
bodySigned = json_stringify(&sortedParams);
if let Value::Dict(__d) = &mut headersSigned { std::sync::Arc::make_mut(__d).insert("Content-Type".into(), Value::Str("application/json".into())); }
}
}
if (method.as_str() == Some("GET")) {
let mut query: Value = self.urlencode_with_array_repeat(sortedParams);
if (Value::Int(query.len() as i64).as_f64() != Some(0.0)) {
endpoint = Value::Str(format!("{}{}", endpoint, Value::Str(format!("{}{}", Value::Str("?".into()), query).into())).into());
}
}
let mut url: Value = Value::Str(format!("{}{}", apiUrl.map(Value::from).unwrap_or(Value::Null), endpoint).into());
let mut headersResolved: Value = (if (apiName.as_str() == Some("private")) { headersSigned } else { Value::Null });
let mut bodyResolved: Value = Value::Null;
if (apiName.as_str() == Some("private")) && (method.as_str() != Some("GET")) {
bodyResolved = bodySigned;
}
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 generate_batch_payload(&self, mut params: Value, mut ts: Value, mut recvWindow: Value, mut instruction: Value) -> Option<String> {
let mut payload: Value = Value::Str("".into());
let mut paramsLength: Value = get_array_length(¶ms);
{
let mut i: Value = Value::Int(0);
let mut __for_first_261: bool = true;
while { if !__for_first_261 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_261 = false; i.as_f64().unwrap_or(f64::NAN) < paramsLength.as_f64().unwrap_or(f64::NAN) } {
let mut order: Value = self.safe_dict(params.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut sortedOrder: Value = self.keysort(order, &[]);
let mut orderQuery: Value = self.urlencode(sortedOrder, &[]);
payload = Value::Str(format!("{}{}", payload, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("instruction=".into()), instruction).into()), Value::Str("&".into())).into()), orderQuery).into()), Value::Str("&".into())).into())).into());
if (i.as_f64() == ((match (&(paramsLength), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null })).as_f64()) {
payload = Value::Str(format!("{}{}", payload, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("timestamp=".into()), ts).into()), Value::Str("&window=".into())).into()), recvWindow).into())).into());
}
}
}
return payload.as_str().map(str::to_owned);
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
let mut errorCode: Option<String> = self.safe_string_k_opt(response.clone(), "code", &[]);
let mut message: Option<String> = self.safe_string_k_opt(response, "message", &[]);
if (errorCode.is_some()) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode.map(Value::from).unwrap_or(Value::Null), feedback.clone());
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(feedback));
}
return Value::Null;
Value::Null
}
}